Skip to content

Commit

Permalink
vga buffer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeebuscrossaint committed Jul 6, 2024
1 parent 0369e2b commit 78086b5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
test-success-exit-code = 33 # (0x10 << 1) | 1
test-timeout = 300 # (in seconds)
25 changes: 18 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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<T> Testable for T
where
T: Fn(),
{
fn run(&self) {
serial_print!("{}...\t", core::any::type_name::<T>());
self();
serial_println!("[ok]");
}
}
22 changes: 22 additions & 0 deletions src/vga_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 78086b5

Please sign in to comment.