mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Merge branch 'post-09' into post-10
This commit is contained in:
@@ -109,13 +109,8 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: &mut Interrup
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
use crate::{serial_print, serial_println};
|
|
||||||
|
|
||||||
#[test_case]
|
#[test_case]
|
||||||
fn test_breakpoint_exception() {
|
fn test_breakpoint_exception() {
|
||||||
serial_print!("test_breakpoint_exception...");
|
|
||||||
// invoke a breakpoint exception
|
// invoke a breakpoint exception
|
||||||
x86_64::instructions::interrupts::int3();
|
x86_64::instructions::interrupts::int3();
|
||||||
serial_println!("[ok]");
|
|
||||||
}
|
}
|
||||||
|
|||||||
18
src/lib.rs
18
src/lib.rs
@@ -23,11 +23,25 @@ pub fn init() {
|
|||||||
unsafe { interrupts::PICS.lock().initialize() };
|
unsafe { interrupts::PICS.lock().initialize() };
|
||||||
x86_64::instructions::interrupts::enable();
|
x86_64::instructions::interrupts::enable();
|
||||||
}
|
}
|
||||||
|
pub trait Testable {
|
||||||
|
fn run(&self) -> ();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn test_runner(tests: &[&dyn Fn()]) {
|
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 Testable]) {
|
||||||
serial_println!("Running {} tests", tests.len());
|
serial_println!("Running {} tests", tests.len());
|
||||||
for test in tests {
|
for test in tests {
|
||||||
test();
|
test.run();
|
||||||
}
|
}
|
||||||
exit_qemu(QemuExitCode::Success);
|
exit_qemu(QemuExitCode::Success);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,3 +71,8 @@ fn panic(info: &PanicInfo) -> ! {
|
|||||||
fn panic(info: &PanicInfo) -> ! {
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
blog_os::test_panic_handler(info)
|
blog_os::test_panic_handler(info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn trivial_assertion() {
|
||||||
|
assert_eq!(1, 1);
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,9 +3,6 @@ use lazy_static::lazy_static;
|
|||||||
use spin::Mutex;
|
use spin::Mutex;
|
||||||
use volatile::Volatile;
|
use volatile::Volatile;
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
use crate::{serial_print, serial_println};
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
/// A global `Writer` instance that can be used for printing to the VGA text buffer.
|
/// A global `Writer` instance that can be used for printing to the VGA text buffer.
|
||||||
///
|
///
|
||||||
@@ -180,18 +177,14 @@ pub fn _print(args: fmt::Arguments) {
|
|||||||
|
|
||||||
#[test_case]
|
#[test_case]
|
||||||
fn test_println_simple() {
|
fn test_println_simple() {
|
||||||
serial_print!("test_println... ");
|
|
||||||
println!("test_println_simple output");
|
println!("test_println_simple output");
|
||||||
serial_println!("[ok]");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test_case]
|
#[test_case]
|
||||||
fn test_println_many() {
|
fn test_println_many() {
|
||||||
serial_print!("test_println_many... ");
|
|
||||||
for _ in 0..200 {
|
for _ in 0..200 {
|
||||||
println!("test_println_many output");
|
println!("test_println_many output");
|
||||||
}
|
}
|
||||||
serial_println!("[ok]");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test_case]
|
#[test_case]
|
||||||
@@ -199,8 +192,6 @@ fn test_println_output() {
|
|||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
use x86_64::instructions::interrupts;
|
use x86_64::instructions::interrupts;
|
||||||
|
|
||||||
serial_print!("test_println_output... ");
|
|
||||||
|
|
||||||
let s = "Some test string that fits on a single line";
|
let s = "Some test string that fits on a single line";
|
||||||
interrupts::without_interrupts(|| {
|
interrupts::without_interrupts(|| {
|
||||||
let mut writer = WRITER.lock();
|
let mut writer = WRITER.lock();
|
||||||
@@ -210,6 +201,4 @@ fn test_println_output() {
|
|||||||
assert_eq!(char::from(screen_char.ascii_character), c);
|
assert_eq!(char::from(screen_char.ascii_character), c);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
serial_println!("[ok]");
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#![test_runner(blog_os::test_runner)]
|
#![test_runner(blog_os::test_runner)]
|
||||||
#![reexport_test_harness_main = "test_main"]
|
#![reexport_test_harness_main = "test_main"]
|
||||||
|
|
||||||
use blog_os::{println, serial_print, serial_println};
|
use blog_os::println;
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
#[no_mangle] // don't mangle the name of this function
|
#[no_mangle] // don't mangle the name of this function
|
||||||
@@ -21,7 +21,5 @@ fn panic(info: &PanicInfo) -> ! {
|
|||||||
|
|
||||||
#[test_case]
|
#[test_case]
|
||||||
fn test_println() {
|
fn test_println() {
|
||||||
serial_print!("test_println... ");
|
|
||||||
println!("test_println output");
|
println!("test_println output");
|
||||||
serial_println!("[ok]");
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ pub extern "C" fn _start() -> ! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn should_fail() {
|
fn should_fail() {
|
||||||
serial_print!("should_fail... ");
|
serial_print!("should_panic::should_fail...\t");
|
||||||
assert_eq!(0, 1);
|
assert_eq!(0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn _start() -> ! {
|
pub extern "C" fn _start() -> ! {
|
||||||
serial_print!("stack_overflow... ");
|
serial_print!("stack_overflow::stack_overflow...\t");
|
||||||
|
|
||||||
blog_os::gdt::init();
|
blog_os::gdt::init();
|
||||||
init_test_idt();
|
init_test_idt();
|
||||||
|
|||||||
Reference in New Issue
Block a user