3 use std::ffi::OsString;
5 use std::path::{Path, PathBuf};
8 use crate::util::PathBufExt;
11 #[derive(Clone, Copy, PartialEq, Debug)]
30 pub fn disambiguator(self) -> &'static str {
31 // Pretty-printing tests could run concurrently, and if they do,
32 // they need to keep their output segregated.
40 impl FromStr for Mode {
42 fn from_str(s: &str) -> Result<Mode, ()> {
44 "compile-fail" => Ok(CompileFail),
45 "run-fail" => Ok(RunFail),
46 "run-pass-valgrind" => Ok(RunPassValgrind),
47 "pretty" => Ok(Pretty),
48 "debuginfo" => Ok(DebugInfo),
49 "codegen" => Ok(Codegen),
50 "rustdoc" => Ok(Rustdoc),
51 "codegen-units" => Ok(CodegenUnits),
52 "incremental" => Ok(Incremental),
53 "run-make" => Ok(RunMake),
55 "js-doc-test" => Ok(JsDocTest),
56 "mir-opt" => Ok(MirOpt),
57 "assembly" => Ok(Assembly),
63 impl fmt::Display for Mode {
64 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
66 CompileFail => "compile-fail",
67 RunFail => "run-fail",
68 RunPassValgrind => "run-pass-valgrind",
70 DebugInfo => "debuginfo",
73 CodegenUnits => "codegen-units",
74 Incremental => "incremental",
75 RunMake => "run-make",
77 JsDocTest => "js-doc-test",
79 Assembly => "assembly",
81 fmt::Display::fmt(s, f)
85 #[derive(Clone, Copy, PartialEq, Debug, Hash)]
92 impl FromStr for PassMode {
94 fn from_str(s: &str) -> Result<Self, ()> {
96 "check" => Ok(PassMode::Check),
97 "build" => Ok(PassMode::Build),
98 "run" => Ok(PassMode::Run),
104 impl fmt::Display for PassMode {
105 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
106 let s = match *self {
107 PassMode::Check => "check",
108 PassMode::Build => "build",
109 PassMode::Run => "run",
111 fmt::Display::fmt(s, f)
115 #[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
122 #[derive(Clone, Debug, PartialEq)]
123 pub enum CompareMode {
130 pub(crate) fn to_str(&self) -> &'static str {
132 CompareMode::Nll => "nll",
133 CompareMode::Polonius => "polonius",
134 CompareMode::Chalk => "chalk",
138 pub fn parse(s: String) -> CompareMode {
140 "nll" => CompareMode::Nll,
141 "polonius" => CompareMode::Polonius,
142 "chalk" => CompareMode::Chalk,
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 /// Configuration for compiletest
172 #[derive(Debug, Clone)]
174 /// `true` to to overwrite stderr/stdout files instead of complaining about changes in output.
177 /// The library paths required for running the compiler.
178 pub compile_lib_path: PathBuf,
180 /// The library paths required for running compiled programs.
181 pub run_lib_path: PathBuf,
183 /// The rustc executable.
184 pub rustc_path: PathBuf,
186 /// The rustdoc executable.
187 pub rustdoc_path: Option<PathBuf>,
189 /// The rust-demangler executable.
190 pub rust_demangler_path: Option<PathBuf>,
192 /// The Python executable to use for LLDB.
193 pub lldb_python: String,
195 /// The Python executable to use for htmldocck.
196 pub docck_python: String,
198 /// The LLVM `FileCheck` binary path.
199 pub llvm_filecheck: Option<PathBuf>,
201 /// Path to LLVM's bin directory.
202 pub llvm_bin_dir: Option<PathBuf>,
204 /// The valgrind path.
205 pub valgrind_path: Option<String>,
207 /// Whether to fail if we can't run run-pass-valgrind tests under valgrind
208 /// (or, alternatively, to silently run them like regular run-pass tests).
209 pub force_valgrind: bool,
211 /// The path to the Clang executable to run Clang-based tests with. If
212 /// `None` then these tests will be ignored.
213 pub run_clang_based_tests_with: Option<String>,
215 /// The directory containing the tests to run
216 pub src_base: PathBuf,
218 /// The directory where programs should be built
219 pub build_base: PathBuf,
221 /// The name of the stage being built (stage1, etc)
222 pub stage_id: String,
224 /// The test mode, compile-fail, run-fail, ui
227 /// The test suite (essentially which directory is running, but without the
228 /// directory prefix such as src/test)
231 /// The debugger to use in debuginfo mode. Unset otherwise.
232 pub debugger: Option<Debugger>,
234 /// Run ignored tests
235 pub run_ignored: bool,
237 /// Only run tests that match this filter
238 pub filter: Option<String>,
240 /// Exactly match the filter, rather than a substring
241 pub filter_exact: bool,
243 /// Force the pass mode of a check/build/run-pass test to this mode.
244 pub force_pass_mode: Option<PassMode>,
246 /// Write out a parseable log of tests that were run
247 pub logfile: Option<PathBuf>,
249 /// A command line to prefix program execution with,
250 /// for running under valgrind
251 pub runtool: Option<String>,
253 /// Flags to pass to the compiler when building for the host
254 pub host_rustcflags: Option<String>,
256 /// Flags to pass to the compiler when building for the target
257 pub target_rustcflags: Option<String>,
259 /// Target system to be tested
262 /// Host triple for the compiler being invoked
265 /// Path to / name of the Microsoft Console Debugger (CDB) executable
266 pub cdb: Option<OsString>,
269 pub cdb_version: Option<[u16; 4]>,
271 /// Path to / name of the GDB executable
272 pub gdb: Option<String>,
274 /// Version of GDB, encoded as ((major * 1000) + minor) * 1000 + patch
275 pub gdb_version: Option<u32>,
277 /// Whether GDB has native rust support
278 pub gdb_native_rust: bool,
281 pub lldb_version: Option<u32>,
283 /// Whether LLDB has native rust support
284 pub lldb_native_rust: bool,
287 pub llvm_version: Option<u32>,
289 /// Is LLVM a system LLVM
290 pub system_llvm: bool,
292 /// Path to the android tools
293 pub android_cross_path: PathBuf,
295 /// Extra parameter to run adb on arm-linux-androideabi
296 pub adb_path: String,
298 /// Extra parameter to run test suite on arm-linux-androideabi
299 pub adb_test_dir: String,
301 /// status whether android device available or not
302 pub adb_device_status: bool,
304 /// the path containing LLDB's Python module
305 pub lldb_python_dir: Option<String>,
307 /// Explain what's going on
310 /// Print one character per test instead of one line
313 /// Whether to use colors in test.
314 pub color: ColorConfig,
316 /// where to find the remote test client process, if we're using it
317 pub remote_test_client: Option<PathBuf>,
319 /// mode describing what file the actual ui output will be compared to
320 pub compare_mode: Option<CompareMode>,
322 /// If true, this will generate a coverage file with UI test files that run `MachineApplicable`
323 /// diagnostics but are missing `run-rustfix` annotations. The generated coverage file is
324 /// created in `/<build_base>/rustfix_missing_coverage.txt`
325 pub rustfix_coverage: bool,
327 // Configuration for various run-make tests frobbing things like C compilers
328 // or querying about various LLVM component information.
333 pub linker: Option<String>,
334 pub llvm_components: String,
336 /// Path to a NodeJS executable. Used for JS doctests, emscripten and WASM tests
337 pub nodejs: Option<String>,
340 #[derive(Debug, Clone)]
341 pub struct TestPaths {
342 pub file: PathBuf, // e.g., compile-test/foo/bar/baz.rs
343 pub relative_dir: PathBuf, // e.g., foo/bar
346 /// Used by `ui` tests to generate things like `foo.stderr` from `foo.rs`.
347 pub fn expected_output_path(
348 testpaths: &TestPaths,
349 revision: Option<&str>,
350 compare_mode: &Option<CompareMode>,
353 assert!(UI_EXTENSIONS.contains(&kind));
354 let mut parts = Vec::new();
356 if let Some(x) = revision {
359 if let Some(ref x) = *compare_mode {
360 parts.push(x.to_str());
364 let extension = parts.join(".");
365 testpaths.file.with_extension(extension)
368 pub const UI_EXTENSIONS: &[&str] = &[UI_STDERR, UI_STDOUT, UI_FIXED, UI_RUN_STDERR, UI_RUN_STDOUT];
369 pub const UI_STDERR: &str = "stderr";
370 pub const UI_STDOUT: &str = "stdout";
371 pub const UI_FIXED: &str = "fixed";
372 pub const UI_RUN_STDERR: &str = "run.stderr";
373 pub const UI_RUN_STDOUT: &str = "run.stdout";
375 /// Absolute path to the directory where all output for all tests in the given
376 /// `relative_dir` group should reside. Example:
377 /// /path/to/build/host-triple/test/ui/relative/
378 /// This is created early when tests are collected to avoid race conditions.
379 pub fn output_relative_path(config: &Config, relative_dir: &Path) -> PathBuf {
380 config.build_base.join(relative_dir)
383 /// Generates a unique name for the test, such as `testname.revision.mode`.
384 pub fn output_testname_unique(
386 testpaths: &TestPaths,
387 revision: Option<&str>,
389 let mode = config.compare_mode.as_ref().map_or("", |m| m.to_str());
390 let debugger = config.debugger.as_ref().map_or("", |m| m.to_str());
391 PathBuf::from(&testpaths.file.file_stem().unwrap())
392 .with_extra_extension(revision.unwrap_or(""))
393 .with_extra_extension(mode)
394 .with_extra_extension(debugger)
397 /// Absolute path to the directory where all output for the given
398 /// test/revision should reside. Example:
399 /// /path/to/build/host-triple/test/ui/relative/testname.revision.mode/
400 pub fn output_base_dir(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> PathBuf {
401 output_relative_path(config, &testpaths.relative_dir)
402 .join(output_testname_unique(config, testpaths, revision))
405 /// Absolute path to the base filename used as output for the given
406 /// test/revision. Example:
407 /// /path/to/build/host-triple/test/ui/relative/testname.revision.mode/testname
408 pub fn output_base_name(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> PathBuf {
409 output_base_dir(config, testpaths, revision).join(testpaths.file.file_stem().unwrap())