diff --git a/Cargo.toml b/Cargo.toml index 01ce126..9647d82 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,4 +31,5 @@ test-args = [ "-device", "isa-debug-exit,iobase=0xf4,iosize=0x04", "-serial", "stdio", "-display", "none" ] -test-success-exit-code = 33 # (0x10 << 1) | 1 \ No newline at end of file +test-success-exit-code = 33 # (0x10 << 1) | 1 +test-timeout = 300 # (in seconds) \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 7703c80..920e6ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,21 +69,17 @@ pub extern "C" fn _start() -> ! { // ON CARGO TEST IN SOME CASES. TO FIX REMOVE/COMMENT OUT THE ' panic = "abort" ' // FOR A PROFILE IN THE CARGO.TOML FILE #[cfg(test)] -fn test_runner(tests: &[&dyn Fn()]) { +pub fn test_runner(tests: &[&dyn Testable]) { // new serial_println!("Running {} tests", tests.len()); - println!("Running {} tests", tests.len()); for test in tests { - test(); + test.run(); // new } - //new exit_qemu(QemuExitCode::Success); } #[test_case] fn trivial_assertion() { - serial_print!("trivial assertion... "); - assert_eq!(0, 1); - serial_println!("[ok]"); + assert_eq!(1, 1); } #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -100,4 +96,19 @@ pub fn exit_qemu(exit_code: QemuExitCode) { let mut port = Port::new(0xf4); port.write(exit_code as u32); } +} + +pub trait Testable { + fn run(&self) -> (); +} + +impl Testable for T +where + T: Fn(), +{ + fn run(&self) { + serial_print!("{}...\t", core::any::type_name::()); + self(); + serial_println!("[ok]"); + } } \ No newline at end of file diff --git a/src/vga_buffer.rs b/src/vga_buffer.rs index c402ef6..6c86f86 100644 --- a/src/vga_buffer.rs +++ b/src/vga_buffer.rs @@ -168,4 +168,26 @@ macro_rules! println { pub fn _print(args: fmt::Arguments) { use core::fmt::Write; WRITER.lock().write_fmt(args).unwrap(); +} + +#[test_case] +fn test_println_simple() { + println!("test_println_simple output"); +} + +#[test_case] +fn test_println_many() { + for _ in 0..200 { + println!("test_println_many output"); + } +} + +#[test_case] +fn test_println_output() { + let s = "Some test string that fits on a single line"; + println!("{}", s); + for (i, c) in s.chars().enumerate() { + let screen_char = WRITER.lock().buffer.chars[BUFFER_HEIGHT - 2][i].read(); + assert_eq!(char::from(screen_char.ascii_character), c); + } } \ No newline at end of file