summaryrefslogtreecommitdiff
path: root/kernel/src/testing
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/src/testing')
-rw-r--r--kernel/src/testing/mod.rs3
-rw-r--r--kernel/src/testing/panic.rs51
-rw-r--r--kernel/src/testing/runner.rs51
3 files changed, 105 insertions, 0 deletions
diff --git a/kernel/src/testing/mod.rs b/kernel/src/testing/mod.rs
new file mode 100644
index 0000000..e328433
--- /dev/null
+++ b/kernel/src/testing/mod.rs
@@ -0,0 +1,3 @@
+pub mod runner;
+
+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
new file mode 100644
index 0000000..7fb769b
--- /dev/null
+++ b/kernel/src/testing/panic.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);
+}
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);
+}