Skip to content

Commit 744ba62

Browse files
committed
core::rt: Add a test mod and put run_in_newsched_task there
1 parent 1f97e6d commit 744ba62

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/libcore/rt/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ mod context;
4949
mod thread;
5050
pub mod env;
5151

52+
/// Tools for testing the runtime
53+
#[cfg(test)]
54+
pub mod test;
55+
5256
#[cfg(stage0)]
5357
pub fn start(main: *u8, _argc: int, _argv: *c_char, _crate_map: *u8) -> int {
5458
use self::sched::{Scheduler, Task};

src/libcore/rt/test.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// For setting up tests of the new scheduler
12+
pub fn run_in_newsched_task(f: ~fn()) {
13+
use cell::Cell;
14+
use unstable::run_in_bare_thread;
15+
use super::sched::Task;
16+
use super::uvio::UvEventLoop;
17+
18+
let f = Cell(Cell(f));
19+
20+
do run_in_bare_thread {
21+
let mut sched = ~UvEventLoop::new_scheduler();
22+
let f = f.take();
23+
let task = ~do Task::new(&mut sched.stack_pool) {
24+
(f.take())();
25+
};
26+
sched.task_queue.push_back(task);
27+
sched.run();
28+
}
29+
}

src/libcore/task/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ fn test_spawn_thread_on_demand() {
12291229

12301230
#[test]
12311231
fn test_simple_newsched_spawn() {
1232-
use rt::run_in_newsched_task;
1232+
use rt::test::run_in_newsched_task;
12331233

12341234
do run_in_newsched_task {
12351235
spawn(||())

0 commit comments

Comments
 (0)