diff options
author | Nick Fitzgerald <fitzgen@gmail.com> | 2017-09-25 13:30:04 -0700 |
---|---|---|
committer | Nick Fitzgerald <fitzgen@gmail.com> | 2017-09-25 13:30:04 -0700 |
commit | ba2db57c78df73cea85d227001d4b505b3a1fb9a (patch) | |
tree | 416738ca828aab2888caa00d42622ca8358a18a5 /csmith-fuzzing/driver.py | |
parent | a0f6fbbc37b273162cc4aa9a97ce8af2dbd9575f (diff) |
C-Smith: compile bindings and execute layout tests
This makes us fall over flat on our faces almost immediately...
Diffstat (limited to 'csmith-fuzzing/driver.py')
-rw-r--r-- | csmith-fuzzing/driver.py | 46 |
1 files changed, 37 insertions, 9 deletions
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 |