X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=test-cargo-miri%2Frun-test.py;h=877a2a5706196e3d9864c6600aa21b4c0f8c0dba;hb=504c617cd4d1f67e8f472b559d32ab081b9c804e;hp=19e0a147408f29430559da11572af42f3b2a5bfe;hpb=3e603c38d74935689d7454ec961c49ab2470bf46;p=rust.git diff --git a/test-cargo-miri/run-test.py b/test-cargo-miri/run-test.py index 19e0a147408..877a2a57061 100755 --- a/test-cargo-miri/run-test.py +++ b/test-cargo-miri/run-test.py @@ -5,17 +5,35 @@ Assumes the `MIRI_SYSROOT` env var to be set appropriately, and the working directory to contain the cargo-miri-test project. ''' -import sys, subprocess +import sys, subprocess, os -def test(name, cmd, stdout_ref, stderr_ref): +CGREEN = '\33[32m' +CBOLD = '\33[1m' +CEND = '\33[0m' + +def fail(msg): + 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, stdin=b'', env={}): print("==> Testing `{}` <==".format(name)) ## Call `cargo miri`, capture all output + p_env = os.environ.copy() + p_env.update(env) p = subprocess.Popen( cmd, + stdin=subprocess.PIPE, stdout=subprocess.PIPE, - stderr=subprocess.PIPE + stderr=subprocess.PIPE, + env=p_env, ) - (stdout, stderr) = p.communicate() + (stdout, stderr) = p.communicate(input=stdin) stdout = stdout.decode("UTF-8") stderr = stderr.decode("UTF-8") # Show output @@ -25,20 +43,59 @@ def test(name, cmd, stdout_ref, stderr_ref): print(stderr, end="") # Test for failures if p.returncode != 0: - sys.exit(1) + fail("Non-zero exit status") if stdout != open(stdout_ref).read(): - print("stdout does not match reference") - sys.exit(1) + fail("stdout does not match reference") if stderr != open(stderr_ref).read(): - print("stderr does not match reference") - sys.exit(1) + fail("stderr does not match reference") def test_cargo_miri_run(): - test("cargo miri run", ["cargo", "miri", "run", "-q"], "stdout.ref", "stderr.ref") + test("cargo miri run", + cargo_miri("run"), + "stdout.ref", "stderr.ref", + stdin=b'12\n21\n', + env={'MIRIFLAGS': "-Zmiri-disable-isolation"}, + ) + test("cargo miri run (with arguments and target)", + cargo_miri("run") + ["--bin", "cargo-miri-test", "--", "hello world", '"hello world"'], + "stdout.ref2", "stderr.ref2" + ) def test_cargo_miri_test(): - test("cargo miri test", ["cargo", "miri", "test", "-q"], "test.stdout.ref", "test.stderr.ref") + test("cargo miri test", + cargo_miri("test"), + "test.stdout.ref", "test.stderr.ref", + env={'MIRIFLAGS': "-Zmiri-seed=feed"}, + ) + test("cargo miri test (with filter)", + cargo_miri("test") + ["--", "--format=pretty", "le1"], + "test.stdout.ref2", "test.stderr.ref" + ) + test("cargo miri test (without isolation)", + cargo_miri("test") + ["--", "--format=pretty", "num_cpus"], + "test.stdout.ref3", "test.stderr.ref", + env={'MIRIFLAGS': "-Zmiri-disable-isolation"}, + ) + test("cargo miri test (test target)", + cargo_miri("test") + ["--test", "test", "--", "--format=pretty"], + "test.stdout.ref4", "test.stderr.ref" + ) + test("cargo miri test (bin target)", + cargo_miri("test") + ["--bin", "cargo-miri-test", "--", "--format=pretty"], + "test.stdout.ref5", "test.stderr.ref" + ) +os.chdir(os.path.dirname(os.path.realpath(__file__))) + +target_str = " for target {}".format(os.environ['MIRI_TEST_TARGET']) if 'MIRI_TEST_TARGET' in os.environ else "" +print(CGREEN + CBOLD + "## Running `cargo miri` tests{}".format(target_str) + CEND) + +if not 'MIRI_SYSROOT' in os.environ: + # Make sure we got a working sysroot. + # (If the sysroot gets built later when output is compared, that leads to test failures.) + subprocess.run(cargo_miri("setup"), check=True) test_cargo_miri_run() test_cargo_miri_test() + +print("\nTEST SUCCESSFUL!") sys.exit(0)