1
0
Fork 0
forked from AbleOS/ableos
ableos/kernel/src/ktest.rs
funky f3a4a6b4f5 Fixed failing test
I'm dumb
2024-11-24 19:13:32 +11:00

49 lines
1.2 KiB
Rust

use {
alloc::string::String,
log::debug,
};
pub use ktest_macro::*;
extern "C" {
static __ktest_start: fn() -> Result<String, String>;
static __ktest_end: fn() -> Result<String, String>;
}
// TODO: Implement ktest for arm and riscv (Later problems, see below)
// Allow for arch specific tests (Leave for now)
pub fn test_main() {
unsafe {
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;
let test_name = test_fn();
match test_name {
Ok(name) => {
debug!("Test: {} passed", name);
pass += 1;
},
Err(ename) => {
debug!("Test: {} failed", ename);
fail += 1;
}
}
current_test = current_test.add(1);
}
debug!("{}/{} tests passed", pass, pass + fail);
}
}
#[ktest]
fn trivial_assertion() {
ktest_eq!(1, 1);
ktest_neq!(0, 1);
}