Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --test-threads option to test binaries #35414

Merged
merged 1 commit into from
Aug 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion man/rustc.1
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ which link to the standard library.
.TP
\fBRUST_TEST_THREADS\fR
The test framework Rust provides executes tests in parallel. This variable sets
the maximum number of threads used for this purpose.
the maximum number of threads used for this purpose. This setting is overridden
by the --test-threads option.

.TP
\fBRUST_TEST_NOCAPTURE\fR
Expand Down
27 changes: 23 additions & 4 deletions src/libtest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ pub struct TestOpts {
pub nocapture: bool,
pub color: ColorConfig,
pub quiet: bool,
pub test_threads: Option<usize>,
}

impl TestOpts {
Expand All @@ -314,6 +315,7 @@ impl TestOpts {
nocapture: false,
color: AutoColor,
quiet: false,
test_threads: None,
}
}
}
Expand All @@ -331,6 +333,8 @@ fn optgroups() -> Vec<getopts::OptGroup> {
of stdout", "PATH"),
getopts::optflag("", "nocapture", "don't capture stdout/stderr of each \
task, allow printing directly"),
getopts::optopt("", "test-threads", "Number of threads used for running tests \
in parallel", "n_threads"),
getopts::optflag("q", "quiet", "Display one character per test instead of one line"),
getopts::optopt("", "color", "Configure coloring of output:
auto = colorize if stdout is a tty and tests are run on serially (default);
Expand All @@ -346,7 +350,8 @@ The FILTER string is tested against the name of all tests, and only those
tests whose names contain the filter are run.

By default, all tests are run in parallel. This can be altered with the
RUST_TEST_THREADS environment variable when running tests (set it to 1).
--test-threads flag or the RUST_TEST_THREADS environment variable when running
tests (set it to 1).

All tests have their standard output and standard error captured by default.
This can be overridden with the --nocapture flag or setting RUST_TEST_NOCAPTURE
Expand Down Expand Up @@ -405,6 +410,18 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
};
}

let test_threads = match matches.opt_str("test-threads") {
Some(n_str) =>
match n_str.parse::<usize>() {
Ok(n) => Some(n),
Err(e) =>
return Some(Err(format!("argument for --test-threads must be a number > 0 \
(error: {})", e)))
},
None =>
None,
};

let color = match matches.opt_str("color").as_ref().map(|s| &**s) {
Some("auto") | None => AutoColor,
Some("always") => AlwaysColor,
Expand All @@ -426,6 +443,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
nocapture: nocapture,
color: color,
quiet: quiet,
test_threads: test_threads,
};

Some(Ok(test_opts))
Expand Down Expand Up @@ -857,9 +875,10 @@ fn run_tests<F>(opts: &TestOpts, tests: Vec<TestDescAndFn>, mut callback: F) ->
}
});

// It's tempting to just spawn all the tests at once, but since we have
// many tests that run in other processes we would be making a big mess.
let concurrency = get_concurrency();
let concurrency = match opts.test_threads {
Some(n) => n,
None => get_concurrency(),
};

let mut remaining = filtered_tests;
remaining.reverse();
Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ pub fn test_opts(config: &Config) -> test::TestOpts {
Err(_) => false
},
color: test::AutoColor,
test_threads: None,
}
}

Expand Down