Auto merge of #3702 - Mandragorian:multiple_targets, r=RalfJung
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
This commit is contained in:
commit
86995400f3
4 changed files with 61 additions and 11 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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__)))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue