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