| 252 | |
| 253 | |
| 254 | def run_once(*, fuzz_pool, corpus, test_list, src_dir, build_dir, use_valgrind): |
| 255 | jobs = [] |
| 256 | for t in test_list: |
| 257 | corpus_path = os.path.join(corpus, t) |
| 258 | os.makedirs(corpus_path, exist_ok=True) |
| 259 | args = [ |
| 260 | os.path.join(build_dir, 'src', 'test', 'fuzz', 'fuzz'), |
| 261 | '-runs=1', |
| 262 | corpus_path, |
| 263 | ] |
| 264 | if use_valgrind: |
| 265 | args = ['valgrind', '--quiet', '--error-exitcode=1'] + args |
| 266 | |
| 267 | def job(t, args): |
| 268 | output = 'Run {} with args {}'.format(t, args) |
| 269 | result = subprocess.run( |
| 270 | args, |
| 271 | env=get_fuzz_env(target=t, source_dir=src_dir), |
| 272 | stderr=subprocess.PIPE, |
| 273 | universal_newlines=True, |
| 274 | ) |
| 275 | output += result.stderr |
| 276 | return output, result |
| 277 | |
| 278 | jobs.append(fuzz_pool.submit(job, t, args)) |
| 279 | |
| 280 | for future in as_completed(jobs): |
| 281 | output, result = future.result() |
| 282 | logging.debug(output) |
| 283 | try: |
| 284 | result.check_returncode() |
| 285 | except subprocess.CalledProcessError as e: |
| 286 | if e.stdout: |
| 287 | logging.info(e.stdout) |
| 288 | if e.stderr: |
| 289 | logging.info(e.stderr) |
| 290 | logging.info("Target \"{}\" failed with exit code {}".format(" ".join(result.args), e.returncode)) |
| 291 | sys.exit(1) |
| 292 | |
| 293 | |
| 294 | def parse_test_list(*, fuzz_bin): |