Skip to content

Commit 86a321b

Browse files
committed
Another round of test fixes from previous commits
1 parent 3a3eefc commit 86a321b

19 files changed

+312
-75
lines changed

mk/rt.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ $$(LIBUV_MAKEFILE_$(1)): $$(LIBUV_DEPS)
218218
ifdef CFG_WINDOWSY_$(1)
219219
$$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
220220
$$(Q)$$(MAKE) -C $$(S)src/libuv -f Makefile.mingw \
221-
CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
221+
CC="$$(CC) $$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
222222
AR="$$(AR_$(1))" \
223223
V=$$(VERBOSE)
224224
$$(Q)cp $$(S)src/libuv/libuv.a $$@

src/librustuv/file.rs

+22-19
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ use std::c_str::CString;
1212
use std::c_str;
1313
use std::cast::transmute;
1414
use std::cast;
15-
use std::libc::{c_int, c_char, c_void, c_uint};
15+
use std::libc::{c_int, c_char, c_void, size_t};
1616
use std::libc;
1717
use std::rt::BlockedTask;
1818
use std::rt::io::{FileStat, IoError};
1919
use std::rt::io;
2020
use std::rt::local::Local;
2121
use std::rt::rtio;
2222
use std::rt::sched::{Scheduler, SchedHandle};
23+
use std::task;
2324
use std::vec;
2425

2526
use super::{Loop, UvError, uv_error_to_io_error, wait_until_woken_after};
@@ -79,7 +80,7 @@ impl FsRequest {
7980
execute_nop(|req, cb| unsafe {
8081
uvll::uv_fs_write(loop_.handle, req,
8182
fd, vec::raw::to_ptr(buf) as *c_void,
82-
buf.len() as c_uint, offset, cb)
83+
buf.len() as size_t, offset, cb)
8384
})
8485
}
8586

@@ -89,7 +90,7 @@ impl FsRequest {
8990
do execute(|req, cb| unsafe {
9091
uvll::uv_fs_read(loop_.handle, req,
9192
fd, vec::raw::to_ptr(buf) as *c_void,
92-
buf.len() as c_uint, offset, cb)
93+
buf.len() as size_t, offset, cb)
9394
}).map |req| {
9495
req.get_result() as int
9596
}
@@ -297,24 +298,26 @@ impl Drop for FsRequest {
297298
fn execute(f: &fn(*uvll::uv_fs_t, uvll::uv_fs_cb) -> c_int)
298299
-> Result<FsRequest, UvError>
299300
{
300-
let mut req = FsRequest {
301-
fired: false,
302-
req: unsafe { uvll::malloc_req(uvll::UV_FS) }
303-
};
304-
return match f(req.req, fs_cb) {
305-
0 => {
306-
req.fired = true;
307-
let mut slot = None;
308-
do wait_until_woken_after(&mut slot) {
309-
unsafe { uvll::set_data_for_req(req.req, &slot) }
310-
}
311-
match req.get_result() {
312-
n if n < 0 => Err(UvError(n)),
313-
_ => Ok(req),
301+
return do task::unkillable {
302+
let mut req = FsRequest {
303+
fired: false,
304+
req: unsafe { uvll::malloc_req(uvll::UV_FS) }
305+
};
306+
match f(req.req, fs_cb) {
307+
0 => {
308+
req.fired = true;
309+
let mut slot = None;
310+
do wait_until_woken_after(&mut slot) {
311+
unsafe { uvll::set_data_for_req(req.req, &slot) }
312+
}
313+
match req.get_result() {
314+
n if n < 0 => Err(UvError(n)),
315+
_ => Ok(req),
316+
}
314317
}
315-
}
316-
n => Err(UvError(n))
318+
n => Err(UvError(n))
317319

320+
}
318321
};
319322

320323
extern fn fs_cb(req: *uvll::uv_fs_t) {

src/librustuv/idle.rs

+9
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ mod test {
126126
tube.recv();
127127
}
128128

129+
#[test] #[should_fail]
130+
fn smoke_fail() {
131+
let tube = Tube::new();
132+
let cb = ~MyCallback(tube.clone(), 1);
133+
let mut idle = IdleWatcher::new(local_loop(), cb as ~Callback);
134+
idle.resume();
135+
fail!();
136+
}
137+
129138
#[test]
130139
fn fun_combinations_of_methods() {
131140
let mut tube = Tube::new();

src/librustuv/lib.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,26 @@ pub trait UvHandle<T> {
154154
}
155155
}
156156

157+
pub struct ForbidSwitch {
158+
msg: &'static str,
159+
sched: uint,
160+
}
161+
162+
impl ForbidSwitch {
163+
fn new(s: &'static str) -> ForbidSwitch {
164+
ForbidSwitch {
165+
msg: s, sched: Local::borrow(|s: &mut Scheduler| s.sched_id())
166+
}
167+
}
168+
}
169+
170+
impl Drop for ForbidSwitch {
171+
fn drop(&mut self) {
172+
assert!(self.sched == Local::borrow(|s: &mut Scheduler| s.sched_id()),
173+
"didnt want a scheduler switch: {}", self.msg);
174+
}
175+
}
176+
157177
pub struct ForbidUnwind {
158178
msg: &'static str,
159179
failing_before: bool,
@@ -170,7 +190,7 @@ impl ForbidUnwind {
170190
impl Drop for ForbidUnwind {
171191
fn drop(&mut self) {
172192
assert!(self.failing_before == task::failing(),
173-
"failing sadface {}", self.msg);
193+
"didnt want an unwind during: {}", self.msg);
174194
}
175195
}
176196

src/librustuv/net.rs

+50
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,56 @@ mod test {
11681168
}
11691169
}
11701170
1171+
#[should_fail] #[test]
1172+
fn tcp_listener_fail_cleanup() {
1173+
let addr = next_test_ip4();
1174+
let w = TcpListener::bind(local_loop(), addr).unwrap();
1175+
let _w = w.listen().unwrap();
1176+
fail!();
1177+
}
1178+
1179+
#[should_fail] #[test]
1180+
fn tcp_stream_fail_cleanup() {
1181+
let (port, chan) = oneshot();
1182+
let chan = Cell::new(chan);
1183+
let addr = next_test_ip4();
1184+
1185+
do task::spawn_unlinked { // please no linked failure
1186+
let w = TcpListener::bind(local_loop(), addr).unwrap();
1187+
let mut w = w.listen().unwrap();
1188+
chan.take().send(());
1189+
w.accept();
1190+
}
1191+
port.recv();
1192+
let _w = TcpWatcher::connect(local_loop(), addr).unwrap();
1193+
fail!();
1194+
}
1195+
1196+
#[should_fail] #[test]
1197+
fn udp_listener_fail_cleanup() {
1198+
let addr = next_test_ip4();
1199+
let _w = UdpWatcher::bind(local_loop(), addr).unwrap();
1200+
fail!();
1201+
}
1202+
1203+
#[should_fail] #[test]
1204+
fn udp_fail_other_task() {
1205+
let addr = next_test_ip4();
1206+
let (port, chan) = oneshot();
1207+
let chan = Cell::new(chan);
1208+
1209+
// force the handle to be created on a different scheduler, failure in
1210+
// the original task will force a homing operation back to this
1211+
// scheduler.
1212+
do task::spawn_sched(task::SingleThreaded) {
1213+
let w = UdpWatcher::bind(local_loop(), addr).unwrap();
1214+
chan.take().send(w);
1215+
}
1216+
1217+
let _w = port.recv();
1218+
fail!();
1219+
}
1220+
11711221
#[should_fail]
11721222
#[test]
11731223
#[ignore(reason = "linked failure")]

src/librustuv/pipe.rs

+88
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,91 @@ impl RtioUnixAcceptor for PipeAcceptor {
238238
impl HomingIO for PipeAcceptor {
239239
fn home<'r>(&'r mut self) -> &'r mut SchedHandle { self.listener.home() }
240240
}
241+
242+
#[cfg(test)]
243+
mod tests {
244+
use std::cell::Cell;
245+
use std::comm::oneshot;
246+
use std::rt::rtio::{RtioUnixListener, RtioUnixAcceptor, RtioPipe};
247+
use std::rt::test::next_test_unix;
248+
use std::task;
249+
250+
use super::*;
251+
use super::super::local_loop;
252+
253+
#[test]
254+
fn connect_err() {
255+
match PipeWatcher::connect(local_loop(), &"path/to/nowhere".to_c_str()) {
256+
Ok(*) => fail!(),
257+
Err(*) => {}
258+
}
259+
}
260+
261+
#[test]
262+
fn bind_err() {
263+
match PipeListener::bind(local_loop(), &"path/to/nowhere".to_c_str()) {
264+
Ok(*) => fail!(),
265+
Err(e) => assert_eq!(e.name(), ~"EACCES"),
266+
}
267+
}
268+
269+
#[test]
270+
fn bind() {
271+
let p = next_test_unix().to_c_str();
272+
match PipeListener::bind(local_loop(), &p) {
273+
Ok(*) => {}
274+
Err(*) => fail!(),
275+
}
276+
}
277+
278+
#[test] #[should_fail]
279+
fn bind_fail() {
280+
let p = next_test_unix().to_c_str();
281+
let _w = PipeListener::bind(local_loop(), &p).unwrap();
282+
fail!();
283+
}
284+
285+
#[test]
286+
fn connect() {
287+
let path = next_test_unix();
288+
let path2 = path.clone();
289+
let (port, chan) = oneshot();
290+
let chan = Cell::new(chan);
291+
292+
do spawn {
293+
let p = PipeListener::bind(local_loop(), &path2.to_c_str()).unwrap();
294+
let mut p = p.listen().unwrap();
295+
chan.take().send(());
296+
let mut client = p.accept().unwrap();
297+
let mut buf = [0];
298+
assert!(client.read(buf).unwrap() == 1);
299+
assert_eq!(buf[0], 1);
300+
assert!(client.write([2]).is_ok());
301+
}
302+
port.recv();
303+
let mut c = PipeWatcher::connect(local_loop(), &path.to_c_str()).unwrap();
304+
assert!(c.write([1]).is_ok());
305+
let mut buf = [0];
306+
assert!(c.read(buf).unwrap() == 1);
307+
assert_eq!(buf[0], 2);
308+
}
309+
310+
#[test] #[should_fail]
311+
fn connect_fail() {
312+
let path = next_test_unix();
313+
let path2 = path.clone();
314+
let (port, chan) = oneshot();
315+
let chan = Cell::new(chan);
316+
317+
do task::spawn_unlinked { // plz no linked failure
318+
let p = PipeListener::bind(local_loop(), &path2.to_c_str()).unwrap();
319+
let mut p = p.listen().unwrap();
320+
chan.take().send(());
321+
p.accept();
322+
}
323+
port.recv();
324+
let _c = PipeWatcher::connect(local_loop(), &path.to_c_str()).unwrap();
325+
fail!()
326+
327+
}
328+
}

src/librustuv/process.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,18 @@ impl Process {
7777
};
7878

7979
let handle = UvHandle::alloc(None::<Process>, uvll::UV_PROCESS);
80+
let process = ~Process {
81+
handle: handle,
82+
home: get_handle_to_current_scheduler!(),
83+
to_wake: None,
84+
exit_status: None,
85+
term_signal: None,
86+
};
8087
match unsafe {
8188
uvll::uv_spawn(loop_.handle, handle, &options)
8289
} {
83-
0 => {
84-
let process = ~Process {
85-
handle: handle,
86-
home: get_handle_to_current_scheduler!(),
87-
to_wake: None,
88-
exit_status: None,
89-
term_signal: None,
90-
};
91-
Ok(process.install())
92-
}
93-
err => {
94-
unsafe { uvll::free_handle(handle) }
95-
Err(UvError(err))
96-
}
90+
0 => Ok(process.install()),
91+
err => Err(UvError(err)),
9792
}
9893
}
9994
};

0 commit comments

Comments
 (0)