3 use std::ffi::OsString;
5 use std::path::{Path, PathBuf};
8 use crate::util::PathBufExt;
11 #[derive(Clone, Copy, PartialEq, Debug)]
31 pub fn disambiguator(self) -> &'static str {
32 // Pretty-printing tests could run concurrently, and if they do,
33 // they need to keep their output segregated.
41 impl FromStr for Mode {
43 fn from_str(s: &str) -> Result<Mode, ()> {
45 "compile-fail" => Ok(CompileFail),
46 "run-fail" => Ok(RunFail),
47 "run-pass-valgrind" => Ok(RunPassValgrind),
48 "pretty" => Ok(Pretty),
49 "debuginfo" => Ok(DebugInfo),
50 "codegen" => Ok(Codegen),
51 "rustdoc" => Ok(Rustdoc),
52 "rustdoc-json" => Ok(RustdocJson),
53 "codegen-units" => Ok(CodegenUnits),
54 "incremental" => Ok(Incremental),
55 "run-make" => Ok(RunMake),
57 "js-doc-test" => Ok(JsDocTest),
58 "mir-opt" => Ok(MirOpt),
59 "assembly" => Ok(Assembly),
65 impl fmt::Display for Mode {
66 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
68 CompileFail => "compile-fail",
69 RunFail => "run-fail",
70 RunPassValgrind => "run-pass-valgrind",
72 DebugInfo => "debuginfo",
75 RustdocJson => "rustdoc-json",
76 CodegenUnits => "codegen-units",
77 Incremental => "incremental",
78 RunMake => "run-make",
80 JsDocTest => "js-doc-test",
82 Assembly => "assembly",
84 fmt::Display::fmt(s, f)
88 #[derive(Clone, Copy, PartialEq, Debug, Hash)]
95 impl FromStr for PassMode {
97 fn from_str(s: &str) -> Result<Self, ()> {
99 "check" => Ok(PassMode::Check),
100 "build" => Ok(PassMode::Build),
101 "run" => Ok(PassMode::Run),
107 impl fmt::Display for PassMode {
108 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
109 let s = match *self {
110 PassMode::Check => "check",
111 PassMode::Build => "build",
112 PassMode::Run => "run",
114 fmt::Display::fmt(s, f)
118 #[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
125 #[derive(Clone, Debug, PartialEq)]
126 pub enum CompareMode {
135 pub(crate) fn to_str(&self) -> &'static str {
137 CompareMode::Nll => "nll",
138 CompareMode::Polonius => "polonius",
139 CompareMode::Chalk => "chalk",
140 CompareMode::SplitDwarf => "split-dwarf",
141 CompareMode::SplitDwarfSingle => "split-dwarf-single",
145 pub fn parse(s: String) -> CompareMode {
147 "nll" => CompareMode::Nll,
148 "polonius" => CompareMode::Polonius,
149 "chalk" => CompareMode::Chalk,
150 "split-dwarf" => CompareMode::SplitDwarf,
151 "split-dwarf-single" => CompareMode::SplitDwarfSingle,
152 x => panic!("unknown --compare-mode option: {}", x),
157 #[derive(Clone, Copy, Debug, PartialEq)]
165 fn to_str(&self) -> &'static str {
167 Debugger::Cdb => "cdb",
168 Debugger::Gdb => "gdb",
169 Debugger::Lldb => "lldb",
174 impl fmt::Display for Debugger {
175 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
176 fmt::Display::fmt(self.to_str(), f)
180 /// Configuration for compiletest
181 #[derive(Debug, Clone)]
183 /// `true` to to overwrite stderr/stdout files instead of complaining about changes in output.
186 /// The library paths required for running the compiler.
187 pub compile_lib_path: PathBuf,
189 /// The library paths required for running compiled programs.
190 pub run_lib_path: PathBuf,
192 /// The rustc executable.
193 pub rustc_path: PathBuf,
195 /// The rustdoc executable.
196 pub rustdoc_path: Option<PathBuf>,
198 /// The rust-demangler executable.
199 pub rust_demangler_path: Option<PathBuf>,
201 /// The Python executable to use for LLDB.
202 pub lldb_python: String,
204 /// The Python executable to use for htmldocck.
205 pub docck_python: String,
207 /// The LLVM `FileCheck` binary path.
208 pub llvm_filecheck: Option<PathBuf>,
210 /// Path to LLVM's bin directory.
211 pub llvm_bin_dir: Option<PathBuf>,
213 /// The valgrind path.
214 pub valgrind_path: Option<String>,
216 /// Whether to fail if we can't run run-pass-valgrind tests under valgrind
217 /// (or, alternatively, to silently run them like regular run-pass tests).
218 pub force_valgrind: bool,
220 /// The path to the Clang executable to run Clang-based tests with. If
221 /// `None` then these tests will be ignored.
222 pub run_clang_based_tests_with: Option<String>,
224 /// The directory containing the tests to run
225 pub src_base: PathBuf,
227 /// The directory where programs should be built
228 pub build_base: PathBuf,
230 /// The name of the stage being built (stage1, etc)
231 pub stage_id: String,
233 /// The test mode, compile-fail, run-fail, ui
236 /// The test suite (essentially which directory is running, but without the
237 /// directory prefix such as src/test)
240 /// The debugger to use in debuginfo mode. Unset otherwise.
241 pub debugger: Option<Debugger>,
243 /// Run ignored tests
244 pub run_ignored: bool,
246 /// Only run tests that match this filter
247 pub filter: Option<String>,
249 /// Exactly match the filter, rather than a substring
250 pub filter_exact: bool,
252 /// Force the pass mode of a check/build/run-pass test to this mode.
253 pub force_pass_mode: Option<PassMode>,
255 /// Write out a parseable log of tests that were run
256 pub logfile: Option<PathBuf>,
258 /// A command line to prefix program execution with,
259 /// for running under valgrind
260 pub runtool: Option<String>,
262 /// Flags to pass to the compiler when building for the host
263 pub host_rustcflags: Option<String>,
265 /// Flags to pass to the compiler when building for the target
266 pub target_rustcflags: Option<String>,
268 /// Target system to be tested
271 /// Host triple for the compiler being invoked
274 /// Path to / name of the Microsoft Console Debugger (CDB) executable
275 pub cdb: Option<OsString>,
278 pub cdb_version: Option<[u16; 4]>,
280 /// Path to / name of the GDB executable
281 pub gdb: Option<String>,
283 /// Version of GDB, encoded as ((major * 1000) + minor) * 1000 + patch
284 pub gdb_version: Option<u32>,
286 /// Whether GDB has native rust support
287 pub gdb_native_rust: bool,
290 pub lldb_version: Option<u32>,
292 /// Whether LLDB has native rust support
293 pub lldb_native_rust: bool,
296 pub llvm_version: Option<u32>,
298 /// Is LLVM a system LLVM
299 pub system_llvm: bool,
301 /// Path to the android tools
302 pub android_cross_path: PathBuf,
304 /// Extra parameter to run adb on arm-linux-androideabi
305 pub adb_path: String,
307 /// Extra parameter to run test suite on arm-linux-androideabi
308 pub adb_test_dir: String,
310 /// status whether android device available or not
311 pub adb_device_status: bool,
313 /// the path containing LLDB's Python module
314 pub lldb_python_dir: Option<String>,
316 /// Explain what's going on
319 /// Print one character per test instead of one line
322 /// Whether to use colors in test.
323 pub color: ColorConfig,
325 /// where to find the remote test client process, if we're using it
326 pub remote_test_client: Option<PathBuf>,
328 /// mode describing what file the actual ui output will be compared to
329 pub compare_mode: Option<CompareMode>,
331 /// If true, this will generate a coverage file with UI test files that run `MachineApplicable`
332 /// diagnostics but are missing `run-rustfix` annotations. The generated coverage file is
333 /// created in `/<build_base>/rustfix_missing_coverage.txt`
334 pub rustfix_coverage: bool,
336 /// whether to run `tidy` when a rustdoc test fails
339 // Configuration for various run-make tests frobbing things like C compilers
340 // or querying about various LLVM component information.
345 pub linker: Option<String>,
346 pub llvm_components: String,
348 /// Path to a NodeJS executable. Used for JS doctests, emscripten and WASM tests
349 pub nodejs: Option<String>,
352 #[derive(Debug, Clone)]
353 pub struct TestPaths {
354 pub file: PathBuf, // e.g., compile-test/foo/bar/baz.rs
355 pub relative_dir: PathBuf, // e.g., foo/bar
358 /// Used by `ui` tests to generate things like `foo.stderr` from `foo.rs`.
359 pub fn expected_output_path(
360 testpaths: &TestPaths,
361 revision: Option<&str>,
362 compare_mode: &Option<CompareMode>,
365 assert!(UI_EXTENSIONS.contains(&kind));
366 let mut parts = Vec::new();
368 if let Some(x) = revision {
371 if let Some(ref x) = *compare_mode {
372 parts.push(x.to_str());
376 let extension = parts.join(".");
377 testpaths.file.with_extension(extension)
380 pub const UI_EXTENSIONS: &[&str] = &[UI_STDERR, UI_STDOUT, UI_FIXED, UI_RUN_STDERR, UI_RUN_STDOUT];
381 pub const UI_STDERR: &str = "stderr";
382 pub const UI_STDOUT: &str = "stdout";
383 pub const UI_FIXED: &str = "fixed";
384 pub const UI_RUN_STDERR: &str = "run.stderr";
385 pub const UI_RUN_STDOUT: &str = "run.stdout";
387 /// Absolute path to the directory where all output for all tests in the given
388 /// `relative_dir` group should reside. Example:
389 /// /path/to/build/host-triple/test/ui/relative/
390 /// This is created early when tests are collected to avoid race conditions.
391 pub fn output_relative_path(config: &Config, relative_dir: &Path) -> PathBuf {
392 config.build_base.join(relative_dir)
395 /// Generates a unique name for the test, such as `testname.revision.mode`.
396 pub fn output_testname_unique(
398 testpaths: &TestPaths,
399 revision: Option<&str>,
401 let mode = config.compare_mode.as_ref().map_or("", |m| m.to_str());
402 let debugger = config.debugger.as_ref().map_or("", |m| m.to_str());
403 PathBuf::from(&testpaths.file.file_stem().unwrap())
404 .with_extra_extension(revision.unwrap_or(""))
405 .with_extra_extension(mode)
406 .with_extra_extension(debugger)
409 /// Absolute path to the directory where all output for the given
410 /// test/revision should reside. Example:
411 /// /path/to/build/host-triple/test/ui/relative/testname.revision.mode/
412 pub fn output_base_dir(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> PathBuf {
413 output_relative_path(config, &testpaths.relative_dir)
414 .join(output_testname_unique(config, testpaths, revision))
417 /// Absolute path to the base filename used as output for the given
418 /// test/revision. Example:
419 /// /path/to/build/host-triple/test/ui/relative/testname.revision.mode/testname
420 pub fn output_base_name(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> PathBuf {
421 output_base_dir(config, testpaths, revision).join(testpaths.file.file_stem().unwrap())