Skip to content

Commit afca9dc

Browse files
committed
Auto merge of rust-lang#2594 - RalfJung:target, r=RalfJung
print the target also when running tests on the host That makes errors a bit easier to analyze.
2 parents 3e5ffd8 + 4dc7532 commit afca9dc

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

src/tools/miri/Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ dependencies = [
419419
"rand",
420420
"regex",
421421
"rustc-workspace-hack",
422+
"rustc_version",
422423
"shell-escape",
423424
"smallvec",
424425
"ui_test",

src/tools/miri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ libloading = "0.7"
4141
[dev-dependencies]
4242
colored = "2"
4343
ui_test = "0.3.1"
44+
rustc_version = "0.4"
4445
# Features chosen to match those required by env_logger, to avoid rebuilds
4546
regex = { version = "1.5.5", default-features = false, features = ["perf", "std"] }
4647
lazy_static = "1.4.0"

src/tools/miri/tests/compiletest.rs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ fn miri_path() -> PathBuf {
88
PathBuf::from(option_env!("MIRI").unwrap_or(env!("CARGO_BIN_EXE_miri")))
99
}
1010

11+
fn get_host() -> String {
12+
rustc_version::VersionMeta::for_command(std::process::Command::new(miri_path()))
13+
.expect("failed to parse rustc version info")
14+
.host
15+
}
16+
1117
// Build the shared object file for testing external C function calls.
1218
fn build_so_for_c_ffi_tests() -> PathBuf {
1319
let cc = option_env!("CC").unwrap_or("cc");
@@ -37,14 +43,9 @@ fn build_so_for_c_ffi_tests() -> PathBuf {
3743
so_file_path
3844
}
3945

40-
fn run_tests(
41-
mode: Mode,
42-
path: &str,
43-
target: Option<String>,
44-
with_dependencies: bool,
45-
) -> Result<()> {
46+
fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> Result<()> {
4647
let mut config = Config {
47-
target,
48+
target: Some(target.to_owned()),
4849
stderr_filters: STDERR.clone(),
4950
stdout_filters: STDOUT.clone(),
5051
root_dir: PathBuf::from(path),
@@ -179,13 +180,8 @@ enum Dependencies {
179180

180181
use Dependencies::*;
181182

182-
fn ui(mode: Mode, path: &str, with_dependencies: Dependencies) -> Result<()> {
183-
let target = get_target();
184-
185-
let msg = format!(
186-
"## Running ui tests in {path} against miri for {}",
187-
target.as_deref().unwrap_or("host")
188-
);
183+
fn ui(mode: Mode, path: &str, target: &str, with_dependencies: Dependencies) -> Result<()> {
184+
let msg = format!("## Running ui tests in {path} against miri for {target}");
189185
eprintln!("{}", msg.green().bold());
190186

191187
let with_dependencies = match with_dependencies {
@@ -195,25 +191,31 @@ fn ui(mode: Mode, path: &str, with_dependencies: Dependencies) -> Result<()> {
195191
run_tests(mode, path, target, with_dependencies)
196192
}
197193

198-
fn get_target() -> Option<String> {
199-
env::var("MIRI_TEST_TARGET").ok()
194+
fn get_target() -> String {
195+
env::var("MIRI_TEST_TARGET").ok().unwrap_or_else(get_host)
200196
}
201197

202198
fn main() -> Result<()> {
203199
ui_test::color_eyre::install()?;
200+
let target = get_target();
204201

205202
// Add a test env var to do environment communication tests.
206203
env::set_var("MIRI_ENV_VAR_TEST", "0");
207204
// Let the tests know where to store temp files (they might run for a different target, which can make this hard to find).
208205
env::set_var("MIRI_TEMP", env::temp_dir());
209206

210-
ui(Mode::Pass, "tests/pass", WithoutDependencies)?;
211-
ui(Mode::Pass, "tests/pass-dep", WithDependencies)?;
212-
ui(Mode::Panic, "tests/panic", WithDependencies)?;
213-
ui(Mode::Fail { require_patterns: true }, "tests/fail", WithDependencies)?;
207+
ui(Mode::Pass, "tests/pass", &target, WithoutDependencies)?;
208+
ui(Mode::Pass, "tests/pass-dep", &target, WithDependencies)?;
209+
ui(Mode::Panic, "tests/panic", &target, WithDependencies)?;
210+
ui(Mode::Fail { require_patterns: true }, "tests/fail", &target, WithDependencies)?;
214211
if cfg!(target_os = "linux") {
215-
ui(Mode::Pass, "tests/extern-so/pass", WithoutDependencies)?;
216-
ui(Mode::Fail { require_patterns: true }, "tests/extern-so/fail", WithoutDependencies)?;
212+
ui(Mode::Pass, "tests/extern-so/pass", &target, WithoutDependencies)?;
213+
ui(
214+
Mode::Fail { require_patterns: true },
215+
"tests/extern-so/fail",
216+
&target,
217+
WithoutDependencies,
218+
)?;
217219
}
218220

219221
Ok(())

0 commit comments

Comments
 (0)