1
Fork 0

libcore: Fix core test. rs=broken

This commit is contained in:
Patrick Walton 2013-01-10 22:36:54 -08:00
parent 83675895af
commit c6fe93d9b5
3 changed files with 84 additions and 76 deletions

View file

@ -1233,34 +1233,36 @@ mod tests {
#[test] #[test]
fn copy_file_ok() { fn copy_file_ok() {
let tempdir = getcwd(); // would like to use $TMPDIR, unsafe {
// doesn't seem to work on Linux let tempdir = getcwd(); // would like to use $TMPDIR,
assert (str::len(tempdir.to_str()) > 0u); // doesn't seem to work on Linux
let in = tempdir.push("in.txt"); assert (str::len(tempdir.to_str()) > 0u);
let out = tempdir.push("out.txt"); let in = tempdir.push("in.txt");
let out = tempdir.push("out.txt");
/* Write the temp input file */ /* Write the temp input file */
let ostream = do as_c_charp(in.to_str()) |fromp| { let ostream = do as_c_charp(in.to_str()) |fromp| {
do as_c_charp("w+b") |modebuf| { do as_c_charp("w+b") |modebuf| {
libc::fopen(fromp, modebuf) libc::fopen(fromp, modebuf)
} }
}; };
assert (ostream as uint != 0u); assert (ostream as uint != 0u);
let s = ~"hello"; let s = ~"hello";
let mut buf = vec::to_mut(str::to_bytes(s) + ~[0 as u8]); let mut buf = vec::to_mut(str::to_bytes(s) + ~[0 as u8]);
do vec::as_mut_buf(buf) |b, _len| { do vec::as_mut_buf(buf) |b, _len| {
assert (libc::fwrite(b as *c_void, 1u as size_t, assert (libc::fwrite(b as *c_void, 1u as size_t,
(str::len(s) + 1u) as size_t, ostream) (str::len(s) + 1u) as size_t, ostream)
== buf.len() as size_t)}; == buf.len() as size_t)};
assert (libc::fclose(ostream) == (0u as c_int)); assert (libc::fclose(ostream) == (0u as c_int));
let rs = os::copy_file(&in, &out); let rs = os::copy_file(&in, &out);
if (!os::path_exists(&in)) { if (!os::path_exists(&in)) {
fail (fmt!("%s doesn't exist", in.to_str())); fail (fmt!("%s doesn't exist", in.to_str()));
} }
assert(rs); assert(rs);
let rslt = run::run_program(~"diff", ~[in.to_str(), out.to_str()]); let rslt = run::run_program(~"diff", ~[in.to_str(), out.to_str()]);
assert (rslt == 0); assert (rslt == 0);
assert (remove_file(&in)); assert (remove_file(&in));
assert (remove_file(&out)); assert (remove_file(&out));
}
} }
} }

View file

@ -2674,9 +2674,11 @@ mod tests {
#[test] #[test]
fn test_to_lower() { fn test_to_lower() {
assert ~"" == map(~"", |c| libc::tolower(c as c_char) as char); unsafe {
assert ~"ymca" == map(~"YMCA", assert ~"" == map(~"", |c| libc::tolower(c as c_char) as char);
|c| libc::tolower(c as c_char) as char); assert ~"ymca" == map(~"YMCA",
|c| libc::tolower(c as c_char) as char);
}
} }
#[test] #[test]
@ -3192,9 +3194,11 @@ mod tests {
#[test] #[test]
fn test_map() { fn test_map() {
assert ~"" == map(~"", |c| libc::toupper(c as c_char) as char); unsafe {
assert ~"YMCA" == map(~"ymca", assert ~"" == map(~"", |c| libc::toupper(c as c_char) as char);
|c| libc::toupper(c as c_char) as char); assert ~"YMCA" == map(~"ymca",
|c| libc::toupper(c as c_char) as char);
}
} }
#[test] #[test]

View file

@ -957,59 +957,61 @@ extern mod testrt {
#[test] #[test]
fn test_spawn_sched_blocking() { fn test_spawn_sched_blocking() {
unsafe {
// Testing that a task in one scheduler can block in foreign code // Testing that a task in one scheduler can block in foreign code
// without affecting other schedulers // without affecting other schedulers
for iter::repeat(20u) { for iter::repeat(20u) {
let start_po = oldcomm::Port(); let start_po = oldcomm::Port();
let start_ch = oldcomm::Chan(&start_po); let start_ch = oldcomm::Chan(&start_po);
let fin_po = oldcomm::Port(); let fin_po = oldcomm::Port();
let fin_ch = oldcomm::Chan(&fin_po); let fin_ch = oldcomm::Chan(&fin_po);
let lock = testrt::rust_dbg_lock_create(); let lock = testrt::rust_dbg_lock_create();
do spawn_sched(SingleThreaded) { do spawn_sched(SingleThreaded) {
testrt::rust_dbg_lock_lock(lock); testrt::rust_dbg_lock_lock(lock);
oldcomm::send(start_ch, ()); oldcomm::send(start_ch, ());
// Block the scheduler thread // Block the scheduler thread
testrt::rust_dbg_lock_wait(lock); testrt::rust_dbg_lock_wait(lock);
testrt::rust_dbg_lock_unlock(lock); testrt::rust_dbg_lock_unlock(lock);
oldcomm::send(fin_ch, ()); oldcomm::send(fin_ch, ());
}; };
// Wait until the other task has its lock // Wait until the other task has its lock
oldcomm::recv(start_po); oldcomm::recv(start_po);
fn pingpong(po: oldcomm::Port<int>, ch: oldcomm::Chan<int>) { fn pingpong(po: oldcomm::Port<int>, ch: oldcomm::Chan<int>) {
let mut val = 20; let mut val = 20;
while val > 0 { while val > 0 {
val = oldcomm::recv(po); val = oldcomm::recv(po);
oldcomm::send(ch, val - 1); oldcomm::send(ch, val - 1);
}
} }
let setup_po = oldcomm::Port();
let setup_ch = oldcomm::Chan(&setup_po);
let parent_po = oldcomm::Port();
let parent_ch = oldcomm::Chan(&parent_po);
do spawn {
let child_po = oldcomm::Port();
oldcomm::send(setup_ch, oldcomm::Chan(&child_po));
pingpong(child_po, parent_ch);
};
let child_ch = oldcomm::recv(setup_po);
oldcomm::send(child_ch, 20);
pingpong(parent_po, child_ch);
testrt::rust_dbg_lock_lock(lock);
testrt::rust_dbg_lock_signal(lock);
testrt::rust_dbg_lock_unlock(lock);
oldcomm::recv(fin_po);
testrt::rust_dbg_lock_destroy(lock);
} }
let setup_po = oldcomm::Port();
let setup_ch = oldcomm::Chan(&setup_po);
let parent_po = oldcomm::Port();
let parent_ch = oldcomm::Chan(&parent_po);
do spawn {
let child_po = oldcomm::Port();
oldcomm::send(setup_ch, oldcomm::Chan(&child_po));
pingpong(child_po, parent_ch);
};
let child_ch = oldcomm::recv(setup_po);
oldcomm::send(child_ch, 20);
pingpong(parent_po, child_ch);
testrt::rust_dbg_lock_lock(lock);
testrt::rust_dbg_lock_signal(lock);
testrt::rust_dbg_lock_unlock(lock);
oldcomm::recv(fin_po);
testrt::rust_dbg_lock_destroy(lock);
} }
} }