Skip to content

Commit

Permalink
Merge branch 'post-05' into post-06
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-opp committed Jun 8, 2020
2 parents f944688 + 7846bd0 commit 8c10bbb
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
5 changes: 0 additions & 5 deletions src/interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,8 @@ extern "x86-interrupt" fn double_fault_handler(
panic!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame);
}

#[cfg(test)]
use crate::{serial_print, serial_println};

#[test_case]
fn test_breakpoint_exception() {
serial_print!("test_breakpoint_exception...");
// invoke a breakpoint exception
x86_64::instructions::interrupts::int3();
serial_println!("[ok]");
}
18 changes: 16 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,25 @@ pub fn init() {
gdt::init();
interrupts::init_idt();
}
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]");
}
}

pub fn test_runner(tests: &[&dyn Fn()]) {
pub fn test_runner(tests: &[&dyn Testable]) {
serial_println!("Running {} tests", tests.len());
for test in tests {
test();
test.run();
}
exit_qemu(QemuExitCode::Success);
}
Expand Down
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ fn panic(info: &PanicInfo) -> ! {
fn panic(info: &PanicInfo) -> ! {
blog_os::test_panic_handler(info)
}

#[test_case]
fn trivial_assertion() {
assert_eq!(1, 1);
}
11 changes: 0 additions & 11 deletions src/vga_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ use lazy_static::lazy_static;
use spin::Mutex;
use volatile::Volatile;

#[cfg(test)]
use crate::{serial_print, serial_println};

lazy_static! {
/// A global `Writer` instance that can be used for printing to the VGA text buffer.
///
Expand Down Expand Up @@ -175,30 +172,22 @@ pub fn _print(args: fmt::Arguments) {

#[test_case]
fn test_println_simple() {
serial_print!("test_println... ");
println!("test_println_simple output");
serial_println!("[ok]");
}

#[test_case]
fn test_println_many() {
serial_print!("test_println_many... ");
for _ in 0..200 {
println!("test_println_many output");
}
serial_println!("[ok]");
}

#[test_case]
fn test_println_output() {
serial_print!("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);
}

serial_println!("[ok]");
}
4 changes: 1 addition & 3 deletions tests/basic_boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![test_runner(blog_os::test_runner)]
#![reexport_test_harness_main = "test_main"]

use blog_os::{println, serial_print, serial_println};
use blog_os::println;
use core::panic::PanicInfo;

#[no_mangle] // don't mangle the name of this function
Expand All @@ -21,7 +21,5 @@ fn panic(info: &PanicInfo) -> ! {

#[test_case]
fn test_println() {
serial_print!("test_println... ");
println!("test_println output");
serial_println!("[ok]");
}
2 changes: 1 addition & 1 deletion tests/should_panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub extern "C" fn _start() -> ! {
}

fn should_fail() {
serial_print!("should_fail... ");
serial_print!("should_panic::should_fail...\t");
assert_eq!(0, 1);
}

Expand Down

0 comments on commit 8c10bbb

Please sign in to comment.