Generates new corpus. Run {targets} without input, and outputs the generated corpus to {corpus_dir}.
(*, fuzz_pool, src_dir, build_dir, corpus_dir, targets)
| 184 | |
| 185 | |
| 186 | def generate_corpus(*, fuzz_pool, src_dir, build_dir, corpus_dir, targets): |
| 187 | """Generates new corpus. |
| 188 | |
| 189 | Run {targets} without input, and outputs the generated corpus to |
| 190 | {corpus_dir}. |
| 191 | """ |
| 192 | logging.info("Generating corpus to {}".format(corpus_dir)) |
| 193 | |
| 194 | def job(command, t): |
| 195 | logging.debug("Running '{}'\n".format(" ".join(command))) |
| 196 | logging.debug("Command '{}' output:\n'{}'\n".format( |
| 197 | ' '.join(command), |
| 198 | subprocess.run( |
| 199 | command, |
| 200 | env=get_fuzz_env(target=t, source_dir=src_dir), |
| 201 | check=True, |
| 202 | stderr=subprocess.PIPE, |
| 203 | universal_newlines=True, |
| 204 | ).stderr)) |
| 205 | |
| 206 | futures = [] |
| 207 | for target in targets: |
| 208 | target_corpus_dir = os.path.join(corpus_dir, target) |
| 209 | os.makedirs(target_corpus_dir, exist_ok=True) |
| 210 | command = [ |
| 211 | os.path.join(build_dir, 'src', 'test', 'fuzz', 'fuzz'), |
| 212 | "-runs=100000", |
| 213 | target_corpus_dir, |
| 214 | ] |
| 215 | futures.append(fuzz_pool.submit(job, command, target)) |
| 216 | |
| 217 | for future in as_completed(futures): |
| 218 | future.result() |
| 219 | |
| 220 | |
| 221 | def merge_inputs(*, fuzz_pool, corpus, test_list, src_dir, build_dir, merge_dir): |