diff options
author | Dennis Kobert <dennis@kobert.dev> | 2019-11-09 15:11:50 +0100 |
---|---|---|
committer | Dennis Kobert <dennis@kobert.dev> | 2019-11-09 15:11:50 +0100 |
commit | 26a7561196674b39f9adadcb374f36c503361adb (patch) | |
tree | 3031e026feae853f7c46b91975beaa4e20cf755c /kernel/src/testing | |
parent | b17a0a41bea7789178919f4a0999ea8519e1f897 (diff) |
Add basic tests
Diffstat (limited to 'kernel/src/testing')
-rw-r--r-- | kernel/src/testing/mod.rs | 2 | ||||
-rw-r--r-- | kernel/src/testing/panic.rs | 53 | ||||
-rw-r--r-- | kernel/src/testing/runner.rs | 20 |
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); } |