Auto merge of #2377 - rust-lang:only-on-host, r=oli-obk

Add test flag for running a test only on the host
This commit is contained in:
bors 2022-07-17 11:00:55 +00:00
commit 006bb3cd26
4 changed files with 16 additions and 10 deletions

7
miri
View File

@ -133,10 +133,9 @@ find_sysroot() {
# Run command.
case "$COMMAND" in
install)
# "--locked" to respect the Cargo.lock file if it exists,
# "--offline" to avoid querying the registry (for yanked packages).
$CARGO install $CARGO_EXTRA_FLAGS --path "$MIRIDIR" --force --locked --offline "$@"
$CARGO install $CARGO_EXTRA_FLAGS --path "$MIRIDIR"/cargo-miri --force --locked --offline "$@"
# "--locked" to respect the Cargo.lock file if it exists.
$CARGO install $CARGO_EXTRA_FLAGS --path "$MIRIDIR" --force --locked "$@"
$CARGO install $CARGO_EXTRA_FLAGS --path "$MIRIDIR"/cargo-miri --force --locked "$@"
;;
check)
# Check, and let caller control flags.

View File

@ -25,8 +25,10 @@ their command specifies, or the test will fail without even being run.
* `//@ignore-XXX` avoids running the test on targets whose triple contains `XXX`
* `XXX` can also be one of `64bit`, `32bit` or `16bit`
* `XXX` can also be `on-host`, which will only run the test during cross compilation testing.
* `//@only-XXX` avoids running the test on targets whose triple **does not** contain `XXX`
* `XXX` can also be one of `64bit`, `32bit` or `16bit`
* `XXX` can also be `on-host`, which will not run the test during cross compilation testing
* `//@stderr-per-bitwidth` produces one stderr file per bitwidth, as they may differ significantly sometimes
* `//@error-pattern: XXX` make sure the stderr output contains `XXX`
* `//@revisions: XXX YYY` runs the test once for each space separated name in the list

View File

@ -109,7 +109,7 @@ pub fn run_tests(config: Config) -> Result<()> {
}
let comments = Comments::parse_file(&path)?;
// Ignore file if only/ignore rules do (not) apply
if !test_file_conditions(&comments, &target) {
if !test_file_conditions(&comments, &target, &config) {
ignored.fetch_add(1, Ordering::Relaxed);
eprintln!(
"{} ... {}",
@ -499,19 +499,20 @@ fn output_path(path: &Path, comments: &Comments, kind: String, target: &str) ->
path.with_extension(kind)
}
fn test_condition(condition: &Condition, target: &str) -> bool {
fn test_condition(condition: &Condition, target: &str, config: &Config) -> bool {
match condition {
Condition::Bitwidth(bits) => get_pointer_width(target) == *bits,
Condition::Target(t) => target.contains(t),
Condition::OnHost => config.target.is_none(),
}
}
/// Returns whether according to the in-file conditions, this file should be run.
fn test_file_conditions(comments: &Comments, target: &str) -> bool {
if comments.ignore.iter().any(|c| test_condition(c, target)) {
fn test_file_conditions(comments: &Comments, target: &str, config: &Config) -> bool {
if comments.ignore.iter().any(|c| test_condition(c, target, config)) {
return false;
}
comments.only.iter().all(|c| test_condition(c, target))
comments.only.iter().all(|c| test_condition(c, target, config))
}
// Taken 1:1 from compiletest-rs

View File

@ -43,6 +43,8 @@ pub(crate) enum Condition {
Target(String),
/// Tests that the bitwidth is the given one.
Bitwidth(u8),
/// Tests that the target is the host.
OnHost,
}
#[derive(Debug, Clone)]
@ -64,7 +66,9 @@ pub(crate) struct ErrorMatch {
impl Condition {
fn parse(c: &str) -> Self {
if let Some(bits) = c.strip_suffix("bit") {
if c == "on-host" {
Condition::OnHost
} else if let Some(bits) = c.strip_suffix("bit") {
let bits: u8 = bits.parse().expect(
"ignore/only filter ending in 'bit' must be of the form 'Nbit' for some integer N",
);