rewrite cargo-miri test in Python

This commit is contained in:
Ralf Jung 2018-10-30 11:26:53 +01:00
parent 9c57f2ba35
commit f6b1f9e487
2 changed files with 48 additions and 22 deletions

View File

@ -36,35 +36,18 @@ script:
- |
# Test and install plain miri
cargo build --release --all-features &&
#cargo test --release --all-features &&
cargo test --release --all-features &&
cargo install --all-features --force --path .
- |
# get ourselves a MIR-full libstd
xargo/build.sh &&
export MIRI_SYSROOT=~/.xargo/HOST
#- |
# # run all tests with full mir
# cargo test --release --all-features
- |
# run all tests with full mir
cargo test --release --all-features
- |
# Test cargo integration
cd cargo-miri-test &&
# Test `cargo miri`
# We ignore the exit code because we want to see the output even on failure, and
# I found no way to preserve the exit code so that we can test for it later.
# Variables set in this subshell in the parenthesis are not available
# on the outside.
# We assume that if this fails, it'll also print something about the failure on
# stdout/stderr and we'll catch that.
# FIXME: Disabling validation, still investigating whether there is UB here
(cargo miri -q >stdout.real 2>stderr.real -- -Zmiri-disable-validation || true) &&
# Print file names and contents (`cat` would just print contents)
tail -n +0 stdout.real stderr.real &&
# Verify output
diff -u stdout.ref stdout.real &&
diff -u stderr.ref stderr.real &&
# test `cargo miri test`
cargo miri test &&
cd ..
(cd cargo-miri-test && ./run-test.py)
notifications:
email:

43
cargo-miri-test/run-test.py Executable file
View File

@ -0,0 +1,43 @@
#!/usr/bin/python3
'''
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
def test_cargo_miri():
print("==> Testing `cargo miri` <==")
## Call `cargo miri`, capture all output
# FIXME: Disabling validation, still investigating whether there is UB here
p = subprocess.Popen(
["cargo", "miri", "-q", "--", "-Zmiri-disable-validation"],
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:
sys.exit(1)
if stdout != open('stdout.ref').read():
print("stdout does not match reference")
sys.exit(1)
if stderr != open('stderr.ref').read():
print("stderr does not match reference")
sys.exit(1)
def test_cargo_miri_test():
print("==> Testing `cargo miri test` <==")
subprocess.check_call(["cargo", "miri", "test"])
test_cargo_miri()
test_cargo_miri_test()
sys.exit(0)