summaryrefslogtreecommitdiff
path: root/kernel/src/testing/runner.rs
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/src/testing/runner.rs')
-rw-r--r--kernel/src/testing/runner.rs51
1 files changed, 51 insertions, 0 deletions
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);
+}