2024-11-27 02:09:15 -06:00
|
|
|
pub use ktest_macro::*;
|
|
|
|
|
|
|
|
use {
|
|
|
|
alloc::string::String,
|
|
|
|
log::{error, info},
|
|
|
|
};
|
2024-11-23 18:21:39 -06:00
|
|
|
|
|
|
|
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-23 18:21:39 -06:00
|
|
|
}
|
|
|
|
|
2024-11-27 02:09:15 -06:00
|
|
|
// TODO: Implement ktest for arm and riscv (Later problems, see below)
|
2024-11-23 18:21:39 -06:00
|
|
|
// Allow for arch specific tests (Leave for now)
|
2024-11-27 02:09:15 -06:00
|
|
|
// Should panic tests
|
|
|
|
// Test specific panic handler
|
2024-11-23 18:21:39 -06:00
|
|
|
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;
|
2024-11-23 18:21:39 -06:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2024-11-23 18:21:39 -06:00
|
|
|
|
|
|
|
current_test = current_test.add(1);
|
|
|
|
}
|
2024-11-27 02:09:15 -06:00
|
|
|
|
|
|
|
info!("{}/{} tests passed", pass, pass + fail);
|
2024-11-23 18:21:39 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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
|
|
|
}
|