提交 f41b363e 编写于 作者: B Brian Anderson

Update libtest for single-threaded emscripten support

上级 b8b50f0e
......@@ -1182,26 +1182,63 @@ fn flush(&mut self) -> io::Result<()> {
}
}
thread::spawn(move || {
let data = Arc::new(Mutex::new(Vec::new()));
let data2 = data.clone();
let cfg = thread::Builder::new().name(match desc.name {
DynTestName(ref name) => name.clone(),
StaticTestName(name) => name.to_owned(),
// If the platform is single-threaded we're just going to run
// the test synchronously, regardless of the concurrency
// level.
let supports_threads = !cfg!(target_os = "emscripten");
// Buffer for capturing standard I/O
let data = Arc::new(Mutex::new(Vec::new()));
let data2 = data.clone();
if supports_threads {
thread::spawn(move || {
let cfg = thread::Builder::new().name(match desc.name {
DynTestName(ref name) => name.clone(),
StaticTestName(name) => name.to_owned(),
});
let result_guard = cfg.spawn(move || {
if !nocapture {
io::set_print(box Sink(data2.clone()));
io::set_panic(box Sink(data2));
}
testfn()
})
.unwrap();
let test_result = calc_result(&desc, result_guard.join());
let stdout = data.lock().unwrap().to_vec();
monitor_ch.send((desc.clone(), test_result, stdout)).unwrap();
});
} else {
let oldio = if !nocapture {
Some((
io::set_print(box Sink(data2.clone())),
io::set_panic(box Sink(data2))
))
} else {
None
};
use std::panic::{catch_unwind, AssertUnwindSafe};
let result_guard = cfg.spawn(move || {
if !nocapture {
io::set_print(box Sink(data2.clone()));
io::set_panic(box Sink(data2));
}
testfn()
})
.unwrap();
let test_result = calc_result(&desc, result_guard.join());
let result = catch_unwind(AssertUnwindSafe(|| {
testfn()
}));
if let Some((printio, panicio)) = oldio {
if let Some(printio) = printio {
io::set_print(printio);
}
if let Some(panicio) = panicio {
io::set_panic(panicio);
}
};
let test_result = calc_result(&desc, result);
let stdout = data.lock().unwrap().to_vec();
monitor_ch.send((desc.clone(), test_result, stdout)).unwrap();
});
}
}
match testfn {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册