Skip to content

Commit e489d83

Browse files
committed
difftest: switch to mimic-libtest from tester
1 parent e6e3964 commit e489d83

File tree

10 files changed

+166
-166
lines changed

10 files changed

+166
-166
lines changed

Cargo.lock

Lines changed: 28 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ members = [
2828
"tests/compiletests",
2929
"tests/compiletests/deps-helper",
3030
"tests/difftests/bin",
31+
"tests/difftests/runner",
3132
"tests/difftests/lib",
3233
]
3334

@@ -50,6 +51,7 @@ spirv-tools = { version = "0.12", default-features = false }
5051
rustc_codegen_spirv = { path = "./crates/rustc_codegen_spirv", version = "=0.9.0", default-features = false }
5152
rustc_codegen_spirv-types = { path = "./crates/rustc_codegen_spirv-types", version = "=0.9.0" }
5253
rustc_codegen_spirv-target-specs = { path = "crates/rustc_codegen_spirv-target-specs", version = "=0.9.0" }
54+
difftest-runner = { path = "tests/difftests/runner" }
5355
tracing = "0.1"
5456
tracing-subscriber = { version = "0.3.3", features = ["env-filter", "json"] }
5557

tests/difftests/bin/Cargo.toml

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,17 @@ repository.workspace = true
99
# See rustc_codegen_spirv/Cargo.toml for details on these features
1010
[features]
1111
default = ["use-compiled-tools"]
12-
use-installed-tools = []
13-
use-compiled-tools = []
12+
use-installed-tools = ["difftest-runner/use-installed-tools"]
13+
use-compiled-tools = ["difftest-runner/use-compiled-tools"]
1414

1515
[dependencies]
1616
anyhow = "1.0"
17-
tracing = "0.1"
18-
tracing-subscriber = { version = "0.3", features = ["fmt", "env-filter"] }
19-
tester = "0.9.1"
20-
serde = { version = "1.0", features = ["derive"] }
21-
serde_json = "1.0"
22-
thiserror = "1.0"
23-
toml = { version = "0.8.20", default-features = false, features = ["parse"] }
24-
bytesize = "2.0.1"
25-
bytemuck = "1.21.0"
26-
difftest = { path = "../lib" }
27-
tabled = { version = "0.15", default-features = false, features = ["std"] }
28-
29-
[dev-dependencies]
30-
tempfile = "3.5"
17+
difftest-runner.workspace = true
3118

3219
[lints]
3320
workspace = true
21+
22+
[[test]]
23+
name = "difftests"
24+
path = "src/test.rs"
25+
harness = false

tests/difftests/bin/src/main.rs

Lines changed: 0 additions & 148 deletions
This file was deleted.

tests/difftests/bin/src/test.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use anyhow::Result;
2+
use std::process::ExitCode;
3+
4+
pub fn main() -> Result<ExitCode> {
5+
difftest_runner::run()
6+
}

tests/difftests/runner/Cargo.toml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[package]
2+
name = "difftest-runner"
3+
version.workspace = true
4+
authors.workspace = true
5+
edition.workspace = true
6+
license.workspace = true
7+
repository.workspace = true
8+
9+
# See rustc_codegen_spirv/Cargo.toml for details on these features
10+
[features]
11+
default = ["use-compiled-tools"]
12+
use-installed-tools = []
13+
use-compiled-tools = []
14+
15+
[dependencies]
16+
anyhow = "1.0"
17+
tracing = "0.1"
18+
tracing-subscriber = { version = "0.3", features = ["fmt", "env-filter"] }
19+
libtest-mimic = "0.8.1"
20+
serde = { version = "1.0", features = ["derive"] }
21+
serde_json = "1.0"
22+
thiserror = "1.0"
23+
toml = { version = "0.8.20", default-features = false, features = ["parse"] }
24+
bytesize = "2.0.1"
25+
bytemuck = "1.21.0"
26+
difftest = { path = "../lib" }
27+
tabled = { version = "0.15", default-features = false, features = ["std"] }
28+
29+
[dev-dependencies]
30+
tempfile = "3.5"
31+
32+
[lints]
33+
workspace = true

tests/difftests/runner/src/lib.rs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#![allow(clippy::exit)]
2+
3+
use crate::testcase::collect_test_dirs;
4+
use anyhow::Result;
5+
use libtest_mimic::{Arguments, Trial};
6+
use runner::Runner;
7+
use std::process::ExitCode;
8+
use std::sync::Arc;
9+
use std::{
10+
env, fs,
11+
process::{self},
12+
};
13+
use tracing_subscriber::FmtSubscriber;
14+
15+
mod differ;
16+
mod runner;
17+
mod testcase;
18+
19+
pub fn run() -> Result<ExitCode> {
20+
let subscriber = FmtSubscriber::builder()
21+
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
22+
.finish();
23+
tracing::subscriber::set_global_default(subscriber).expect("Failed to set global subscriber");
24+
25+
let mut args = Arguments::from_args();
26+
27+
// If filters are provided that look like paths (contain '/'), convert them to test names
28+
if let Some(filter) = &mut args.filter {
29+
*filter = filter.replace('/', "::");
30+
}
31+
32+
let tests = collect_tests()?;
33+
Ok(libtest_mimic::run(&args, tests).exit_code())
34+
}
35+
36+
fn collect_tests() -> Result<Vec<Trial>> {
37+
// Find the manifest directory at compile time and locate tests in ../tests.
38+
let manifest_dir = env!("CARGO_MANIFEST_DIR");
39+
let base = std::path::Path::new(manifest_dir)
40+
.join("../tests")
41+
.canonicalize()
42+
.expect("Failed to canonicalize tests directory");
43+
tracing::debug!("Using tests directory: {}", base.display());
44+
45+
let output_dir = std::path::Path::new(manifest_dir).join("../tests/target/difftest");
46+
fs::create_dir_all(&output_dir)?;
47+
let output_dir = output_dir
48+
.canonicalize()
49+
.expect("Failed to canonicalize tests directory");
50+
tracing::debug!("Using output directory: {}", output_dir.display());
51+
52+
let runner = Arc::new(Runner {
53+
base_dir: base.clone(),
54+
output_dir,
55+
});
56+
57+
let test_cases = collect_test_dirs(&base).expect("Failed to collect test case directories");
58+
if test_cases.is_empty() {
59+
eprintln!("No valid tests found in {}", base.display());
60+
process::exit(1);
61+
}
62+
63+
// // We build first to ensure that the tests are compiled before running them and to
64+
// // passthrough stdout and stderr from cargo to help debugging.
65+
// let mut cmd = Command::new("cargo");
66+
// let cmd = cmd.arg("build").arg("--release");
67+
// runner::forward_features(cmd);
68+
// cmd.current_dir(&base)
69+
// .stderr(process::Stdio::inherit())
70+
// .stdout(process::Stdio::inherit());
71+
// tracing::debug!("Running cargo command: {:?}", cmd);
72+
//
73+
// let output = cmd.output().expect("build output");
74+
// let exit_code = output.status.code().unwrap_or(-1);
75+
// tracing::debug!("Cargo build exited with code {}", exit_code);
76+
// if !output.status.success() {
77+
// tracing::error!("Cargo build failed");
78+
// process::exit(exit_code);
79+
// }
80+
81+
let trails = test_cases
82+
.into_iter()
83+
.map(|case| {
84+
let runner = runner.clone();
85+
Trial::test(case.to_string(), move || Ok(runner.run_test_case(&case)?))
86+
})
87+
.collect();
88+
Ok(trails)
89+
}

0 commit comments

Comments
 (0)