summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/src/io/serial.rs25
-rw-r--r--kernel/src/lib.rs22
-rw-r--r--kernel/src/testing/mod.rs3
-rw-r--r--kernel/src/testing/panic.rs51
-rw-r--r--kernel/src/testing/runner.rs51
5 files changed, 118 insertions, 34 deletions
diff --git a/kernel/src/io/serial.rs b/kernel/src/io/serial.rs
index eb9377c..3f661e9 100644
--- a/kernel/src/io/serial.rs
+++ b/kernel/src/io/serial.rs
@@ -1,23 +1,15 @@
+use lazy_static::lazy_static;
use spin::Mutex;
use uart_16550::SerialPort;
-/*lazy_static! {
+const SERIAL_IO_PORT: u16 = 0x3F8;
+
+lazy_static! {
pub static ref SERIAL1: Mutex<SerialPort> = {
- let mut serial_port = unsafe { SerialPort::new(0x3F8) };
+ let mut serial_port = unsafe { SerialPort::new(SERIAL_IO_PORT) };
serial_port.init();
Mutex::new(serial_port)
};
-}*/
-const SERIAL_IO_PORT: u16 = 0x3F8;
-
-static CONNECTION: Mutex<Serial> = Mutex::new(Serial {
- initialized: false,
- port: unsafe { SerialPort::new(SERIAL_IO_PORT) },
-});
-
-struct Serial {
- pub initialized: bool,
- pub port: SerialPort,
}
pub struct SerialStream {}
@@ -30,11 +22,6 @@ impl SerialStream {
impl core::fmt::Write for SerialStream {
fn write_str(&mut self, s: &str) -> core::fmt::Result {
- let mut guard = CONNECTION.lock();
- if !guard.initialized {
- guard.port.init();
- guard.initialized = true;
- }
- guard.port.write_str(s)
+ SERIAL1.lock().write_str(s)
}
}
diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs
index 87e8066..a81520b 100644
--- a/kernel/src/lib.rs
+++ b/kernel/src/lib.rs
@@ -3,26 +3,18 @@
#![feature(custom_test_frameworks)]
#![feature(abi_x86_interrupt)]
#![feature(panic_info_message)]
-#![test_runner(crate::test_runner)]
+#![test_runner(crate::testing::serial_test_runner)]
#![reexport_test_harness_main = "test_main"]
#![no_std]
-mod interrupts;
-mod io;
+pub mod interrupts;
+pub mod io;
+pub mod testing;
use core::fmt::Write;
-use io::vga_text::OStream;
-use io::{qemu, serial, vga_text};
-
-#[cfg(test)]
-pub fn test_runner(tests: &[&dyn Fn(&mut OStream)]) {
- let mut stdout = OStream::new();
- stdout.clear();
- write!(&mut stdout, "running {} tests\n", tests.len()).unwrap();
- for test in tests {
- test(&mut stdout)
- }
-}
+pub use io::qemu::{exit_qemu, QemuExitCode};
+pub use io::vga_text::OStream;
+pub use io::{qemu, serial, vga_text};
#[no_mangle]
pub extern "C" fn _start() -> ! {
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);
+}