1#!/usr/bin/env python
2
3# Copyright 2020 Google Inc.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17################################################################################
18"""Script to find fuzzers in a Pigweed build."""
19
20import argparse
21import json
22import os
23import shutil
24import sys
25
26
27def main():
28  """ Use pw_module_tests.testinfo.json files to find and copy fuzzers. """
29  parser = argparse.ArgumentParser()
30  parser.add_argument('--buildroot')
31  parser.add_argument('--out')
32  args = parser.parse_args()
33  print('  buildroot: ' + args.buildroot)
34  print('        out: ' + args.out)
35
36  testinfo = os.path.join(args.buildroot, 'host_clang_fuzz',
37                          'obj',
38                          'pw_module_tests.testinfo.json')
39  tests = []
40  with open(testinfo) as json_file:
41    tests = json.load(json_file)
42  for test in tests:
43    if test['type'] != 'fuzzer':
44      # Skip unit tests
45      continue
46    fuzzer = test['test_name']
47    objdir = test['test_directory']
48    module = os.path.basename(os.path.dirname(objdir))
49    if module == 'pw_fuzzer':
50      # Skip examples
51      continue
52    src = os.path.join(args.buildroot, objdir, fuzzer)
53    dst = os.path.join(args.out, '{}_{}'.format(module, fuzzer))
54    print('Copying {} to {}'.format(src, dst))
55    shutil.copy(src, dst)
56  return 0
57
58
59if __name__ == '__main__':
60  sys.exit(main())
61