Page MenuHomePhabricator

D8277.diff
No OneTemporary

D8277.diff

diff --git a/test/fuzz/test_runner.py b/test/fuzz/test_runner.py
--- a/test/fuzz/test_runner.py
+++ b/test/fuzz/test_runner.py
@@ -6,6 +6,7 @@
"""
import argparse
+from concurrent.futures import ThreadPoolExecutor, as_completed
import configparser
import logging
import os
@@ -35,6 +36,12 @@
'--exclude',
help="A comma-separated list of targets to exclude",
)
+ parser.add_argument(
+ '--par',
+ type=int,
+ default=4,
+ help='How many targets to merge or execute in parallel.',
+ )
parser.add_argument(
'seed_dir',
help='The seed corpus to run on (must contain subfolders for each fuzz target).',
@@ -144,29 +151,33 @@
"subprocess timed out: Currently only libFuzzer is supported")
sys.exit(1)
- if args.m_dir:
- merge_inputs(
+ with ThreadPoolExecutor(max_workers=args.par) as fuzz_pool:
+ if args.m_dir:
+ merge_inputs(
+ fuzz_pool=fuzz_pool,
+ corpus=args.seed_dir,
+ test_list=test_list_selection,
+ test_dir=test_dir,
+ merge_dir=args.m_dir,
+ )
+ return
+
+ run_once(
+ fuzz_pool=fuzz_pool,
corpus=args.seed_dir,
test_list=test_list_selection,
- build_dir=config["environment"]["BUILDDIR"],
- merge_dir=args.m_dir,
+ test_dir=test_dir,
+ use_valgrind=args.valgrind,
)
- return
-
- run_once(
- corpus=args.seed_dir,
- test_list=test_list_selection,
- test_dir=test_dir,
- use_valgrind=args.valgrind,
- )
-def merge_inputs(*, corpus, test_list, build_dir, merge_dir):
+def merge_inputs(*, fuzz_pool, corpus, test_list, test_dir, merge_dir):
logging.info(
"Merge the inputs in the passed dir into the seed_dir. Passed dir {}".format(merge_dir))
+ jobs = []
for t in test_list:
args = [
- os.path.join(build_dir, 'src', 'test', 'fuzz', t),
+ os.path.join(test_dir, t),
'-merge=1',
# Also done by oss-fuzz
# https://github.com/google/oss-fuzz/issues/1406#issuecomment-387790487
@@ -176,16 +187,23 @@
]
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 job(t, args):
+ output = 'Run {} with args {}\n'.format(t, " ".join(args))
+ output += subprocess.run(args,
+ check=True,
+ stderr=subprocess.PIPE,
+ universal_newlines=True).stderr
+ logging.debug(output)
+
+ jobs.append(fuzz_pool.submit(job, t, args))
+
+ for future in as_completed(jobs):
+ future.result()
-def run_once(*, corpus, test_list, test_dir, use_valgrind):
+def run_once(*, fuzz_pool, corpus, test_list, test_dir, use_valgrind):
+ jobs = []
for t in test_list:
corpus_path = os.path.join(corpus, t)
os.makedirs(corpus_path, exist_ok=True)
@@ -199,13 +217,21 @@
'valgrind',
'--quiet',
'--error-exitcode=1'] + args
- logging.debug('Run {} with args {}'.format(t, args))
- result = subprocess.run(
- args,
- stderr=subprocess.PIPE,
- universal_newlines=True)
- output = result.stderr
- logging.debug('Output: {}'.format(output))
+
+ def job(t, args):
+ output = 'Run {} with args {}'.format(t, args)
+ result = subprocess.run(
+ args,
+ stderr=subprocess.PIPE,
+ universal_newlines=True)
+ output += result.stderr
+ return output, result
+
+ jobs.append(fuzz_pool.submit(job, t, args))
+
+ for future in as_completed(jobs):
+ output, result = future.result()
+ logging.debug(output)
try:
result.check_returncode()
except subprocess.CalledProcessError as e:
@@ -214,8 +240,10 @@
if e.stderr:
logging.info(e.stderr)
logging.info(
- "Target \"{}\" failed with exit code {}: {}".format(
- t, e.returncode, " ".join(args)))
+ "Target \"{}\" failed with exit code {}".format(
+ " ".join(
+ result.args),
+ e.returncode))
sys.exit(1)

File Metadata

Mime Type
text/plain
Expires
Sat, Mar 1, 12:20 (20 m, 11 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5187831
Default Alt Text
D8277.diff (4 KB)

Event Timeline