diff options
| author | Brian Anderson <banderson@mozilla.com> | 2013-06-05 22:35:23 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2013-06-06 17:53:13 -0700 |
| commit | 8afec77cb07394c5f2d54dcc0ebe075fc304efb7 (patch) | |
| tree | f45fe95500d4a0cec52b03325bfb01f6320eb626 /src/libstd | |
| parent | f9a5005f52d528797d6b98a3bee73ab2d71b9aa3 (diff) | |
| download | rust-8afec77cb07394c5f2d54dcc0ebe075fc304efb7.tar.gz rust-8afec77cb07394c5f2d54dcc0ebe075fc304efb7.zip | |
std::rt: Configure test threads with RUST_TEST_THREADS. Default is ncores x2
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/rt/test.rs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/libstd/rt/test.rs b/src/libstd/rt/test.rs index 907d289fb07..c8df3a61203 100644 --- a/src/libstd/rt/test.rs +++ b/src/libstd/rt/test.rs @@ -59,13 +59,24 @@ pub fn run_in_newsched_task(f: ~fn()) { /// in one of the schedulers. The schedulers will stay alive /// until the function `f` returns. pub fn run_in_mt_newsched_task(f: ~fn()) { + use libc; + use os; + use from_str::FromStr; use rt::uv::uvio::UvEventLoop; use rt::sched::Shutdown; let f_cell = Cell(f); do run_in_bare_thread { - static N: uint = 4; + let nthreads = match os::getenv("RUST_TEST_THREADS") { + Some(nstr) => FromStr::from_str(nstr).get(), + None => unsafe { + // Using more threads than cores in test code + // to force the OS to preempt them frequently. + // Assuming that this help stress test concurrent types. + rust_get_num_cpus() * 2 + } + }; let sleepers = SleeperList::new(); let work_queue = WorkQueue::new(); @@ -73,7 +84,7 @@ pub fn run_in_mt_newsched_task(f: ~fn()) { let mut handles = ~[]; let mut scheds = ~[]; - for uint::range(0, N) |_| { + for uint::range(0, nthreads) |_| { let loop_ = ~UvEventLoop::new(); let mut sched = ~Scheduler::new(loop_, work_queue.clone(), sleepers.clone()); let handle = sched.make_handle(); @@ -111,6 +122,10 @@ pub fn run_in_mt_newsched_task(f: ~fn()) { // Wait for schedulers let _threads = threads; } + + extern { + fn rust_get_num_cpus() -> libc::uintptr_t; + } } /// Test tasks will abort on failure instead of unwinding |
