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 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 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 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 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 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 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 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 enum FailMode {
121 Check,
122 Build,
123 Run(RunFailMode),
124}
125
126string_enum! {
127 #[derive(Clone, Debug, PartialEq)]
128 pub 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 query_rustc_path: Option<Utf8PathBuf>,
314
315 /// Path to the `rustdoc`-under-test. Like [`Self::rustc_path`], this `rustdoc` is *staged*.
316 pub rustdoc_path: Option<Utf8PathBuf>,
317
318 /// Path to the `src/tools/coverage-dump/` bootstrap tool executable.
319 pub coverage_dump_path: Option<Utf8PathBuf>,
320
321 /// Path to the Python 3 executable to use for htmldocck and some run-make tests.
322 pub python: String,
323
324 /// Path to the `src/tools/jsondocck/` bootstrap tool executable.
325 pub jsondocck_path: Option<Utf8PathBuf>,
326
327 /// Path to the `src/tools/jsondoclint/` bootstrap tool executable.
328 pub jsondoclint_path: Option<Utf8PathBuf>,
329
330 /// Path to a host LLVM `FileCheck` executable.
331 pub 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 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 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 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 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 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 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 sysroot_base: Utf8PathBuf,
388
389 /// The number of the stage under test.
390 pub 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 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 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 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 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 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 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 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 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 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 skip: Vec<String>,
462
463 /// Exactly match the filter, rather than a substring.
464 ///
465 /// FIXME(#139660): ditto on test matching behavior.
466 pub 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 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 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 runner: Option<String>,
493
494 /// Compiler flags to pass to the *staged* `rustc`-under-test when building for the **host**
495 /// platform.
496 pub 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 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 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 optimize_tests: bool,
512
513 /// Target platform tuple.
514 pub target: String,
515
516 /// Host platform tuple.
517 pub 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 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 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 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 gdb_version: Option<u32>,
551
552 /// Path to or name of the LLDB executable to use for debuginfo tests.
553 pub 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 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 llvm_version: Option<Version>,
565
566 /// Is LLVM a system LLVM.
567 pub 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 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 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 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 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 verbose: bool,
605
606 /// Where to find the remote test client process, if we're using it.
607 ///
608 /// Note: this is *only* used for target platform executables created by `run-make` test
609 /// recipes.
610 ///
611 /// Note: this is not to be confused with [`Self::runner`], which is a different scheme.
612 ///
613 /// FIXME: the `remote_test_client` scheme is very under-documented.
614 pub remote_test_client: Option<Utf8PathBuf>,
615
616 /// [`CompareMode`] describing what file the actual ui output will be compared to.
617 ///
618 /// FIXME: currently, [`CompareMode`] is a mishmash of lot of things (different borrow-checker
619 /// model, different trait solver, different debugger, etc.).
620 pub compare_mode: Option<CompareMode>,
621
622 /// If true, this will generate a coverage file with UI test files that run `MachineApplicable`
623 /// diagnostics but are missing `run-rustfix` annotations. The generated coverage file is
624 /// created in `$test_suite_build_root/rustfix_missing_coverage.txt`
625 pub rustfix_coverage: bool,
626
627 /// Whether to run `enzyme` autodiff tests.
628 pub has_enzyme: bool,
629
630 /// Whether to run `offload` autodiff tests.
631 pub has_offload: bool,
632
633 /// The current Rust channel info.
634 ///
635 /// FIXME: treat this more carefully; "stable", "beta" and "nightly" are definitely valid, but
636 /// channel might also be "dev" or such, which should be treated as "nightly".
637 pub channel: String,
638
639 /// Whether adding git commit information such as the commit hash has been enabled for building.
640 ///
641 /// FIXME: `compiletest` cannot trust `bootstrap` for this information, because `bootstrap` can
642 /// have bugs and had bugs on that logic. We need to figure out how to obtain this e.g. directly
643 /// from CI or via git locally.
644 pub git_hash: bool,
645
646 /// The default Rust edition.
647 pub edition: Option<Edition>,
648
649 // Configuration for various run-make tests frobbing things like C compilers or querying about
650 // various LLVM component information.
651 //
652 // FIXME: this really should be better packaged together.
653 // FIXME: these need better docs, e.g. for *host*, or for *target*?
654 pub cc: String,
655 pub cxx: String,
656 pub cflags: String,
657 pub cxxflags: String,
658 pub ar: String,
659 pub target_linker: Option<String>,
660 pub host_linker: Option<String>,
661 pub llvm_components: String,
662
663 /// Path to a NodeJS executable. Used for JS doctests, emscripten and WASM tests.
664 pub nodejs: Option<Utf8PathBuf>,
665
666 /// Whether to rerun tests even if the inputs are unchanged.
667 pub force_rerun: bool,
668
669 /// Only rerun the tests that result has been modified according to `git status`.
670 ///
671 /// FIXME: this is undocumented.
672 ///
673 /// FIXME: how does this interact with [`Self::force_rerun`]?
674 pub only_modified: bool,
675
676 // FIXME: these are really not "config"s, but rather are information derived from
677 // `rustc`-under-test. This poses an interesting conundrum: if we're testing the
678 // `rustc`-under-test, can we trust its print request outputs and target cfgs? In theory, this
679 // itself can break or be unreliable -- ideally, we'd be sharing these kind of information not
680 // through `rustc`-under-test's execution output. In practice, however, print requests are very
681 // unlikely to completely break (we also have snapshot ui tests for them). Furthermore, even if
682 // we share them via some kind of static config, that static config can still be wrong! Who
683 // tests the tester? Therefore, we make a pragmatic compromise here, and use information derived
684 // from print requests produced by the `rustc`-under-test.
685 //
686 // FIXME: move them out from `Config`, because they are *not* configs.
687 pub target_cfgs: OnceLock<TargetCfgs>,
688 pub builtin_cfg_names: OnceLock<HashSet<String>>,
689 pub supported_crate_types: OnceLock<HashSet<String>>,
690
691 /// Should we capture console output that would be printed by test runners via their `stdout`
692 /// and `stderr` trait objects, or via the custom panic hook.
693 ///
694 /// The default is `true`. This can be disabled via the compiletest cli flag `--no-capture`
695 /// (which mirrors the libtest `--no-capture` flag).
696 pub capture: bool,
697
698 /// Needed both to construct [`build_helper::git::GitConfig`].
699 pub nightly_branch: String,
700 pub git_merge_commit_email: String,
701
702 /// True if the profiler runtime is enabled for this target. Used by the
703 /// `needs-profiler-runtime` directive in test files.
704 pub profiler_runtime: bool,
705
706 /// Command for visual diff display, e.g. `diff-tool --color=always`.
707 pub diff_command: Option<String>,
708
709 /// Path to minicore aux library (`tests/auxiliary/minicore.rs`), used for `no_core` tests that
710 /// need `core` stubs in cross-compilation scenarios that do not otherwise want/need to
711 /// `-Zbuild-std`. Used in e.g. ABI tests.
712 pub minicore_path: Utf8PathBuf,
713
714 /// Current codegen backend used.
715 pub default_codegen_backend: CodegenBackend,
716 /// Name/path of the backend to use instead of `default_codegen_backend`.
717 pub override_codegen_backend: Option<String>,
718 /// Whether to ignore `//@ ignore-backends`.
719 pub bypass_ignore_backends: bool,
720
721 /// Number of parallel jobs configured for the build.
722 ///
723 /// This is forwarded from bootstrap's `jobs` configuration.
724 pub jobs: u32,
725
726 /// Number of parallel threads to use for the frontend when building test artifacts.
727 pub parallel_frontend_threads: u32,
728 /// Number of times to execute each test.
729 pub iteration_count: u32,
730}
731
732impl Config {
733 pub const DEFAULT_PARALLEL_FRONTEND_THREADS: u32 = 1;
734 pub const DEFAULT_ITERATION_COUNT: u32 = 1;
735
736 /// FIXME: this run scheme is... confusing.
737 pub fn run_enabled(&self) -> bool {
738 self.run.unwrap_or_else(|| {
739 // Auto-detect whether to run based on the platform.
740 !self.target.ends_with("-fuchsia")
741 })
742 }
743
744 pub fn target_cfgs(&self) -> &TargetCfgs {
745 self.target_cfgs.get_or_init(|| TargetCfgs::new(self))
746 }
747
748 pub fn target_cfg(&self) -> &TargetCfg {
749 &self.target_cfgs().current
750 }
751
752 pub fn matches_arch(&self, arch: &str) -> bool {
753 self.target_cfg().arch == arch
754 || {
755 // Matching all the thumb variants as one can be convenient.
756 // (thumbv6m, thumbv7em, thumbv7m, etc.)
757 arch == "thumb" && self.target.starts_with("thumb")
758 }
759 || (arch == "i586" && self.target.starts_with("i586-"))
760 }
761
762 pub fn matches_os(&self, os: &str) -> bool {
763 self.target_cfg().os == os
764 }
765
766 pub fn matches_env(&self, env: &str) -> bool {
767 self.target_cfg().env == env
768 }
769
770 pub fn matches_abi(&self, abi: &str) -> bool {
771 self.target_cfg().abi == abi
772 }
773
774 #[cfg_attr(not(test), expect(dead_code, reason = "only used by tests for `ignore-{family}`"))]
775 pub(crate) fn matches_family(&self, family: &str) -> bool {
776 self.target_cfg().families.iter().any(|f| f == family)
777 }
778
779 pub fn is_big_endian(&self) -> bool {
780 self.target_cfg().endian == Endian::Big
781 }
782
783 pub fn get_pointer_width(&self) -> u32 {
784 *&self.target_cfg().pointer_width
785 }
786
787 pub fn can_unwind(&self) -> bool {
788 self.target_cfg().panic == PanicStrategy::Unwind
789 }
790
791 /// Get the list of builtin, 'well known' cfg names
792 pub fn builtin_cfg_names(&self) -> &HashSet<String> {
793 self.builtin_cfg_names.get_or_init(|| builtin_cfg_names(self))
794 }
795
796 /// Get the list of crate types that the target platform supports.
797 pub fn supported_crate_types(&self) -> &HashSet<String> {
798 self.supported_crate_types.get_or_init(|| supported_crate_types(self))
799 }
800
801 pub fn has_threads(&self) -> bool {
802 // Wasm targets don't have threads unless `-threads` is in the target
803 // name, such as `wasm32-wasip1-threads`.
804 if self.target.starts_with("wasm") {
805 return self.target.contains("threads");
806 }
807 true
808 }
809
810 pub fn has_asm_support(&self) -> bool {
811 // This should match the stable list in `LoweringContext::lower_inline_asm`.
812 static ASM_SUPPORTED_ARCHS: &[&str] = &[
813 "x86",
814 "x86_64",
815 "arm",
816 "aarch64",
817 "arm64ec",
818 "riscv32",
819 "riscv64",
820 "loongarch32",
821 "loongarch64",
822 "s390x",
823 // These targets require an additional asm_experimental_arch feature.
824 // "nvptx64", "hexagon", "mips", "mips64", "spirv", "wasm32",
825 ];
826 ASM_SUPPORTED_ARCHS.contains(&self.target_cfg().arch.as_str())
827 }
828
829 pub fn git_config(&self) -> GitConfig<'_> {
830 GitConfig {
831 nightly_branch: &self.nightly_branch,
832 git_merge_commit_email: &self.git_merge_commit_email,
833 }
834 }
835
836 pub fn has_subprocess_support(&self) -> bool {
837 // FIXME(#135928): compiletest is always a **host** tool. Building and running an
838 // capability detection executable against the **target** is not trivial. The short term
839 // solution here is to hard-code some targets to allow/deny, unfortunately.
840
841 let unsupported_target = self.target_cfg().env == "sgx"
842 || matches!(self.target_cfg().arch.as_str(), "wasm32" | "wasm64")
843 || self.target_cfg().os == "emscripten";
844 !unsupported_target
845 }
846
847 /// Whether the parallel frontend is enabled,
848 /// which is the case when `parallel_frontend_threads` is not set to `1`.
849 ///
850 /// - `0` means auto-detect: use the number of available hardware threads on the host.
851 /// But we treat it as the parallel frontend being enabled in this case.
852 /// - `1` means single-threaded (parallel frontend disabled).
853 /// - `>1` means an explicitly configured thread count.
854 pub fn parallel_frontend_enabled(&self) -> bool {
855 self.parallel_frontend_threads != 1
856 }
857}
858
859/// Known widths of `target_has_atomic`.
860pub const KNOWN_TARGET_HAS_ATOMIC_WIDTHS: &[&str] = &["8", "16", "32", "64", "128", "ptr"];
861
862#[derive(Debug, Clone)]
863pub struct TargetCfgs {
864 pub current: TargetCfg,
865 pub all_targets: HashSet<String>,
866 pub all_archs: HashSet<String>,
867 pub all_oses: HashSet<String>,
868 pub all_oses_and_envs: HashSet<String>,
869 pub all_envs: HashSet<String>,
870 pub all_abis: HashSet<String>,
871 pub all_families: HashSet<String>,
872 pub all_pointer_widths: HashSet<String>,
873 pub all_rustc_abis: HashSet<String>,
874}
875
876impl TargetCfgs {
877 fn new(config: &Config) -> TargetCfgs {
878 let mut targets: HashMap<String, TargetCfg> = serde_json::from_str(&query_rustc_output(
879 config,
880 &["--print=all-target-specs-json", "-Zunstable-options"],
881 Default::default(),
882 ))
883 .unwrap();
884
885 let mut all_targets = HashSet::new();
886 let mut all_archs = HashSet::new();
887 let mut all_oses = HashSet::new();
888 let mut all_oses_and_envs = HashSet::new();
889 let mut all_envs = HashSet::new();
890 let mut all_abis = HashSet::new();
891 let mut all_families = HashSet::new();
892 let mut all_pointer_widths = HashSet::new();
893 // NOTE: for distinction between `abi` and `rustc_abi`, see comment on
894 // `TargetCfg::rustc_abi`.
895 let mut all_rustc_abis = HashSet::new();
896
897 // If current target is not included in the `--print=all-target-specs-json` output,
898 // we check whether it is a custom target from the user or a synthetic target from bootstrap.
899 if !targets.contains_key(&config.target) {
900 let mut envs: HashMap<String, String> = HashMap::new();
901
902 if let Ok(t) = std::env::var("RUST_TARGET_PATH") {
903 envs.insert("RUST_TARGET_PATH".into(), t);
904 }
905
906 // This returns false only when the target is neither a synthetic target
907 // nor a custom target from the user, indicating it is most likely invalid.
908 if config.target.ends_with(".json") || !envs.is_empty() {
909 targets.insert(
910 config.target.clone(),
911 serde_json::from_str(&query_rustc_output(
912 config,
913 &[
914 "--print=target-spec-json",
915 "-Zunstable-options",
916 "--target",
917 &config.target,
918 ],
919 envs,
920 ))
921 .unwrap(),
922 );
923 }
924 }
925
926 for (target, cfg) in targets.iter() {
927 all_archs.insert(cfg.arch.clone());
928 all_oses.insert(cfg.os.clone());
929 all_oses_and_envs.insert(cfg.os_and_env());
930 all_envs.insert(cfg.env.clone());
931 all_abis.insert(cfg.abi.clone());
932 for family in &cfg.families {
933 all_families.insert(family.clone());
934 }
935 all_pointer_widths.insert(format!("{}bit", cfg.pointer_width));
936 if let Some(rustc_abi) = &cfg.rustc_abi {
937 all_rustc_abis.insert(rustc_abi.clone());
938 }
939 all_targets.insert(target.clone());
940 }
941
942 Self {
943 current: Self::get_current_target_config(config, &targets),
944 all_targets,
945 all_archs,
946 all_oses,
947 all_oses_and_envs,
948 all_envs,
949 all_abis,
950 all_families,
951 all_pointer_widths,
952 all_rustc_abis,
953 }
954 }
955
956 fn get_current_target_config(
957 config: &Config,
958 targets: &HashMap<String, TargetCfg>,
959 ) -> TargetCfg {
960 let mut cfg = targets[&config.target].clone();
961
962 // To get the target information for the current target, we take the target spec obtained
963 // from `--print=all-target-specs-json`, and then we enrich it with the information
964 // gathered from `--print=cfg --target=$target`.
965 //
966 // This is done because some parts of the target spec can be overridden with `-C` flags,
967 // which are respected for `--print=cfg` but not for `--print=all-target-specs-json`. The
968 // code below extracts them from `--print=cfg`: make sure to only override fields that can
969 // actually be changed with `-C` flags.
970 for config in query_rustc_output(
971 config,
972 // `-Zunstable-options` is necessary when compiletest is running with custom targets
973 // (such as synthetic targets used to bless mir-opt tests).
974 &["-Zunstable-options", "--print=cfg", "--target", &config.target],
975 Default::default(),
976 )
977 .trim()
978 .lines()
979 {
980 let (name, value) = config
981 .split_once("=\"")
982 .map(|(name, value)| {
983 (
984 name,
985 Some(
986 value
987 .strip_suffix('\"')
988 .expect("key-value pair should be properly quoted"),
989 ),
990 )
991 })
992 .unwrap_or_else(|| (config, None));
993
994 match (name, value) {
995 // Can be overridden with `-C panic=$strategy`.
996 ("panic", Some("abort")) => cfg.panic = PanicStrategy::Abort,
997 ("panic", Some("unwind")) => cfg.panic = PanicStrategy::Unwind,
998 ("panic", other) => panic!("unexpected value for panic cfg: {other:?}"),
999
1000 ("target_has_atomic", Some(width))
1001 if KNOWN_TARGET_HAS_ATOMIC_WIDTHS.contains(&width) =>
1002 {
1003 cfg.target_has_atomic.insert(width.to_string());
1004 }
1005 ("target_has_atomic", Some(other)) => {
1006 panic!("unexpected value for `target_has_atomic` cfg: {other:?}")
1007 }
1008 // Nightly-only std-internal impl detail.
1009 ("target_has_atomic", None) => {}
1010 _ => {}
1011 }
1012 }
1013
1014 cfg
1015 }
1016}
1017
1018#[derive(Clone, Debug, serde::Deserialize)]
1019#[serde(rename_all = "kebab-case")]
1020pub struct TargetCfg {
1021 pub(crate) arch: String,
1022 #[serde(default = "default_os")]
1023 pub(crate) os: String,
1024 #[serde(default)]
1025 pub(crate) env: String,
1026 #[serde(default)]
1027 pub(crate) abi: String,
1028 #[serde(rename = "target-family", default)]
1029 pub(crate) families: Vec<String>,
1030 #[serde(rename = "target-pointer-width")]
1031 pub(crate) pointer_width: u32,
1032 #[serde(rename = "target-endian", default)]
1033 endian: Endian,
1034 #[serde(rename = "panic-strategy", default)]
1035 pub(crate) panic: PanicStrategy,
1036 #[serde(default)]
1037 pub(crate) dynamic_linking: bool,
1038 #[serde(rename = "supported-sanitizers", default)]
1039 pub(crate) sanitizers: Vec<Sanitizer>,
1040 #[serde(rename = "supports-xray", default)]
1041 pub(crate) xray: bool,
1042 #[serde(default = "default_reloc_model")]
1043 pub(crate) relocation_model: String,
1044 // NOTE: `rustc_abi` should not be confused with `abi`. `rustc_abi` was introduced in #137037 to
1045 // make SSE2 *required* by the ABI (kind of a hack to make a target feature *required* via the
1046 // target spec).
1047 pub(crate) rustc_abi: Option<String>,
1048
1049 /// ELF is the "default" binary format, so the compiler typically doesn't
1050 /// emit a `"binary-format"` field for ELF targets.
1051 ///
1052 /// See `impl ToJson for Target` in `compiler/rustc_target/src/spec/json.rs`.
1053 #[serde(default = "default_binary_format_elf")]
1054 pub(crate) binary_format: Cow<'static, str>,
1055
1056 // Not present in target cfg json output, additional derived information.
1057 #[serde(skip)]
1058 /// Supported target atomic widths: e.g. `8` to `128` or `ptr`. This is derived from the builtin
1059 /// `target_has_atomic` `cfg`s e.g. `target_has_atomic="8"`.
1060 pub(crate) target_has_atomic: BTreeSet<String>,
1061}
1062
1063impl TargetCfg {
1064 pub(crate) fn os_and_env(&self) -> String {
1065 format!("{}-{}", self.os, self.env)
1066 }
1067}
1068
1069fn default_os() -> String {
1070 "none".into()
1071}
1072
1073fn default_reloc_model() -> String {
1074 "pic".into()
1075}
1076
1077fn default_binary_format_elf() -> Cow<'static, str> {
1078 Cow::Borrowed("elf")
1079}
1080
1081#[derive(Eq, PartialEq, Clone, Debug, Default, serde::Deserialize)]
1082#[serde(rename_all = "kebab-case")]
1083pub enum Endian {
1084 #[default]
1085 Little,
1086 Big,
1087}
1088
1089fn builtin_cfg_names(config: &Config) -> HashSet<String> {
1090 query_rustc_output(
1091 config,
1092 &["--print=check-cfg", "-Zunstable-options", "--check-cfg=cfg()"],
1093 Default::default(),
1094 )
1095 .lines()
1096 .map(|l| extract_cfg_name(&l).unwrap().to_string())
1097 .chain(std::iter::once(String::from("test")))
1098 .collect()
1099}
1100
1101/// Extract the cfg name from `cfg(name, values(...))` lines
1102fn extract_cfg_name(check_cfg_line: &str) -> Result<&str, &'static str> {
1103 let trimmed = check_cfg_line.trim();
1104
1105 #[rustfmt::skip]
1106 let inner = trimmed
1107 .strip_prefix("cfg(")
1108 .ok_or("missing cfg(")?
1109 .strip_suffix(")")
1110 .ok_or("missing )")?;
1111
1112 let first_comma = inner.find(',').ok_or("no comma found")?;
1113
1114 Ok(inner[..first_comma].trim())
1115}
1116
1117pub const KNOWN_CRATE_TYPES: &[&str] =
1118 &["bin", "cdylib", "dylib", "lib", "proc-macro", "rlib", "staticlib"];
1119
1120fn supported_crate_types(config: &Config) -> HashSet<String> {
1121 let crate_types: HashSet<_> = query_rustc_output(
1122 config,
1123 &["--target", &config.target, "--print=supported-crate-types", "-Zunstable-options"],
1124 Default::default(),
1125 )
1126 .lines()
1127 .map(|l| l.to_string())
1128 .collect();
1129
1130 for crate_type in crate_types.iter() {
1131 assert!(
1132 KNOWN_CRATE_TYPES.contains(&crate_type.as_str()),
1133 "unexpected crate type `{}`: known crate types are {:?}",
1134 crate_type,
1135 KNOWN_CRATE_TYPES
1136 );
1137 }
1138
1139 crate_types
1140}
1141
1142pub(crate) fn query_rustc_output(
1143 config: &Config,
1144 args: &[&str],
1145 envs: HashMap<String, String>,
1146) -> String {
1147 let query_rustc_path = config.query_rustc_path.as_deref().unwrap_or(&config.rustc_path);
1148
1149 let mut command = Command::new(query_rustc_path);
1150 add_dylib_path(&mut command, iter::once(&config.host_compile_lib_path));
1151 command.args(&config.target_rustcflags).args(args);
1152 command.env("RUSTC_BOOTSTRAP", "1");
1153 command.envs(envs);
1154
1155 let output = match command.output() {
1156 Ok(output) => output,
1157 Err(e) => {
1158 fatal!("failed to run {command:?}: {e}");
1159 }
1160 };
1161 if !output.status.success() {
1162 fatal!(
1163 "failed to run {command:?}\n--- stdout\n{}\n--- stderr\n{}",
1164 String::from_utf8(output.stdout).unwrap(),
1165 String::from_utf8(output.stderr).unwrap(),
1166 );
1167 }
1168 String::from_utf8(output.stdout).unwrap()
1169}
1170
1171/// Path information for a single test file.
1172#[derive(Debug, Clone)]
1173pub(crate) struct TestPaths {
1174 /// Full path to the test file.
1175 ///
1176 /// For example:
1177 /// - `/home/ferris/rust/tests/ui/warnings/hello-world.rs`
1178 ///
1179 /// ---
1180 ///
1181 /// For `run-make` tests, this path is the _directory_ that contains
1182 /// `rmake.rs`.
1183 ///
1184 /// For example:
1185 /// - `/home/ferris/rust/tests/run-make/emit`
1186 pub(crate) file: Utf8PathBuf,
1187
1188 /// Subset of the full path that excludes the suite directory and the
1189 /// test filename. For tests in the root of their test suite directory,
1190 /// this is blank.
1191 ///
1192 /// For example:
1193 /// - `file`: `/home/ferris/rust/tests/ui/warnings/hello-world.rs`
1194 /// - `relative_dir`: `warnings`
1195 pub(crate) relative_dir: Utf8PathBuf,
1196}
1197
1198/// Used by `ui` tests to generate things like `foo.stderr` from `foo.rs`.
1199pub fn expected_output_path(
1200 testpaths: &TestPaths,
1201 revision: Option<&str>,
1202 compare_mode: &Option<CompareMode>,
1203 kind: &str,
1204) -> Utf8PathBuf {
1205 assert!(UI_EXTENSIONS.contains(&kind));
1206 let mut parts = Vec::new();
1207
1208 if let Some(x) = revision {
1209 parts.push(x);
1210 }
1211 if let Some(ref x) = *compare_mode {
1212 parts.push(x.to_str());
1213 }
1214 parts.push(kind);
1215
1216 let extension = parts.join(".");
1217 testpaths.file.with_extension(extension)
1218}
1219
1220pub const UI_EXTENSIONS: &[&str] = &[
1221 UI_STDERR,
1222 UI_SVG,
1223 UI_WINDOWS_SVG,
1224 UI_STDOUT,
1225 UI_FIXED,
1226 UI_RUN_STDERR,
1227 UI_RUN_STDOUT,
1228 UI_STDERR_64,
1229 UI_STDERR_32,
1230 UI_STDERR_16,
1231 UI_COVERAGE,
1232 UI_COVERAGE_MAP,
1233];
1234pub const UI_STDERR: &str = "stderr";
1235pub const UI_SVG: &str = "svg";
1236pub const UI_WINDOWS_SVG: &str = "windows.svg";
1237pub const UI_STDOUT: &str = "stdout";
1238pub const UI_FIXED: &str = "fixed";
1239pub const UI_RUN_STDERR: &str = "run.stderr";
1240pub const UI_RUN_STDOUT: &str = "run.stdout";
1241pub const UI_STDERR_64: &str = "64bit.stderr";
1242pub const UI_STDERR_32: &str = "32bit.stderr";
1243pub const UI_STDERR_16: &str = "16bit.stderr";
1244pub const UI_COVERAGE: &str = "coverage";
1245pub const UI_COVERAGE_MAP: &str = "cov-map";
1246
1247/// Absolute path to the directory where all output for all tests in the given `relative_dir` group
1248/// should reside. Example:
1249///
1250/// ```text
1251/// /path/to/build/host-tuple/test/ui/relative/
1252/// ```
1253///
1254/// This is created early when tests are collected to avoid race conditions.
1255pub fn output_relative_path(config: &Config, relative_dir: &Utf8Path) -> Utf8PathBuf {
1256 config.build_test_suite_root.join(relative_dir)
1257}
1258
1259/// Generates a unique name for the test, such as `testname.revision.mode`.
1260pub fn output_testname_unique(
1261 config: &Config,
1262 testpaths: &TestPaths,
1263 revision: Option<&str>,
1264) -> Utf8PathBuf {
1265 let mode = config.compare_mode.as_ref().map_or("", |m| m.to_str());
1266 let debugger = config.debugger.as_ref().map_or("", |m| m.to_str());
1267 Utf8PathBuf::from(&testpaths.file.file_stem().unwrap())
1268 .with_extra_extension(config.mode.output_dir_disambiguator())
1269 .with_extra_extension(revision.unwrap_or(""))
1270 .with_extra_extension(mode)
1271 .with_extra_extension(debugger)
1272}
1273
1274/// Absolute path to the directory where all output for the given
1275/// test/revision should reside. Example:
1276/// /path/to/build/host-tuple/test/ui/relative/testname.revision.mode/
1277pub fn output_base_dir(
1278 config: &Config,
1279 testpaths: &TestPaths,
1280 revision: Option<&str>,
1281) -> Utf8PathBuf {
1282 output_relative_path(config, &testpaths.relative_dir)
1283 .join(output_testname_unique(config, testpaths, revision))
1284}
1285
1286/// Absolute path to the base filename used as output for the given
1287/// test/revision. Example:
1288/// /path/to/build/host-tuple/test/ui/relative/testname.revision.mode/testname
1289pub fn output_base_name(
1290 config: &Config,
1291 testpaths: &TestPaths,
1292 revision: Option<&str>,
1293) -> Utf8PathBuf {
1294 output_base_dir(config, testpaths, revision).join(testpaths.file.file_stem().unwrap())
1295}
1296
1297/// Absolute path to the directory to use for incremental compilation. Example:
1298/// /path/to/build/host-tuple/test/ui/relative/testname.mode/testname.inc
1299pub fn incremental_dir(
1300 config: &Config,
1301 testpaths: &TestPaths,
1302 revision: Option<&str>,
1303) -> Utf8PathBuf {
1304 output_base_name(config, testpaths, revision).with_extension("inc")
1305}