Skip to content

Commit e65d0cb

Browse files
committed
extra: Make test runner compatible with newsched
1 parent d071f51 commit e65d0cb

File tree

4 files changed

+18
-23
lines changed

4 files changed

+18
-23
lines changed

src/libextra/test.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ use core::to_str::ToStr;
3131
use core::uint;
3232
use core::vec;
3333

34-
pub mod rustrt {
35-
use core::libc::size_t;
36-
37-
#[abi = "cdecl"]
38-
pub extern {
39-
pub unsafe fn rust_sched_threads() -> size_t;
40-
}
41-
}
4234

4335
// The name of a test. By convention this follows the rules for rust
4436
// paths; i.e. it should be a series of identifiers separated by double
@@ -488,11 +480,10 @@ static sched_overcommit : uint = 1;
488480
static sched_overcommit : uint = 4u;
489481
490482
fn get_concurrency() -> uint {
491-
unsafe {
492-
let threads = rustrt::rust_sched_threads() as uint;
493-
if threads == 1 { 1 }
494-
else { threads * sched_overcommit }
495-
}
483+
use core::rt;
484+
let threads = rt::util::default_sched_threads();
485+
if threads == 1 { 1 }
486+
else { threads * sched_overcommit }
496487
}
497488
498489
#[allow(non_implicitly_copyable_typarams)]

src/libstd/rt/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,9 @@ Several modules in `core` are clients of `rt`:
6363
use cell::Cell;
6464
use clone::Clone;
6565
use container::Container;
66-
use from_str::FromStr;
6766
use iter::Times;
6867
use iterator::IteratorUtil;
69-
use option::{Some, None};
70-
use os;
68+
use option::Some;
7169
use ptr::RawPtr;
7270
use rt::sched::{Scheduler, Coroutine, Shutdown};
7371
use rt::sleeper_list::SleeperList;
@@ -223,10 +221,7 @@ pub fn run(main: ~fn()) -> int {
223221

224222
static DEFAULT_ERROR_CODE: int = 101;
225223

226-
let nthreads = match os::getenv("RUST_THREADS") {
227-
Some(nstr) => FromStr::from_str(nstr).get(),
228-
None => util::num_cpus()
229-
};
224+
let nthreads = util::default_sched_threads();
230225

231226
// The shared list of sleeping schedulers. Schedulers wake each other
232227
// occassionally to do new work.

src/libstd/rt/util.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
// except according to those terms.
1010

1111
use container::Container;
12+
use from_str::FromStr;
1213
use iterator::IteratorUtil;
1314
use libc;
15+
use option::{Some, None};
16+
use os;
1417
use str::StrSlice;
1518

1619
/// Get the number of cores available
@@ -24,6 +27,15 @@ pub fn num_cpus() -> uint {
2427
}
2528
}
2629

30+
/// Get's the number of scheduler threads requested by the environment
31+
/// either `RUST_THREADS` or `num_cpus`.
32+
pub fn default_sched_threads() -> uint {
33+
match os::getenv("RUST_THREADS") {
34+
Some(nstr) => FromStr::from_str(nstr).get(),
35+
None => num_cpus()
36+
}
37+
}
38+
2739
pub fn dumb_println(s: &str) {
2840
use io::WriterUtil;
2941
let dbg = ::libc::STDERR_FILENO as ::io::fd_t;

src/test/run-pass/morestack6.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@ mod rustrt {
2323
pub fn rust_get_sched_id() -> libc::intptr_t;
2424
pub fn rust_get_argc() -> libc::c_int;
2525
pub fn get_task_id() -> libc::intptr_t;
26-
pub fn rust_sched_threads();
2726
pub fn rust_get_task();
2827
}
2928
}
3029

3130
fn calllink01() { unsafe { rustrt::rust_get_sched_id(); } }
3231
fn calllink02() { unsafe { rustrt::rust_get_argc(); } }
3332
fn calllink08() { unsafe { rustrt::get_task_id(); } }
34-
fn calllink09() { unsafe { rustrt::rust_sched_threads(); } }
3533
fn calllink10() { unsafe { rustrt::rust_get_task(); } }
3634

3735
fn runtest(f: extern fn(), frame_backoff: u32) {
@@ -64,7 +62,6 @@ pub fn main() {
6462
calllink01,
6563
calllink02,
6664
calllink08,
67-
calllink09,
6865
calllink10
6966
];
7067
let mut rng = rand::rng();

0 commit comments

Comments
 (0)