1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10 pub use self::Mode::*;
13 use std::path::{Path, PathBuf};
14 use std::str::FromStr;
16 use test::ColorConfig;
19 #[derive(Clone, Copy, PartialEq, Debug)]
23 /// This now behaves like a `ui` test that has an implict `// run-pass`.
40 pub fn disambiguator(self) -> &'static str {
41 // Run-pass and pretty run-pass tests could run concurrently, and if they do,
42 // they need to keep their output segregated. Same is true for debuginfo tests that
43 // can be run both on gdb and lldb.
46 DebugInfoGdb => ".gdb",
47 DebugInfoLldb => ".lldb",
53 impl FromStr for Mode {
55 fn from_str(s: &str) -> Result<Mode, ()> {
57 "compile-fail" => Ok(CompileFail),
58 "run-fail" => Ok(RunFail),
59 "run-pass" => Ok(RunPass),
60 "run-pass-valgrind" => Ok(RunPassValgrind),
61 "pretty" => Ok(Pretty),
62 "debuginfo-both" => Ok(DebugInfoBoth),
63 "debuginfo-lldb" => Ok(DebugInfoLldb),
64 "debuginfo-gdb" => Ok(DebugInfoGdb),
65 "codegen" => Ok(Codegen),
66 "rustdoc" => Ok(Rustdoc),
67 "codegen-units" => Ok(CodegenUnits),
68 "incremental" => Ok(Incremental),
69 "run-make" => Ok(RunMake),
71 "mir-opt" => Ok(MirOpt),
77 impl fmt::Display for Mode {
78 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
80 CompileFail => "compile-fail",
81 RunFail => "run-fail",
82 RunPass => "run-pass",
83 RunPassValgrind => "run-pass-valgrind",
85 DebugInfoBoth => "debuginfo-both",
86 DebugInfoGdb => "debuginfo-gdb",
87 DebugInfoLldb => "debuginfo-lldb",
90 CodegenUnits => "codegen-units",
91 Incremental => "incremental",
92 RunMake => "run-make",
96 fmt::Display::fmt(s, f)
100 #[derive(Clone, Debug, PartialEq)]
101 pub enum CompareMode {
107 pub(crate) fn to_str(&self) -> &'static str {
109 CompareMode::Nll => "nll",
110 CompareMode::Polonius => "polonius",
114 pub fn parse(s: String) -> CompareMode {
116 "nll" => CompareMode::Nll,
117 "polonius" => CompareMode::Polonius,
118 x => panic!("unknown --compare-mode option: {}", x),
125 /// Whether to overwrite stderr/stdout files instead of complaining about changes in output
128 /// The library paths required for running the compiler
129 pub compile_lib_path: PathBuf,
131 /// The library paths required for running compiled programs
132 pub run_lib_path: PathBuf,
134 /// The rustc executable
135 pub rustc_path: PathBuf,
137 /// The rustdoc executable
138 pub rustdoc_path: Option<PathBuf>,
140 /// The python executable to use for LLDB
141 pub lldb_python: String,
143 /// The python executable to use for htmldocck
144 pub docck_python: String,
146 /// The llvm FileCheck binary path
147 pub llvm_filecheck: Option<PathBuf>,
149 /// The valgrind path
150 pub valgrind_path: Option<String>,
152 /// Whether to fail if we can't run run-pass-valgrind tests under valgrind
153 /// (or, alternatively, to silently run them like regular run-pass tests).
154 pub force_valgrind: bool,
156 /// The directory containing the tests to run
157 pub src_base: PathBuf,
159 /// The directory where programs should be built
160 pub build_base: PathBuf,
162 /// The name of the stage being built (stage1, etc)
163 pub stage_id: String,
165 /// The test mode, compile-fail, run-fail, run-pass
168 /// Run ignored tests
169 pub run_ignored: bool,
171 /// Only run tests that match this filter
172 pub filter: Option<String>,
174 /// Exactly match the filter, rather than a substring
175 pub filter_exact: bool,
177 /// Write out a parseable log of tests that were run
178 pub logfile: Option<PathBuf>,
180 /// A command line to prefix program execution with,
181 /// for running under valgrind
182 pub runtool: Option<String>,
184 /// Flags to pass to the compiler when building for the host
185 pub host_rustcflags: Option<String>,
187 /// Flags to pass to the compiler when building for the target
188 pub target_rustcflags: Option<String>,
190 /// Target system to be tested
193 /// Host triple for the compiler being invoked
196 /// Path to / name of the GDB executable
197 pub gdb: Option<String>,
199 /// Version of GDB, encoded as ((major * 1000) + minor) * 1000 + patch
200 pub gdb_version: Option<u32>,
202 /// Whether GDB has native rust support
203 pub gdb_native_rust: bool,
206 pub lldb_version: Option<String>,
208 /// Whether LLDB has native rust support
209 pub lldb_native_rust: bool,
212 pub llvm_version: Option<String>,
214 /// Is LLVM a system LLVM
215 pub system_llvm: bool,
217 /// Path to the android tools
218 pub android_cross_path: PathBuf,
220 /// Extra parameter to run adb on arm-linux-androideabi
221 pub adb_path: String,
223 /// Extra parameter to run test suite on arm-linux-androideabi
224 pub adb_test_dir: String,
226 /// status whether android device available or not
227 pub adb_device_status: bool,
229 /// the path containing LLDB's Python module
230 pub lldb_python_dir: Option<String>,
232 /// Explain what's going on
235 /// Print one character per test instead of one line
238 /// Whether to use colors in test.
239 pub color: ColorConfig,
241 /// where to find the remote test client process, if we're using it
242 pub remote_test_client: Option<PathBuf>,
244 /// mode describing what file the actual ui output will be compared to
245 pub compare_mode: Option<CompareMode>,
247 // Configuration for various run-make tests frobbing things like C compilers
248 // or querying about various LLVM component information.
253 pub linker: Option<String>,
254 pub llvm_components: String,
255 pub llvm_cxxflags: String,
256 pub nodejs: Option<String>,
259 #[derive(Debug, Clone)]
260 pub struct TestPaths {
261 pub file: PathBuf, // e.g., compile-test/foo/bar/baz.rs
262 pub relative_dir: PathBuf, // e.g., foo/bar
265 /// Used by `ui` tests to generate things like `foo.stderr` from `foo.rs`.
266 pub fn expected_output_path(
267 testpaths: &TestPaths,
268 revision: Option<&str>,
269 compare_mode: &Option<CompareMode>,
272 assert!(UI_EXTENSIONS.contains(&kind));
273 let mut parts = Vec::new();
275 if let Some(x) = revision {
278 if let Some(ref x) = *compare_mode {
279 parts.push(x.to_str());
283 let extension = parts.join(".");
284 testpaths.file.with_extension(extension)
287 pub const UI_EXTENSIONS: &[&str] = &[UI_STDERR, UI_STDOUT, UI_FIXED];
288 pub const UI_STDERR: &str = "stderr";
289 pub const UI_STDOUT: &str = "stdout";
290 pub const UI_FIXED: &str = "fixed";
292 /// Absolute path to the directory where all output for all tests in the given
293 /// `relative_dir` group should reside. Example:
294 /// /path/to/build/host-triple/test/ui/relative/
295 /// This is created early when tests are collected to avoid race conditions.
296 pub fn output_relative_path(config: &Config, relative_dir: &Path) -> PathBuf {
297 config.build_base.join(relative_dir)
300 /// Generates a unique name for the test, such as `testname.revision.mode`.
301 pub fn output_testname_unique(
303 testpaths: &TestPaths,
304 revision: Option<&str>,
306 let mode = config.compare_mode.as_ref().map_or("", |m| m.to_str());
307 PathBuf::from(&testpaths.file.file_stem().unwrap())
308 .with_extra_extension(revision.unwrap_or(""))
309 .with_extra_extension(mode)
312 /// Absolute path to the directory where all output for the given
313 /// test/revision should reside. Example:
314 /// /path/to/build/host-triple/test/ui/relative/testname.revision.mode/
315 pub fn output_base_dir(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> PathBuf {
316 output_relative_path(config, &testpaths.relative_dir)
317 .join(output_testname_unique(config, testpaths, revision))
320 /// Absolute path to the base filename used as output for the given
321 /// test/revision. Example:
322 /// /path/to/build/host-triple/test/ui/relative/testname.revision.mode/testname
323 pub fn output_base_name(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> PathBuf {
324 output_base_dir(config, testpaths, revision).join(testpaths.file.file_stem().unwrap())