|
6 | 6 | """
|
7 | 7 |
|
8 | 8 | from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 9 | +from pathlib import Path |
9 | 10 | import argparse
|
10 | 11 | import configparser
|
11 | 12 | import logging
|
@@ -41,6 +42,11 @@ def main():
|
41 | 42 | action='store_true',
|
42 | 43 | help='If true, run fuzzing binaries under the valgrind memory error detector',
|
43 | 44 | )
|
| 45 | + parser.add_argument( |
| 46 | + "--empty_min_time", |
| 47 | + type=int, |
| 48 | + help="If set, run at least this long, if the existing fuzz inputs directory is empty.", |
| 49 | + ) |
44 | 50 | parser.add_argument(
|
45 | 51 | '-x',
|
46 | 52 | '--exclude',
|
@@ -76,6 +82,7 @@ def main():
|
76 | 82 | )
|
77 | 83 |
|
78 | 84 | args = parser.parse_args()
|
| 85 | + args.corpus_dir = Path(args.corpus_dir) |
79 | 86 |
|
80 | 87 | # Set up logging
|
81 | 88 | logging.basicConfig(
|
@@ -180,6 +187,7 @@ def main():
|
180 | 187 | src_dir=config['environment']['SRCDIR'],
|
181 | 188 | build_dir=config["environment"]["BUILDDIR"],
|
182 | 189 | use_valgrind=args.valgrind,
|
| 190 | + empty_min_time=args.empty_min_time, |
183 | 191 | )
|
184 | 192 |
|
185 | 193 |
|
@@ -251,16 +259,22 @@ def job(t, args):
|
251 | 259 | future.result()
|
252 | 260 |
|
253 | 261 |
|
254 |
| -def run_once(*, fuzz_pool, corpus, test_list, src_dir, build_dir, use_valgrind): |
| 262 | +def run_once(*, fuzz_pool, corpus, test_list, src_dir, build_dir, use_valgrind, empty_min_time): |
255 | 263 | jobs = []
|
256 | 264 | for t in test_list:
|
257 |
| - corpus_path = os.path.join(corpus, t) |
| 265 | + corpus_path = corpus / t |
258 | 266 | os.makedirs(corpus_path, exist_ok=True)
|
259 | 267 | args = [
|
260 | 268 | os.path.join(build_dir, 'src', 'test', 'fuzz', 'fuzz'),
|
261 |
| - '-runs=1', |
262 |
| - corpus_path, |
263 | 269 | ]
|
| 270 | + empty_dir = not any(corpus_path.iterdir()) |
| 271 | + if empty_min_time and empty_dir: |
| 272 | + args += [f"-max_total_time={empty_min_time}"] |
| 273 | + else: |
| 274 | + args += [ |
| 275 | + "-runs=1", |
| 276 | + corpus_path, |
| 277 | + ] |
264 | 278 | if use_valgrind:
|
265 | 279 | args = ['valgrind', '--quiet', '--error-exitcode=1'] + args
|
266 | 280 |
|
|
0 commit comments