mirror of
https://gitee.com/openharmony/third_party_rust_bindgen
synced 2024-11-27 09:20:23 +00:00
C-Smith: compile bindings and execute layout tests
This makes us fall over flat on our faces almost immediately...
This commit is contained in:
parent
a0f6fbbc37
commit
ba2db57c78
3
.gitignore
vendored
3
.gitignore
vendored
@ -11,3 +11,6 @@ ir.png
|
||||
|
||||
# Output of the --dump-preprocessed-input flag.
|
||||
__bindgen.*
|
||||
|
||||
# Generated by C-Smith
|
||||
csmith-fuzzing/platform.info
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user