Skip to content

Commit 3139962

Browse files
committed
Another round of test fixes from previous commits
1 parent cd4ebab commit 3139962

File tree

13 files changed

+216
-43
lines changed

13 files changed

+216
-43
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: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ 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};
@@ -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/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/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/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];

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ impl Process {
105105
Process {
106106
pid: res.pid,
107107
handle: res.handle,
108-
input: in_pipe.map(|pipe| file::FileDesc::new(pipe.out)),
109-
output: out_pipe.map(|pipe| file::FileDesc::new(pipe.input)),
110-
error: err_pipe.map(|pipe| file::FileDesc::new(pipe.input)),
108+
input: in_pipe.map(|pipe| file::FileDesc::new(pipe.out, true)),
109+
output: out_pipe.map(|pipe| file::FileDesc::new(pipe.input, true)),
110+
error: err_pipe.map(|pipe| file::FileDesc::new(pipe.input, true)),
111111
exit_code: None,
112112
}
113113
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ pub struct StdIn {
3636

3737
impl StdIn {
3838
/// Duplicates the stdin file descriptor, returning an io::Reader
39-
#[fixed_stack_segment] #[inline(never)]
4039
pub fn new() -> StdIn {
41-
let fd = unsafe { libc::dup(libc::STDIN_FILENO) };
42-
StdIn { fd: file::FileDesc::new(fd) }
40+
StdIn { fd: file::FileDesc::new(libc::STDIN_FILENO, false) }
4341
}
4442
}
4543

@@ -54,10 +52,8 @@ pub struct StdOut {
5452

5553
impl StdOut {
5654
/// Duplicates the specified file descriptor, returning an io::Writer
57-
#[fixed_stack_segment] #[inline(never)]
5855
pub fn new(fd: file::fd_t) -> StdOut {
59-
let fd = unsafe { libc::dup(fd) };
60-
StdOut { fd: file::FileDesc::new(fd) }
56+
StdOut { fd: file::FileDesc::new(fd, false) }
6157
}
6258
}
6359

src/libstd/rt/macros.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ macro_rules! rtassert (
4242

4343

4444
macro_rules! rtabort (
45-
($msg:expr $($arg:tt)*) => ( {
46-
::rt::util::abort(format!(concat!(file!(), ":", line!(), " ", $msg)
47-
$($arg)*));
45+
($($arg:tt)*) => ( {
46+
::rt::util::abort(format!($($arg)*));
4847
} )
4948
)

src/libstd/run.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,13 +436,13 @@ mod tests {
436436
}
437437
438438
fn writeclose(fd: c_int, s: &str) {
439-
let mut writer = file::FileDesc::new(fd);
439+
let mut writer = file::FileDesc::new(fd, true);
440440
writer.write(s.as_bytes());
441441
}
442442
443443
fn readclose(fd: c_int) -> ~str {
444444
let mut res = ~[];
445-
let mut reader = file::FileDesc::new(fd);
445+
let mut reader = file::FileDesc::new(fd, true);
446446
let mut buf = [0, ..1024];
447447
loop {
448448
match reader.read(buf) {

src/test/run-pass/rtio-processes.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
//
2424
// See #9341
2525

26+
use std::rt::io;
2627
use std::rt::io::process::{Process, ProcessConfig, CreatePipe, Ignored};
27-
use std::rt::io::{Reader, Writer};
2828
use std::str;
2929

3030
#[test]
@@ -55,10 +55,10 @@ fn smoke_failure() {
5555
cwd: None,
5656
io: io,
5757
};
58-
let p = Process::new(args);
59-
assert!(p.is_some());
60-
let mut p = p.unwrap();
61-
assert!(p.wait() != 0);
58+
match io::result(|| Process::new(args)) {
59+
Ok(*) => fail!(),
60+
Err(*) => {}
61+
}
6262
}
6363

6464
#[test]

0 commit comments

Comments
 (0)