about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2013-06-23 18:22:57 -0700
committerBrian Anderson <banderson@mozilla.com>2013-06-24 17:07:03 -0700
commite65d0cbabebc73f2c9733a7ed158576c9702e71e (patch)
tree717d289c5fda8bc54c7d5fb340a94949a6432ac2 /src
parentd071f51cdc7c3492ae2bc4180ffbf13bcdb31439 (diff)
downloadrust-e65d0cbabebc73f2c9733a7ed158576c9702e71e.tar.gz
rust-e65d0cbabebc73f2c9733a7ed158576c9702e71e.zip
extra: Make test runner compatible with newsched
Diffstat (limited to 'src')
-rw-r--r--src/libextra/test.rs17
-rw-r--r--src/libstd/rt/mod.rs9
-rw-r--r--src/libstd/rt/util.rs12
-rw-r--r--src/test/run-pass/morestack6.rs3
4 files changed, 18 insertions, 23 deletions
diff --git a/src/libextra/test.rs b/src/libextra/test.rs
index 72837cb4ae1..64c6a822a86 100644
--- a/src/libextra/test.rs
+++ b/src/libextra/test.rs
@@ -31,14 +31,6 @@ use core::to_str::ToStr;
 use core::uint;
 use core::vec;
 
-pub mod rustrt {
-    use core::libc::size_t;
-
-    #[abi = "cdecl"]
-    pub extern {
-        pub unsafe fn rust_sched_threads() -> size_t;
-    }
-}
 
 // The name of a test. By convention this follows the rules for rust
 // paths; i.e. it should be a series of identifiers separated by double
@@ -488,11 +480,10 @@ static sched_overcommit : uint = 1;
 static sched_overcommit : uint = 4u;
 
 fn get_concurrency() -> uint {
-    unsafe {
-        let threads = rustrt::rust_sched_threads() as uint;
-        if threads == 1 { 1 }
-        else { threads * sched_overcommit }
-    }
+    use core::rt;
+    let threads = rt::util::default_sched_threads();
+    if threads == 1 { 1 }
+    else { threads * sched_overcommit }
 }
 
 #[allow(non_implicitly_copyable_typarams)]
diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs
index 8713cf05a47..bbf1cf0d9b7 100644
--- a/src/libstd/rt/mod.rs
+++ b/src/libstd/rt/mod.rs
@@ -63,11 +63,9 @@ Several modules in `core` are clients of `rt`:
 use cell::Cell;
 use clone::Clone;
 use container::Container;
-use from_str::FromStr;
 use iter::Times;
 use iterator::IteratorUtil;
-use option::{Some, None};
-use os;
+use option::Some;
 use ptr::RawPtr;
 use rt::sched::{Scheduler, Coroutine, Shutdown};
 use rt::sleeper_list::SleeperList;
@@ -223,10 +221,7 @@ pub fn run(main: ~fn()) -> int {
 
     static DEFAULT_ERROR_CODE: int = 101;
 
-    let nthreads = match os::getenv("RUST_THREADS") {
-        Some(nstr) => FromStr::from_str(nstr).get(),
-        None => util::num_cpus()
-    };
+    let nthreads = util::default_sched_threads();
 
     // The shared list of sleeping schedulers. Schedulers wake each other
     // occassionally to do new work.
diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs
index 904b2f8bbb9..5219ae1d540 100644
--- a/src/libstd/rt/util.rs
+++ b/src/libstd/rt/util.rs
@@ -9,8 +9,11 @@
 // except according to those terms.
 
 use container::Container;
+use from_str::FromStr;
 use iterator::IteratorUtil;
 use libc;
+use option::{Some, None};
+use os;
 use str::StrSlice;
 
 /// Get the number of cores available
@@ -24,6 +27,15 @@ pub fn num_cpus() -> uint {
     }
 }
 
+/// Get's the number of scheduler threads requested by the environment
+/// either `RUST_THREADS` or `num_cpus`.
+pub fn default_sched_threads() -> uint {
+    match os::getenv("RUST_THREADS") {
+        Some(nstr) => FromStr::from_str(nstr).get(),
+        None => num_cpus()
+    }
+}
+
 pub fn dumb_println(s: &str) {
     use io::WriterUtil;
     let dbg = ::libc::STDERR_FILENO as ::io::fd_t;
diff --git a/src/test/run-pass/morestack6.rs b/src/test/run-pass/morestack6.rs
index 1dc8503aeb2..0e0bf2a13e1 100644
--- a/src/test/run-pass/morestack6.rs
+++ b/src/test/run-pass/morestack6.rs
@@ -23,7 +23,6 @@ mod rustrt {
         pub fn rust_get_sched_id() -> libc::intptr_t;
         pub fn rust_get_argc() -> libc::c_int;
         pub fn get_task_id() -> libc::intptr_t;
-        pub fn rust_sched_threads();
         pub fn rust_get_task();
     }
 }
@@ -31,7 +30,6 @@ mod rustrt {
 fn calllink01() { unsafe { rustrt::rust_get_sched_id(); } }
 fn calllink02() { unsafe { rustrt::rust_get_argc(); } }
 fn calllink08() { unsafe { rustrt::get_task_id(); } }
-fn calllink09() { unsafe { rustrt::rust_sched_threads(); } }
 fn calllink10() { unsafe { rustrt::rust_get_task(); } }
 
 fn runtest(f: extern fn(), frame_backoff: u32) {
@@ -64,7 +62,6 @@ pub fn main() {
         calllink01,
         calllink02,
         calllink08,
-        calllink09,
         calllink10
     ];
     let mut rng = rand::rng();