1
0
Fork 0
forked from AbleOS/ableos
ableos-idl/kernel/src/ktest.rs

52 lines
1.2 KiB
Rust
Raw Normal View History

2024-11-27 02:09:15 -06:00
pub use ktest_macro::*;
use {
alloc::string::String,
log::{error, info},
};
extern "C" {
2024-11-27 02:09:15 -06:00
static __ktest_start: fn() -> Result<String, String>;
static __ktest_end: fn() -> Result<String, String>;
}
2024-11-27 02:09:15 -06:00
// TODO: Implement ktest for arm and riscv (Later problems, see below)
// Allow for arch specific tests (Leave for now)
2024-11-27 02:09:15 -06:00
// Should panic tests
// Test specific panic handler
pub fn test_main() {
unsafe {
2024-11-27 02:09:15 -06:00
let mut current_test = &__ktest_start as *const fn() -> Result<String, String>;
let test_end = &__ktest_end as *const fn() -> Result<String, String>;
let mut pass = 0;
let mut fail = 0;
while current_test < test_end {
let test_fn = *current_test;
2024-11-27 02:09:15 -06:00
let test_name = test_fn();
match test_name {
Ok(name) => {
info!("Test: {} passed", name);
pass += 1;
},
Err(name) => {
error!("Test: {} failed", name);
fail += 1;
}
}
current_test = current_test.add(1);
}
2024-11-27 02:09:15 -06:00
info!("{}/{} tests passed", pass, pass + fail);
}
}
#[ktest]
pub fn trivial_assertion() {
2024-11-27 02:09:15 -06:00
ktest_eq!(1, 1);
ktest_neq!(0, 1);
2024-11-26 16:02:54 -06:00
}