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 {
133 pub(crate) fn to_str(&self) -> &'static str {
135 CompareMode::Nll => "nll",
136 CompareMode::Polonius => "polonius",
137 CompareMode::Chalk => "chalk",
141 pub fn parse(s: String) -> CompareMode {
143 "nll" => CompareMode::Nll,
144 "polonius" => CompareMode::Polonius,
145 "chalk" => CompareMode::Chalk,
146 x => panic!("unknown --compare-mode option: {}", x),
151 #[derive(Clone, Copy, Debug, PartialEq)]
159 fn to_str(&self) -> &'static str {
161 Debugger::Cdb => "cdb",
162 Debugger::Gdb => "gdb",
163 Debugger::Lldb => "lldb",
168 impl fmt::Display for Debugger {
169 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
170 fmt::Display::fmt(self.to_str(), f)
174 /// Configuration for compiletest
175 #[derive(Debug, Clone)]
177 /// `true` to to overwrite stderr/stdout files instead of complaining about changes in output.
180 /// The library paths required for running the compiler.
181 pub compile_lib_path: PathBuf,
183 /// The library paths required for running compiled programs.
184 pub run_lib_path: PathBuf,
186 /// The rustc executable.
187 pub rustc_path: PathBuf,
189 /// The rustdoc executable.
190 pub rustdoc_path: Option<PathBuf>,
192 /// The rust-demangler executable.
193 pub rust_demangler_path: Option<PathBuf>,
195 /// The Python executable to use for LLDB.
196 pub lldb_python: String,
198 /// The Python executable to use for htmldocck.
199 pub docck_python: String,
201 /// The LLVM `FileCheck` binary path.
202 pub llvm_filecheck: Option<PathBuf>,
204 /// Path to LLVM's bin directory.
205 pub llvm_bin_dir: Option<PathBuf>,
207 /// The valgrind path.
208 pub valgrind_path: Option<String>,
210 /// Whether to fail if we can't run run-pass-valgrind tests under valgrind
211 /// (or, alternatively, to silently run them like regular run-pass tests).
212 pub force_valgrind: bool,
214 /// The path to the Clang executable to run Clang-based tests with. If
215 /// `None` then these tests will be ignored.
216 pub run_clang_based_tests_with: Option<String>,
218 /// The directory containing the tests to run
219 pub src_base: PathBuf,
221 /// The directory where programs should be built
222 pub build_base: PathBuf,
224 /// The name of the stage being built (stage1, etc)
225 pub stage_id: String,
227 /// The test mode, compile-fail, run-fail, ui
230 /// The test suite (essentially which directory is running, but without the
231 /// directory prefix such as src/test)
234 /// The debugger to use in debuginfo mode. Unset otherwise.
235 pub debugger: Option<Debugger>,
237 /// Run ignored tests
238 pub run_ignored: bool,
240 /// Only run tests that match this filter
241 pub filter: Option<String>,
243 /// Exactly match the filter, rather than a substring
244 pub filter_exact: bool,
246 /// Force the pass mode of a check/build/run-pass test to this mode.
247 pub force_pass_mode: Option<PassMode>,
249 /// Write out a parseable log of tests that were run
250 pub logfile: Option<PathBuf>,
252 /// A command line to prefix program execution with,
253 /// for running under valgrind
254 pub runtool: Option<String>,
256 /// Flags to pass to the compiler when building for the host
257 pub host_rustcflags: Option<String>,
259 /// Flags to pass to the compiler when building for the target
260 pub target_rustcflags: Option<String>,
262 /// Target system to be tested
265 /// Host triple for the compiler being invoked
268 /// Path to / name of the Microsoft Console Debugger (CDB) executable
269 pub cdb: Option<OsString>,
272 pub cdb_version: Option<[u16; 4]>,
274 /// Path to / name of the GDB executable
275 pub gdb: Option<String>,
277 /// Version of GDB, encoded as ((major * 1000) + minor) * 1000 + patch
278 pub gdb_version: Option<u32>,
280 /// Whether GDB has native rust support
281 pub gdb_native_rust: bool,
284 pub lldb_version: Option<u32>,
286 /// Whether LLDB has native rust support
287 pub lldb_native_rust: bool,
290 pub llvm_version: Option<u32>,
292 /// Is LLVM a system LLVM
293 pub system_llvm: bool,
295 /// Path to the android tools
296 pub android_cross_path: PathBuf,
298 /// Extra parameter to run adb on arm-linux-androideabi
299 pub adb_path: String,
301 /// Extra parameter to run test suite on arm-linux-androideabi
302 pub adb_test_dir: String,
304 /// status whether android device available or not
305 pub adb_device_status: bool,
307 /// the path containing LLDB's Python module
308 pub lldb_python_dir: Option<String>,
310 /// Explain what's going on
313 /// Print one character per test instead of one line
316 /// Whether to use colors in test.
317 pub color: ColorConfig,
319 /// where to find the remote test client process, if we're using it
320 pub remote_test_client: Option<PathBuf>,
322 /// mode describing what file the actual ui output will be compared to
323 pub compare_mode: Option<CompareMode>,
325 /// If true, this will generate a coverage file with UI test files that run `MachineApplicable`
326 /// diagnostics but are missing `run-rustfix` annotations. The generated coverage file is
327 /// created in `/<build_base>/rustfix_missing_coverage.txt`
328 pub rustfix_coverage: bool,
330 // Configuration for various run-make tests frobbing things like C compilers
331 // or querying about various LLVM component information.
336 pub linker: Option<String>,
337 pub llvm_components: String,
339 /// Path to a NodeJS executable. Used for JS doctests, emscripten and WASM tests
340 pub nodejs: Option<String>,
343 #[derive(Debug, Clone)]
344 pub struct TestPaths {
345 pub file: PathBuf, // e.g., compile-test/foo/bar/baz.rs
346 pub relative_dir: PathBuf, // e.g., foo/bar
349 /// Used by `ui` tests to generate things like `foo.stderr` from `foo.rs`.
350 pub fn expected_output_path(
351 testpaths: &TestPaths,
352 revision: Option<&str>,
353 compare_mode: &Option<CompareMode>,
356 assert!(UI_EXTENSIONS.contains(&kind));
357 let mut parts = Vec::new();
359 if let Some(x) = revision {
362 if let Some(ref x) = *compare_mode {
363 parts.push(x.to_str());
367 let extension = parts.join(".");
368 testpaths.file.with_extension(extension)
371 pub const UI_EXTENSIONS: &[&str] = &[UI_STDERR, UI_STDOUT, UI_FIXED, UI_RUN_STDERR, UI_RUN_STDOUT];
372 pub const UI_STDERR: &str = "stderr";
373 pub const UI_STDOUT: &str = "stdout";
374 pub const UI_FIXED: &str = "fixed";
375 pub const UI_RUN_STDERR: &str = "run.stderr";
376 pub const UI_RUN_STDOUT: &str = "run.stdout";
378 /// Absolute path to the directory where all output for all tests in the given
379 /// `relative_dir` group should reside. Example:
380 /// /path/to/build/host-triple/test/ui/relative/
381 /// This is created early when tests are collected to avoid race conditions.
382 pub fn output_relative_path(config: &Config, relative_dir: &Path) -> PathBuf {
383 config.build_base.join(relative_dir)
386 /// Generates a unique name for the test, such as `testname.revision.mode`.
387 pub fn output_testname_unique(
389 testpaths: &TestPaths,
390 revision: Option<&str>,
392 let mode = config.compare_mode.as_ref().map_or("", |m| m.to_str());
393 let debugger = config.debugger.as_ref().map_or("", |m| m.to_str());
394 PathBuf::from(&testpaths.file.file_stem().unwrap())
395 .with_extra_extension(revision.unwrap_or(""))
396 .with_extra_extension(mode)
397 .with_extra_extension(debugger)
400 /// Absolute path to the directory where all output for the given
401 /// test/revision should reside. Example:
402 /// /path/to/build/host-triple/test/ui/relative/testname.revision.mode/
403 pub fn output_base_dir(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> PathBuf {
404 output_relative_path(config, &testpaths.relative_dir)
405 .join(output_testname_unique(config, testpaths, revision))
408 /// Absolute path to the base filename used as output for the given
409 /// test/revision. Example:
410 /// /path/to/build/host-triple/test/ui/relative/testname.revision.mode/testname
411 pub fn output_base_name(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> PathBuf {
412 output_base_dir(config, testpaths, revision).join(testpaths.file.file_stem().unwrap())