2022-11-09 12:33:41 +00:00
|
|
|
#![no_std]
|
|
|
|
|
#![no_main]
|
|
|
|
|
#![feature(custom_test_frameworks)]
|
2022-11-22 08:42:26 +00:00
|
|
|
#![test_runner(jinux_frame::test_runner)]
|
2022-11-09 12:33:41 +00:00
|
|
|
#![reexport_test_harness_main = "test_main"]
|
2022-11-22 08:42:26 +00:00
|
|
|
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;
|
2022-11-22 08:42:26 +00:00
|
|
|
use jinux_frame::println;
|
2022-11-09 12:33:41 +00:00
|
|
|
|
|
|
|
|
static mut TICK: usize = 0;
|
|
|
|
|
|
2023-03-06 07:32:25 +00:00
|
|
|
#[no_mangle]
|
2023-07-19 02:08:59 +00:00
|
|
|
pub fn jinux_main() -> ! {
|
2023-03-06 07:32:25 +00:00
|
|
|
jinux_frame::init();
|
2022-11-09 12:33:41 +00:00
|
|
|
test_main();
|
|
|
|
|
loop {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[panic_handler]
|
|
|
|
|
fn panic(info: &PanicInfo) -> ! {
|
2022-11-22 08:42:26 +00:00
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|