From 30820dda996c67caa88fcc3ad65ccfc753de294d Mon Sep 17 00:00:00 2001 From: Mathias Baumann Date: Mon, 1 Apr 2019 16:57:32 +0200 Subject: [PATCH 1/2] Support multiple input files with solfuzzer --- test/tools/afl_fuzzer.cpp | 53 +++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/test/tools/afl_fuzzer.cpp b/test/tools/afl_fuzzer.cpp index 18d783563..31e05716e 100644 --- a/test/tools/afl_fuzzer.cpp +++ b/test/tools/afl_fuzzer.cpp @@ -60,6 +60,10 @@ Allowed options)", "input-file", po::value(), "input file" + )( + "input-files", + po::value>()->multitoken(), + "input files" ) ( "without-optimizer", @@ -93,18 +97,47 @@ Allowed options)", return 0; } - string input; + vector inputs; if (arguments.count("input-file")) - input = readFileAsString(arguments["input-file"].as()); + inputs.push_back(arguments["input-file"].as()); + else if (arguments.count("input-files")) + inputs = arguments["input-files"].as>(); else - input = readStandardInput(); + inputs.push_back(""); - if (arguments.count("const-opt")) - FuzzerUtil::testConstantOptimizer(input, quiet); - else if (arguments.count("standard-json")) - FuzzerUtil::testStandardCompiler(input, quiet); - else - FuzzerUtil::testCompiler(input, !arguments.count("without-optimizer"), quiet); + bool optimize = !arguments.count("without-optimizer"); + int retResult = 0; - return 0; + for (string const& inputFile: inputs) + { + string input; + if (inputFile.size() == 0) + input = readStandardInput(); + else + input = readFileAsString(inputFile); + + try + { + if (arguments.count("const-opt")) + FuzzerUtil::testConstantOptimizer(input, quiet); + else if (arguments.count("standard-json")) + FuzzerUtil::testStandardCompiler(input, quiet); + else + FuzzerUtil::testCompiler(input, optimize, quiet); + } + catch (exception const& _exc) + { + retResult = 1; + + if (inputFile.size() == 0) + throw _exc; + + cerr << "Fuzzer " + << (optimize ? "" : "(without optimizer) ") + << "failed on " + << inputFile; + } + } + + return retResult; } From 3216e5d8462cb699db78c7cea4ecf96edd5ee9bf Mon Sep 17 00:00:00 2001 From: Mathias Baumann Date: Mon, 1 Apr 2019 16:57:58 +0200 Subject: [PATCH 2/2] Run several instances of solfuzzer in parallel --- test/cmdlineTests.sh | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/test/cmdlineTests.sh b/test/cmdlineTests.sh index 37c319e7d..76aa0229e 100755 --- a/test/cmdlineTests.sh +++ b/test/cmdlineTests.sh @@ -392,26 +392,9 @@ SOLTMPDIR=$(mktemp -d) cd "$SOLTMPDIR" "$REPO_ROOT"/scripts/isolate_tests.py "$REPO_ROOT"/test/ "$REPO_ROOT"/scripts/isolate_tests.py "$REPO_ROOT"/docs/ docs - for f in *.sol - do - set +e - "$REPO_ROOT"/build/test/tools/solfuzzer --quiet < "$f" - if [ $? -ne 0 ] - then - printError "Fuzzer failed on:" - cat "$f" - exit 1 - fi - "$REPO_ROOT"/build/test/tools/solfuzzer --without-optimizer --quiet < "$f" - if [ $? -ne 0 ] - then - printError "Fuzzer (without optimizer) failed on:" - cat "$f" - exit 1 - fi - set -e - done + echo *.sol | xargs -P 4 -n 50 "$REPO_ROOT"/build/test/tools/solfuzzer --quiet --input-files + echo *.sol | xargs -P 4 -n 50 "$REPO_ROOT"/build/test/tools/solfuzzer --without-optimizer --quiet --input-files ) rm -rf "$SOLTMPDIR"