compiletest/common.rs
1use std::borrow::Cow;
2use std::collections::{BTreeSet, HashMap, HashSet};
3use std::iter;
4use std::process::Command;
5use std::sync::OnceLock;
6
7use build_helper::git::GitConfig;
8use camino::{Utf8Path, Utf8PathBuf};
9use semver::Version;
10
11use crate::edition::Edition;
12use crate::fatal;
13use crate::util::{Utf8PathBufExt, add_dylib_path, string_enum};
14
15string_enum! {
16 #[derive(Clone, Copy, PartialEq, Debug)]
17 pub(crate) enum TestMode {
18 Pretty => "pretty",
19 DebugInfo => "debuginfo",
20 Codegen => "codegen",
21 RustdocHtml => "rustdoc-html",
22 RustdocJson => "rustdoc-json",
23 CodegenUnits => "codegen-units",
24 Incremental => "incremental",
25 RunMake => "run-make",
26 Ui => "ui",
27 RustdocJs => "rustdoc-js",
28 MirOpt => "mir-opt",
29 Assembly => "assembly",
30 CoverageMap => "coverage-map",
31 CoverageRun => "coverage-run",
32 Crashes => "crashes",
33 }
34}
35
36impl TestMode {
37 pub(crate) fn aux_dir_disambiguator(self) -> &'static str {
38 // Pretty-printing tests could run concurrently, and if they do,
39 // they need to keep their output segregated.
40 match self {
41 TestMode::Pretty => ".pretty",
42 _ => "",
43 }
44 }
45
46 pub(crate) fn output_dir_disambiguator(self) -> &'static str {
47 // Coverage tests use the same test files for multiple test modes,
48 // so each mode should have a separate output directory.
49 match self {
50 TestMode::CoverageMap | TestMode::CoverageRun => self.to_str(),
51 _ => "",
52 }
53 }
54}
55
56// Note that coverage tests use the same test files for multiple test modes.
57string_enum! {
58 #[derive(Clone, Copy, PartialEq, Debug)]
59 pub(crate) enum TestSuite {
60 AssemblyLlvm => "assembly-llvm",
61 CodegenLlvm => "codegen-llvm",
62 CodegenUnits => "codegen-units",
63 Coverage => "coverage",
64 CoverageRunRustdoc => "coverage-run-rustdoc",
65 Crashes => "crashes",
66 Debuginfo => "debuginfo",
67 Incremental => "incremental",
68 MirOpt => "mir-opt",
69 Pretty => "pretty",
70 RunMake => "run-make",
71 RunMakeCargo => "run-make-cargo",
72 RustdocHtml => "rustdoc-html",
73 RustdocGui => "rustdoc-gui",
74 RustdocJs => "rustdoc-js",
75 RustdocJsStd=> "rustdoc-js-std",
76 RustdocJson => "rustdoc-json",
77 RustdocUi => "rustdoc-ui",
78 Ui => "ui",
79 UiFullDeps => "ui-fulldeps",
80 BuildStd => "build-std",
81 }
82}
83
84string_enum! {
85 #[derive(Clone, Copy, PartialEq, Debug, Hash)]
86 pub(crate) enum PassMode {
87 Check => "check",
88 Build => "build",
89 Run => "run",
90 }
91}
92
93string_enum! {
94 #[derive(Clone, Copy, PartialEq, Debug, Hash)]
95 pub(crate) enum RunResult {
96 Pass => "run-pass",
97 Fail => "run-fail",
98 Crash => "run-crash",
99 }
100}
101
102#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
103pub(crate) enum RunFailMode {
104 /// Running the program must make it exit with a regular failure exit code
105 /// in the range `1..=127`. If the program is terminated by e.g. a signal
106 /// the test will fail.
107 Fail,
108 /// Running the program must result in a crash, e.g. by `SIGABRT` or
109 /// `SIGSEGV` on Unix or on Windows by having an appropriate NTSTATUS high
110 /// bit in the exit code.
111 Crash,
112 /// Running the program must either fail or crash. Useful for e.g. sanitizer
113 /// tests since some sanitizer implementations exit the process with code 1
114 /// to in the face of memory errors while others abort (crash) the process
115 /// in the face of memory errors.
116 FailOrCrash,
117}
118
119#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
120pub(crate) enum FailMode {
121 Check,
122 Build,
123 Run(RunFailMode),
124}
125
126string_enum! {
127 #[derive(Clone, Debug, PartialEq)]
128 pub(crate) enum CompareMode {
129 Polonius => "polonius",
130 NextSolver => "next-solver",
131 NextSolverCoherence => "next-solver-coherence",
132 SplitDwarf => "split-dwarf",
133 SplitDwarfSingle => "split-dwarf-single",
134 }
135}
136
137string_enum! {
138 #[derive(Clone, Copy, Debug, PartialEq)]
139 pub(crate) enum Debugger {
140 Cdb => "cdb",
141 Gdb => "gdb",
142 Lldb => "lldb",
143 }
144}
145
146#[derive(Clone, Copy, Debug, PartialEq, Default, serde::Deserialize)]
147#[serde(rename_all = "kebab-case")]
148pub(crate) enum PanicStrategy {
149 #[default]
150 Unwind,
151 Abort,
152}
153
154impl PanicStrategy {
155 pub(crate) fn for_miropt_test_tools(&self) -> miropt_test_tools::PanicStrategy {
156 match self {
157 PanicStrategy::Unwind => miropt_test_tools::PanicStrategy::Unwind,
158 PanicStrategy::Abort => miropt_test_tools::PanicStrategy::Abort,
159 }
160 }
161}
162
163#[derive(Clone, Debug, PartialEq, serde::Deserialize)]
164#[serde(rename_all = "kebab-case")]
165pub(crate) enum Sanitizer {
166 Address,
167 Cfi,
168 Dataflow,
169 Kcfi,
170 KernelAddress,
171 KernelHwaddress,
172 Leak,
173 Memory,
174 Memtag,
175 Safestack,
176 ShadowCallStack,
177 Thread,
178 Hwaddress,
179 Realtime,
180}
181
182#[derive(Clone, Copy, Debug, PartialEq)]
183pub(crate) enum CodegenBackend {
184 Cranelift,
185 Gcc,
186 Llvm,
187}
188
189impl<'a> TryFrom<&'a str> for CodegenBackend {
190 type Error = &'static str;
191
192 fn try_from(value: &'a str) -> Result<Self, Self::Error> {
193 match value.to_lowercase().as_str() {
194 "cranelift" => Ok(Self::Cranelift),
195 "gcc" => Ok(Self::Gcc),
196 "llvm" => Ok(Self::Llvm),
197 _ => Err("unknown backend"),
198 }
199 }
200}
201
202impl CodegenBackend {
203 pub(crate) fn as_str(self) -> &'static str {
204 match self {
205 Self::Cranelift => "cranelift",
206 Self::Gcc => "gcc",
207 Self::Llvm => "llvm",
208 }
209 }
210
211 pub(crate) fn is_llvm(self) -> bool {
212 matches!(self, Self::Llvm)
213 }
214}
215
216/// Configuration for `compiletest` *per invocation*.
217///
218/// In terms of `bootstrap`, this means that `./x test tests/ui tests/run-make` actually correspond
219/// to *two* separate invocations of `compiletest`.
220///
221/// FIXME: this `Config` struct should be broken up into smaller logically contained sub-config
222/// structs, it's too much of a "soup" of everything at the moment.
223///
224/// # Configuration sources
225///
226/// Configuration values for `compiletest` comes from several sources:
227///
228/// - CLI args passed from `bootstrap` while running the `compiletest` binary.
229/// - Env vars.
230/// - Discovery (e.g. trying to identify a suitable debugger based on filesystem discovery).
231/// - Cached output of running the `rustc` under test (e.g. output of `rustc` print requests).
232///
233/// FIXME: make sure we *clearly* account for sources of *all* config options.
234///
235/// FIXME: audit these options to make sure we are not hashing less than necessary for build stamp
236/// (for changed test detection).
237#[derive(Debug, Clone)]
238pub(crate) struct Config {
239 /// Some [`TestMode`]s support [snapshot testing], where a *reference snapshot* of outputs (of
240 /// `stdout`, `stderr`, or other form of artifacts) can be compared to the *actual output*.
241 ///
242 /// This option can be set to `true` to update the *reference snapshots* in-place, otherwise
243 /// `compiletest` will only try to compare.
244 ///
245 /// [snapshot testing]: https://jestjs.io/docs/snapshot-testing
246 pub(crate) bless: bool,
247
248 /// Attempt to stop as soon as possible after any test fails. We may still run a few more tests
249 /// before stopping when multiple test threads are used.
250 pub(crate) fail_fast: bool,
251
252 /// Path to libraries needed to run the *staged* `rustc`-under-test on the **host** platform.
253 ///
254 /// For example:
255 /// - `/home/ferris/rust/build/x86_64-unknown-linux-gnu/stage1/bin/lib`
256 pub(crate) host_compile_lib_path: Utf8PathBuf,
257
258 /// Path to libraries needed to run the compiled executable for the **target** platform. This
259 /// corresponds to the **target** sysroot libraries, including the **target** standard library.
260 ///
261 /// For example:
262 /// - `/home/ferris/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/i686-unknown-linux-gnu/lib`
263 ///
264 /// FIXME: this is very under-documented in conjunction with the `remote-test-client` scheme and
265 /// `RUNNER` scheme to actually run the target executable under the target platform environment,
266 /// cf. [`Self::remote_test_client`] and [`Self::runner`].
267 pub(crate) target_run_lib_path: Utf8PathBuf,
268
269 /// Path to the `rustc`-under-test.
270 ///
271 /// For `ui-fulldeps` test suite specifically:
272 ///
273 /// - This is the **stage 0** compiler when testing `ui-fulldeps` under `--stage=1`.
274 /// - This is the **stage 2** compiler when testing `ui-fulldeps` under `--stage=2`.
275 ///
276 /// See [`Self::query_rustc_path`] for the `--stage=1` `ui-fulldeps` scenario where a separate
277 /// in-tree `rustc` is used for querying target information.
278 ///
279 /// For example:
280 /// - `/home/ferris/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc`
281 ///
282 /// # Note on forced stage0
283 ///
284 /// It is possible for this `rustc` to be a stage 0 `rustc` if explicitly configured with the
285 /// bootstrap option `build.compiletest-allow-stage0=true` and specifying `--stage=0`.
286 pub(crate) rustc_path: Utf8PathBuf,
287
288 /// Path to a *staged* **host** platform cargo executable (unless stage 0 is forced). This
289 /// staged `cargo` is only used within `run-make` test recipes during recipe run time (and is
290 /// *not* used to compile the test recipes), and so must be staged as there may be differences
291 /// between e.g. beta `cargo` vs in-tree `cargo`.
292 ///
293 /// For example:
294 /// - `/home/ferris/rust/build/x86_64-unknown-linux-gnu/stage1-tools-bin/cargo`
295 ///
296 /// FIXME: maybe rename this to reflect that this is a *staged* host cargo.
297 pub(crate) cargo_path: Option<Utf8PathBuf>,
298
299 /// Path to the stage 0 `rustc` used to build `run-make` recipes. This must not be confused with
300 /// [`Self::rustc_path`].
301 ///
302 /// For example:
303 /// - `/home/ferris/rust/build/x86_64-unknown-linux-gnu/stage0/bin/rustc`
304 pub(crate) stage0_rustc_path: Option<Utf8PathBuf>,
305
306 /// Path to the stage 1 or higher `rustc` used to obtain target information via
307 /// `--print=all-target-specs-json` and similar queries.
308 ///
309 /// Normally this is unset, because [`Self::rustc_path`] can be used instead.
310 /// But when running "stage 1" ui-fulldeps tests, `rustc_path` is a stage 0
311 /// compiler, whereas target specs must be obtained from a stage 1+ compiler
312 /// (in case the JSON format has changed since the last bootstrap bump).
313 pub(crate) query_rustc_path: Option<Utf8PathBuf>,
314
315 /// Path to the `rustdoc`-under-test. Like [`Self::rustc_path`], this `rustdoc` is *staged*.
316 pub(crate) rustdoc_path: Option<Utf8PathBuf>,
317
318 /// Path to the `src/tools/coverage-dump/` bootstrap tool executable.
319 pub(crate) coverage_dump_path: Option<Utf8PathBuf>,
320
321 /// Path to the Python 3 executable to use for htmldocck and some run-make tests.
322 pub(crate) python: String,
323
324 /// Path to the `src/tools/jsondocck/` bootstrap tool executable.
325 pub(crate) jsondocck_path: Option<Utf8PathBuf>,
326
327 /// Path to the `src/tools/jsondoclint/` bootstrap tool executable.
328 pub(crate) jsondoclint_path: Option<Utf8PathBuf>,
329
330 /// Path to a host LLVM `FileCheck` executable.
331 pub(crate) llvm_filecheck: Option<Utf8PathBuf>,
332
333 /// Path to a host LLVM bintools directory.
334 ///
335 /// For example:
336 /// - `/home/ferris/rust/build/x86_64-unknown-linux-gnu/llvm/bin`
337 pub(crate) llvm_bin_dir: Option<Utf8PathBuf>,
338
339 /// The path to the **target** `clang` executable to run `clang`-based tests with. If `None`,
340 /// then these tests will be ignored.
341 pub(crate) run_clang_based_tests_with: Option<Utf8PathBuf>,
342
343 /// Path to the directory containing the sources. This corresponds to the root folder of a
344 /// `rust-lang/rust` checkout.
345 ///
346 /// For example:
347 /// - `/home/ferris/rust`
348 ///
349 /// FIXME: this name is confusing, because this is actually `$checkout_root`, **not** the
350 /// `$checkout_root/src/` folder.
351 pub(crate) src_root: Utf8PathBuf,
352
353 /// Absolute path to the test suite directory.
354 ///
355 /// For example:
356 /// - `/home/ferris/rust/tests/ui`
357 /// - `/home/ferris/rust/tests/coverage`
358 pub(crate) src_test_suite_root: Utf8PathBuf,
359
360 /// Path to the top-level build directory used by bootstrap.
361 ///
362 /// For example:
363 /// - `/home/ferris/rust/build`
364 pub(crate) build_root: Utf8PathBuf,
365
366 /// Path to the build directory used by the current test suite.
367 ///
368 /// For example:
369 /// - `/home/ferris/rust/build/x86_64-unknown-linux-gnu/test/ui`
370 /// - `/home/ferris/rust/build/x86_64-unknown-linux-gnu/test/coverage`
371 pub(crate) build_test_suite_root: Utf8PathBuf,
372
373 /// Path to the directory containing the sysroot of the `rustc`-under-test.
374 ///
375 /// For example:
376 /// - `/home/ferris/rust/build/x86_64-unknown-linux-gnu/stage1`
377 /// - `/home/ferris/rust/build/x86_64-unknown-linux-gnu/stage2`
378 ///
379 /// When stage 0 is forced, this will correspond to the sysroot *of* that specified stage 0
380 /// `rustc`.
381 ///
382 /// FIXME: this name is confusing, because it doesn't specify *which* compiler this sysroot
383 /// corresponds to. It's actually the `rustc`-under-test, and not the bootstrap `rustc`, unless
384 /// stage 0 is forced and no custom stage 0 `rustc` was otherwise specified (so that it
385 /// *happens* to run against the bootstrap `rustc`, but this non-custom bootstrap `rustc` case
386 /// is not really supported).
387 pub(crate) sysroot_base: Utf8PathBuf,
388
389 /// The number of the stage under test.
390 pub(crate) stage: u32,
391
392 /// The id of the stage under test (stage1-xxx, etc).
393 ///
394 /// FIXME: reconsider this string; this is hashed for test build stamp.
395 pub(crate) stage_id: String,
396
397 /// The [`TestMode`]. E.g. [`TestMode::Ui`]. Each test mode can correspond to one or more test
398 /// suites.
399 ///
400 /// FIXME: stop using stringly-typed test suites!
401 pub(crate) mode: TestMode,
402
403 /// The test suite.
404 ///
405 /// Example: `tests/ui/` is [`TestSuite::Ui`] test *suite*, which happens to also be of the
406 /// [`TestMode::Ui`] test *mode*.
407 ///
408 /// Note that the same test suite (e.g. `tests/coverage/`) may correspond to multiple test
409 /// modes, e.g. `tests/coverage/` can be run under both [`TestMode::CoverageRun`] and
410 /// [`TestMode::CoverageMap`].
411 pub(crate) suite: TestSuite,
412
413 /// When specified, **only** the specified [`Debugger`] will be used to run against the
414 /// `tests/debuginfo` test suite. When unspecified, `compiletest` will attempt to find all three
415 /// of {`lldb`, `cdb`, `gdb`} implicitly, and then try to run the `debuginfo` test suite against
416 /// all three debuggers.
417 ///
418 /// FIXME: this implicit behavior is really nasty, in that it makes it hard for the user to
419 /// control *which* debugger(s) are available and used to run the debuginfo test suite. We
420 /// should have `bootstrap` allow the user to *explicitly* configure the debuggers, and *not*
421 /// try to implicitly discover some random debugger from the user environment. This makes the
422 /// debuginfo test suite particularly hard to work with.
423 pub(crate) debugger: Option<Debugger>,
424
425 /// Run ignored tests *unconditionally*, overriding their ignore reason.
426 ///
427 /// FIXME: this is wired up through the test execution logic, but **not** accessible from
428 /// `bootstrap` directly; `compiletest` exposes this as `--ignored`. I.e. you'd have to use `./x
429 /// test $test_suite -- --ignored=true`.
430 pub(crate) run_ignored: bool,
431
432 /// Whether *staged* `rustc`-under-test was built with debug assertions.
433 ///
434 /// FIXME: make it clearer that this refers to the staged `rustc`-under-test, not stage 0
435 /// `rustc`.
436 pub(crate) with_rustc_debug_assertions: bool,
437
438 /// Whether *staged* `std` was built with debug assertions.
439 ///
440 /// FIXME: make it clearer that this refers to the staged `std`, not stage 0 `std`.
441 pub(crate) with_std_debug_assertions: bool,
442
443 /// Whether *staged* `std` was built with remapping of debuginfo.
444 ///
445 /// FIXME: make it clearer that this refers to the staged `std`, not stage 0 `std`.
446 pub(crate) with_std_remap_debuginfo: bool,
447
448 /// Only run tests that match these filters (using `libtest` "test name contains" filter logic).
449 ///
450 /// FIXME(#139660): the current hand-rolled test executor intentionally mimics the `libtest`
451 /// "test name contains" filter matching logic to preserve previous `libtest` executor behavior,
452 /// but this is often not intuitive. We should consider changing that behavior with an MCP to do
453 /// test path *prefix* matching which better corresponds to how `compiletest` `tests/` are
454 /// organized, and how users would intuitively expect the filtering logic to work like.
455 pub(crate) filters: Vec<String>,
456
457 /// Skip tests matching these substrings. The matching logic exactly corresponds to
458 /// [`Self::filters`] but inverted.
459 ///
460 /// FIXME(#139660): ditto on test matching behavior.
461 pub(crate) skip: Vec<String>,
462
463 /// Exactly match the filter, rather than a substring.
464 ///
465 /// FIXME(#139660): ditto on test matching behavior.
466 pub(crate) filter_exact: bool,
467
468 /// Force the pass mode of a check/build/run test to instead use this mode instead.
469 ///
470 /// FIXME: make it even more obvious (especially in PR CI where `--pass=check` is used) when a
471 /// pass mode is forced when the test fails, because it can be very non-obvious when e.g. an
472 /// error is emitted only when `//@ build-pass` but not `//@ check-pass`.
473 pub(crate) force_pass_mode: Option<PassMode>,
474
475 /// Explicitly enable or disable running of the target test binary.
476 ///
477 /// FIXME: this scheme is a bit confusing, and at times questionable. Re-evaluate this run
478 /// scheme.
479 ///
480 /// FIXME: Currently `--run` is a tri-state, it can be `--run={auto,always,never}`, and when
481 /// `--run=auto` is specified, it's run if the platform doesn't end with `-fuchsia`. See
482 /// [`Config::run_enabled`].
483 pub(crate) run: Option<bool>,
484
485 /// A command line to prefix target program execution with, for running under valgrind for
486 /// example, i.e. `$runner target.exe [args..]`. Similar to `CARGO_*_RUNNER` configuration.
487 ///
488 /// Note: this is not to be confused with [`Self::remote_test_client`], which is a different
489 /// scheme.
490 ///
491 /// FIXME: the runner scheme is very under-documented.
492 pub(crate) runner: Option<String>,
493
494 /// Compiler flags to pass to the *staged* `rustc`-under-test when building for the **host**
495 /// platform.
496 pub(crate) host_rustcflags: Vec<String>,
497
498 /// Compiler flags to pass to the *staged* `rustc`-under-test when building for the **target**
499 /// platform.
500 pub(crate) target_rustcflags: Vec<String>,
501
502 /// Whether the *staged* `rustc`-under-test and the associated *staged* `std` has been built
503 /// with randomized struct layouts.
504 pub(crate) rust_randomized_layout: bool,
505
506 /// Whether tests should be optimized by default (`-O`). Individual test suites and test files
507 /// may override this setting.
508 ///
509 /// FIXME: this flag / config option is somewhat misleading. For instance, in ui tests, it's
510 /// *only* applied to the [`PassMode::Run`] test crate and not its auxiliaries.
511 pub(crate) optimize_tests: bool,
512
513 /// Target platform tuple.
514 pub(crate) target: String,
515
516 /// Host platform tuple.
517 pub(crate) host: String,
518
519 /// Path to / name of the Microsoft Console Debugger (CDB) executable.
520 ///
521 /// FIXME: this is an *opt-in* "override" option. When this isn't provided, we try to conjure a
522 /// cdb by looking at the user's program files on Windows... See `debuggers::find_cdb`.
523 pub(crate) cdb: Option<Utf8PathBuf>,
524
525 /// Version of CDB.
526 ///
527 /// FIXME: `cdb_version` is *derived* from cdb, but it's *not* technically a config!
528 ///
529 /// FIXME: audit cdb version gating.
530 pub(crate) cdb_version: Option<[u16; 4]>,
531
532 /// Path to / name of the GDB executable.
533 ///
534 /// FIXME: the fallback path when `gdb` isn't provided tries to find *a* `gdb` or `gdb.exe` from
535 /// `PATH`, which is... arguably questionable.
536 ///
537 /// FIXME: we are propagating a python from `PYTHONPATH`, not from an explicit config for gdb
538 /// debugger script.
539 pub(crate) gdb: Option<Utf8PathBuf>,
540
541 /// Version of GDB, encoded as ((major * 1000) + minor) * 1000 + patch
542 ///
543 /// FIXME: this gdb version gating scheme is possibly questionable -- gdb does not use semver,
544 /// only its major version is likely materially meaningful, cf.
545 /// <https://sourceware.org/gdb/wiki/Internals%20Versions>. Even the major version I'm not sure
546 /// is super meaningful. Maybe min gdb `major.minor` version gating is sufficient for the
547 /// purposes of debuginfo tests?
548 ///
549 /// FIXME: `gdb_version` is *derived* from gdb, but it's *not* technically a config!
550 pub(crate) gdb_version: Option<u32>,
551
552 /// Path to or name of the LLDB executable to use for debuginfo tests.
553 pub(crate) lldb: Option<Utf8PathBuf>,
554
555 /// Version of LLDB.
556 ///
557 /// FIXME: `lldb_version` is *derived* from lldb, but it's *not* technically a config!
558 pub(crate) lldb_version: Option<u32>,
559
560 /// Version of LLVM.
561 ///
562 /// FIXME: Audit the fallback derivation of
563 /// [`crate::directives::extract_llvm_version_from_binary`], that seems very questionable?
564 pub(crate) llvm_version: Option<Version>,
565
566 /// Is LLVM a system LLVM.
567 pub(crate) system_llvm: bool,
568
569 /// Path to the android tools.
570 ///
571 /// Note: this is only used for android gdb debugger script in the debuginfo test suite.
572 ///
573 /// FIXME: take a look at this; this is piggy-backing off of gdb code paths but only for
574 /// `arm-linux-androideabi` target.
575 pub(crate) android_cross_path: Option<Utf8PathBuf>,
576
577 /// Extra parameter to run adb on `arm-linux-androideabi`.
578 ///
579 /// FIXME: is this *only* `arm-linux-androideabi`, or is it also for other Tier 2/3 android
580 /// targets?
581 ///
582 /// FIXME: take a look at this; this is piggy-backing off of gdb code paths but only for
583 /// `arm-linux-androideabi` target.
584 pub(crate) adb_path: Option<Utf8PathBuf>,
585
586 /// Extra parameter to run test suite on `arm-linux-androideabi`.
587 ///
588 /// FIXME: is this *only* `arm-linux-androideabi`, or is it also for other Tier 2/3 android
589 /// targets?
590 ///
591 /// FIXME: take a look at this; this is piggy-backing off of gdb code paths but only for
592 /// `arm-linux-androideabi` target.
593 pub(crate) adb_test_dir: Option<Utf8PathBuf>,
594
595 /// Status whether android device available or not. When unavailable, this will cause tests to
596 /// panic when the test binary is attempted to be run.
597 ///
598 /// FIXME: take a look at this; this also influences adb in gdb code paths in a strange way.
599 pub(crate) adb_device_status: bool,
600
601 /// Verbose dump a lot of info.
602 ///
603 /// FIXME: this is *way* too coarse; the user can't select *which* info to verbosely dump.
604 pub(crate) verbose: bool,
605
606 /// Whether to enable verbose subprocess output for run-make tests.
607 /// Set to false to suppress output for passing tests (e.g. for cg_clif with --no-capture).
608 pub verbose_run_make_subprocess_output: bool,
609
610 /// Where to find the remote test client process, if we're using it.
611 ///
612 /// Note: this is *only* used for target platform executables created by `run-make` test
613 /// recipes.
614 ///
615 /// Note: this is not to be confused with [`Self::runner`], which is a different scheme.
616 ///
617 /// FIXME: the `remote_test_client` scheme is very under-documented.
618 pub(crate) remote_test_client: Option<Utf8PathBuf>,
619
620 /// [`CompareMode`] describing what file the actual ui output will be compared to.
621 ///
622 /// FIXME: currently, [`CompareMode`] is a mishmash of lot of things (different borrow-checker
623 /// model, different trait solver, different debugger, etc.).
624 pub(crate) compare_mode: Option<CompareMode>,
625
626 /// If true, this will generate a coverage file with UI test files that run `MachineApplicable`
627 /// diagnostics but are missing `run-rustfix` annotations. The generated coverage file is
628 /// created in `$test_suite_build_root/rustfix_missing_coverage.txt`
629 pub(crate) rustfix_coverage: bool,
630
631 /// Whether to run `enzyme` autodiff tests.
632 pub(crate) has_enzyme: bool,
633
634 /// Whether to run `offload` autodiff tests.
635 pub(crate) has_offload: bool,
636
637 /// The current Rust channel info.
638 ///
639 /// FIXME: treat this more carefully; "stable", "beta" and "nightly" are definitely valid, but
640 /// channel might also be "dev" or such, which should be treated as "nightly".
641 pub(crate) channel: String,
642
643 /// Whether adding git commit information such as the commit hash has been enabled for building.
644 ///
645 /// FIXME: `compiletest` cannot trust `bootstrap` for this information, because `bootstrap` can
646 /// have bugs and had bugs on that logic. We need to figure out how to obtain this e.g. directly
647 /// from CI or via git locally.
648 pub(crate) git_hash: bool,
649
650 /// The default Rust edition.
651 pub(crate) edition: Option<Edition>,
652
653 // Configuration for various run-make tests frobbing things like C compilers or querying about
654 // various LLVM component information.
655 //
656 // FIXME: this really should be better packaged together.
657 // FIXME: these need better docs, e.g. for *host*, or for *target*?
658 pub(crate) cc: String,
659 pub(crate) cxx: String,
660 pub(crate) cflags: String,
661 pub(crate) cxxflags: String,
662 pub(crate) ar: String,
663 pub(crate) target_linker: Option<String>,
664 pub(crate) host_linker: Option<String>,
665 pub(crate) llvm_components: String,
666
667 /// Path to a NodeJS executable. Used for JS doctests, emscripten and WASM tests.
668 pub(crate) nodejs: Option<Utf8PathBuf>,
669
670 /// Whether to rerun tests even if the inputs are unchanged.
671 pub(crate) force_rerun: bool,
672
673 /// Only rerun the tests that result has been modified according to `git status`.
674 ///
675 /// FIXME: this is undocumented.
676 ///
677 /// FIXME: how does this interact with [`Self::force_rerun`]?
678 pub(crate) only_modified: bool,
679
680 // FIXME: these are really not "config"s, but rather are information derived from
681 // `rustc`-under-test. This poses an interesting conundrum: if we're testing the
682 // `rustc`-under-test, can we trust its print request outputs and target cfgs? In theory, this
683 // itself can break or be unreliable -- ideally, we'd be sharing these kind of information not
684 // through `rustc`-under-test's execution output. In practice, however, print requests are very
685 // unlikely to completely break (we also have snapshot ui tests for them). Furthermore, even if
686 // we share them via some kind of static config, that static config can still be wrong! Who
687 // tests the tester? Therefore, we make a pragmatic compromise here, and use information derived
688 // from print requests produced by the `rustc`-under-test.
689 //
690 // FIXME: move them out from `Config`, because they are *not* configs.
691 pub(crate) target_cfgs: OnceLock<TargetCfgs>,
692 pub(crate) builtin_cfg_names: OnceLock<HashSet<String>>,
693 pub(crate) supported_crate_types: OnceLock<HashSet<String>>,
694
695 /// Should we capture console output that would be printed by test runners via their `stdout`
696 /// and `stderr` trait objects, or via the custom panic hook.
697 ///
698 /// The default is `true`. This can be disabled via the compiletest cli flag `--no-capture`
699 /// (which mirrors the libtest `--no-capture` flag).
700 pub(crate) capture: bool,
701
702 /// Needed both to construct [`build_helper::git::GitConfig`].
703 pub(crate) nightly_branch: String,
704 pub(crate) git_merge_commit_email: String,
705
706 /// True if the profiler runtime is enabled for this target. Used by the
707 /// `needs-profiler-runtime` directive in test files.
708 pub(crate) profiler_runtime: bool,
709
710 /// Command for visual diff display, e.g. `diff-tool --color=always`.
711 pub(crate) diff_command: Option<String>,
712
713 /// Path to minicore aux library (`tests/auxiliary/minicore.rs`), used for `no_core` tests that
714 /// need `core` stubs in cross-compilation scenarios that do not otherwise want/need to
715 /// `-Zbuild-std`. Used in e.g. ABI tests.
716 pub(crate) minicore_path: Utf8PathBuf,
717
718 /// Current codegen backend used.
719 pub(crate) default_codegen_backend: CodegenBackend,
720 /// Name/path of the backend to use instead of `default_codegen_backend`.
721 pub(crate) override_codegen_backend: Option<String>,
722 /// Whether to ignore `//@ ignore-backends`.
723 pub(crate) bypass_ignore_backends: bool,
724
725 /// Number of parallel jobs configured for the build.
726 ///
727 /// This is forwarded from bootstrap's `jobs` configuration.
728 pub(crate) jobs: u32,
729
730 /// Number of parallel threads to use for the frontend when building test artifacts.
731 pub(crate) parallel_frontend_threads: u32,
732 /// Number of times to execute each test.
733 pub(crate) iteration_count: u32,
734}
735
736impl Config {
737 pub(crate) const DEFAULT_PARALLEL_FRONTEND_THREADS: u32 = 1;
738 pub(crate) const DEFAULT_ITERATION_COUNT: u32 = 1;
739
740 /// FIXME: this run scheme is... confusing.
741 pub(crate) fn run_enabled(&self) -> bool {
742 self.run.unwrap_or_else(|| {
743 // Auto-detect whether to run based on the platform.
744 !self.target.ends_with("-fuchsia")
745 })
746 }
747
748 pub(crate) fn target_cfgs(&self) -> &TargetCfgs {
749 self.target_cfgs.get_or_init(|| TargetCfgs::new(self))
750 }
751
752 pub(crate) fn target_cfg(&self) -> &TargetCfg {
753 &self.target_cfgs().current
754 }
755
756 pub(crate) fn matches_arch(&self, arch: &str) -> bool {
757 self.target_cfg().arch == arch
758 || {
759 // Matching all the thumb variants as one can be convenient.
760 // (thumbv6m, thumbv7em, thumbv7m, etc.)
761 arch == "thumb" && self.target.starts_with("thumb")
762 }
763 || (arch == "i586" && self.target.starts_with("i586-"))
764 }
765
766 pub(crate) fn matches_os(&self, os: &str) -> bool {
767 self.target_cfg().os == os
768 }
769
770 pub(crate) fn matches_env(&self, env: &str) -> bool {
771 self.target_cfg().env == env
772 }
773
774 pub(crate) fn matches_abi(&self, abi: &str) -> bool {
775 self.target_cfg().abi == abi
776 }
777
778 #[cfg_attr(not(test), expect(dead_code, reason = "only used by tests for `ignore-{family}`"))]
779 pub(crate) fn matches_family(&self, family: &str) -> bool {
780 self.target_cfg().families.iter().any(|f| f == family)
781 }
782
783 pub(crate) fn is_big_endian(&self) -> bool {
784 self.target_cfg().endian == Endian::Big
785 }
786
787 pub(crate) fn get_pointer_width(&self) -> u32 {
788 *&self.target_cfg().pointer_width
789 }
790
791 pub(crate) fn can_unwind(&self) -> bool {
792 self.target_cfg().panic == PanicStrategy::Unwind
793 }
794
795 /// Get the list of builtin, 'well known' cfg names
796 pub(crate) fn builtin_cfg_names(&self) -> &HashSet<String> {
797 self.builtin_cfg_names.get_or_init(|| builtin_cfg_names(self))
798 }
799
800 /// Get the list of crate types that the target platform supports.
801 pub(crate) fn supported_crate_types(&self) -> &HashSet<String> {
802 self.supported_crate_types.get_or_init(|| supported_crate_types(self))
803 }
804
805 pub(crate) fn has_threads(&self) -> bool {
806 // Wasm targets don't have threads unless `-threads` is in the target
807 // name, such as `wasm32-wasip1-threads`.
808 if self.target.starts_with("wasm") {
809 return self.target.contains("threads");
810 }
811 true
812 }
813
814 pub(crate) fn has_asm_support(&self) -> bool {
815 // This should match the stable list in `LoweringContext::lower_inline_asm`.
816 static ASM_SUPPORTED_ARCHS: &[&str] = &[
817 "x86",
818 "x86_64",
819 "arm",
820 "aarch64",
821 "arm64ec",
822 "riscv32",
823 "riscv64",
824 "loongarch32",
825 "loongarch64",
826 "s390x",
827 // These targets require an additional asm_experimental_arch feature.
828 // "nvptx64", "hexagon", "mips", "mips64", "spirv", "wasm32",
829 ];
830 ASM_SUPPORTED_ARCHS.contains(&self.target_cfg().arch.as_str())
831 }
832
833 pub(crate) fn git_config(&self) -> GitConfig<'_> {
834 GitConfig {
835 nightly_branch: &self.nightly_branch,
836 git_merge_commit_email: &self.git_merge_commit_email,
837 }
838 }
839
840 pub(crate) fn has_subprocess_support(&self) -> bool {
841 // FIXME(#135928): compiletest is always a **host** tool. Building and running an
842 // capability detection executable against the **target** is not trivial. The short term
843 // solution here is to hard-code some targets to allow/deny, unfortunately.
844
845 let unsupported_target = self.target_cfg().env == "sgx"
846 || matches!(self.target_cfg().arch.as_str(), "wasm32" | "wasm64")
847 || self.target_cfg().os == "emscripten";
848 !unsupported_target
849 }
850
851 /// Whether the parallel frontend is enabled,
852 /// which is the case when `parallel_frontend_threads` is not set to `1`.
853 ///
854 /// - `0` means auto-detect: use the number of available hardware threads on the host.
855 /// But we treat it as the parallel frontend being enabled in this case.
856 /// - `1` means single-threaded (parallel frontend disabled).
857 /// - `>1` means an explicitly configured thread count.
858 pub(crate) fn parallel_frontend_enabled(&self) -> bool {
859 self.parallel_frontend_threads != 1
860 }
861}
862
863/// Known widths of `target_has_atomic`.
864pub(crate) const KNOWN_TARGET_HAS_ATOMIC_WIDTHS: &[&str] = &["8", "16", "32", "64", "128", "ptr"];
865
866#[derive(Debug, Clone)]
867pub(crate) struct TargetCfgs {
868 pub(crate) current: TargetCfg,
869 pub(crate) all_targets: HashSet<String>,
870 pub(crate) all_archs: HashSet<String>,
871 pub(crate) all_oses: HashSet<String>,
872 pub(crate) all_oses_and_envs: HashSet<String>,
873 pub(crate) all_envs: HashSet<String>,
874 pub(crate) all_abis: HashSet<String>,
875 pub(crate) all_families: HashSet<String>,
876 pub(crate) all_pointer_widths: HashSet<String>,
877 pub(crate) all_rustc_abis: HashSet<String>,
878}
879
880impl TargetCfgs {
881 fn new(config: &Config) -> TargetCfgs {
882 let mut targets: HashMap<String, TargetCfg> = serde_json::from_str(&query_rustc_output(
883 config,
884 &["--print=all-target-specs-json", "-Zunstable-options"],
885 Default::default(),
886 ))
887 .unwrap();
888
889 let mut all_targets = HashSet::new();
890 let mut all_archs = HashSet::new();
891 let mut all_oses = HashSet::new();
892 let mut all_oses_and_envs = HashSet::new();
893 let mut all_envs = HashSet::new();
894 let mut all_abis = HashSet::new();
895 let mut all_families = HashSet::new();
896 let mut all_pointer_widths = HashSet::new();
897 // NOTE: for distinction between `abi` and `rustc_abi`, see comment on
898 // `TargetCfg::rustc_abi`.
899 let mut all_rustc_abis = HashSet::new();
900
901 // If current target is not included in the `--print=all-target-specs-json` output,
902 // we check whether it is a custom target from the user or a synthetic target from bootstrap.
903 if !targets.contains_key(&config.target) {
904 let mut envs: HashMap<String, String> = HashMap::new();
905
906 if let Ok(t) = std::env::var("RUST_TARGET_PATH") {
907 envs.insert("RUST_TARGET_PATH".into(), t);
908 }
909
910 // This returns false only when the target is neither a synthetic target
911 // nor a custom target from the user, indicating it is most likely invalid.
912 if config.target.ends_with(".json") || !envs.is_empty() {
913 targets.insert(
914 config.target.clone(),
915 serde_json::from_str(&query_rustc_output(
916 config,
917 &[
918 "--print=target-spec-json",
919 "-Zunstable-options",
920 "--target",
921 &config.target,
922 ],
923 envs,
924 ))
925 .unwrap(),
926 );
927 }
928 }
929
930 for (target, cfg) in targets.iter() {
931 all_archs.insert(cfg.arch.clone());
932 all_oses.insert(cfg.os.clone());
933 all_oses_and_envs.insert(cfg.os_and_env());
934 all_envs.insert(cfg.env.clone());
935 all_abis.insert(cfg.abi.clone());
936 for family in &cfg.families {
937 all_families.insert(family.clone());
938 }
939 all_pointer_widths.insert(format!("{}bit", cfg.pointer_width));
940 if let Some(rustc_abi) = &cfg.rustc_abi {
941 all_rustc_abis.insert(rustc_abi.clone());
942 }
943 all_targets.insert(target.clone());
944 }
945
946 Self {
947 current: Self::get_current_target_config(config, &targets),
948 all_targets,
949 all_archs,
950 all_oses,
951 all_oses_and_envs,
952 all_envs,
953 all_abis,
954 all_families,
955 all_pointer_widths,
956 all_rustc_abis,
957 }
958 }
959
960 fn get_current_target_config(
961 config: &Config,
962 targets: &HashMap<String, TargetCfg>,
963 ) -> TargetCfg {
964 let mut cfg = targets[&config.target].clone();
965
966 // To get the target information for the current target, we take the target spec obtained
967 // from `--print=all-target-specs-json`, and then we enrich it with the information
968 // gathered from `--print=cfg --target=$target`.
969 //
970 // This is done because some parts of the target spec can be overridden with `-C` flags,
971 // which are respected for `--print=cfg` but not for `--print=all-target-specs-json`. The
972 // code below extracts them from `--print=cfg`: make sure to only override fields that can
973 // actually be changed with `-C` flags.
974 for config in query_rustc_output(
975 config,
976 // `-Zunstable-options` is necessary when compiletest is running with custom targets
977 // (such as synthetic targets used to bless mir-opt tests).
978 &["-Zunstable-options", "--print=cfg", "--target", &config.target],
979 Default::default(),
980 )
981 .trim()
982 .lines()
983 {
984 let (name, value) = config
985 .split_once("=\"")
986 .map(|(name, value)| {
987 (
988 name,
989 Some(
990 value
991 .strip_suffix('\"')
992 .expect("key-value pair should be properly quoted"),
993 ),
994 )
995 })
996 .unwrap_or_else(|| (config, None));
997
998 match (name, value) {
999 // Can be overridden with `-C panic=$strategy`.
1000 ("panic", Some("abort")) => cfg.panic = PanicStrategy::Abort,
1001 ("panic", Some("unwind")) => cfg.panic = PanicStrategy::Unwind,
1002 ("panic", other) => panic!("unexpected value for panic cfg: {other:?}"),
1003
1004 ("target_has_atomic", Some(width))
1005 if KNOWN_TARGET_HAS_ATOMIC_WIDTHS.contains(&width) =>
1006 {
1007 cfg.target_has_atomic.insert(width.to_string());
1008 }
1009 ("target_has_atomic", Some(other)) => {
1010 panic!("unexpected value for `target_has_atomic` cfg: {other:?}")
1011 }
1012 // Nightly-only std-internal impl detail.
1013 ("target_has_atomic", None) => {}
1014 _ => {}
1015 }
1016 }
1017
1018 cfg
1019 }
1020}
1021
1022#[derive(Clone, Debug, serde::Deserialize)]
1023#[serde(rename_all = "kebab-case")]
1024pub(crate) struct TargetCfg {
1025 pub(crate) arch: String,
1026 #[serde(default = "default_os")]
1027 pub(crate) os: String,
1028 #[serde(default)]
1029 pub(crate) env: String,
1030 #[serde(default)]
1031 pub(crate) abi: String,
1032 #[serde(rename = "target-family", default)]
1033 pub(crate) families: Vec<String>,
1034 #[serde(rename = "target-pointer-width")]
1035 pub(crate) pointer_width: u32,
1036 #[serde(rename = "target-endian", default)]
1037 endian: Endian,
1038 #[serde(rename = "panic-strategy", default)]
1039 pub(crate) panic: PanicStrategy,
1040 #[serde(default)]
1041 pub(crate) dynamic_linking: bool,
1042 #[serde(rename = "supported-sanitizers", default)]
1043 pub(crate) sanitizers: Vec<Sanitizer>,
1044 #[serde(rename = "supports-xray", default)]
1045 pub(crate) xray: bool,
1046 #[serde(default = "default_reloc_model")]
1047 pub(crate) relocation_model: String,
1048 // NOTE: `rustc_abi` should not be confused with `abi`. `rustc_abi` was introduced in #137037 to
1049 // make SSE2 *required* by the ABI (kind of a hack to make a target feature *required* via the
1050 // target spec).
1051 pub(crate) rustc_abi: Option<String>,
1052
1053 /// ELF is the "default" binary format, so the compiler typically doesn't
1054 /// emit a `"binary-format"` field for ELF targets.
1055 ///
1056 /// See `impl ToJson for Target` in `compiler/rustc_target/src/spec/json.rs`.
1057 #[serde(default = "default_binary_format_elf")]
1058 pub(crate) binary_format: Cow<'static, str>,
1059
1060 // Not present in target cfg json output, additional derived information.
1061 #[serde(skip)]
1062 /// Supported target atomic widths: e.g. `8` to `128` or `ptr`. This is derived from the builtin
1063 /// `target_has_atomic` `cfg`s e.g. `target_has_atomic="8"`.
1064 pub(crate) target_has_atomic: BTreeSet<String>,
1065}
1066
1067impl TargetCfg {
1068 pub(crate) fn os_and_env(&self) -> String {
1069 format!("{}-{}", self.os, self.env)
1070 }
1071}
1072
1073fn default_os() -> String {
1074 "none".into()
1075}
1076
1077fn default_reloc_model() -> String {
1078 "pic".into()
1079}
1080
1081fn default_binary_format_elf() -> Cow<'static, str> {
1082 Cow::Borrowed("elf")
1083}
1084
1085#[derive(Eq, PartialEq, Clone, Debug, Default, serde::Deserialize)]
1086#[serde(rename_all = "kebab-case")]
1087pub(crate) enum Endian {
1088 #[default]
1089 Little,
1090 Big,
1091}
1092
1093fn builtin_cfg_names(config: &Config) -> HashSet<String> {
1094 query_rustc_output(
1095 config,
1096 &["--print=check-cfg", "-Zunstable-options", "--check-cfg=cfg()"],
1097 Default::default(),
1098 )
1099 .lines()
1100 .map(|l| extract_cfg_name(&l).unwrap().to_string())
1101 .chain(std::iter::once(String::from("test")))
1102 .collect()
1103}
1104
1105/// Extract the cfg name from `cfg(name, values(...))` lines
1106fn extract_cfg_name(check_cfg_line: &str) -> Result<&str, &'static str> {
1107 let trimmed = check_cfg_line.trim();
1108
1109 #[rustfmt::skip]
1110 let inner = trimmed
1111 .strip_prefix("cfg(")
1112 .ok_or("missing cfg(")?
1113 .strip_suffix(")")
1114 .ok_or("missing )")?;
1115
1116 let first_comma = inner.find(',').ok_or("no comma found")?;
1117
1118 Ok(inner[..first_comma].trim())
1119}
1120
1121pub(crate) const KNOWN_CRATE_TYPES: &[&str] =
1122 &["bin", "cdylib", "dylib", "lib", "proc-macro", "rlib", "staticlib"];
1123
1124fn supported_crate_types(config: &Config) -> HashSet<String> {
1125 let crate_types: HashSet<_> = query_rustc_output(
1126 config,
1127 &["--target", &config.target, "--print=supported-crate-types", "-Zunstable-options"],
1128 Default::default(),
1129 )
1130 .lines()
1131 .map(|l| l.to_string())
1132 .collect();
1133
1134 for crate_type in crate_types.iter() {
1135 assert!(
1136 KNOWN_CRATE_TYPES.contains(&crate_type.as_str()),
1137 "unexpected crate type `{}`: known crate types are {:?}",
1138 crate_type,
1139 KNOWN_CRATE_TYPES
1140 );
1141 }
1142
1143 crate_types
1144}
1145
1146pub(crate) fn query_rustc_output(
1147 config: &Config,
1148 args: &[&str],
1149 envs: HashMap<String, String>,
1150) -> String {
1151 let query_rustc_path = config.query_rustc_path.as_deref().unwrap_or(&config.rustc_path);
1152
1153 let mut command = Command::new(query_rustc_path);
1154 add_dylib_path(&mut command, iter::once(&config.host_compile_lib_path));
1155 command.args(&config.target_rustcflags).args(args);
1156 command.env("RUSTC_BOOTSTRAP", "1");
1157 command.envs(envs);
1158
1159 let output = match command.output() {
1160 Ok(output) => output,
1161 Err(e) => {
1162 fatal!("failed to run {command:?}: {e}");
1163 }
1164 };
1165 if !output.status.success() {
1166 fatal!(
1167 "failed to run {command:?}\n--- stdout\n{}\n--- stderr\n{}",
1168 String::from_utf8(output.stdout).unwrap(),
1169 String::from_utf8(output.stderr).unwrap(),
1170 );
1171 }
1172 String::from_utf8(output.stdout).unwrap()
1173}
1174
1175/// Path information for a single test file.
1176#[derive(Debug, Clone)]
1177pub(crate) struct TestPaths {
1178 /// Full path to the test file.
1179 ///
1180 /// For example:
1181 /// - `/home/ferris/rust/tests/ui/warnings/hello-world.rs`
1182 ///
1183 /// ---
1184 ///
1185 /// For `run-make` tests, this path is the _directory_ that contains
1186 /// `rmake.rs`.
1187 ///
1188 /// For example:
1189 /// - `/home/ferris/rust/tests/run-make/emit`
1190 pub(crate) file: Utf8PathBuf,
1191
1192 /// Subset of the full path that excludes the suite directory and the
1193 /// test filename. For tests in the root of their test suite directory,
1194 /// this is blank.
1195 ///
1196 /// For example:
1197 /// - `file`: `/home/ferris/rust/tests/ui/warnings/hello-world.rs`
1198 /// - `relative_dir`: `warnings`
1199 pub(crate) relative_dir: Utf8PathBuf,
1200}
1201
1202/// Used by `ui` tests to generate things like `foo.stderr` from `foo.rs`.
1203pub(crate) fn expected_output_path(
1204 testpaths: &TestPaths,
1205 revision: Option<&str>,
1206 compare_mode: &Option<CompareMode>,
1207 kind: &str,
1208) -> Utf8PathBuf {
1209 assert!(UI_EXTENSIONS.contains(&kind));
1210 let mut parts = Vec::new();
1211
1212 if let Some(x) = revision {
1213 parts.push(x);
1214 }
1215 if let Some(ref x) = *compare_mode {
1216 parts.push(x.to_str());
1217 }
1218 parts.push(kind);
1219
1220 let extension = parts.join(".");
1221 testpaths.file.with_extension(extension)
1222}
1223
1224pub(crate) const UI_EXTENSIONS: &[&str] = &[
1225 UI_STDERR,
1226 UI_SVG,
1227 UI_WINDOWS_SVG,
1228 UI_STDOUT,
1229 UI_FIXED,
1230 UI_RUN_STDERR,
1231 UI_RUN_STDOUT,
1232 UI_STDERR_64,
1233 UI_STDERR_32,
1234 UI_STDERR_16,
1235 UI_COVERAGE,
1236 UI_COVERAGE_MAP,
1237];
1238pub(crate) const UI_STDERR: &str = "stderr";
1239pub(crate) const UI_SVG: &str = "svg";
1240pub(crate) const UI_WINDOWS_SVG: &str = "windows.svg";
1241pub(crate) const UI_STDOUT: &str = "stdout";
1242pub(crate) const UI_FIXED: &str = "fixed";
1243pub(crate) const UI_RUN_STDERR: &str = "run.stderr";
1244pub(crate) const UI_RUN_STDOUT: &str = "run.stdout";
1245pub(crate) const UI_STDERR_64: &str = "64bit.stderr";
1246pub(crate) const UI_STDERR_32: &str = "32bit.stderr";
1247pub(crate) const UI_STDERR_16: &str = "16bit.stderr";
1248pub(crate) const UI_COVERAGE: &str = "coverage";
1249pub(crate) const UI_COVERAGE_MAP: &str = "cov-map";
1250
1251/// Absolute path to the directory where all output for all tests in the given `relative_dir` group
1252/// should reside. Example:
1253///
1254/// ```text
1255/// /path/to/build/host-tuple/test/ui/relative/
1256/// ```
1257///
1258/// This is created early when tests are collected to avoid race conditions.
1259pub(crate) fn output_relative_path(config: &Config, relative_dir: &Utf8Path) -> Utf8PathBuf {
1260 config.build_test_suite_root.join(relative_dir)
1261}
1262
1263/// Generates a unique name for the test, such as `testname.revision.mode`.
1264pub(crate) fn output_testname_unique(
1265 config: &Config,
1266 testpaths: &TestPaths,
1267 revision: Option<&str>,
1268) -> Utf8PathBuf {
1269 let mode = config.compare_mode.as_ref().map_or("", |m| m.to_str());
1270 let debugger = config.debugger.as_ref().map_or("", |m| m.to_str());
1271 Utf8PathBuf::from(&testpaths.file.file_stem().unwrap())
1272 .with_extra_extension(config.mode.output_dir_disambiguator())
1273 .with_extra_extension(revision.unwrap_or(""))
1274 .with_extra_extension(mode)
1275 .with_extra_extension(debugger)
1276}
1277
1278/// Absolute path to the directory where all output for the given
1279/// test/revision should reside. Example:
1280/// /path/to/build/host-tuple/test/ui/relative/testname.revision.mode/
1281pub(crate) fn output_base_dir(
1282 config: &Config,
1283 testpaths: &TestPaths,
1284 revision: Option<&str>,
1285) -> Utf8PathBuf {
1286 output_relative_path(config, &testpaths.relative_dir)
1287 .join(output_testname_unique(config, testpaths, revision))
1288}
1289
1290/// Absolute path to the base filename used as output for the given
1291/// test/revision. Example:
1292/// /path/to/build/host-tuple/test/ui/relative/testname.revision.mode/testname
1293pub(crate) fn output_base_name(
1294 config: &Config,
1295 testpaths: &TestPaths,
1296 revision: Option<&str>,
1297) -> Utf8PathBuf {
1298 output_base_dir(config, testpaths, revision).join(testpaths.file.file_stem().unwrap())
1299}
1300
1301/// Absolute path to the directory to use for incremental compilation. Example:
1302/// /path/to/build/host-tuple/test/ui/relative/testname.mode/testname.inc
1303pub(crate) fn incremental_dir(
1304 config: &Config,
1305 testpaths: &TestPaths,
1306 revision: Option<&str>,
1307) -> Utf8PathBuf {
1308 output_base_name(config, testpaths, revision).with_extension("inc")
1309}