diff options
author | MarcoFalke <falke.marco@gmail.com> | 2020-03-18 15:51:30 -0400 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2020-03-18 15:51:44 -0400 |
commit | 5c9d408b2dd8c7a5b40b3e6051bb095eaad62604 (patch) | |
tree | 592abc524afa08b2079ebab86ed140f172bb6eee /test/fuzz/test_runner.py | |
parent | e83a1de4c03f305f4a89febc648168003a6e7987 (diff) | |
parent | fa3fa27c45618bcd8e325b27728b5f6c175d1a03 (diff) | |
download | bitcoin-5c9d408b2dd8c7a5b40b3e6051bb095eaad62604.tar.xz |
Merge #18300: fuzz: Add option to merge input dir to test runner
fa3fa27c45618bcd8e325b27728b5f6c175d1a03 fuzz: Remove option --export_coverage from test_runner (MarcoFalke)
aaaa055ff72a33241a3fdc2308d77bcbf51c262d fuzz: Add option to merge input dir to test runner (MarcoFalke)
fa4fa88d7648bfeb75fac941cdff79dcc38affbf doc: Remove --disable-ccache from docs (MarcoFalke)
Pull request description:
This is mainly useful for myself to merge pull requests like https://github.com/bitcoin-core/qa-assets/pull/4
I thought it wouldn't hurt to share the code.
Also remove the `--disable-ccache` from the docs to speed up builds when developing fuzzers.
Top commit has no ACKs.
Tree-SHA512: 818d85a90db86a7f4e8b001cc88342e5b28b02029d2bd4174440b28a8c4cc29b5406bd6348f72ddf909bb3d0f9bf7b1011976f6480e4418c8b7da5ecccae93e8
Diffstat (limited to 'test/fuzz/test_runner.py')
-rwxr-xr-x | test/fuzz/test_runner.py | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/test/fuzz/test_runner.py b/test/fuzz/test_runner.py index 520a2b5a95..1786c39c36 100755 --- a/test/fuzz/test_runner.py +++ b/test/fuzz/test_runner.py @@ -14,7 +14,10 @@ import logging def main(): - parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser = argparse.ArgumentParser( + formatter_class=argparse.ArgumentDefaultsHelpFormatter, + description='''Run the fuzz targets with all inputs from the seed_dir once.''', + ) parser.add_argument( "-l", "--loglevel", @@ -23,11 +26,6 @@ def main(): help="log events at this level and higher to the console. Can be set to DEBUG, INFO, WARNING, ERROR or CRITICAL. Passing --loglevel DEBUG will output all logs to console.", ) parser.add_argument( - '--export_coverage', - action='store_true', - help='If true, export coverage information to files in the seed corpus', - ) - parser.add_argument( '--valgrind', action='store_true', help='If true, run fuzzing binaries under the valgrind memory error detector', @@ -46,6 +44,10 @@ def main(): nargs='*', help='The target(s) to run. Default is to run all targets.', ) + parser.add_argument( + '--m_dir', + help='Merge inputs from this directory into the seed_dir. Needs /target subdirectory.', + ) args = parser.parse_args() @@ -122,16 +124,39 @@ def main(): logging.error("subprocess timed out: Currently only libFuzzer is supported") sys.exit(1) + if args.m_dir: + merge_inputs( + corpus=args.seed_dir, + test_list=test_list_selection, + build_dir=config["environment"]["BUILDDIR"], + merge_dir=args.m_dir, + ) + run_once( corpus=args.seed_dir, test_list=test_list_selection, build_dir=config["environment"]["BUILDDIR"], - export_coverage=args.export_coverage, use_valgrind=args.valgrind, ) -def run_once(*, corpus, test_list, build_dir, export_coverage, use_valgrind): +def merge_inputs(*, corpus, test_list, build_dir, merge_dir): + logging.info("Merge the inputs in the passed dir into the seed_dir. Passed dir {}".format(merge_dir)) + for t in test_list: + args = [ + os.path.join(build_dir, 'src', 'test', 'fuzz', t), + '-merge=1', + os.path.join(corpus, t), + os.path.join(merge_dir, t), + ] + os.makedirs(os.path.join(corpus, t), exist_ok=True) + os.makedirs(os.path.join(merge_dir, t), exist_ok=True) + logging.debug('Run {} with args {}'.format(t, args)) + output = subprocess.run(args, check=True, stderr=subprocess.PIPE, universal_newlines=True).stderr + logging.debug('Output: {}'.format(output)) + + +def run_once(*, corpus, test_list, build_dir, use_valgrind): for t in test_list: corpus_path = os.path.join(corpus, t) os.makedirs(corpus_path, exist_ok=True) @@ -155,13 +180,6 @@ def run_once(*, corpus, test_list, build_dir, export_coverage, use_valgrind): logging.info(e.stderr) logging.info("Target \"{}\" failed with exit code {}: {}".format(t, e.returncode, " ".join(args))) sys.exit(1) - if not export_coverage: - continue - for l in output.splitlines(): - if 'INITED' in l: - with open(os.path.join(corpus, t + '_coverage'), 'w', encoding='utf-8') as cov_file: - cov_file.write(l) - break def parse_test_list(makefile): |