asterinas/tests/timer_test.rs

44 lines
910 B
Rust
Raw Normal View History

2022-11-09 12:33:41 +00:00
#![no_std]
#![no_main]
#![feature(custom_test_frameworks)]
#![test_runner(jinux_frame::test_runner)]
2022-11-09 12:33:41 +00:00
#![reexport_test_harness_main = "test_main"]
use jinux_frame::timer::Timer;
2022-11-09 12:33:41 +00:00
extern crate alloc;
use alloc::sync::Arc;
use core::panic::PanicInfo;
2022-11-11 02:14:42 +00:00
use core::time::Duration;
use jinux_frame::println;
2022-11-09 12:33:41 +00:00
static mut TICK: usize = 0;
#[no_mangle]
pub fn jinux_main() -> ! {
jinux_frame::init();
2022-11-09 12:33:41 +00:00
test_main();
loop {}
}
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
jinux_frame::test_panic_handler(info)
2022-11-09 12:33:41 +00:00
}
#[test_case]
fn test_timer() {
2023-03-25 09:16:37 +00:00
x86_64::instructions::interrupts::enable();
2022-11-09 12:33:41 +00:00
unsafe {
let timer = Timer::new(timer_callback).unwrap();
timer.set(Duration::from_secs(1));
while TICK < 5 {}
}
}
pub fn timer_callback(timer: Arc<Timer>) {
unsafe {
2022-11-11 02:14:42 +00:00
TICK += 1;
println!("TICK:{}", TICK);
2022-11-09 12:33:41 +00:00
timer.set(Duration::from_secs(1));
}
}