3 use std::ffi::OsString;
5 use std::path::{Path, PathBuf};
8 use crate::util::PathBufExt;
11 #[derive(Clone, Copy, PartialEq, Debug)]
29 pub fn disambiguator(self) -> &'static str {
30 // Pretty-printing tests could run concurrently, and if they do,
31 // they need to keep their output segregated.
39 impl FromStr for Mode {
41 fn from_str(s: &str) -> Result<Mode, ()> {
43 "run-pass-valgrind" => Ok(RunPassValgrind),
44 "pretty" => Ok(Pretty),
45 "debuginfo" => Ok(DebugInfo),
46 "codegen" => Ok(Codegen),
47 "rustdoc" => Ok(Rustdoc),
48 "rustdoc-json" => Ok(RustdocJson),
49 "codegen-units" => Ok(CodegenUnits),
50 "incremental" => Ok(Incremental),
51 "run-make" => Ok(RunMake),
53 "js-doc-test" => Ok(JsDocTest),
54 "mir-opt" => Ok(MirOpt),
55 "assembly" => Ok(Assembly),
61 impl fmt::Display for Mode {
62 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
64 RunPassValgrind => "run-pass-valgrind",
66 DebugInfo => "debuginfo",
69 RustdocJson => "rustdoc-json",
70 CodegenUnits => "codegen-units",
71 Incremental => "incremental",
72 RunMake => "run-make",
74 JsDocTest => "js-doc-test",
76 Assembly => "assembly",
78 fmt::Display::fmt(s, f)
82 #[derive(Clone, Copy, PartialEq, Debug, Hash)]
89 impl FromStr for PassMode {
91 fn from_str(s: &str) -> Result<Self, ()> {
93 "check" => Ok(PassMode::Check),
94 "build" => Ok(PassMode::Build),
95 "run" => Ok(PassMode::Run),
101 impl fmt::Display for PassMode {
102 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
103 let s = match *self {
104 PassMode::Check => "check",
105 PassMode::Build => "build",
106 PassMode::Run => "run",
108 fmt::Display::fmt(s, f)
112 #[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
119 #[derive(Clone, Debug, PartialEq)]
120 pub enum CompareMode {
128 pub(crate) fn to_str(&self) -> &'static str {
130 CompareMode::Polonius => "polonius",
131 CompareMode::Chalk => "chalk",
132 CompareMode::SplitDwarf => "split-dwarf",
133 CompareMode::SplitDwarfSingle => "split-dwarf-single",
137 pub fn parse(s: String) -> CompareMode {
139 "polonius" => CompareMode::Polonius,
140 "chalk" => CompareMode::Chalk,
141 "split-dwarf" => CompareMode::SplitDwarf,
142 "split-dwarf-single" => CompareMode::SplitDwarfSingle,
143 x => panic!("unknown --compare-mode option: {}", x),
148 #[derive(Clone, Copy, Debug, PartialEq)]
156 fn to_str(&self) -> &'static str {
158 Debugger::Cdb => "cdb",
159 Debugger::Gdb => "gdb",
160 Debugger::Lldb => "lldb",
165 impl fmt::Display for Debugger {
166 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
167 fmt::Display::fmt(self.to_str(), f)
171 #[derive(Clone, Copy, Debug, PartialEq)]
172 pub enum PanicStrategy {
177 /// Configuration for compiletest
178 #[derive(Debug, Clone)]
180 /// `true` to overwrite stderr/stdout files instead of complaining about changes in output.
183 /// The library paths required for running the compiler.
184 pub compile_lib_path: PathBuf,
186 /// The library paths required for running compiled programs.
187 pub run_lib_path: PathBuf,
189 /// The rustc executable.
190 pub rustc_path: PathBuf,
192 /// The rustdoc executable.
193 pub rustdoc_path: Option<PathBuf>,
195 /// The rust-demangler executable.
196 pub rust_demangler_path: Option<PathBuf>,
198 /// The Python executable to use for LLDB and htmldocck.
201 /// The jsondocck executable.
202 pub jsondocck_path: Option<String>,
204 /// The LLVM `FileCheck` binary path.
205 pub llvm_filecheck: Option<PathBuf>,
207 /// Path to LLVM's bin directory.
208 pub llvm_bin_dir: Option<PathBuf>,
210 /// The valgrind path.
211 pub valgrind_path: Option<String>,
213 /// Whether to fail if we can't run run-pass-valgrind tests under valgrind
214 /// (or, alternatively, to silently run them like regular run-pass tests).
215 pub force_valgrind: bool,
217 /// The path to the Clang executable to run Clang-based tests with. If
218 /// `None` then these tests will be ignored.
219 pub run_clang_based_tests_with: Option<String>,
221 /// The directory containing the tests to run
222 pub src_base: PathBuf,
224 /// The directory where programs should be built
225 pub build_base: PathBuf,
227 /// The name of the stage being built (stage1, etc)
228 pub stage_id: String,
230 /// The test mode, e.g. ui or debuginfo.
233 /// The test suite (essentially which directory is running, but without the
234 /// directory prefix such as src/test)
237 /// The debugger to use in debuginfo mode. Unset otherwise.
238 pub debugger: Option<Debugger>,
240 /// Run ignored tests
241 pub run_ignored: bool,
243 /// Only run tests that match these filters
244 pub filters: Vec<String>,
246 /// Skip tests tests matching these substrings. Corresponds to
247 /// `test::TestOpts::skip`. `filter_exact` does not apply to these flags.
248 pub skip: Vec<String>,
250 /// Exactly match the filter, rather than a substring
251 pub filter_exact: bool,
253 /// Force the pass mode of a check/build/run-pass test to this mode.
254 pub force_pass_mode: Option<PassMode>,
256 /// Explicitly enable or disable running.
257 pub run: Option<bool>,
259 /// Write out a parseable log of tests that were run
260 pub logfile: Option<PathBuf>,
262 /// A command line to prefix program execution with,
263 /// for running under valgrind
264 pub runtool: Option<String>,
266 /// Flags to pass to the compiler when building for the host
267 pub host_rustcflags: Option<String>,
269 /// Flags to pass to the compiler when building for the target
270 pub target_rustcflags: Option<String>,
272 /// What panic strategy the target is built with. Unwind supports Abort, but
274 pub target_panic: PanicStrategy,
276 /// Target system to be tested
279 /// Host triple for the compiler being invoked
282 /// Path to / name of the Microsoft Console Debugger (CDB) executable
283 pub cdb: Option<OsString>,
286 pub cdb_version: Option<[u16; 4]>,
288 /// Path to / name of the GDB executable
289 pub gdb: Option<String>,
291 /// Version of GDB, encoded as ((major * 1000) + minor) * 1000 + patch
292 pub gdb_version: Option<u32>,
294 /// Whether GDB has native rust support
295 pub gdb_native_rust: bool,
298 pub lldb_version: Option<u32>,
300 /// Whether LLDB has native rust support
301 pub lldb_native_rust: bool,
304 pub llvm_version: Option<u32>,
306 /// Is LLVM a system LLVM
307 pub system_llvm: bool,
309 /// Path to the android tools
310 pub android_cross_path: PathBuf,
312 /// Extra parameter to run adb on arm-linux-androideabi
313 pub adb_path: String,
315 /// Extra parameter to run test suite on arm-linux-androideabi
316 pub adb_test_dir: String,
318 /// status whether android device available or not
319 pub adb_device_status: bool,
321 /// the path containing LLDB's Python module
322 pub lldb_python_dir: Option<String>,
324 /// Explain what's going on
327 /// Print one character per test instead of one line
330 /// Whether to use colors in test.
331 pub color: ColorConfig,
333 /// where to find the remote test client process, if we're using it
334 pub remote_test_client: Option<PathBuf>,
336 /// mode describing what file the actual ui output will be compared to
337 pub compare_mode: Option<CompareMode>,
339 /// If true, this will generate a coverage file with UI test files that run `MachineApplicable`
340 /// diagnostics but are missing `run-rustfix` annotations. The generated coverage file is
341 /// created in `/<build_base>/rustfix_missing_coverage.txt`
342 pub rustfix_coverage: bool,
344 /// whether to run `tidy` when a rustdoc test fails
347 /// The current Rust channel
350 /// The default Rust edition
351 pub edition: Option<String>,
353 // Configuration for various run-make tests frobbing things like C compilers
354 // or querying about various LLVM component information.
358 pub cxxflags: String,
360 pub linker: Option<String>,
361 pub llvm_components: String,
363 /// Path to a NodeJS executable. Used for JS doctests, emscripten and WASM tests
364 pub nodejs: Option<String>,
365 /// Path to a npm executable. Used for rustdoc GUI tests
366 pub npm: Option<String>,
368 /// Whether to rerun tests even if the inputs are unchanged.
369 pub force_rerun: bool,
373 pub fn run_enabled(&self) -> bool {
374 self.run.unwrap_or_else(|| {
375 // Auto-detect whether to run based on the platform.
376 !self.target.ends_with("-fuchsia")
381 #[derive(Debug, Clone)]
382 pub struct TestPaths {
383 pub file: PathBuf, // e.g., compile-test/foo/bar/baz.rs
384 pub relative_dir: PathBuf, // e.g., foo/bar
387 /// Used by `ui` tests to generate things like `foo.stderr` from `foo.rs`.
388 pub fn expected_output_path(
389 testpaths: &TestPaths,
390 revision: Option<&str>,
391 compare_mode: &Option<CompareMode>,
394 assert!(UI_EXTENSIONS.contains(&kind));
395 let mut parts = Vec::new();
397 if let Some(x) = revision {
400 if let Some(ref x) = *compare_mode {
401 parts.push(x.to_str());
405 let extension = parts.join(".");
406 testpaths.file.with_extension(extension)
409 pub const UI_EXTENSIONS: &[&str] = &[
419 pub const UI_STDERR: &str = "stderr";
420 pub const UI_STDOUT: &str = "stdout";
421 pub const UI_FIXED: &str = "fixed";
422 pub const UI_RUN_STDERR: &str = "run.stderr";
423 pub const UI_RUN_STDOUT: &str = "run.stdout";
424 pub const UI_STDERR_64: &str = "64bit.stderr";
425 pub const UI_STDERR_32: &str = "32bit.stderr";
426 pub const UI_STDERR_16: &str = "16bit.stderr";
428 /// Absolute path to the directory where all output for all tests in the given
429 /// `relative_dir` group should reside. Example:
430 /// /path/to/build/host-triple/test/ui/relative/
431 /// This is created early when tests are collected to avoid race conditions.
432 pub fn output_relative_path(config: &Config, relative_dir: &Path) -> PathBuf {
433 config.build_base.join(relative_dir)
436 /// Generates a unique name for the test, such as `testname.revision.mode`.
437 pub fn output_testname_unique(
439 testpaths: &TestPaths,
440 revision: Option<&str>,
442 let mode = config.compare_mode.as_ref().map_or("", |m| m.to_str());
443 let debugger = config.debugger.as_ref().map_or("", |m| m.to_str());
444 PathBuf::from(&testpaths.file.file_stem().unwrap())
445 .with_extra_extension(revision.unwrap_or(""))
446 .with_extra_extension(mode)
447 .with_extra_extension(debugger)
450 /// Absolute path to the directory where all output for the given
451 /// test/revision should reside. Example:
452 /// /path/to/build/host-triple/test/ui/relative/testname.revision.mode/
453 pub fn output_base_dir(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> PathBuf {
454 output_relative_path(config, &testpaths.relative_dir)
455 .join(output_testname_unique(config, testpaths, revision))
458 /// Absolute path to the base filename used as output for the given
459 /// test/revision. Example:
460 /// /path/to/build/host-triple/test/ui/relative/testname.revision.mode/testname
461 pub fn output_base_name(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> PathBuf {
462 output_base_dir(config, testpaths, revision).join(testpaths.file.file_stem().unwrap())
465 /// Absolute path to the directory to use for incremental compilation. Example:
466 /// /path/to/build/host-triple/test/ui/relative/testname.mode/testname.inc
467 pub fn incremental_dir(config: &Config, testpaths: &TestPaths) -> PathBuf {
468 output_base_name(config, testpaths, None).with_extension("inc")