rust/test-cargo-miri/run-test.py

75 lines
2.1 KiB
Python
Raw Normal View History

2018-10-30 09:07:40 -05:00
#!/usr/bin/env python3
2018-10-30 05:26:53 -05:00
'''
Test whether cargo-miri works properly.
Assumes the `MIRI_SYSROOT` env var to be set appropriately,
and the working directory to contain the cargo-miri-test project.
'''
import sys, subprocess, os
2018-10-30 05:26:53 -05:00
def fail(msg):
2019-06-29 06:33:47 -05:00
print("\nTEST FAIL: {}".format(msg))
sys.exit(1)
def cargo_miri(cmd):
args = ["cargo", "miri", cmd, "-q"]
if 'MIRI_TEST_TARGET' in os.environ:
args += ["--target", os.environ['MIRI_TEST_TARGET']]
return args
def test(name, cmd, stdout_ref, stderr_ref):
print("==> Testing `{}` <==".format(name))
2018-10-30 05:26:53 -05:00
## Call `cargo miri`, capture all output
p = subprocess.Popen(
cmd,
2018-10-30 05:26:53 -05:00
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
(stdout, stderr) = p.communicate()
stdout = stdout.decode("UTF-8")
stderr = stderr.decode("UTF-8")
# Show output
print("=> captured stdout <=")
print(stdout, end="")
print("=> captured stderr <=")
print(stderr, end="")
# Test for failures
if p.returncode != 0:
fail("Non-zero exit status")
if stdout != open(stdout_ref).read():
fail("stdout does not match reference")
if stderr != open(stderr_ref).read():
fail("stderr does not match reference")
2018-10-30 05:26:53 -05:00
def test_cargo_miri_run():
test("cargo miri run",
cargo_miri("run"),
"stdout.ref", "stderr.ref"
)
test("cargo miri run (with arguments)",
cargo_miri("run") + ["--", "--", "hello world", '"hello world"'],
"stdout.ref", "stderr.ref2"
)
2018-10-30 05:26:53 -05:00
def test_cargo_miri_test():
test("cargo miri test",
cargo_miri("test") + ["--", "-Zmiri-seed=feed"],
"test.stdout.ref", "test.stderr.ref"
)
test("cargo miri test (with filter)",
2019-06-29 06:33:47 -05:00
cargo_miri("test") + ["--", "--", "le1"],
"test.stdout.ref2", "test.stderr.ref"
)
2019-08-29 04:09:34 -05:00
test("cargo miri test (without isolation)",
cargo_miri("test") + ["--", "-Zmiri-disable-isolation", "--", "num_cpus"],
"test.stdout.ref3", "test.stderr.ref"
)
2018-10-30 05:26:53 -05:00
os.chdir(os.path.dirname(os.path.realpath(__file__)))
test_cargo_miri_run()
2018-10-30 05:26:53 -05:00
test_cargo_miri_test()
2019-06-29 06:33:47 -05:00
print("\nTEST SUCCESSFUL!")
2018-10-30 05:26:53 -05:00
sys.exit(0)