diff options
| author | Konstantinos Andrikopoulos <mandragore@protonmail.com> | 2024-06-22 16:36:54 +0200 |
|---|---|---|
| committer | Konstantinos Andrikopoulos <andrikopoulos@google.com> | 2024-07-04 21:39:46 +0200 |
| commit | 2d33d7bc6236b2c9add0aec9befa1459ef160583 (patch) | |
| tree | 4b59e79745b8348ff1a9309f3e83569c80c77dfb | |
| parent | b0d791d3cf13a7b61b3db49591b432d88af2aec8 (diff) | |
| download | rust-2d33d7bc6236b2c9add0aec9befa1459ef160583.tar.gz rust-2d33d7bc6236b2c9add0aec9befa1459ef160583.zip | |
Run tests for all specified targets
Currently cargo-miri uses the first target specified in the command line. However, when multiple targets are specified in a `cargo build` invocation, cargo will build for all of them. Miri should match this behaviour to reduce surprises. Fixes: #3460
| -rw-r--r-- | src/tools/miri/cargo-miri/src/phases.rs | 26 | ||||
| -rwxr-xr-x | src/tools/miri/ci/ci.sh | 4 | ||||
| -rwxr-xr-x | src/tools/miri/test-cargo-miri/run-test.py | 20 | ||||
| -rw-r--r-- | src/tools/miri/test-cargo-miri/test.multiple_targets.stdout.ref | 22 |
4 files changed, 61 insertions, 11 deletions
diff --git a/src/tools/miri/cargo-miri/src/phases.rs b/src/tools/miri/cargo-miri/src/phases.rs index 8d48b9c8ad1..3743446e276 100644 --- a/src/tools/miri/cargo-miri/src/phases.rs +++ b/src/tools/miri/cargo-miri/src/phases.rs @@ -104,9 +104,17 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) { miri_for_host() ) }); - let host = &rustc_version.host; - let target = get_arg_flag_value("--target"); - let target = target.as_ref().unwrap_or(host); + let mut targets = get_arg_flag_values("--target").collect::<Vec<_>>(); + // If `targets` is empty, we need to add a `--target $HOST` flag ourselves, and also ensure + // that the host target is indeed setup. + let target_flag = if targets.is_empty() { + let host = &rustc_version.host; + targets.push(host.clone()); + Some(host) + } else { + // We don't need to add a `--target` flag, we just forward the user's flags. + None + }; // If cleaning the target directory & sysroot cache, // delete them then exit. There is no reason to setup a new @@ -118,8 +126,11 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) { return; } - // We always setup. - let miri_sysroot = setup(&subcommand, target, &rustc_version, verbose, quiet); + for target in &targets { + // We always setup. + setup(&subcommand, target.as_str(), &rustc_version, verbose, quiet); + } + let miri_sysroot = get_sysroot_dir(); // Invoke actual cargo for the job, but with different flags. // We re-use `cargo test` and `cargo run`, which makes target and binary handling very easy but @@ -155,10 +166,9 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) { // This is needed to make the `target.runner` settings do something, // and it later helps us detect which crates are proc-macro/build-script // (host crates) and which crates are needed for the program itself. - if get_arg_flag_value("--target").is_none() { - // No target given. Explicitly pick the host. + if let Some(target_flag) = target_flag { cmd.arg("--target"); - cmd.arg(host); + cmd.arg(target_flag); } // Set ourselves as runner for al binaries invoked by cargo. diff --git a/src/tools/miri/ci/ci.sh b/src/tools/miri/ci/ci.sh index 67985f9b7d6..5e75638f467 100755 --- a/src/tools/miri/ci/ci.sh +++ b/src/tools/miri/ci/ci.sh @@ -41,9 +41,11 @@ function run_tests { if [ -n "${TEST_TARGET-}" ]; then begingroup "Testing foreign architecture $TEST_TARGET" TARGET_FLAG="--target $TEST_TARGET" + MULTI_TARGET_FLAG="" else begingroup "Testing host architecture" TARGET_FLAG="" + MULTI_TARGET_FLAG="--multi-target" fi ## ui test suite @@ -93,7 +95,7 @@ function run_tests { echo 'build.rustc-wrapper = "thisdoesnotexist"' > .cargo/config.toml fi # Run the actual test - time ${PYTHON} test-cargo-miri/run-test.py $TARGET_FLAG + time ${PYTHON} test-cargo-miri/run-test.py $TARGET_FLAG $MULTI_TARGET_FLAG # Clean up unset RUSTC MIRI rm -rf .cargo diff --git a/src/tools/miri/test-cargo-miri/run-test.py b/src/tools/miri/test-cargo-miri/run-test.py index d855c333a75..5b77092979d 100755 --- a/src/tools/miri/test-cargo-miri/run-test.py +++ b/src/tools/miri/test-cargo-miri/run-test.py @@ -22,12 +22,17 @@ def fail(msg): print("\nTEST FAIL: {}".format(msg)) sys.exit(1) -def cargo_miri(cmd, quiet = True): +def cargo_miri(cmd, quiet = True, targets = None): args = ["cargo", "miri", cmd] + CARGO_EXTRA_FLAGS if quiet: args += ["-q"] - if ARGS.target: + + if targets is not None: + for target in targets: + args.extend(("--target", target)) + elif ARGS.target is not None: args += ["--target", ARGS.target] + return args def normalize_stdout(str): @@ -186,10 +191,21 @@ def test_cargo_miri_test(): default_ref, "test.stderr-empty.ref", env={'MIRIFLAGS': "-Zmiri-permissive-provenance"}, ) + if ARGS.multi_target: + test_cargo_miri_multi_target() + + +def test_cargo_miri_multi_target(): + test("`cargo miri test` (multiple targets)", + cargo_miri("test", targets = ["aarch64-unknown-linux-gnu", "s390x-unknown-linux-gnu"]), + "test.multiple_targets.stdout.ref", "test.stderr-empty.ref", + env={'MIRIFLAGS': "-Zmiri-permissive-provenance"}, + ) args_parser = argparse.ArgumentParser(description='`cargo miri` testing') args_parser.add_argument('--target', help='the target to test') args_parser.add_argument('--bless', help='bless the reference files', action='store_true') +args_parser.add_argument('--multi-target', help='run tests related to multiple targets', action='store_true') ARGS = args_parser.parse_args() os.chdir(os.path.dirname(os.path.realpath(__file__))) diff --git a/src/tools/miri/test-cargo-miri/test.multiple_targets.stdout.ref b/src/tools/miri/test-cargo-miri/test.multiple_targets.stdout.ref new file mode 100644 index 00000000000..567c5db07d0 --- /dev/null +++ b/src/tools/miri/test-cargo-miri/test.multiple_targets.stdout.ref @@ -0,0 +1,22 @@ + +running 2 tests +.. +test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + + +running 2 tests +.. +test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + +imported main +imported main + +running 6 tests +...i.. +test result: ok. 5 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME + + +running 6 tests +...i.. +test result: ok. 5 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME + |
