Skip to content

Commit 66a7f8f

Browse files
committed
Another round of test fixes from previous commits
1 parent 22c021b commit 66a7f8f

File tree

18 files changed

+235
-68
lines changed

18 files changed

+235
-68
lines changed

mk/rt.mk

Lines changed: 1 addition & 1 deletion
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

Lines changed: 22 additions & 19 deletions
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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl ForbidUnwind {
169169
impl Drop for ForbidUnwind {
170170
fn drop(&mut self) {
171171
assert!(self.failing_before == task::failing(),
172-
"failing sadface {}", self.msg);
172+
"didnt want an unwind during: {}", self.msg);
173173
}
174174
}
175175

src/librustuv/net.rs

Lines changed: 50 additions & 0 deletions
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

Lines changed: 88 additions & 0 deletions
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

Lines changed: 9 additions & 14 deletions
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
};

src/librustuv/timer.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,24 @@ mod test {
168168
timer.sleep(1);
169169
timer.sleep(1);
170170
}
171+
172+
#[test] #[should_fail]
173+
fn oneshot_fail() {
174+
let mut timer = TimerWatcher::new(local_loop());
175+
let _port = timer.oneshot(1);
176+
fail!();
177+
}
178+
179+
#[test] #[should_fail]
180+
fn period_fail() {
181+
let mut timer = TimerWatcher::new(local_loop());
182+
let _port = timer.period(1);
183+
fail!();
184+
}
185+
186+
#[test] #[should_fail]
187+
fn normal_fail() {
188+
let _timer = TimerWatcher::new(local_loop());
189+
fail!();
190+
}
171191
}

src/librustuv/uvll.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,9 @@ externfn!(fn uv_fs_open(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char,
676676
externfn!(fn uv_fs_unlink(loop_ptr: *uv_loop_t, req: *uv_fs_t, path: *c_char,
677677
cb: uv_fs_cb) -> c_int)
678678
externfn!(fn uv_fs_write(l: *uv_loop_t, req: *uv_fs_t, fd: c_int, buf: *c_void,
679-
len: c_uint, offset: i64, cb: uv_fs_cb) -> c_int)
679+
len: size_t, offset: i64, cb: uv_fs_cb) -> c_int)
680680
externfn!(fn uv_fs_read(l: *uv_loop_t, req: *uv_fs_t, fd: c_int, buf: *c_void,
681-
len: c_uint, offset: i64, cb: uv_fs_cb) -> c_int)
681+
len: size_t, offset: i64, cb: uv_fs_cb) -> c_int)
682682
externfn!(fn uv_fs_close(l: *uv_loop_t, req: *uv_fs_t, fd: c_int,
683683
cb: uv_fs_cb) -> c_int)
684684
externfn!(fn uv_fs_stat(l: *uv_loop_t, req: *uv_fs_t, path: *c_char,

src/libstd/rt/io/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,11 @@ pub fn ignore_io_error<T>(cb: &fn() -> T) -> T {
423423
/// closure if no error occurred.
424424
pub fn result<T>(cb: &fn() -> T) -> Result<T, IoError> {
425425
let mut err = None;
426-
let ret = io_error::cond.trap(|e| err = Some(e)).inside(cb);
426+
let ret = io_error::cond.trap(|e| {
427+
if err.is_none() {
428+
err = Some(e);
429+
}
430+
}).inside(cb);
427431
match err {
428432
Some(e) => Err(e),
429433
None => Ok(ret),

src/libstd/rt/io/native/file.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,20 @@ pub type fd_t = libc::c_int;
8080

8181
pub struct FileDesc {
8282
priv fd: fd_t,
83+
priv close_on_drop: bool,
8384
}
8485

8586
impl FileDesc {
8687
/// Create a `FileDesc` from an open C file descriptor.
8788
///
8889
/// The `FileDesc` will take ownership of the specified file descriptor and
89-
/// close it upon destruction.
90+
/// close it upon destruction if the `close_on_drop` flag is true, otherwise
91+
/// it will not close the file descriptor when this `FileDesc` is dropped.
9092
///
9193
/// Note that all I/O operations done on this object will be *blocking*, but
9294
/// they do not require the runtime to be active.
93-
pub fn new(fd: fd_t) -> FileDesc {
94-
FileDesc { fd: fd }
95+
pub fn new(fd: fd_t, close_on_drop: bool) -> FileDesc {
96+
FileDesc { fd: fd, close_on_drop: close_on_drop }
9597
}
9698
}
9799

@@ -137,7 +139,9 @@ impl Writer for FileDesc {
137139
impl Drop for FileDesc {
138140
#[fixed_stack_segment] #[inline(never)]
139141
fn drop(&mut self) {
140-
unsafe { libc::close(self.fd); }
142+
if self.close_on_drop {
143+
unsafe { libc::close(self.fd); }
144+
}
141145
}
142146
}
143147

@@ -245,8 +249,8 @@ mod tests {
245249
// opening or closing files.
246250
unsafe {
247251
let os::Pipe { input, out } = os::pipe();
248-
let mut reader = FileDesc::new(input);
249-
let mut writer = FileDesc::new(out);
252+
let mut reader = FileDesc::new(input, true);
253+
let mut writer = FileDesc::new(out, true);
250254

251255
writer.write(bytes!("test"));
252256
let mut buf = [0u8, ..4];

0 commit comments

Comments
 (0)