Skip to content

Commit

Permalink
Another round of test fixes from previous commits
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Nov 10, 2013
1 parent 3a3eefc commit 86a321b
Show file tree
Hide file tree
Showing 19 changed files with 312 additions and 75 deletions.
2 changes: 1 addition & 1 deletion mk/rt.mk
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ $$(LIBUV_MAKEFILE_$(1)): $$(LIBUV_DEPS)
ifdef CFG_WINDOWSY_$(1)
$$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
$$(Q)$$(MAKE) -C $$(S)src/libuv -f Makefile.mingw \
CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
CC="$$(CC) $$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
AR="$$(AR_$(1))" \
V=$$(VERBOSE)
$$(Q)cp $$(S)src/libuv/libuv.a $$@
Expand Down
41 changes: 22 additions & 19 deletions src/librustuv/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ use std::c_str::CString;
use std::c_str;
use std::cast::transmute;
use std::cast;
use std::libc::{c_int, c_char, c_void, c_uint};
use std::libc::{c_int, c_char, c_void, size_t};
use std::libc;
use std::rt::BlockedTask;
use std::rt::io::{FileStat, IoError};
use std::rt::io;
use std::rt::local::Local;
use std::rt::rtio;
use std::rt::sched::{Scheduler, SchedHandle};
use std::task;
use std::vec;

use super::{Loop, UvError, uv_error_to_io_error, wait_until_woken_after};
Expand Down Expand Up @@ -79,7 +80,7 @@ impl FsRequest {
execute_nop(|req, cb| unsafe {
uvll::uv_fs_write(loop_.handle, req,
fd, vec::raw::to_ptr(buf) as *c_void,
buf.len() as c_uint, offset, cb)
buf.len() as size_t, offset, cb)
})
}

