2014-05-20 12:15:34 -05:00
|
|
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
2012-12-03 18:48:01 -06:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-03-21 20:05:05 -05:00
|
|
|
#![crate_type = "bin"]
|
2014-09-26 00:48:16 -05:00
|
|
|
#![feature(phase, slicing_syntax)]
|
2012-01-17 16:40:59 -06:00
|
|
|
|
2014-03-21 20:05:05 -05:00
|
|
|
#![deny(warnings)]
|
2012-06-04 20:34:24 -05:00
|
|
|
|
2014-02-13 19:49:11 -06:00
|
|
|
extern crate test;
|
2014-02-14 12:10:06 -06:00
|
|
|
extern crate getopts;
|
2014-06-11 20:47:09 -05:00
|
|
|
#[phase(plugin, link)] extern crate log;
|
2014-05-24 23:15:16 -05:00
|
|
|
|
2014-05-05 07:19:38 -05:00
|
|
|
extern crate regex;
|
|
|
|
|
2013-06-30 21:36:55 -05:00
|
|
|
use std::os;
|
2013-12-13 23:14:08 -06:00
|
|
|
use std::io;
|
2013-11-11 00:46:32 -06:00
|
|
|
use std::io::fs;
|
2014-04-15 23:56:39 -05:00
|
|
|
use std::from_str::FromStr;
|
2014-02-03 21:14:40 -06:00
|
|
|
use getopts::{optopt, optflag, reqopt};
|
2014-04-15 23:56:39 -05:00
|
|
|
use common::Config;
|
2014-10-26 04:57:29 -05:00
|
|
|
use common::{Pretty, DebugInfoGdb, DebugInfoLldb, Codegen};
|
2012-11-18 19:56:50 -06:00
|
|
|
use util::logv;
|
2014-05-20 12:15:34 -05:00
|
|
|
use regex::Regex;
|
2012-11-18 19:56:50 -06:00
|
|
|
|
2013-03-26 21:53:33 -05:00
|
|
|
pub mod procsrv;
|
|
|
|
pub mod util;
|
|
|
|
pub mod header;
|
|
|
|
pub mod runtest;
|
|
|
|
pub mod common;
|
|
|
|
pub mod errors;
|
|
|
|
|
2013-01-30 16:10:03 -06:00
|
|
|
pub fn main() {
|
2012-11-18 19:56:50 -06:00
|
|
|
let args = os::args();
|
2014-06-25 00:35:54 -05:00
|
|
|
let config = parse_config(args);
|
2014-10-08 18:11:37 -05:00
|
|
|
|
|
|
|
if config.valgrind_path.is_none() && config.force_valgrind {
|
|
|
|
fail!("Can't find Valgrind to run Valgrind tests");
|
|
|
|
}
|
|
|
|
|
2013-05-11 21:45:28 -05:00
|
|
|
log_config(&config);
|
|
|
|
run_tests(&config);
|
2012-11-18 19:56:50 -06:00
|
|
|
}
|
|
|
|
|
2014-05-22 18:57:53 -05:00
|
|
|
pub fn parse_config(args: Vec<String> ) -> Config {
|
2013-07-06 02:44:40 -05:00
|
|
|
|
2014-03-05 17:28:08 -06:00
|
|
|
let groups : Vec<getopts::OptGroup> =
|
|
|
|
vec!(reqopt("", "compile-lib-path", "path to host shared libraries", "PATH"),
|
2013-08-30 15:17:32 -05:00
|
|
|
reqopt("", "run-lib-path", "path to target shared libraries", "PATH"),
|
|
|
|
reqopt("", "rustc-path", "path to rustc to use for compiling", "PATH"),
|
|
|
|
optopt("", "clang-path", "path to executable for codegen tests", "PATH"),
|
2014-10-08 18:11:37 -05:00
|
|
|
optopt("", "valgrind-path", "path to Valgrind executable for Valgrind tests", "PROGRAM"),
|
|
|
|
optflag("", "force-valgrind", "fail if Valgrind tests cannot be run under Valgrind"),
|
2013-08-30 15:17:32 -05:00
|
|
|
optopt("", "llvm-bin-path", "path to directory holding llvm binaries", "DIR"),
|
|
|
|
reqopt("", "src-base", "directory to scan for test files", "PATH"),
|
|
|
|
reqopt("", "build-base", "directory to deposit test outputs", "PATH"),
|
|
|
|
reqopt("", "aux-base", "directory to find auxiliary test files", "PATH"),
|
|
|
|
reqopt("", "stage-id", "the target-stage identifier", "stageN-TARGET"),
|
|
|
|
reqopt("", "mode", "which sort of compile tests to run",
|
2014-10-07 02:00:26 -05:00
|
|
|
"(compile-fail|run-fail|run-pass|run-pass-valgrind|pretty|debug-info)"),
|
2014-02-07 13:08:32 -06:00
|
|
|
optflag("", "ignored", "run tests marked as ignored"),
|
2013-08-30 15:17:32 -05:00
|
|
|
optopt("", "runtool", "supervisor program to run tests under \
|
2013-07-06 02:44:40 -05:00
|
|
|
(eg. emulator, valgrind)", "PROGRAM"),
|
2014-02-11 15:51:08 -06:00
|
|
|
optopt("", "host-rustcflags", "flags to pass to rustc for host", "FLAGS"),
|
|
|
|
optopt("", "target-rustcflags", "flags to pass to rustc for target", "FLAGS"),
|
2013-07-06 02:44:40 -05:00
|
|
|
optflag("", "verbose", "run tests verbosely, showing all output"),
|
|
|
|
optopt("", "logfile", "file to log test execution to", "FILE"),
|
2013-07-15 20:51:20 -05:00
|
|
|
optopt("", "save-metrics", "file to save metrics to", "FILE"),
|
|
|
|
optopt("", "ratchet-metrics", "file to ratchet metrics against", "FILE"),
|
|
|
|
optopt("", "ratchet-noise-percent",
|
|
|
|
"percent change in metrics to consider noise", "N"),
|
2013-07-06 02:44:40 -05:00
|
|
|
optflag("", "jit", "run tests under the JIT"),
|
|
|
|
optopt("", "target", "the target to build for", "TARGET"),
|
2014-01-17 12:18:02 -06:00
|
|
|
optopt("", "host", "the host to build for", "HOST"),
|
2014-10-02 04:35:24 -05:00
|
|
|
optopt("", "gdb-version", "the version of GDB used", "VERSION STRING"),
|
|
|
|
optopt("", "lldb-version", "the version of LLDB used", "VERSION STRING"),
|
2014-05-13 13:44:30 -05:00
|
|
|
optopt("", "android-cross-path", "Android NDK standalone path", "PATH"),
|
2013-07-06 02:44:40 -05:00
|
|
|
optopt("", "adb-path", "path to the android debugger", "PATH"),
|
|
|
|
optopt("", "adb-test-dir", "path to tests for the android debugger", "PATH"),
|
2014-04-24 04:35:48 -05:00
|
|
|
optopt("", "lldb-python-dir", "directory containing LLDB's python module", "PATH"),
|
2013-08-23 17:30:23 -05:00
|
|
|
optopt("", "test-shard", "run shard A, of B shards, worth of the testsuite", "A.B"),
|
2014-03-05 17:28:08 -06:00
|
|
|
optflag("h", "help", "show this message"));
|
2012-11-18 19:56:50 -06:00
|
|
|
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(!args.is_empty());
|
2014-07-14 18:37:25 -05:00
|
|
|
let argv0 = args[0].clone();
|
2013-06-27 07:36:27 -05:00
|
|
|
let args_ = args.tail();
|
2014-07-14 18:37:25 -05:00
|
|
|
if args[1].as_slice() == "-h" || args[1].as_slice() == "--help" {
|
2013-09-29 15:18:51 -05:00
|
|
|
let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0);
|
2014-05-16 12:45:16 -05:00
|
|
|
println!("{}", getopts::usage(message.as_slice(), groups.as_slice()));
|
2014-01-09 04:06:55 -06:00
|
|
|
println!("");
|
2013-10-21 15:08:31 -05:00
|
|
|
fail!()
|
2013-07-06 02:44:40 -05:00
|
|
|
}
|
|
|
|
|
2012-11-18 19:56:50 -06:00
|
|
|
let matches =
|
2014-05-14 23:39:11 -05:00
|
|
|
&match getopts::getopts(args_.as_slice(), groups.as_slice()) {
|
2012-11-18 19:56:50 -06:00
|
|
|
Ok(m) => m,
|
2014-06-13 20:11:09 -05:00
|
|
|
Err(f) => fail!("{}", f)
|
2012-11-18 19:56:50 -06:00
|
|
|
};
|
|
|
|
|
2013-09-17 20:42:23 -05:00
|
|
|
if matches.opt_present("h") || matches.opt_present("help") {
|
2013-09-29 15:18:51 -05:00
|
|
|
let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0);
|
2014-05-16 12:45:16 -05:00
|
|
|
println!("{}", getopts::usage(message.as_slice(), groups.as_slice()));
|
2014-01-09 04:06:55 -06:00
|
|
|
println!("");
|
2013-10-21 15:08:31 -05:00
|
|
|
fail!()
|
2013-07-06 02:44:40 -05:00
|
|
|
}
|
|
|
|
|
2013-05-23 11:39:48 -05:00
|
|
|
fn opt_path(m: &getopts::Matches, nm: &str) -> Path {
|
2013-12-03 21:15:12 -06:00
|
|
|
Path::new(m.opt_str(nm).unwrap())
|
2012-11-18 19:56:50 -06:00
|
|
|
}
|
2013-08-12 13:15:05 -05:00
|
|
|
|
2014-05-05 07:19:38 -05:00
|
|
|
let filter = if !matches.free.is_empty() {
|
2014-07-14 18:37:25 -05:00
|
|
|
let s = matches.free[0].as_slice();
|
2014-05-05 07:19:38 -05:00
|
|
|
match regex::Regex::new(s) {
|
|
|
|
Ok(re) => Some(re),
|
|
|
|
Err(e) => {
|
|
|
|
println!("failed to parse filter /{}/: {}", s, e);
|
|
|
|
fail!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2014-04-15 23:56:39 -05:00
|
|
|
Config {
|
2014-06-25 00:35:54 -05:00
|
|
|
compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
|
|
|
|
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
|
2013-05-23 11:39:48 -05:00
|
|
|
rustc_path: opt_path(matches, "rustc-path"),
|
2013-12-03 21:15:12 -06:00
|
|
|
clang_path: matches.opt_str("clang-path").map(|s| Path::new(s)),
|
2014-10-07 02:00:26 -05:00
|
|
|
valgrind_path: matches.opt_str("valgrind-path"),
|
2014-10-08 18:11:37 -05:00
|
|
|
force_valgrind: matches.opt_present("force-valgrind"),
|
2013-12-03 21:15:12 -06:00
|
|
|
llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| Path::new(s)),
|
2013-08-30 15:17:32 -05:00
|
|
|
src_base: opt_path(matches, "src-base"),
|
2013-05-23 11:39:48 -05:00
|
|
|
build_base: opt_path(matches, "build-base"),
|
|
|
|
aux_base: opt_path(matches, "aux-base"),
|
2014-06-25 00:35:54 -05:00
|
|
|
stage_id: matches.opt_str("stage-id").unwrap(),
|
2014-05-14 23:39:11 -05:00
|
|
|
mode: FromStr::from_str(matches.opt_str("mode")
|
|
|
|
.unwrap()
|
|
|
|
.as_slice()).expect("invalid mode"),
|
2013-09-17 20:42:23 -05:00
|
|
|
run_ignored: matches.opt_present("ignored"),
|
2014-05-05 07:19:38 -05:00
|
|
|
filter: filter,
|
2014-05-20 12:15:34 -05:00
|
|
|
cfail_regex: Regex::new(errors::EXPECTED_PATTERN).unwrap(),
|
2013-12-03 21:15:12 -06:00
|
|
|
logfile: matches.opt_str("logfile").map(|s| Path::new(s)),
|
|
|
|
save_metrics: matches.opt_str("save-metrics").map(|s| Path::new(s)),
|
2013-07-15 20:51:20 -05:00
|
|
|
ratchet_metrics:
|
2013-12-03 21:15:12 -06:00
|
|
|
matches.opt_str("ratchet-metrics").map(|s| Path::new(s)),
|
2013-07-15 20:51:20 -05:00
|
|
|
ratchet_noise_percent:
|
2014-05-14 23:39:11 -05:00
|
|
|
matches.opt_str("ratchet-noise-percent")
|
|
|
|
.and_then(|s| from_str::<f64>(s.as_slice())),
|
2014-06-25 00:35:54 -05:00
|
|
|
runtool: matches.opt_str("runtool"),
|
|
|
|
host_rustcflags: matches.opt_str("host-rustcflags"),
|
|
|
|
target_rustcflags: matches.opt_str("target-rustcflags"),
|
2013-09-17 20:42:23 -05:00
|
|
|
jit: matches.opt_present("jit"),
|
2014-06-25 00:35:54 -05:00
|
|
|
target: opt_str2(matches.opt_str("target")),
|
|
|
|
host: opt_str2(matches.opt_str("host")),
|
2014-08-20 05:53:50 -05:00
|
|
|
gdb_version: extract_gdb_version(matches.opt_str("gdb-version")),
|
2014-10-02 04:35:24 -05:00
|
|
|
lldb_version: extract_lldb_version(matches.opt_str("lldb-version")),
|
2014-05-13 13:44:30 -05:00
|
|
|
android_cross_path: opt_path(matches, "android-cross-path"),
|
2014-06-25 00:35:54 -05:00
|
|
|
adb_path: opt_str2(matches.opt_str("adb-path")),
|
|
|
|
adb_test_dir: opt_str2(matches.opt_str("adb-test-dir")),
|
2013-05-03 20:35:07 -05:00
|
|
|
adb_device_status:
|
2014-05-14 22:47:24 -05:00
|
|
|
"arm-linux-androideabi" ==
|
2014-06-25 00:35:54 -05:00
|
|
|
opt_str2(matches.opt_str("target")).as_slice() &&
|
2014-05-14 22:47:24 -05:00
|
|
|
"(none)" !=
|
2014-06-25 00:35:54 -05:00
|
|
|
opt_str2(matches.opt_str("adb-test-dir")).as_slice() &&
|
|
|
|
!opt_str2(matches.opt_str("adb-test-dir")).is_empty(),
|
|
|
|
lldb_python_dir: matches.opt_str("lldb-python-dir"),
|
|
|
|
test_shard: test::opt_shard(matches.opt_str("test-shard")),
|
2014-10-08 18:11:37 -05:00
|
|
|
verbose: matches.opt_present("verbose"),
|
2013-02-21 17:19:40 -06:00
|
|
|
}
|
2012-11-18 19:56:50 -06:00
|
|
|
}
|
|
|
|
|
2014-04-15 23:56:39 -05:00
|
|
|
pub fn log_config(config: &Config) {
|
2012-11-18 19:56:50 -06:00
|
|
|
let c = config;
|
2014-05-27 22:44:58 -05:00
|
|
|
logv(c, format!("configuration:"));
|
|
|
|
logv(c, format!("compile_lib_path: {}", config.compile_lib_path));
|
|
|
|
logv(c, format!("run_lib_path: {}", config.run_lib_path));
|
|
|
|
logv(c, format!("rustc_path: {}", config.rustc_path.display()));
|
|
|
|
logv(c, format!("src_base: {}", config.src_base.display()));
|
|
|
|
logv(c, format!("build_base: {}", config.build_base.display()));
|
|
|
|
logv(c, format!("stage_id: {}", config.stage_id));
|
|
|
|
logv(c, format!("mode: {}", config.mode));
|
|
|
|
logv(c, format!("run_ignored: {}", config.run_ignored));
|
|
|
|
logv(c, format!("filter: {}",
|
|
|
|
opt_str(&config.filter
|
|
|
|
.as_ref()
|
|
|
|
.map(|re| {
|
2014-06-21 05:39:03 -05:00
|
|
|
re.to_string().into_string()
|
2014-05-27 22:44:58 -05:00
|
|
|
}))));
|
|
|
|
logv(c, format!("runtool: {}", opt_str(&config.runtool)));
|
|
|
|
logv(c, format!("host-rustcflags: {}",
|
|
|
|
opt_str(&config.host_rustcflags)));
|
|
|
|
logv(c, format!("target-rustcflags: {}",
|
|
|
|
opt_str(&config.target_rustcflags)));
|
|
|
|
logv(c, format!("jit: {}", config.jit));
|
|
|
|
logv(c, format!("target: {}", config.target));
|
|
|
|
logv(c, format!("host: {}", config.host));
|
|
|
|
logv(c, format!("android-cross-path: {}",
|
|
|
|
config.android_cross_path.display()));
|
|
|
|
logv(c, format!("adb_path: {}", config.adb_path));
|
|
|
|
logv(c, format!("adb_test_dir: {}", config.adb_test_dir));
|
|
|
|
logv(c, format!("adb_device_status: {}",
|
|
|
|
config.adb_device_status));
|
2013-08-23 17:30:23 -05:00
|
|
|
match config.test_shard {
|
2014-05-25 05:17:19 -05:00
|
|
|
None => logv(c, "test_shard: (all)".to_string()),
|
2014-05-27 22:44:58 -05:00
|
|
|
Some((a,b)) => logv(c, format!("test_shard: {}.{}", a, b))
|
2013-08-23 17:30:23 -05:00
|
|
|
}
|
2014-05-27 22:44:58 -05:00
|
|
|
logv(c, format!("verbose: {}", config.verbose));
|
|
|
|
logv(c, format!("\n"));
|
2012-11-18 19:56:50 -06:00
|
|
|
}
|
|
|
|
|
2014-05-22 18:57:53 -05:00
|
|
|
pub fn opt_str<'a>(maybestr: &'a Option<String>) -> &'a str {
|
2013-05-11 21:45:28 -05:00
|
|
|
match *maybestr {
|
2013-06-30 21:36:55 -05:00
|
|
|
None => "(none)",
|
2014-05-14 22:47:24 -05:00
|
|
|
Some(ref s) => s.as_slice(),
|
2013-05-11 21:45:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 18:57:53 -05:00
|
|
|
pub fn opt_str2(maybestr: Option<String>) -> String {
|
2014-05-14 22:47:24 -05:00
|
|
|
match maybestr {
|
2014-05-25 05:17:19 -05:00
|
|
|
None => "(none)".to_string(),
|
2014-05-14 22:47:24 -05:00
|
|
|
Some(s) => s,
|
|
|
|
}
|
2012-11-18 19:56:50 -06:00
|
|
|
}
|
|
|
|
|
2014-04-15 23:56:39 -05:00
|
|
|
pub fn run_tests(config: &Config) {
|
2014-05-14 22:47:24 -05:00
|
|
|
if config.target.as_slice() == "arm-linux-androideabi" {
|
2014-04-15 23:56:39 -05:00
|
|
|
match config.mode {
|
|
|
|
DebugInfoGdb => {
|
2014-01-09 04:06:55 -06:00
|
|
|
println!("arm-linux-androideabi debug-info \
|
|
|
|
test uses tcp 5039 port. please reserve it");
|
2013-11-04 00:53:01 -06:00
|
|
|
}
|
|
|
|
_ =>{}
|
|
|
|
}
|
2014-02-13 23:17:02 -06:00
|
|
|
|
|
|
|
//arm-linux-androideabi debug-info test uses remote debugger
|
|
|
|
//so, we test 1 task at once.
|
|
|
|
// also trying to isolate problems with adb_run_wrapper.sh ilooping
|
|
|
|
os::setenv("RUST_TEST_TASKS","1");
|
2013-11-04 00:53:01 -06:00
|
|
|
}
|
|
|
|
|
2014-10-26 04:57:29 -05:00
|
|
|
match config.mode {
|
|
|
|
DebugInfoLldb => {
|
|
|
|
// Some older versions of LLDB seem to have problems with multiple
|
|
|
|
// instances running in parallel, so only run one test task at a
|
|
|
|
// time.
|
|
|
|
os::setenv("RUST_TEST_TASKS", "1");
|
|
|
|
}
|
|
|
|
_ => { /* proceed */ }
|
|
|
|
}
|
|
|
|
|
2012-11-18 19:56:50 -06:00
|
|
|
let opts = test_opts(config);
|
|
|
|
let tests = make_tests(config);
|
2013-09-02 23:50:50 -05:00
|
|
|
// sadly osx needs some file descriptor limits raised for running tests in
|
|
|
|
// parallel (especially when we have lots and lots of child processes).
|
|
|
|
// For context, see #8904
|
2013-12-13 23:14:08 -06:00
|
|
|
io::test::raise_fd_limit();
|
2014-09-14 22:27:36 -05:00
|
|
|
let res = test::run_tests_console(&opts, tests.into_iter().collect());
|
2014-01-30 16:37:10 -06:00
|
|
|
match res {
|
|
|
|
Ok(true) => {}
|
|
|
|
Ok(false) => fail!("Some tests failed"),
|
|
|
|
Err(e) => {
|
|
|
|
println!("I/O failure during tests: {}", e);
|
|
|
|
}
|
|
|
|
}
|
2012-11-18 19:56:50 -06:00
|
|
|
}
|
|
|
|
|
2014-04-15 23:56:39 -05:00
|
|
|
pub fn test_opts(config: &Config) -> test::TestOpts {
|
2013-01-22 10:44:24 -06:00
|
|
|
test::TestOpts {
|
2014-05-13 18:44:05 -05:00
|
|
|
filter: match config.filter {
|
|
|
|
None => None,
|
2014-05-05 07:19:38 -05:00
|
|
|
Some(ref filter) => Some(filter.clone()),
|
2014-05-13 18:44:05 -05:00
|
|
|
},
|
2013-01-22 10:44:24 -06:00
|
|
|
run_ignored: config.run_ignored,
|
2013-07-02 14:47:32 -05:00
|
|
|
logfile: config.logfile.clone(),
|
2013-02-13 13:46:14 -06:00
|
|
|
run_tests: true,
|
2013-07-15 20:51:20 -05:00
|
|
|
run_benchmarks: true,
|
2013-07-17 20:03:48 -05:00
|
|
|
ratchet_metrics: config.ratchet_metrics.clone(),
|
|
|
|
ratchet_noise_percent: config.ratchet_noise_percent.clone(),
|
|
|
|
save_metrics: config.save_metrics.clone(),
|
2014-04-23 11:38:46 -05:00
|
|
|
test_shard: config.test_shard.clone(),
|
|
|
|
nocapture: false,
|
2014-06-08 19:10:27 -05:00
|
|
|
color: test::AutoColor,
|
2012-11-18 19:56:50 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-15 23:56:39 -05:00
|
|
|
pub fn make_tests(config: &Config) -> Vec<test::TestDescAndFn> {
|
2013-10-21 15:08:31 -05:00
|
|
|
debug!("making tests from {}",
|
2013-09-26 19:21:59 -05:00
|
|
|
config.src_base.display());
|
2014-03-05 17:28:08 -06:00
|
|
|
let mut tests = Vec::new();
|
2014-01-30 16:37:10 -06:00
|
|
|
let dirs = fs::readdir(&config.src_base).unwrap();
|
2013-08-03 11:45:23 -05:00
|
|
|
for file in dirs.iter() {
|
2013-07-21 12:33:29 -05:00
|
|
|
let file = file.clone();
|
2013-10-21 15:08:31 -05:00
|
|
|
debug!("inspecting file {}", file.display());
|
2013-07-21 12:33:29 -05:00
|
|
|
if is_test(config, &file) {
|
2013-11-21 19:23:21 -06:00
|
|
|
let t = make_test(config, &file, || {
|
2013-07-15 20:51:20 -05:00
|
|
|
match config.mode {
|
2014-04-15 23:56:39 -05:00
|
|
|
Codegen => make_metrics_test_closure(config, &file),
|
2013-07-21 12:33:29 -05:00
|
|
|
_ => make_test_closure(config, &file)
|
2013-07-15 20:51:20 -05:00
|
|
|
}
|
2013-11-21 19:23:21 -06:00
|
|
|
});
|
2013-07-15 20:51:20 -05:00
|
|
|
tests.push(t)
|
2012-11-18 19:56:50 -06:00
|
|
|
}
|
|
|
|
}
|
2013-02-15 03:11:38 -06:00
|
|
|
tests
|
2012-11-18 19:56:50 -06:00
|
|
|
}
|
|
|
|
|
2014-04-15 23:56:39 -05:00
|
|
|
pub fn is_test(config: &Config, testfile: &Path) -> bool {
|
2012-11-18 19:56:50 -06:00
|
|
|
// Pretty-printer does not work with .rc files yet
|
|
|
|
let valid_extensions =
|
|
|
|
match config.mode {
|
2014-05-25 05:10:11 -05:00
|
|
|
Pretty => vec!(".rs".to_string()),
|
|
|
|
_ => vec!(".rc".to_string(), ".rs".to_string())
|
2012-11-18 19:56:50 -06:00
|
|
|
};
|
2014-05-25 05:10:11 -05:00
|
|
|
let invalid_prefixes = vec!(".".to_string(), "#".to_string(), "~".to_string());
|
2013-09-26 19:21:59 -05:00
|
|
|
let name = testfile.filename_str().unwrap();
|
2012-11-18 19:56:50 -06:00
|
|
|
|
|
|
|
let mut valid = false;
|
|
|
|
|
2013-08-03 11:45:23 -05:00
|
|
|
for ext in valid_extensions.iter() {
|
2014-05-20 01:19:56 -05:00
|
|
|
if name.ends_with(ext.as_slice()) {
|
|
|
|
valid = true;
|
|
|
|
}
|
2012-11-18 19:56:50 -06:00
|
|
|
}
|
|
|
|
|
2013-08-03 11:45:23 -05:00
|
|
|
for pre in invalid_prefixes.iter() {
|
2014-05-20 01:19:56 -05:00
|
|
|
if name.starts_with(pre.as_slice()) {
|
|
|
|
valid = false;
|
|
|
|
}
|
2012-11-18 19:56:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
2014-04-15 23:56:39 -05:00
|
|
|
pub fn make_test(config: &Config, testfile: &Path, f: || -> test::TestFn)
|
2013-11-19 20:15:10 -06:00
|
|
|
-> test::TestDescAndFn {
|
2013-01-31 19:12:29 -06:00
|
|
|
test::TestDescAndFn {
|
|
|
|
desc: test::TestDesc {
|
|
|
|
name: make_test_name(config, testfile),
|
|
|
|
ignore: header::is_test_ignored(config, testfile),
|
|
|
|
should_fail: false
|
|
|
|
},
|
2013-07-15 20:51:20 -05:00
|
|
|
testfn: f(),
|
2012-11-18 19:56:50 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-15 23:56:39 -05:00
|
|
|
pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
|
2013-06-23 03:27:34 -05:00
|
|
|
|
|
|
|
// Try to elide redundant long paths
|
2014-05-22 18:57:53 -05:00
|
|
|
fn shorten(path: &Path) -> String {
|
2013-09-26 19:21:59 -05:00
|
|
|
let filename = path.filename_str();
|
|
|
|
let p = path.dir_path();
|
|
|
|
let dir = p.filename_str();
|
2014-05-27 22:44:58 -05:00
|
|
|
format!("{}/{}", dir.unwrap_or(""), filename.unwrap_or(""))
|
2013-06-23 03:27:34 -05:00
|
|
|
}
|
2013-06-26 17:34:12 -05:00
|
|
|
|
2014-05-27 22:44:58 -05:00
|
|
|
test::DynTestName(format!("[{}] {}", config.mode, shorten(testfile)))
|
2012-11-18 19:56:50 -06:00
|
|
|
}
|
|
|
|
|
2014-04-15 23:56:39 -05:00
|
|
|
pub fn make_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
|
2013-12-04 18:29:01 -06:00
|
|
|
let config = (*config).clone();
|
2013-09-26 19:21:59 -05:00
|
|
|
// FIXME (#9639): This needs to handle non-utf8 paths
|
2014-05-25 05:17:19 -05:00
|
|
|
let testfile = testfile.as_str().unwrap().to_string();
|
2014-05-14 22:47:24 -05:00
|
|
|
test::DynTestFn(proc() {
|
|
|
|
runtest::run(config, testfile)
|
|
|
|
})
|
2012-11-18 19:56:50 -06:00
|
|
|
}
|
2013-07-15 20:51:20 -05:00
|
|
|
|
2014-04-15 23:56:39 -05:00
|
|
|
pub fn make_metrics_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
|
2013-12-04 18:29:01 -06:00
|
|
|
let config = (*config).clone();
|
2013-09-26 19:21:59 -05:00
|
|
|
// FIXME (#9639): This needs to handle non-utf8 paths
|
2014-05-25 05:17:19 -05:00
|
|
|
let testfile = testfile.as_str().unwrap().to_string();
|
2013-11-22 01:36:52 -06:00
|
|
|
test::DynMetricFn(proc(mm) {
|
2013-12-04 18:29:01 -06:00
|
|
|
runtest::run_metrics(config, testfile, mm)
|
2013-11-22 01:36:52 -06:00
|
|
|
})
|
2013-07-15 20:51:20 -05:00
|
|
|
}
|
2014-08-20 05:53:50 -05:00
|
|
|
|
|
|
|
fn extract_gdb_version(full_version_line: Option<String>) -> Option<String> {
|
|
|
|
match full_version_line {
|
2014-08-27 08:18:16 -05:00
|
|
|
Some(ref full_version_line)
|
|
|
|
if full_version_line.as_slice().trim().len() > 0 => {
|
2014-08-20 05:53:50 -05:00
|
|
|
let full_version_line = full_version_line.as_slice().trim();
|
2014-08-27 08:18:16 -05:00
|
|
|
|
|
|
|
let re = Regex::new(r"(^|[^0-9])([0-9]\.[0-9])([^0-9]|$)").unwrap();
|
2014-08-20 05:53:50 -05:00
|
|
|
|
|
|
|
match re.captures(full_version_line) {
|
|
|
|
Some(captures) => {
|
2014-08-27 08:18:16 -05:00
|
|
|
Some(captures.at(2).to_string())
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
println!("Could not extract GDB version from line '{}'",
|
|
|
|
full_version_line);
|
|
|
|
None
|
2014-08-20 05:53:50 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2014-08-27 08:18:16 -05:00
|
|
|
_ => None
|
2014-08-20 05:53:50 -05:00
|
|
|
}
|
2014-09-14 22:27:36 -05:00
|
|
|
}
|
2014-10-02 04:35:24 -05:00
|
|
|
|
|
|
|
fn extract_lldb_version(full_version_line: Option<String>) -> Option<String> {
|
|
|
|
// Extract the major LLDB version from the given version string.
|
|
|
|
// LLDB version strings are different for Apple and non-Apple platforms.
|
|
|
|
// At the moment, this function only supports the Apple variant, which looks
|
|
|
|
// like this:
|
|
|
|
//
|
|
|
|
// LLDB-179.5 (older versions)
|
|
|
|
// lldb-300.2.51 (new versions)
|
|
|
|
//
|
|
|
|
// We are only interested in the major version number, so this function
|
|
|
|
// will return `Some("179")` and `Some("300")` respectively.
|
|
|
|
|
|
|
|
match full_version_line {
|
|
|
|
Some(ref full_version_line)
|
|
|
|
if full_version_line.as_slice().trim().len() > 0 => {
|
|
|
|
let full_version_line = full_version_line.as_slice().trim();
|
|
|
|
|
|
|
|
let re = Regex::new(r"[Ll][Ll][Dd][Bb]-([0-9]+)").unwrap();
|
|
|
|
|
|
|
|
match re.captures(full_version_line) {
|
|
|
|
Some(captures) => {
|
|
|
|
Some(captures.at(1).to_string())
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
println!("Could not extract LLDB version from line '{}'",
|
|
|
|
full_version_line);
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
}
|