def run_once(*, fuzz_pool, corpus, test_list, build_dir, use_valgrind):
    jobs = []
    for t in test_list:
        corpus_path = os.path.join(corpus, t)
        os.makedirs(corpus_path, exist_ok=True)
        args = [os.path.join(build_dir, 'src', 'test', 'fuzz', t), '-runs=1', corpus_path]
        if use_valgrind:
            args = (['valgrind', '--quiet', '--error-exitcode=1'] + args)

        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:
            if e.stdout:
                logging.info(e.stdout)
            if e.stderr:
                logging.info(e.stderr)
            logging.info('Target "{}" failed with exit code {}'.format(' '.join(result.args), e.returncode))
            sys.exit(1)
def run_once(*, fuzz_pool, corpus, test_list, build_dir, use_valgrind):
    jobs = []
    for t in test_list:
        corpus_path = os.path.join(corpus, t)
        os.makedirs(corpus_path, exist_ok=True)
        args = [os.path.join(build_dir, 'src', 'test', 'fuzz', t), '-runs=1', corpus_path]
        if use_valgrind:
            args = (['valgrind', '--quiet', '--error-exitcode=1'] + args)

        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:
            if e.stdout:
                logging.info(e.stdout)
            if e.stderr:
                logging.info(e.stderr)
            logging.info('Target "{}" failed with exit code {}'.format(' '.join(result.args), e.returncode))
            sys.exit(1)