|
| 1 | +from subprocess import run, DEVNULL, PIPE |
| 2 | + |
| 3 | +csmith_command = [ |
| 4 | + "csmith", |
| 5 | + "--no-checksum", |
| 6 | + "--nomain", |
| 7 | + "--max-block-size", "1", |
| 8 | + "--max-block-depth", "1", |
| 9 | + "--output", "generated.h"] |
| 10 | + |
| 11 | +bindgen_command = ["bindgen", "generated.h"] |
| 12 | + |
| 13 | +if __name__ == "__main__": |
| 14 | + print("Bindgen fuzzing with csmith.") |
| 15 | + print( |
| 16 | + "This script will write to generated.h, bindgen_stdout, bindgen_stderr and platform.info . " |
| 17 | + "These files can be deleted after running.") |
| 18 | + |
| 19 | + iterations = 0 |
| 20 | + while True: |
| 21 | + print("\rIteration: {}".format(iterations), end="", flush=True) |
| 22 | + |
| 23 | + run(csmith_command, stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL) |
| 24 | + with open("bindgen_stdout", "wb") as stdout, open("bindgen_stdout", "wb") as stderr: |
| 25 | + result = run(bindgen_command, stdin=DEVNULL, stdout=stdout, stderr=stderr) |
| 26 | + if result.returncode != 0: |
| 27 | + print() |
| 28 | + print( |
| 29 | + "Error: bindgen existed with non zero exit code {} when ran on generated.h . " |
| 30 | + "You can find its output in bindgen_stoud and bindgen_stderr." |
| 31 | + .format(result.returncode)) |
| 32 | + exit() |
| 33 | + iterations += 1 |
0 commit comments