From f80f28d3a6735a942db44137e91ed5e51c4e21f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Sat, 13 Jan 2018 17:49:10 +0100 Subject: [PATCH 1/2] Fix RunLoop test: Increase time tolerance and dont unwind to C --- core-foundation/src/runloop.rs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/core-foundation/src/runloop.rs b/core-foundation/src/runloop.rs index fa2de80..887303b 100644 --- a/core-foundation/src/runloop.rs +++ b/core-foundation/src/runloop.rs @@ -181,14 +181,21 @@ mod test { use date::{CFDate, CFAbsoluteTime}; use std::mem; use libc::c_void; + use std::sync::mpsc; #[test] fn wait_200_milliseconds() { let run_loop = CFRunLoop::get_current(); - let mut now = CFDate::now().abs_time(); + + let now = CFDate::now().abs_time(); + let (elapsed_tx, elapsed_rx) = mpsc::channel(); + let mut info = Info { + start_time: now, + elapsed_tx, + }; let mut context = unsafe { CFRunLoopTimerContext { version: 0, - info: mem::transmute(&mut now), + info: &mut info as *mut _ as *mut c_void, retain: mem::zeroed(), release: mem::zeroed(), copyDescription: mem::zeroed(), @@ -200,13 +207,21 @@ mod test { run_loop.add_timer(&run_loop_timer, kCFRunLoopDefaultMode); } CFRunLoop::run_current(); + let elapsed = elapsed_rx.try_recv().unwrap(); + println!("wait_200_milliseconds, elapsed: {}", elapsed); + assert!(elapsed > 0.19 && elapsed < 0.30); + } + + struct Info { + start_time: CFAbsoluteTime, + elapsed_tx: mpsc::Sender, } - extern "C" fn timer_popped(_timer: CFRunLoopTimerRef, info: *mut c_void) { - let previous_now_ptr: *const CFAbsoluteTime = unsafe { mem::transmute(info) }; - let previous_now = unsafe { *previous_now_ptr }; + extern "C" fn timer_popped(_timer: CFRunLoopTimerRef, raw_info: *mut c_void) { + let info: *mut Info = unsafe { mem::transmute(raw_info) }; let now = CFDate::now().abs_time(); - assert!(now - previous_now > 0.19 && now - previous_now < 0.21); + let elapsed = now - unsafe { (*info).start_time }; + let _ = unsafe { (*info).elapsed_tx.send(elapsed) }; CFRunLoop::get_current().stop(); } } From 3a471a66ba61c8f85ccbb56a413349d8dc1f721f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Sat, 13 Jan 2018 17:50:35 +0100 Subject: [PATCH 2/2] Don't capture output in travis tests --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d3bdab0..ce6cca9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ os: osx script: - cd core-foundation - cargo build --verbose - - cargo test --verbose + - cargo test --verbose -- --nocapture notifications: webhooks: http://build.servo.org:54856/travis