Skip to content

Commit ba2db57

Browse files
committed
C-Smith: compile bindings and execute layout tests
This makes us fall over flat on our faces almost immediately...
1 parent a0f6fbb commit ba2db57

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ ir.png
1111

1212
# Output of the --dump-preprocessed-input flag.
1313
__bindgen.*
14+
15+
# Generated by C-Smith
16+
csmith-fuzzing/platform.info

csmith-fuzzing/driver.py

+37-9
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@
1010
"--max-block-depth", "1",
1111
]
1212

13+
def cat(path, title=None):
14+
if not title:
15+
title = path
16+
print("-------------------- {} --------------------".format(title))
17+
run(["cat", path])
18+
1319
def run_logged(cmd):
1420
with NamedTemporaryFile() as stdout, NamedTemporaryFile() as stderr:
1521
result = run(cmd, stdin=DEVNULL, stdout=stdout, stderr=stderr)
1622
if result.returncode != 0:
1723
print()
18-
print("Error: {} exited with code {}".format(str(cmd), result.returncode))
19-
print("-------------------- stdout --------------------")
20-
run(["cat", stdout.name])
21-
print("-------------------- stderr --------------------")
22-
run(["cat", stderr.name])
24+
print("Error: '{}' exited with code {}".format(" ".join(cmd), result.returncode))
25+
cat(stdout.name, title="stdout")
26+
cat(stdout.name, title="stderr")
2327
return result
2428

2529
def run_bindgen(input, output):
@@ -33,6 +37,15 @@ def run_bindgen(input, output):
3337
"-I", os.path.abspath(os.path.dirname(sys.argv[0])),
3438
])
3539

40+
def run_rustc(output, test):
41+
return run_logged([
42+
"rustc",
43+
"--crate-type", "lib",
44+
"--test",
45+
output.name,
46+
"-o", test.name,
47+
])
48+
3649
def main():
3750
print("Fuzzing `bindgen` with C-Smith...\n")
3851

@@ -41,21 +54,36 @@ def main():
4154
print("\rIteration: {}".format(iterations), end="", flush=True)
4255

4356
input = NamedTemporaryFile(delete=False, prefix="input-", suffix=".h")
57+
input.close()
4458
result = run_logged(csmith_command + ["-o", input.name])
4559
if result.returncode != 0:
4660
exit(1)
4761

4862
output = NamedTemporaryFile(delete=False, prefix="output-", suffix=".rs")
63+
output.close()
4964
result = run_bindgen(input, output)
5065
if result.returncode != 0:
51-
print("-------------------- {} --------------------".format(input.name))
52-
run(["cat", input.name])
53-
print("-------------------- {} --------------------".format(output.name))
54-
run(["cat", output.name])
66+
cat(input.name)
67+
cat(output.name)
68+
exit(1)
69+
70+
test = NamedTemporaryFile(delete=False, prefix="test-")
71+
test.close()
72+
result = run_rustc(output, test)
73+
if result.returncode != 0:
74+
cat(input.name)
75+
cat(output.name)
76+
exit(1)
77+
78+
result = run_logged([test.name])
79+
if result.returncode != 0:
80+
cat(input.name)
81+
cat(output.name)
5582
exit(1)
5683

5784
os.remove(input.name)
5885
os.remove(output.name)
86+
os.remove(test.name)
5987

6088
iterations += 1
6189

0 commit comments

Comments
 (0)