summaryrefslogtreecommitdiff
path: root/chromium/testing/libfuzzer/gen_fuzzer_config.py
blob: 310b7b934429fd4c3b285118bd7316c1c68280cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python2
#
# Copyright (c) 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Generate or update an existing config (.options file) for libfuzzer test.

Invoked by GN from fuzzer_test.gni.
"""

import argparse
import os
import sys


CONFIG_HEADER = '''# This is an automatically generated config for libFuzzer.
[libfuzzer]
'''

def main():
  parser = argparse.ArgumentParser(description="Generate fuzzer config.")
  parser.add_argument('--config', required=True)
  parser.add_argument('--dict')
  parser.add_argument('--libfuzzer_options', nargs='+', default=[])
  args = parser.parse_args()

  # Script shouldn't be invoked without both arguments, but just in case.
  if not args.dict and not args.libfuzzer_options:
    return

  config_path = args.config
  # Generate .options file.
  with open(config_path, 'w') as options_file:
    options_file.write(CONFIG_HEADER)

    # Dict will be copied into build directory, need only basename for config.
    if args.dict:
      options_file.write('dict = %s\n' % os.path.basename(args.dict))

    for option in args.libfuzzer_options:
      options_file.write(option)
      options_file.write('\n')

if __name__ == '__main__':
  main()