From 1e0422eb84988464836a8f17fd7420b9f3cf277b Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Sat, 9 Nov 2019 03:12:41 +0100 Subject: Add testing runner functions --- kernel/src/testing/runner.rs | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 kernel/src/testing/runner.rs (limited to 'kernel/src/testing/runner.rs') diff --git a/kernel/src/testing/runner.rs b/kernel/src/testing/runner.rs new file mode 100644 index 0000000..0f9d08b --- /dev/null +++ b/kernel/src/testing/runner.rs @@ -0,0 +1,51 @@ +use crate::io::{qemu, serial, vga_text}; +use core::fmt::Write; +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(); + for test in tests { + test(); + write!(stdout, "[test did not panic]").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(); + for test in tests { + test(); + write!(stdout, "[test did not panic]").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(); + for test in tests { + test(); + write!(stdout, "[test did not panic]").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(); + for test in tests { + test(); + write!(stdout, "[test did not panic]").unwrap(); + } + exit_qemu(QemuExitCode::Success); +} -- cgit v1.2.3-70-g09d2