diff --git a/Cargo.toml b/Cargo.toml index 408fd74..d9de3f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,6 @@ bootloader = "0.9" volatile = "0.2.6" spin = "0.5.2" x86_64 = "0.14.2" -uart_16550 = "0.2.0" [dependencies.lazy_static] version = "1.0" @@ -27,13 +26,5 @@ features = ["spin_no_std"] # this enables exiting qemu from the guest system [package.metadata.bootimage] -test-args = [ - "-device", - "isa-debug-exit,iobase=0xf4,iosize=0x04", - "-serial", - "stdio", - "-display", - "none", -] +test-args = ["-device", "isa-debug-exit,iobase=0xf4,iosize=0x04"] test-success-exit-code = 33 # (0x10 << 1) | 1 = 33 -test-timeout = "300" # in seconds diff --git a/src/main.rs b/src/main.rs index 3a03d35..cc96953 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,22 +7,6 @@ use core::panic::PanicInfo; mod vga_buffer; -mod serial; - -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]"); - } -} static HELLO: &[u8] = b"Hello toto :3"; @@ -54,8 +38,7 @@ pub extern "C" fn _start() -> ! { loop {} } -// panic handler -#[cfg(not(test))] +// called on panic #[panic_handler] fn panic(info: &PanicInfo) -> ! { println!("{}", info); @@ -63,23 +46,12 @@ fn panic(info: &PanicInfo) -> ! { loop {} } -// panic handler in test mode #[cfg(test)] -#[panic_handler] -fn panic(info: &PanicInfo) -> ! { - serial_println!("[failed]\n"); - serial_println!("Error: {}\n", info); - exit_qemu(QemuExitCode::Failed); - - loop {} -} - -#[cfg(test)] -pub fn test_runner(tests: &[&dyn Testable]) { - serial_println!("Running {} tests", tests.len()); +pub fn test_runner(tests: &[&dyn Fn()]) { + println!("Running {} tests", tests.len()); for test in tests { - test.run(); + test(); } exit_qemu(QemuExitCode::Success); @@ -87,5 +59,7 @@ pub fn test_runner(tests: &[&dyn Testable]) { #[test_case] fn trivial_assertion() { + print!("asserzione triviale... "); assert_eq!(1, 1); + println!("[ok]"); } diff --git a/src/serial.rs b/src/serial.rs deleted file mode 100644 index 66e6ef3..0000000 --- a/src/serial.rs +++ /dev/null @@ -1,35 +0,0 @@ -use uart_16550::SerialPort; -use spin::Mutex; -use lazy_static::lazy_static; - -lazy_static! { - pub static ref SERIAL1: Mutex = { - let mut serial_port = unsafe { SerialPort::new(0x3F8) }; - serial_port.init(); - Mutex::new(serial_port) - }; -} - -#[doc(hidden)] -pub fn _print(args: ::core::fmt::Arguments) { - use core::fmt::Write; - SERIAL1.lock().write_fmt(args).expect("Printing to serial failed :("); -} - -// prints to the host through the serial interface -#[macro_export] -macro_rules! serial_print { - ($($arg:tt)*) => { - $crate::serial::_print(format_args!($($arg)*)); - }; -} - -// prints to the host through the serial interface -// appending a newline -#[macro_export] -macro_rules! serial_println { - () => ($crate::serial_print!("\n")); - ($fmt:expr) => ($crate::serial_print!(concat!($fmt, "\n"))); - ($fmt:expr, $($arg:tt)*) => ($crate::serial_print!( - concat!($fmt, "\n"), $($arg)*)); -} diff --git a/src/vga_buffer.rs b/src/vga_buffer.rs index 3d7dcff..b99723d 100644 --- a/src/vga_buffer.rs +++ b/src/vga_buffer.rs @@ -155,28 +155,3 @@ impl Writer { } } -#[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 = "loss and gain is the same"; - 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_carachter), c); - } -}