Skip to content

Commit d2ce84e

Browse files
authored
Rollup merge of #145926 - Zalathar:no-libtest, r=jieyouxu
compiletest: Remove several remnants of the old libtest-based executor I noticed a few bits of low-hanging cleanup that are possible now that the non-libtest executor is well and truly established.
2 parents 3f89664 + 113aeac commit d2ce84e

File tree

6 files changed

+53
-90
lines changed

6 files changed

+53
-90
lines changed

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,8 +2025,6 @@ HELP: You can add it into `bootstrap.toml` in `rust.codegen-backends = [{name:?}
20252025
cmd.arg("--verbose");
20262026
}
20272027

2028-
cmd.arg("--json");
2029-
20302028
if builder.config.rustc_debug_assertions {
20312029
cmd.arg("--with-rustc-debug-assertions");
20322030
}

src/tools/compiletest/src/common.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use camino::{Utf8Path, Utf8PathBuf};
88
use semver::Version;
99
use serde::de::{Deserialize, Deserializer, Error as _};
1010

11-
use crate::executor::{ColorConfig, OutputFormat};
11+
use crate::executor::ColorConfig;
1212
use crate::fatal;
1313
use crate::util::{Utf8PathBufExt, add_dylib_path, string_enum};
1414

@@ -565,13 +565,6 @@ pub struct Config {
565565
/// FIXME: this is *way* too coarse; the user can't select *which* info to verbosely dump.
566566
pub verbose: bool,
567567

568-
/// (Useless) Adjust libtest output format.
569-
///
570-
/// FIXME: the hand-rolled executor does not support non-JSON output, because `compiletest` need
571-
/// to package test outcome as `libtest`-esque JSON that `bootstrap` can intercept *anyway*.
572-
/// However, now that we don't use the `libtest` executor, this is useless.
573-
pub format: OutputFormat,
574-
575568
/// Whether to use colors in test output.
576569
///
577570
/// Note: the exact control mechanism is delegated to [`colored`].
@@ -768,7 +761,6 @@ impl Config {
768761
adb_device_status: Default::default(),
769762
lldb_python_dir: Default::default(),
770763
verbose: Default::default(),
771-
format: Default::default(),
772764
color: Default::default(),
773765
remote_test_client: Default::default(),
774766
compare_mode: Default::default(),

src/tools/compiletest/src/executor.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
//! This module contains a reimplementation of the subset of libtest
22
//! functionality needed by compiletest.
3+
//!
4+
//! FIXME(Zalathar): Much of this code was originally designed to mimic libtest
5+
//! as closely as possible, for ease of migration. Now that libtest is no longer
6+
//! used, we can potentially redesign things to be a better fit for compiletest.
37
48
use std::borrow::Cow;
59
use std::collections::HashMap;
@@ -207,7 +211,7 @@ impl TestOutcome {
207211
///
208212
/// Adapted from `filter_tests` in libtest.
209213
///
210-
/// FIXME(#139660): After the libtest dependency is removed, redesign the whole filtering system to
214+
/// FIXME(#139660): Now that libtest has been removed, redesign the whole filtering system to
211215
/// do a better job of understanding and filtering _paths_, instead of being tied to libtest's
212216
/// substring/exact matching behaviour.
213217
fn filter_tests(opts: &Config, tests: Vec<CollectedTest>) -> Vec<CollectedTest> {
@@ -249,15 +253,15 @@ fn get_concurrency() -> usize {
249253
}
250254
}
251255

252-
/// Information needed to create a `test::TestDescAndFn`.
256+
/// Information that was historically needed to create a libtest `TestDescAndFn`.
253257
pub(crate) struct CollectedTest {
254258
pub(crate) desc: CollectedTestDesc,
255259
pub(crate) config: Arc<Config>,
256260
pub(crate) testpaths: TestPaths,
257261
pub(crate) revision: Option<String>,
258262
}
259263

260-
/// Information needed to create a `test::TestDesc`.
264+
/// Information that was historically needed to create a libtest `TestDesc`.
261265
pub(crate) struct CollectedTestDesc {
262266
pub(crate) name: String,
263267
pub(crate) ignore: bool,
@@ -274,18 +278,6 @@ pub enum ColorConfig {
274278
NeverColor,
275279
}
276280

277-
/// Format of the test results output.
278-
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
279-
pub enum OutputFormat {
280-
/// Verbose output
281-
Pretty,
282-
/// Quiet output
283-
#[default]
284-
Terse,
285-
/// JSON output
286-
Json,
287-
}
288-
289281
/// Whether test is expected to panic or not.
290282
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
291283
pub(crate) enum ShouldPanic {

src/tools/compiletest/src/lib.rs

Lines changed: 43 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use crate::common::{
4343
expected_output_path, output_base_dir, output_relative_path,
4444
};
4545
use crate::directives::DirectivesCache;
46-
use crate::executor::{CollectedTest, ColorConfig, OutputFormat};
46+
use crate::executor::{CollectedTest, ColorConfig};
4747
use crate::util::logv;
4848

4949
/// Creates the `Config` instance for this invocation of compiletest.
@@ -137,9 +137,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
137137
"overwrite stderr/stdout files instead of complaining about a mismatch",
138138
)
139139
.optflag("", "fail-fast", "stop as soon as possible after any test fails")
140-
.optflag("", "quiet", "print one character per test instead of one line")
141140
.optopt("", "color", "coloring: auto, always, never", "WHEN")
142-
.optflag("", "json", "emit json output instead of plaintext output")
143141
.optopt("", "target", "the target to build for", "TARGET")
144142
.optopt("", "host", "the host to build for", "HOST")
145143
.optopt("", "cdb", "path to CDB to use for CDB debuginfo tests", "PATH")
@@ -203,7 +201,6 @@ pub fn parse_config(args: Vec<String>) -> Config {
203201
"COMMAND",
204202
)
205203
.reqopt("", "minicore-path", "path to minicore aux library", "PATH")
206-
.optflag("N", "no-new-executor", "disables the new test executor, and uses libtest instead")
207204
.optopt(
208205
"",
209206
"debugger",
@@ -436,12 +433,6 @@ pub fn parse_config(args: Vec<String>) -> Config {
436433
&& !opt_str2(matches.opt_str("adb-test-dir")).is_empty(),
437434
lldb_python_dir: matches.opt_str("lldb-python-dir"),
438435
verbose: matches.opt_present("verbose"),
439-
format: match (matches.opt_present("quiet"), matches.opt_present("json")) {
440-
(true, true) => panic!("--quiet and --json are incompatible"),
441-
(true, false) => OutputFormat::Terse,
442-
(false, true) => OutputFormat::Json,
443-
(false, false) => OutputFormat::Pretty,
444-
},
445436
only_modified: matches.opt_present("only-modified"),
446437
color,
447438
remote_test_client: matches.opt_str("remote-test-client").map(Utf8PathBuf::from),
@@ -527,7 +518,6 @@ pub fn log_config(config: &Config) {
527518
logv(c, format!("target-linker: {:?}", config.target_linker));
528519
logv(c, format!("host-linker: {:?}", config.host_linker));
529520
logv(c, format!("verbose: {}", config.verbose));
530-
logv(c, format!("format: {:?}", config.format));
531521
logv(c, format!("minicore_path: {}", config.minicore_path));
532522
logv(c, "\n".to_string());
533523
}
@@ -601,7 +591,7 @@ pub fn run_tests(config: Arc<Config>) {
601591
configs.push(config.clone());
602592
};
603593

604-
// Discover all of the tests in the test suite directory, and build a libtest
594+
// Discover all of the tests in the test suite directory, and build a `CollectedTest`
605595
// structure for each test (or each revision of a multi-revision test).
606596
let mut tests = Vec::new();
607597
for c in configs {
@@ -613,50 +603,35 @@ pub fn run_tests(config: Arc<Config>) {
613603
// Delegate to the executor to filter and run the big list of test structures
614604
// created during test discovery. When the executor decides to run a test,
615605
// it will return control to the rest of compiletest by calling `runtest::run`.
616-
// FIXME(Zalathar): Once we're confident that we won't need to revert the
617-
// removal of the libtest-based executor, remove this Result and other
618-
// remnants of the old executor.
619-
let res: io::Result<bool> = Ok(executor::run_tests(&config, tests));
620-
621-
// Check the outcome reported by libtest.
622-
match res {
623-
Ok(true) => {}
624-
Ok(false) => {
625-
// We want to report that the tests failed, but we also want to give
626-
// some indication of just what tests we were running. Especially on
627-
// CI, where there can be cross-compiled tests for a lot of
628-
// architectures, without this critical information it can be quite
629-
// easy to miss which tests failed, and as such fail to reproduce
630-
// the failure locally.
631-
632-
let mut msg = String::from("Some tests failed in compiletest");
633-
write!(msg, " suite={}", config.suite).unwrap();
634-
635-
if let Some(compare_mode) = config.compare_mode.as_ref() {
636-
write!(msg, " compare_mode={}", compare_mode).unwrap();
637-
}
606+
let ok = executor::run_tests(&config, tests);
607+
608+
// Check the outcome reported by the executor.
609+
if !ok {
610+
// We want to report that the tests failed, but we also want to give
611+
// some indication of just what tests we were running. Especially on
612+
// CI, where there can be cross-compiled tests for a lot of
613+
// architectures, without this critical information it can be quite
614+
// easy to miss which tests failed, and as such fail to reproduce
615+
// the failure locally.
616+
617+
let mut msg = String::from("Some tests failed in compiletest");
618+
write!(msg, " suite={}", config.suite).unwrap();
619+
620+
if let Some(compare_mode) = config.compare_mode.as_ref() {
621+
write!(msg, " compare_mode={}", compare_mode).unwrap();
622+
}
638623

639-
if let Some(pass_mode) = config.force_pass_mode.as_ref() {
640-
write!(msg, " pass_mode={}", pass_mode).unwrap();
641-
}
624+
if let Some(pass_mode) = config.force_pass_mode.as_ref() {
625+
write!(msg, " pass_mode={}", pass_mode).unwrap();
626+
}
642627

643-
write!(msg, " mode={}", config.mode).unwrap();
644-
write!(msg, " host={}", config.host).unwrap();
645-
write!(msg, " target={}", config.target).unwrap();
628+
write!(msg, " mode={}", config.mode).unwrap();
629+
write!(msg, " host={}", config.host).unwrap();
630+
write!(msg, " target={}", config.target).unwrap();
646631

647-
println!("{msg}");
632+
println!("{msg}");
648633

649-
std::process::exit(1);
650-
}
651-
Err(e) => {
652-
// We don't know if tests passed or not, but if there was an error
653-
// during testing we don't want to just succeed (we may not have
654-
// tested something), so fail.
655-
//
656-
// This should realistically "never" happen, so don't try to make
657-
// this a pretty error message.
658-
panic!("I/O failure during tests: {:?}", e);
659-
}
634+
std::process::exit(1);
660635
}
661636
}
662637

@@ -691,7 +666,11 @@ impl TestCollector {
691666
///
692667
/// This always inspects _all_ test files in the suite (e.g. all 17k+ ui tests),
693668
/// regardless of whether any filters/tests were specified on the command-line,
694-
/// because filtering is handled later by libtest.
669+
/// because filtering is handled later by code that was copied from libtest.
670+
///
671+
/// FIXME(Zalathar): Now that we no longer rely on libtest, try to overhaul
672+
/// test discovery to take into account the filters/tests specified on the
673+
/// command-line, instead of having to enumerate everything.
695674
pub(crate) fn collect_and_make_tests(config: Arc<Config>) -> Vec<CollectedTest> {
696675
debug!("making tests from {}", config.src_test_suite_root);
697676
let common_inputs_stamp = common_inputs_stamp(&config);
@@ -805,7 +784,7 @@ fn modified_tests(config: &Config, dir: &Utf8Path) -> Result<Vec<Utf8PathBuf>, S
805784
}
806785

807786
/// Recursively scans a directory to find test files and create test structures
808-
/// that will be handed over to libtest.
787+
/// that will be handed over to the executor.
809788
fn collect_tests_from_dir(
810789
cx: &TestCollectorCx,
811790
dir: &Utf8Path,
@@ -871,7 +850,7 @@ fn collect_tests_from_dir(
871850
if is_test(file_name)
872851
&& (!cx.config.only_modified || cx.modified_tests.contains(&file_path))
873852
{
874-
// We found a test file, so create the corresponding libtest structures.
853+
// We found a test file, so create the corresponding test structures.
875854
debug!(%file_path, "found test file");
876855

877856
// Record the stem of the test file, to check for overlaps later.
@@ -915,7 +894,7 @@ pub fn is_test(file_name: &str) -> bool {
915894
}
916895

917896
/// For a single test file, creates one or more test structures (one per revision) that can be
918-
/// handed over to libtest to run, possibly in parallel.
897+
/// handed over to the executor to run, possibly in parallel.
919898
fn make_test(cx: &TestCollectorCx, collector: &mut TestCollector, testpaths: &TestPaths) {
920899
// For run-make tests, each "test file" is actually a _directory_ containing an `rmake.rs`. But
921900
// for the purposes of directive parsing, we want to look at that recipe file, not the directory
@@ -929,7 +908,7 @@ fn make_test(cx: &TestCollectorCx, collector: &mut TestCollector, testpaths: &Te
929908
// Scan the test file to discover its revisions, if any.
930909
let early_props = EarlyProps::from_file(&cx.config, &test_path);
931910

932-
// Normally we create one libtest structure per revision, with two exceptions:
911+
// Normally we create one structure per revision, with two exceptions:
933912
// - If a test doesn't use revisions, create a dummy revision (None) so that
934913
// the test can still run.
935914
// - Incremental tests inherently can't run their revisions in parallel, so
@@ -944,12 +923,12 @@ fn make_test(cx: &TestCollectorCx, collector: &mut TestCollector, testpaths: &Te
944923
// For each revision (or the sole dummy revision), create and append a
945924
// `CollectedTest` that can be handed over to the test executor.
946925
collector.tests.extend(revisions.into_iter().map(|revision| {
947-
// Create a test name and description to hand over to libtest.
926+
// Create a test name and description to hand over to the executor.
948927
let src_file = fs::File::open(&test_path).expect("open test file to parse ignores");
949928
let test_name = make_test_name(&cx.config, testpaths, revision);
950-
// Create a libtest description for the test/revision.
929+
// Create a description struct for the test/revision.
951930
// This is where `ignore-*`/`only-*`/`needs-*` directives are handled,
952-
// because they need to set the libtest ignored flag.
931+
// because they historically needed to set the libtest ignored flag.
953932
let mut desc = make_test_description(
954933
&cx.config,
955934
&cx.cache,
@@ -961,10 +940,12 @@ fn make_test(cx: &TestCollectorCx, collector: &mut TestCollector, testpaths: &Te
961940
);
962941

963942
// If a test's inputs haven't changed since the last time it ran,
964-
// mark it as ignored so that libtest will skip it.
943+
// mark it as ignored so that the executor will skip it.
965944
if !cx.config.force_rerun && is_up_to_date(cx, testpaths, &early_props, revision) {
966945
desc.ignore = true;
967946
// Keep this in sync with the "up-to-date" message detected by bootstrap.
947+
// FIXME(Zalathar): Now that we are no longer tied to libtest, we could
948+
// find a less fragile way to communicate this status to bootstrap.
968949
desc.ignore_message = Some("up-to-date".into());
969950
}
970951

@@ -1104,7 +1085,7 @@ impl Stamp {
11041085
}
11051086
}
11061087

1107-
/// Creates a name for this test/revision that can be handed over to libtest.
1088+
/// Creates a name for this test/revision that can be handed over to the executor.
11081089
fn make_test_name(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> String {
11091090
// Print the name of the file, relative to the sources root.
11101091
let path = testpaths.file.strip_prefix(&config.src_root).unwrap();

src/tools/compiletest/src/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2222,7 +2222,7 @@ impl<'test> TestCx<'test> {
22222222
.env("PAGER", "")
22232223
.stdin(File::open(&diff_filename).unwrap())
22242224
// Capture output and print it explicitly so it will in turn be
2225-
// captured by libtest.
2225+
// captured by output-capture.
22262226
.output()
22272227
.unwrap();
22282228
assert!(output.status.success());

src/tools/compiletest/src/runtest/run_make.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ impl TestCx<'_> {
308308
let stdout = String::from_utf8_lossy(&stdout).into_owned();
309309
let stderr = String::from_utf8_lossy(&stderr).into_owned();
310310
// This conditions on `status.success()` so we don't print output twice on error.
311-
// NOTE: this code is called from a libtest thread, so it's hidden by default unless --nocapture is passed.
311+
// NOTE: this code is called from an executor thread, so it's hidden by default unless --no-capture is passed.
312312
self.dump_output(status.success(), &cmd.get_program().to_string_lossy(), &stdout, &stderr);
313313
if !status.success() {
314314
let res = ProcRes { status, stdout, stderr, truncated, cmdline: format!("{:?}", cmd) };

0 commit comments

Comments
 (0)