Skip to content

Commit 0447034

Browse files
committed
Add a way to run the test suite with the new scheduler
TESTARGS=--newrt make check-stage1-rpass Conflicts: src/rt/rustrt.def.in
1 parent a882554 commit 0447034

File tree

8 files changed

+95
-22
lines changed

8 files changed

+95
-22
lines changed

src/compiletest/common.rs

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ pub struct config {
6363
// Run tests using the JIT
6464
jit: bool,
6565

66+
// Run tests using the new runtime
67+
newrt: bool,
68+
6669
// Explain what's going on
6770
verbose: bool
6871

src/compiletest/compiletest.rc

+4-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ pub fn parse_config(args: ~[~str]) -> config {
6161
getopts::optopt(~"runtool"), getopts::optopt(~"rustcflags"),
6262
getopts::optflag(~"verbose"),
6363
getopts::optopt(~"logfile"),
64-
getopts::optflag(~"jit")];
64+
getopts::optflag(~"jit"),
65+
getopts::optflag(~"newrt")];
6566

6667
fail_unless!(!args.is_empty());
6768
let args_ = vec::tail(args);
@@ -95,6 +96,7 @@ pub fn parse_config(args: ~[~str]) -> config {
9596
runtool: getopts::opt_maybe_str(matches, ~"runtool"),
9697
rustcflags: getopts::opt_maybe_str(matches, ~"rustcflags"),
9798
jit: getopts::opt_present(matches, ~"jit"),
99+
newrt: getopts::opt_present(matches, ~"newrt"),
98100
verbose: getopts::opt_present(matches, ~"verbose")
99101
}
100102
}
@@ -114,6 +116,7 @@ pub fn log_config(config: config) {
114116
logv(c, fmt!("runtool: %s", opt_str(config.runtool)));
115117
logv(c, fmt!("rustcflags: %s", opt_str(config.rustcflags)));
116118
logv(c, fmt!("jit: %b", config.jit));
119+
logv(c, fmt!("newrt: %b", config.newrt));
117120
logv(c, fmt!("verbose: %b", config.verbose));
118121
logv(c, fmt!("\n"));
119122
}

src/compiletest/runtest.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,17 @@ fn compile_test_(config: config, props: TestProps,
483483

484484
fn exec_compiled_test(config: config, props: TestProps,
485485
testfile: &Path) -> ProcRes {
486+
487+
// If testing the new runtime then set the RUST_NEWRT env var
488+
let env = if config.newrt {
489+
props.exec_env + ~[(~"RUST_NEWRT", ~"1")]
490+
} else {
491+
props.exec_env
492+
};
493+
486494
compose_and_run(config, testfile,
487495
make_run_args(config, props, testfile),
488-
props.exec_env,
496+
env,
489497
config.run_lib_path, None)
490498
}
491499

src/libcore/rt/mod.rs

+31
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use libc::c_char;
1112

1213
// Some basic logging
1314
macro_rules! rtdebug_ (
@@ -44,3 +45,33 @@ mod stack;
4445
mod context;
4546
mod thread;
4647
pub mod env;
48+
49+
pub fn initialize() {
50+
unsafe { rust_initialize_global_state(); }
51+
extern {
52+
fn rust_initialize_global_state();
53+
}
54+
}
55+
56+
pub fn start(main: *u8, _argc: int, _argv: *c_char, _crate_map: *u8) -> int {
57+
use self::sched::{Scheduler, Task};
58+
use self::uvio::UvEventLoop;
59+
60+
// XXX: Would rather do this lazily in Scheduler
61+
initialize();
62+
63+
let loop_ = ~UvEventLoop::new();
64+
let mut sched = ~Scheduler::new(loop_);
65+
let main_task = ~do Task::new(&mut sched.stack_pool) {
66+
// XXX: Can't call a C function pointer from Rust yet
67+
unsafe { rust_call_nullary_fn(main) };
68+
};
69+
sched.task_queue.push_back(main_task);
70+
sched.run();
71+
return 0;
72+
73+
extern {
74+
fn rust_call_nullary_fn(f: *u8);
75+
}
76+
}
77+

src/libcore/unstable/lang.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,25 @@ pub unsafe fn strdup_uniq(ptr: *c_uchar, len: uint) -> ~str {
120120
#[lang="start"]
121121
pub fn start(main: *u8, argc: int, argv: *c_char,
122122
crate_map: *u8) -> int {
123+
use libc::getenv;
124+
use rt::start;
125+
126+
unsafe {
127+
let use_new_rt = do str::as_c_str("RUST_NEWRT") |s| {
128+
getenv(s).is_null()
129+
};
130+
if use_new_rt {
131+
return rust_start(main as *c_void, argc as c_int, argv,
132+
crate_map as *c_void) as int;
133+
} else {
134+
return start(main, argc, argv, crate_map);
135+
}
136+
}
123137

124138
extern {
125139
fn rust_start(main: *c_void, argc: c_int, argv: *c_char,
126140
crate_map: *c_void) -> c_int;
127141
}
128-
129-
unsafe {
130-
return rust_start(main as *c_void, argc as c_int, argv,
131-
crate_map as *c_void) as int;
132-
}
133142
}
134143

135144
// Local Variables:

src/rt/rust.cpp

-15
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,6 @@
2121

2222
void* global_crate_map = NULL;
2323

24-
#ifndef _WIN32
25-
pthread_key_t sched_key;
26-
#else
27-
DWORD sched_key;
28-
#endif
29-
30-
extern "C" void*
31-
rust_get_sched_tls_key() {
32-
return &sched_key;
33-
}
34-
3524
/**
3625
The runtime entrypoint. The (C ABI) main function generated by rustc calls
3726
`rust_start`, providing the address of the Rust ABI main function, the
@@ -41,10 +30,6 @@ rust_get_sched_tls_key() {
4130
extern "C" CDECL int
4231
rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) {
4332

44-
#ifndef _WIN32
45-
pthread_key_create(&sched_key, NULL);
46-
#endif
47-
4833
// Load runtime configuration options from the environment.
4934
// FIXME #1497: Should provide a way to get these from the command
5035
// line as well.

src/rt/rust_builtin.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,37 @@ rust_get_rt_env() {
882882
return task->kernel->env;
883883
}
884884

885+
typedef void *(*nullary_fn)();
886+
887+
extern "C" CDECL void
888+
rust_call_nullary_fn(nullary_fn f) {
889+
f();
890+
}
891+
892+
893+
#ifndef _WIN32
894+
pthread_key_t sched_key;
895+
#else
896+
DWORD sched_key;
897+
#endif
898+
899+
extern "C" void*
900+
rust_get_sched_tls_key() {
901+
return &sched_key;
902+
}
903+
904+
extern "C" CDECL void
905+
rust_initialize_global_state() {
906+
907+
#ifndef _WIN32
908+
assert(!pthread_key_create(&sched_key, NULL));
909+
#else
910+
sched_key = TlsAlloc();
911+
assert(sched_key != TLS_OUT_OF_INDEXES);
912+
#endif
913+
914+
}
915+
885916
//
886917
// Local Variables:
887918
// mode: C++

src/rt/rustrt.def.in

+3
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,7 @@ rust_uv_ip4_addrp
210210
rust_uv_ip6_addrp
211211
rust_uv_free_ip4_addr
212212
rust_uv_free_ip6_addr
213+
rust_call_nullary_fn
214+
rust_initialize_global_state
215+
213216

0 commit comments

Comments
 (0)