diff --git a/src/virt.rs b/src/virt.rs index 3f3085f9cc0..69bdc98b6cc 100644 --- a/src/virt.rs +++ b/src/virt.rs @@ -8,8 +8,9 @@ mod ui; use std::{ iter, - sync::mpsc::{self, Receiver, Sender}, + sync::mpsc::{self, Receiver, Sender, TryRecvError}, thread, + time::Duration, }; use rand_chacha::ChaCha8Rng; @@ -110,15 +111,16 @@ impl<'a, I: 'static, C> Runner<'a, I, C> { I: Send + Sync, F: FnOnce() -> R, { - let (stop_tx, stop_rx) = mpsc::channel(); let mut service = Service::with_dispatch(platform, dispatch); thread::scope(|s| { + let (stop_tx, stop_rx) = mpsc::channel(); s.spawn(move || { let mut eps = self.eps; - while stop_rx.try_recv().is_err() { + while stop_rx.try_recv() == Err(TryRecvError::Empty) { if self.syscall_rx.try_recv().is_ok() { service.process(&mut eps); } + thread::sleep(Duration::from_millis(1)); } }); let result = f(); diff --git a/tests/virt.rs b/tests/virt.rs index 15492a26025..135a8f7c6d6 100644 --- a/tests/virt.rs +++ b/tests/virt.rs @@ -40,3 +40,12 @@ fn test1() { fn test2() { run_test(2); } + +#[test] +#[should_panic] +fn test_panic() { + // panicking tests should return and not run forever + virt::with_client(virt::StoreConfig::ram(), "test", |_| { + panic!(); + }) +}