Expand All @@ -89,7 +90,7 @@ impl FsRequest {
do execute(|req, cb| unsafe {
uvll::uv_fs_read(loop_.handle, req,
fd, vec::raw::to_ptr(buf) as *c_void,
buf.len() as c_uint, offset, cb)
buf.len() as size_t, offset, cb)
}).map |req| {
req.get_result() as int
}
Expand Down Expand Up @@ -297,24 +298,26 @@ impl Drop for FsRequest {
fn execute(f: &fn(*uvll::uv_fs_t, uvll::uv_fs_cb) -> c_int)
-> Result<FsRequest, UvError>
{
let mut req = FsRequest {
fired: false,
req: unsafe { uvll::malloc_req(uvll::UV_FS) }
};
return match f(req.req, fs_cb) {
0 => {
req.fired = true;
let mut slot = None;
do wait_until_woken_after(&mut slot) {
unsafe { uvll::set_data_for_req(req.req, &slot) }
}
match req.get_result() {
n if n < 0 => Err(UvError(n)),
_ => Ok(req),
return do task::unkillable {
let mut req = FsRequest {
fired: false,
req: unsafe { uvll::malloc_req(uvll::UV_FS) }
};
match f(req.req, fs_cb) {
0 => {
req.fired = true;
let mut slot = None;
do wait_until_woken_after(&mut slot) {
unsafe { uvll::set_data_for_req(req.req, &slot) }
}
match req.get_result() {
n if n < 0 => Err(UvError(n)),
_ => Ok(req),
}
}
}
n => Err(UvError(n))
n => Err(UvError(n))

}
};

extern fn fs_cb(req: *uvll::uv_fs_t) {
Expand Down
9 changes: 9 additions & 0 deletions src/librustuv/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ mod test {
tube.recv();
}

#[test] #[should_fail]
fn smoke_fail() {
let tube = Tube::new();
let cb = ~MyCallback(tube.clone(), 1);
let mut idle = IdleWatcher::new(local_loop(), cb as ~Callback);
idle.resume();
fail!();
}

#[test]
fn fun_combinations_of_methods() {
let mut tube = Tube::new();
Expand Down
22 changes: 21 additions & 1 deletion src/librustuv/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,26 @@ pub trait UvHandle<T> {
}
}

pub struct ForbidSwitch {
msg: &'static str,
sched: uint,
}

impl ForbidSwitch {
fn new(s: &'static str) -> ForbidSwitch {
ForbidSwitch {
msg: s, sched: Local::borrow(|s: &mut Scheduler| s.sched_id())
}
}
}

impl Drop for ForbidSwitch {
fn drop(&mut self) {
assert!(self.sched == Local::borrow(|s: &mut Scheduler| s.sched_id()),
"didnt want a scheduler switch: {}", self.msg);
}
}

pub struct ForbidUnwind {
msg: &'static str,
failing_before: bool,
Expand All @@ -170,7 +190,7 @@ impl ForbidUnwind {
impl Drop for ForbidUnwind {
fn drop(&mut self) {
assert!(self.failing_before == task::failing(),
"failing sadface {}", self.msg);
"didnt want an unwind during: {}", self.msg);
}
}

Expand Down
50 changes: 50 additions & 0 deletions src/librustuv/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,56 @@ mod test {
}
}
#[should_fail] #[test]
fn tcp_listener_fail_cleanup() {
let addr = next_test_ip4();
let w = TcpListener::bind(local_loop(), addr).unwrap();
let _w = w.listen().unwrap();
fail!();
}
#[should_fail] #[test]
fn tcp_stream_fail_cleanup() {
let (port, chan) = oneshot();
let chan = Cell::new(chan);
let addr = next_test_ip4();
do task::spawn_unlinked { // please no linked failure
let w = TcpListener::bind(local_loop(), addr).unwrap();
let mut w = w.listen().unwrap();
chan.take().send(());
w.accept();
}
port.recv();
let _w = TcpWatcher::connect(local_loop(), addr).unwrap();
fail!();
}
#[should_fail] #[test]
fn udp_listener_fail_cleanup() {
let addr = next_test_ip4();
let _w = UdpWatcher::bind(local_loop(), addr).unwrap();
fail!();
}
#[should_fail] #[test]
fn udp_fail_other_task() {
let addr = next_test_ip4();
let (port, chan) = oneshot();
let chan = Cell::new(chan);
// force the handle to be created on a different scheduler, failure in
// the original task will force a homing operation back to this
// scheduler.
do task::spawn_sched(task::SingleThreaded) {
let w = UdpWatcher::bind(local_loop(), addr).unwrap();
chan.take().send(w);
}
let _w = port.recv();
fail!();
}
#[should_fail]
#[test]
#[ignore(reason = "linked failure")]
Expand Down
88 changes: 88 additions & 0 deletions src/librustuv/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,91 @@ impl RtioUnixAcceptor for PipeAcceptor {
impl HomingIO for PipeAcceptor {
fn home<'r>(&'r mut self) -> &'r mut SchedHandle { self.listener.home() }
}

#[cfg(test)]
mod tests {
use std::cell::Cell;
use std::comm::oneshot;
use std::rt::rtio::{RtioUnixListener, RtioUnixAcceptor, RtioPipe};
use std::rt::test::next_test_unix;
use std::task;

use super::*;
use super::super::local_loop;

#[test]
fn connect_err() {
match PipeWatcher::connect(local_loop(), &"path/to/nowhere".to_c_str()) {
Ok(*) => fail!(),
Err(*) => {}
}
}

#[test]
fn bind_err() {
match PipeListener::bind(local_loop(), &"path/to/nowhere".to_c_str()) {
Ok(*) => fail!(),
Err(e) => assert_eq!(e.name(), ~"EACCES"),
}
}

#[test]
fn bind() {
let p = next_test_unix().to_c_str();
match PipeListener::bind(local_loop(), &p) {
Ok(*) => {}
Err(*) => fail!(),
}
}

#[test] #[should_fail]
fn bind_fail() {
let p = next_test_unix().to_c_str();
let _w = PipeListener::bind(local_loop(), &p).unwrap();
fail!();
}

#[test]
fn connect() {
let path = next_test_unix();
let path2 = path.clone();
let (port, chan) = oneshot();
let chan = Cell::new(chan);

do spawn {
let p = PipeListener::bind(local_loop(), &path2.to_c_str()).unwrap();
let mut p = p.listen().unwrap();
chan.take().send(());
let mut client = p.accept().unwrap();
let mut buf = [0];
assert!(client.read(buf).unwrap() == 1);
assert_eq!(buf[0], 1);
assert!(client.write([2]).is_ok());
}
port.recv();
let mut c = PipeWatcher::connect(local_loop(), &path.to_c_str()).unwrap();
assert!(c.write([1]).is_ok());
let mut buf = [0];
assert!(c.read(buf).unwrap() == 1);
assert_eq!(buf[0], 2);
}

#[test] #[should_fail]
fn connect_fail() {
let path = next_test_unix();
let path2 = path.clone();
let (port, chan) = oneshot();
let chan = Cell::new(chan);

do task::spawn_unlinked { // plz no linked failure
let p = PipeListener::bind(local_loop(), &path2.to_c_str()).unwrap();
let mut p = p.listen().unwrap();
chan.take().send(());
p.accept();
}
port.recv();
let _c = PipeWatcher::connect(local_loop(), &path.to_c_str()).unwrap();
fail!()

}
}
23 changes: 9 additions & 14 deletions src/librustuv/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,18 @@ impl Process {
};

let handle = UvHandle::alloc(None::<Process>, uvll::UV_PROCESS);
let process = ~Process {
handle: handle,
home: get_handle_to_current_scheduler!(),
to_wake: None,
exit_status: None,
term_signal: None,
};
match unsafe {
uvll::uv_spawn(loop_.handle, handle, &options)
} {
0 => {
let process = ~Process {
handle: handle,
home: get_handle_to_current_scheduler!(),
to_wake: None,
exit_status: None,
term_signal: None,
};
Ok(process.install())
}
err => {
unsafe { uvll::free_handle(handle) }
Err(UvError(err))
}
0 => Ok(process.install()),
err => Err(UvError(err)),
}
}
};
Expand Down
Loading

0 comments on commit 86a321b

Please sign in to comment.