summaryrefslogtreecommitdiff
path: root/kernel/src/testing
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/src/testing')
-rw-r--r--kernel/src/testing/mod.rs2
-rw-r--r--kernel/src/testing/panic.rs53
-rw-r--r--kernel/src/testing/runner.rs20
3 files changed, 29 insertions, 46 deletions
diff --git a/kernel/src/testing/mod.rs b/kernel/src/testing/mod.rs
index e328433..f9622bd 100644
--- a/kernel/src/testing/mod.rs
+++ b/kernel/src/testing/mod.rs
@@ -1,3 +1,5 @@
+pub mod panic;
pub mod runner;
+pub use panic::{panic, serial_panic, serial_should_panic, should_panic};
pub use runner::{serial_test_runner, serial_test_runner_panic, test_runner, test_runner_panic};
diff --git a/kernel/src/testing/panic.rs b/kernel/src/testing/panic.rs
index 7fb769b..729a45f 100644
--- a/kernel/src/testing/panic.rs
+++ b/kernel/src/testing/panic.rs
@@ -1,51 +1,36 @@
use crate::io::{qemu, serial, vga_text};
use core::fmt::Write;
+use core::panic::PanicInfo;
use qemu::{exit_qemu, QemuExitCode};
use serial::SerialStream;
use vga_text::OStream;
-#[cfg(test)]
-pub fn serial_test_runner_panic(tests: &[&dyn Fn()]) {
+pub fn serial_should_panic(info: &PanicInfo) -> ! {
let mut stdout = SerialStream::new();
- write!(stdout, "Running {} tests", tests.len()).unwrap();
- for test in tests {
- test();
- write!(stdout, "[test did not panic]").unwrap();
- exit_qemu(QemuExitCode::Failed);
- }
+ write!(stdout, "\nOK\nsuccessfully panicked\n").unwrap();
exit_qemu(QemuExitCode::Success);
+ loop {}
}
-#[cfg(test)]
-pub fn serial_test_runner(tests: &[&dyn Fn()]) {
+pub fn serial_panic(info: &PanicInfo) -> ! {
+ crate::io::panic_screen::show(info.message());
let mut stdout = SerialStream::new();
- write!(stdout, "Running {} tests", tests.len()).unwrap();
- for test in tests {
- test();
- write!(stdout, "[test did not panic]").unwrap();
- }
- exit_qemu(QemuExitCode::Success);
+ write!(
+ stdout,
+ "\nERR\nPanicked execute without -serial for more details\n{}",
+ info
+ )
+ .unwrap();
+ exit_qemu(QemuExitCode::Failed);
+ loop {}
}
-#[cfg(test)]
-pub fn test_runner_panic(tests: &[&dyn Fn()]) {
- let mut stdout = OStream::new();
- write!(stdout, "Running {} tests", tests.len()).unwrap();
- for test in tests {
- test();
- write!(stdout, "[test did not panic]").unwrap();
- exit_qemu(QemuExitCode::Failed);
- }
+pub fn should_panic(_info: &PanicInfo) -> ! {
exit_qemu(QemuExitCode::Success);
+ loop {}
}
-#[cfg(test)]
-pub fn test_runner(tests: &[&dyn Fn()]) {
- let mut stdout = OStream::new();
- write!(stdout, "Running {} tests", tests.len()).unwrap();
- for test in tests {
- test();
- write!(stdout, "[test did not panic]").unwrap();
- }
- exit_qemu(QemuExitCode::Success);
+pub fn panic(info: &PanicInfo) -> ! {
+ crate::io::panic_screen::show(info.message());
+ loop {}
}
diff --git a/kernel/src/testing/runner.rs b/kernel/src/testing/runner.rs
index 0f9d08b..38d6d94 100644
--- a/kernel/src/testing/runner.rs
+++ b/kernel/src/testing/runner.rs
@@ -4,48 +4,44 @@ use qemu::{exit_qemu, QemuExitCode};
use serial::SerialStream;
use vga_text::OStream;
-//#[cfg(test)]
pub fn serial_test_runner_panic(tests: &[&dyn Fn()]) {
let mut stdout = SerialStream::new();
- write!(stdout, "Running {} tests", tests.len()).unwrap();
+ write!(stdout, "\nRunning {} tests\n", tests.len()).unwrap();
for test in tests {
test();
- write!(stdout, "[test did not panic]").unwrap();
+ write!(stdout, "\n[test did not panic]\n\n").unwrap();
exit_qemu(QemuExitCode::Failed);
}
exit_qemu(QemuExitCode::Success);
}
-//#[cfg(test)]
pub fn serial_test_runner(tests: &[&dyn Fn()]) {
let mut stdout = SerialStream::new();
- write!(stdout, "Running {} tests", tests.len()).unwrap();
+ write!(stdout, "\nRunning {} tests\n", tests.len()).unwrap();
for test in tests {
test();
- write!(stdout, "[test did not panic]").unwrap();
+ write!(stdout, "\n[OK]\n").unwrap();
}
exit_qemu(QemuExitCode::Success);
}
-//#[cfg(test)]
pub fn test_runner_panic(tests: &[&dyn Fn()]) {
let mut stdout = OStream::new();
- write!(stdout, "Running {} tests", tests.len()).unwrap();
+ write!(stdout, "\nRunning {} tests\n", tests.len()).unwrap();
for test in tests {
test();
- write!(stdout, "[test did not panic]").unwrap();
+ write!(stdout, "\n[test did not panic]\n\n").unwrap();
exit_qemu(QemuExitCode::Failed);
}
exit_qemu(QemuExitCode::Success);
}
-//#[cfg(test)]
pub fn test_runner(tests: &[&dyn Fn()]) {
let mut stdout = OStream::new();
- write!(stdout, "Running {} tests", tests.len()).unwrap();
+ write!(stdout, "\nRunning {} tests\n", tests.len()).unwrap();
for test in tests {
test();
- write!(stdout, "[test did not panic]").unwrap();
+ write!(stdout, "\n[OK]\n").unwrap();
}
exit_qemu(QemuExitCode::Success);
}