diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | csmith-fuzzing/driver.py | 46 |
2 files changed, 40 insertions, 9 deletions
@@ -11,3 +11,6 @@ ir.png # Output of the --dump-preprocessed-input flag. __bindgen.* + +# Generated by C-Smith +csmith-fuzzing/platform.info diff --git a/csmith-fuzzing/driver.py b/csmith-fuzzing/driver.py index fe3d7879..e2816813 100644 --- a/csmith-fuzzing/driver.py +++ b/csmith-fuzzing/driver.py @@ -10,16 +10,20 @@ csmith_command = [ "--max-block-depth", "1", ] +def cat(path, title=None): + if not title: + title = path + print("-------------------- {} --------------------".format(title)) + run(["cat", path]) + def run_logged(cmd): with NamedTemporaryFile() as stdout, NamedTemporaryFile() as stderr: result = run(cmd, stdin=DEVNULL, stdout=stdout, stderr=stderr) if result.returncode != 0: print() - print("Error: {} exited with code {}".format(str(cmd), result.returncode)) - print("-------------------- stdout --------------------") - run(["cat", stdout.name]) - print("-------------------- stderr --------------------") - run(["cat", stderr.name]) + print("Error: '{}' exited with code {}".format(" ".join(cmd), result.returncode)) + cat(stdout.name, title="stdout") + cat(stdout.name, title="stderr") return result def run_bindgen(input, output): @@ -33,6 +37,15 @@ def run_bindgen(input, output): "-I", os.path.abspath(os.path.dirname(sys.argv[0])), ]) +def run_rustc(output, test): + return run_logged([ + "rustc", + "--crate-type", "lib", + "--test", + output.name, + "-o", test.name, + ]) + def main(): print("Fuzzing `bindgen` with C-Smith...\n") @@ -41,21 +54,36 @@ def main(): print("\rIteration: {}".format(iterations), end="", flush=True) input = NamedTemporaryFile(delete=False, prefix="input-", suffix=".h") + input.close() result = run_logged(csmith_command + ["-o", input.name]) if result.returncode != 0: exit(1) output = NamedTemporaryFile(delete=False, prefix="output-", suffix=".rs") + output.close() result = run_bindgen(input, output) if result.returncode != 0: - print("-------------------- {} --------------------".format(input.name)) - run(["cat", input.name]) - print("-------------------- {} --------------------".format(output.name)) - run(["cat", output.name]) + cat(input.name) + cat(output.name) + exit(1) + + test = NamedTemporaryFile(delete=False, prefix="test-") + test.close() + result = run_rustc(output, test) + if result.returncode != 0: + cat(input.name) + cat(output.name) + exit(1) + + result = run_logged([test.name]) + if result.returncode != 0: + cat(input.name) + cat(output.name) exit(1) os.remove(input.name) os.remove(output.name) + os.remove(test.name) iterations += 1 |