Skip to content

Commit 2d5973e

Browse files
committed
更新 ostool 版本至 0.7.24,优化 Qemu 运行测试的线程处理逻辑
1 parent 2b9137c commit 2d5973e

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ostool/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ostool"
3-
version = "0.7.23"
3+
version = "0.7.24"
44
edition = "2024"
55
description = "A tool for operating system development"
66
authors = ["周睿 <[email protected]>"]

ostool/src/step/qemu.rs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use std::{
22
fs,
33
process::{Command, exit},
4+
sync::{Arc, Mutex},
5+
thread,
6+
time::Duration,
47
};
58

69
use colored::Colorize;
@@ -71,23 +74,50 @@ impl Step for Qemu {
7174
self.cmd.arg(project.kernel.as_ref().unwrap());
7275

7376
if self.is_check_test {
77+
let test_success = Arc::new(Mutex::new(false));
78+
let test_success_clone = test_success.clone();
79+
7480
self.cmd
7581
.exec_with_lines(project.is_print_cmd, move |line, child| {
7682
if line.contains("All tests passed") {
7783
println!("{}", "Test passed!".green());
78-
let _ = child.kill();
79-
let _ = child.wait();
80-
exit(0);
84+
{
85+
let mut finished = test_success_clone.lock().unwrap();
86+
*finished = true;
87+
}
88+
89+
// 启动一个线程,1秒后强制退出
90+
thread::spawn(move || {
91+
thread::sleep(Duration::from_secs(1));
92+
child.kill().expect("Failed to kill child process");
93+
child.wait().expect("Failed to wait for child process");
94+
exit(0);
95+
});
8196
}
8297
if line.contains("Test failed") {
8398
println!("{}", "Test failed!".red());
84-
let _ = child.kill();
85-
let _ = child.wait();
86-
exit(1);
99+
{
100+
let mut finished = test_success_clone.lock().unwrap();
101+
*finished = true;
102+
}
103+
104+
// 启动一个线程,1秒后强制退出
105+
thread::spawn(move || {
106+
thread::sleep(Duration::from_secs(1));
107+
child.kill().expect("Failed to kill child process");
108+
child.wait().expect("Failed to wait for child process");
109+
exit(1);
110+
});
87111
}
88112
Ok(())
89113
})
90114
.unwrap();
115+
116+
if test_success.lock().unwrap().clone() {
117+
exit(0);
118+
} else {
119+
exit(1);
120+
}
91121
} else {
92122
self.cmd
93123
.exec(project.is_print_cmd)

0 commit comments

Comments
 (0)