Auto merge of #3588 - RossSmyth:CliTarget, r=RalfJung
Allow test targets to be set via CLI args Fixes #3584 I'm not a pro shell script reader as I am a Windows user, but we shall see if the CI script broke.
This commit is contained in:
commit
42d9b6890e
@ -72,14 +72,14 @@ For example:
|
|||||||
|
|
||||||
You can (cross-)run the entire test suite using:
|
You can (cross-)run the entire test suite using:
|
||||||
|
|
||||||
```
|
```sh
|
||||||
./miri test
|
./miri test
|
||||||
MIRI_TEST_TARGET=i686-unknown-linux-gnu ./miri test
|
./miri test --target i686-unknown-linux-gnu
|
||||||
```
|
```
|
||||||
|
|
||||||
`./miri test FILTER` only runs those tests that contain `FILTER` in their filename (including the
|
`./miri test FILTER` only runs those tests that contain `FILTER` in their filename (including the
|
||||||
base directory, e.g. `./miri test fail` will run all compile-fail tests). These filters are passed
|
base directory, e.g. `./miri test fail` will run all compile-fail tests). Multiple filters
|
||||||
to `cargo test`, so for multiple filters you need to use `./miri test -- FILTER1 FILTER2`.
|
are supported: `./miri test FILTER1 FILTER2`.
|
||||||
|
|
||||||
#### Fine grained logging
|
#### Fine grained logging
|
||||||
|
|
||||||
|
@ -464,7 +464,7 @@ by all intended entry points, i.e. `cargo miri` and `./miri {test,run}`):
|
|||||||
setup -- only set this if you do not want to use the automatically created sysroot. When invoking
|
setup -- only set this if you do not want to use the automatically created sysroot. When invoking
|
||||||
`cargo miri setup`, this indicates where the sysroot will be put.
|
`cargo miri setup`, this indicates where the sysroot will be put.
|
||||||
* `MIRI_TEST_TARGET` (recognized by `./miri {test,run}`) indicates which target
|
* `MIRI_TEST_TARGET` (recognized by `./miri {test,run}`) indicates which target
|
||||||
architecture to test against. `miri` and `cargo miri` accept the `--target` flag for the same
|
architecture to test against. The `--target` flag may be used for the same
|
||||||
purpose.
|
purpose.
|
||||||
* `MIRI_TEST_THREADS` (recognized by `./miri test`): set the number of threads to use for running tests.
|
* `MIRI_TEST_THREADS` (recognized by `./miri test`): set the number of threads to use for running tests.
|
||||||
By default, the number of cores is used.
|
By default, the number of cores is used.
|
||||||
|
@ -59,7 +59,7 @@ function run_tests {
|
|||||||
# them. Also error locations change so we don't run the failing tests.
|
# them. Also error locations change so we don't run the failing tests.
|
||||||
# We explicitly enable debug-assertions here, they are disabled by -O but we have tests
|
# We explicitly enable debug-assertions here, they are disabled by -O but we have tests
|
||||||
# which exist to check that we panic on debug assertion failures.
|
# which exist to check that we panic on debug assertion failures.
|
||||||
time MIRIFLAGS="${MIRIFLAGS-} -O -Zmir-opt-level=4 -Cdebug-assertions=yes" MIRI_SKIP_UI_CHECKS=1 ./miri test -- tests/{pass,panic}
|
time MIRIFLAGS="${MIRIFLAGS-} -O -Zmir-opt-level=4 -Cdebug-assertions=yes" MIRI_SKIP_UI_CHECKS=1 ./miri test tests/{pass,panic}
|
||||||
fi
|
fi
|
||||||
if [ -n "${MANY_SEEDS-}" ]; then
|
if [ -n "${MANY_SEEDS-}" ]; then
|
||||||
# Also run some many-seeds tests.
|
# Also run some many-seeds tests.
|
||||||
@ -107,7 +107,7 @@ function run_tests_minimal {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
time ./miri test -- "$@"
|
time ./miri test "$@"
|
||||||
|
|
||||||
# Ensure that a small smoke test of cargo-miri works.
|
# Ensure that a small smoke test of cargo-miri works.
|
||||||
time cargo miri run --manifest-path test-cargo-miri/no-std-smoke/Cargo.toml --target ${MIRI_TEST_TARGET-$HOST_TARGET}
|
time cargo miri run --manifest-path test-cargo-miri/no-std-smoke/Cargo.toml --target ${MIRI_TEST_TARGET-$HOST_TARGET}
|
||||||
|
@ -23,7 +23,9 @@ const JOSH_PORT: &str = "42042";
|
|||||||
|
|
||||||
impl MiriEnv {
|
impl MiriEnv {
|
||||||
/// Returns the location of the sysroot.
|
/// Returns the location of the sysroot.
|
||||||
fn build_miri_sysroot(&mut self, quiet: bool) -> Result<PathBuf> {
|
///
|
||||||
|
/// If the target is None the sysroot will be built for the host machine.
|
||||||
|
fn build_miri_sysroot(&mut self, quiet: bool, target: Option<&str>) -> Result<PathBuf> {
|
||||||
if let Some(miri_sysroot) = self.sh.var_os("MIRI_SYSROOT") {
|
if let Some(miri_sysroot) = self.sh.var_os("MIRI_SYSROOT") {
|
||||||
// Sysroot already set, use that.
|
// Sysroot already set, use that.
|
||||||
return Ok(miri_sysroot.into());
|
return Ok(miri_sysroot.into());
|
||||||
@ -35,26 +37,27 @@ impl MiriEnv {
|
|||||||
self.build(path!(self.miri_dir / "Cargo.toml"), &[], quiet)?;
|
self.build(path!(self.miri_dir / "Cargo.toml"), &[], quiet)?;
|
||||||
self.build(&manifest_path, &[], quiet)?;
|
self.build(&manifest_path, &[], quiet)?;
|
||||||
|
|
||||||
let target = &match self.sh.var("MIRI_TEST_TARGET") {
|
let target_flag =
|
||||||
Ok(target) => vec!["--target".into(), target],
|
&if let Some(target) = target { vec!["--target", target] } else { vec![] };
|
||||||
Err(_) => vec![],
|
|
||||||
};
|
|
||||||
if !quiet {
|
if !quiet {
|
||||||
match self.sh.var("MIRI_TEST_TARGET") {
|
if let Some(target) = target {
|
||||||
Ok(target) => eprintln!("$ (building Miri sysroot for {target})"),
|
eprintln!("$ (building Miri sysroot for {target})");
|
||||||
Err(_) => eprintln!("$ (building Miri sysroot)"),
|
} else {
|
||||||
|
eprintln!("$ (building Miri sysroot)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let output = cmd!(self.sh,
|
let output = cmd!(self.sh,
|
||||||
"cargo +{toolchain} --quiet run {cargo_extra_flags...} --manifest-path {manifest_path} --
|
"cargo +{toolchain} --quiet run {cargo_extra_flags...} --manifest-path {manifest_path} --
|
||||||
miri setup --print-sysroot {target...}"
|
miri setup --print-sysroot {target_flag...}"
|
||||||
).read();
|
).read();
|
||||||
let Ok(output) = output else {
|
let Ok(output) = output else {
|
||||||
// Run it again (without `--print-sysroot` or `--quiet`) so the user can see the error.
|
// Run it again (without `--print-sysroot` or `--quiet`) so the user can see the error.
|
||||||
cmd!(
|
cmd!(
|
||||||
self.sh,
|
self.sh,
|
||||||
"cargo +{toolchain} run {cargo_extra_flags...} --manifest-path {manifest_path} --
|
"cargo +{toolchain} run {cargo_extra_flags...} --manifest-path {manifest_path} --
|
||||||
miri setup {target...}"
|
miri setup {target_flag...}"
|
||||||
)
|
)
|
||||||
.run()
|
.run()
|
||||||
.with_context(|| "`cargo miri setup` failed")?;
|
.with_context(|| "`cargo miri setup` failed")?;
|
||||||
@ -161,7 +164,7 @@ impl Command {
|
|||||||
Command::Install { flags } => Self::install(flags),
|
Command::Install { flags } => Self::install(flags),
|
||||||
Command::Build { flags } => Self::build(flags),
|
Command::Build { flags } => Self::build(flags),
|
||||||
Command::Check { flags } => Self::check(flags),
|
Command::Check { flags } => Self::check(flags),
|
||||||
Command::Test { bless, flags } => Self::test(bless, flags),
|
Command::Test { bless, flags, target } => Self::test(bless, flags, target),
|
||||||
Command::Run { dep, verbose, many_seeds, flags } =>
|
Command::Run { dep, verbose, many_seeds, flags } =>
|
||||||
Self::run(dep, verbose, many_seeds, flags),
|
Self::run(dep, verbose, many_seeds, flags),
|
||||||
Command::Fmt { flags } => Self::fmt(flags),
|
Command::Fmt { flags } => Self::fmt(flags),
|
||||||
@ -446,16 +449,23 @@ impl Command {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test(bless: bool, flags: Vec<OsString>) -> Result<()> {
|
fn test(bless: bool, flags: Vec<OsString>, target: Option<String>) -> Result<()> {
|
||||||
let mut e = MiriEnv::new()?;
|
let mut e = MiriEnv::new()?;
|
||||||
|
|
||||||
|
if let Some(target) = target.as_deref() {
|
||||||
|
// Tell the sysroot which target to test.
|
||||||
|
e.sh.set_var("MIRI_TEST_TARGET", target);
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare a sysroot.
|
// Prepare a sysroot.
|
||||||
e.build_miri_sysroot(/* quiet */ false)?;
|
e.build_miri_sysroot(/* quiet */ false, target.as_deref())?;
|
||||||
|
|
||||||
// Then test, and let caller control flags.
|
// Then test, and let caller control flags.
|
||||||
// Only in root project as `cargo-miri` has no tests.
|
// Only in root project as `cargo-miri` has no tests.
|
||||||
if bless {
|
if bless {
|
||||||
e.sh.set_var("RUSTC_BLESS", "Gesundheit");
|
e.sh.set_var("RUSTC_BLESS", "Gesundheit");
|
||||||
}
|
}
|
||||||
|
|
||||||
e.test(path!(e.miri_dir / "Cargo.toml"), &flags)?;
|
e.test(path!(e.miri_dir / "Cargo.toml"), &flags)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -476,14 +486,24 @@ impl Command {
|
|||||||
.take_while(|arg| *arg != "--")
|
.take_while(|arg| *arg != "--")
|
||||||
.tuple_windows()
|
.tuple_windows()
|
||||||
.find(|(first, _)| *first == "--target");
|
.find(|(first, _)| *first == "--target");
|
||||||
if let Some((_, target)) = target {
|
|
||||||
|
let target_triple = if let Some((_, target)) = target {
|
||||||
// Found it!
|
// Found it!
|
||||||
e.sh.set_var("MIRI_TEST_TARGET", target);
|
e.sh.set_var("MIRI_TEST_TARGET", target);
|
||||||
|
|
||||||
|
let triple =
|
||||||
|
target.clone().into_string().map_err(|_| anyhow!("target triple is not UTF-8"))?;
|
||||||
|
Some(triple)
|
||||||
} else if let Ok(target) = std::env::var("MIRI_TEST_TARGET") {
|
} else if let Ok(target) = std::env::var("MIRI_TEST_TARGET") {
|
||||||
// Convert `MIRI_TEST_TARGET` into `--target`.
|
// Convert `MIRI_TEST_TARGET` into `--target`.
|
||||||
flags.push("--target".into());
|
flags.push("--target".into());
|
||||||
flags.push(target.into());
|
flags.push(target.clone().into());
|
||||||
}
|
|
||||||
|
Some(target)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
// Scan for "--edition", set one ourselves if that flag is not present.
|
// Scan for "--edition", set one ourselves if that flag is not present.
|
||||||
let have_edition =
|
let have_edition =
|
||||||
flags.iter().take_while(|arg| *arg != "--").any(|arg| *arg == "--edition");
|
flags.iter().take_while(|arg| *arg != "--").any(|arg| *arg == "--edition");
|
||||||
@ -492,7 +512,8 @@ impl Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prepare a sysroot, and add it to the flags.
|
// Prepare a sysroot, and add it to the flags.
|
||||||
let miri_sysroot = e.build_miri_sysroot(/* quiet */ !verbose)?;
|
let miri_sysroot =
|
||||||
|
e.build_miri_sysroot(/* quiet */ !verbose, target_triple.as_deref())?;
|
||||||
flags.push("--sysroot".into());
|
flags.push("--sysroot".into());
|
||||||
flags.push(miri_sysroot.into());
|
flags.push(miri_sysroot.into());
|
||||||
|
|
||||||
|
@ -33,6 +33,9 @@ pub enum Command {
|
|||||||
bless: bool,
|
bless: bool,
|
||||||
/// Flags that are passed through to `cargo test`.
|
/// Flags that are passed through to `cargo test`.
|
||||||
flags: Vec<OsString>,
|
flags: Vec<OsString>,
|
||||||
|
/// The cross-interpretation target.
|
||||||
|
/// If none then the host is the target.
|
||||||
|
target: Option<String>,
|
||||||
},
|
},
|
||||||
/// Build miri, set up a sysroot and then run the driver with the given <flags>.
|
/// Build miri, set up a sysroot and then run the driver with the given <flags>.
|
||||||
/// (Also respects MIRIFLAGS environment variable.)
|
/// (Also respects MIRIFLAGS environment variable.)
|
||||||
@ -84,9 +87,9 @@ Just build miri. <flags> are passed to `cargo build`.
|
|||||||
./miri check <flags>:
|
./miri check <flags>:
|
||||||
Just check miri. <flags> are passed to `cargo check`.
|
Just check miri. <flags> are passed to `cargo check`.
|
||||||
|
|
||||||
./miri test [--bless] <flags>:
|
./miri test [--bless] [--target <target>] <flags>:
|
||||||
Build miri, set up a sysroot and then run the test suite. <flags> are passed
|
Build miri, set up a sysroot and then run the test suite. <flags> are passed
|
||||||
to the final `cargo test` invocation.
|
to the test harness.
|
||||||
|
|
||||||
./miri run [--dep] [-v|--verbose] [--many-seeds|--many-seeds=..to|--many-seeds=from..to] <flags>:
|
./miri run [--dep] [-v|--verbose] [--many-seeds|--many-seeds=..to|--many-seeds=from..to] <flags>:
|
||||||
Build miri, set up a sysroot and then run the driver with the given <flags>.
|
Build miri, set up a sysroot and then run the driver with the given <flags>.
|
||||||
@ -147,12 +150,38 @@ fn main() -> Result<()> {
|
|||||||
Some("build") => Command::Build { flags: args.collect() },
|
Some("build") => Command::Build { flags: args.collect() },
|
||||||
Some("check") => Command::Check { flags: args.collect() },
|
Some("check") => Command::Check { flags: args.collect() },
|
||||||
Some("test") => {
|
Some("test") => {
|
||||||
let bless = args.peek().is_some_and(|a| a.to_str() == Some("--bless"));
|
let mut target = std::env::var("MIRI_TEST_TARGET").ok();
|
||||||
if bless {
|
let mut bless = false;
|
||||||
// Consume the flag.
|
|
||||||
|
while let Some(arg) = args.peek().and_then(|s| s.to_str()) {
|
||||||
|
match arg {
|
||||||
|
"--bless" => bless = true,
|
||||||
|
"--target" => {
|
||||||
|
// Skip "--target"
|
||||||
|
args.next().unwrap();
|
||||||
|
|
||||||
|
// Check that there is a target triple, and that it is unicode.
|
||||||
|
target = if let Some(value) = args.peek() {
|
||||||
|
let target_str = value
|
||||||
|
.clone()
|
||||||
|
.into_string()
|
||||||
|
.map_err(|_| anyhow!("target triple is not UTF-8"))?;
|
||||||
|
Some(target_str)
|
||||||
|
} else {
|
||||||
|
bail!("no target triple found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Only parse the leading flags.
|
||||||
|
_ => break,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Consume the flag, look at the next one.
|
||||||
args.next().unwrap();
|
args.next().unwrap();
|
||||||
}
|
}
|
||||||
Command::Test { bless, flags: args.collect() }
|
|
||||||
|
// Prepend a "--" so that the rest of the arguments are passed to the test driver.
|
||||||
|
let args = std::iter::once(OsString::from("--")).chain(args);
|
||||||
|
Command::Test { bless, flags: args.collect(), target }
|
||||||
}
|
}
|
||||||
Some("run") => {
|
Some("run") => {
|
||||||
let mut dep = false;
|
let mut dep = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user