added serial ports communication + Testable trait
This commit is contained in:
parent
c3f181a641
commit
e009cd22a8
3 changed files with 77 additions and 7 deletions
38
src/main.rs
38
src/main.rs
|
@ -7,6 +7,22 @@
|
|||
use core::panic::PanicInfo;
|
||||
|
||||
mod vga_buffer;
|
||||
mod serial;
|
||||
|
||||
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]");
|
||||
}
|
||||
}
|
||||
|
||||
static HELLO: &[u8] = b"Hello toto :3";
|
||||
|
||||
|
@ -38,7 +54,8 @@ pub extern "C" fn _start() -> ! {
|
|||
loop {}
|
||||
}
|
||||
|
||||
// called on panic
|
||||
// panic handler
|
||||
#[cfg(not(test))]
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
println!("{}", info);
|
||||
|
@ -46,12 +63,23 @@ fn panic(info: &PanicInfo) -> ! {
|
|||
loop {}
|
||||
}
|
||||
|
||||
// panic handler in test mode
|
||||
#[cfg(test)]
|
||||
pub fn test_runner(tests: &[&dyn Fn()]) {
|
||||
println!("Running {} tests", tests.len());
|
||||
#[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());
|
||||
|
||||
for test in tests {
|
||||
test();
|
||||
test.run();
|
||||
}
|
||||
|
||||
exit_qemu(QemuExitCode::Success);
|
||||
|
@ -59,7 +87,5 @@ pub fn test_runner(tests: &[&dyn Fn()]) {
|
|||
|
||||
#[test_case]
|
||||
fn trivial_assertion() {
|
||||
print!("asserzione triviale... ");
|
||||
assert_eq!(1, 1);
|
||||
println!("[ok]");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue