Compare commits
2 Commits
a5fb50ffb5
...
56f003e8cc
Author | SHA1 | Date | |
---|---|---|---|
|
56f003e8cc | ||
|
aa03bdad88 |
@ -17,5 +17,7 @@ features = ["spin_no_std"]
|
|||||||
|
|
||||||
|
|
||||||
[package.metadata.bootimage]
|
[package.metadata.bootimage]
|
||||||
test-args = ["-device", "isa-debug-exit,iobase=0xf4,iosize=0x04", "-serial", "stdio"]
|
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 = 10 # timeout in seconds
|
||||||
|
36
src/main.rs
36
src/main.rs
@ -1,7 +1,6 @@
|
|||||||
// #![feature(abi_x86_interrupt, asm)]
|
// #![feature(abi_x86_interrupt, asm)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
#![feature(custom_test_frameworks)]
|
#![feature(custom_test_frameworks)]
|
||||||
#![test_runner(crate::test_runner)]
|
#![test_runner(crate::test_runner)]
|
||||||
#![reexport_test_harness_main = "test_main"]
|
#![reexport_test_harness_main = "test_main"]
|
||||||
@ -13,12 +12,22 @@ mod serial;
|
|||||||
|
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
|
#[cfg(not(test))]
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
fn panic(info: &PanicInfo) -> ! {
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
println!("{info}");
|
println!("{info}");
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[panic_handler]
|
||||||
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
|
serial_println!("[failed]\n");
|
||||||
|
serial_println!("Error: {}", info);
|
||||||
|
exit_qemu(QemuExitCode::Failed);
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn _start() -> ! {
|
pub extern "C" fn _start() -> ! {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -43,11 +52,26 @@ pub fn exit_qemu(exit_code: QemuExitCode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait TestFunction {
|
||||||
|
fn run(&self) -> ();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> TestFunction for T
|
||||||
|
where
|
||||||
|
T: Fn(),
|
||||||
|
{
|
||||||
|
fn run(&self) {
|
||||||
|
serial_print!("{}...\t", core::any::type_name::<T>());
|
||||||
|
self();
|
||||||
|
serial_println!("[ok]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn test_runner(tests: &[&dyn Fn()]) {
|
fn test_runner(tests: &[&dyn TestFunction]) {
|
||||||
serial_println!("Running {} test(s)", tests.len());
|
serial_println!("Running {} test(s)", tests.len());
|
||||||
for test in tests {
|
for test in tests {
|
||||||
test();
|
test.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
exit_qemu(QemuExitCode::Success);
|
exit_qemu(QemuExitCode::Success);
|
||||||
@ -55,8 +79,10 @@ fn test_runner(tests: &[&dyn Fn()]) {
|
|||||||
|
|
||||||
#[test_case]
|
#[test_case]
|
||||||
fn basic_test() {
|
fn basic_test() {
|
||||||
serial_print!("Trivial test... ");
|
|
||||||
assert_eq!(5, 5);
|
assert_eq!(5, 5);
|
||||||
serial_println!("[ok]");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn basic_test2() {
|
||||||
|
assert_eq!(4, 4);
|
||||||
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use uart_16550::SerialPort;
|
|
||||||
use spin::Mutex;
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
use spin::Mutex;
|
||||||
|
use uart_16550::SerialPort;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref SERIAL1: Mutex<SerialPort> = {
|
pub static ref SERIAL1: Mutex<SerialPort> = {
|
||||||
|
@ -163,3 +163,9 @@ lazy_static! {
|
|||||||
pub static ref WRITER: Mutex<Writer> =
|
pub static ref WRITER: Mutex<Writer> =
|
||||||
Mutex::new(Writer::new(ColorCode::new(Color::Yellow, Color::Black)));
|
Mutex::new(Writer::new(ColorCode::new(Color::Yellow, Color::Black)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn test_println_simple() {
|
||||||
|
println!("Does this work?");
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user