mirror of
https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials.git
synced 2024-11-17 21:25:52 +00:00
2e72a8408f
This update significantly decouples the generic kernel code from the BSP code. Prior to this patch, the BSP had way too much business logic that should have always been the generic kernel's concern.
51 lines
1.3 KiB
Rust
51 lines
1.3 KiB
Rust
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
//
|
|
// Copyright (c) 2019-2022 Andre Richter <andre.o.richter@gmail.com>
|
|
|
|
//! Timer sanity tests.
|
|
|
|
#![feature(custom_test_frameworks)]
|
|
#![no_main]
|
|
#![no_std]
|
|
#![reexport_test_harness_main = "test_main"]
|
|
#![test_runner(libkernel::test_runner)]
|
|
|
|
use core::time::Duration;
|
|
use libkernel::{bsp, cpu, exception, time};
|
|
use test_macros::kernel_test;
|
|
|
|
#[no_mangle]
|
|
unsafe fn kernel_init() -> ! {
|
|
exception::handling_init();
|
|
bsp::driver::qemu_bring_up_console();
|
|
|
|
// Depending on CPU arch, some timer bring-up code could go here. Not needed for the RPi.
|
|
|
|
test_main();
|
|
|
|
cpu::qemu_exit_success()
|
|
}
|
|
|
|
/// Simple check that the timer is running.
|
|
#[kernel_test]
|
|
fn timer_is_counting() {
|
|
assert!(time::time_manager().uptime().as_nanos() > 0)
|
|
}
|
|
|
|
/// Timer resolution must be sufficient.
|
|
#[kernel_test]
|
|
fn timer_resolution_is_sufficient() {
|
|
assert!(time::time_manager().resolution().as_nanos() > 0);
|
|
assert!(time::time_manager().resolution().as_nanos() < 100)
|
|
}
|
|
|
|
/// Sanity check spin_for() implementation.
|
|
#[kernel_test]
|
|
fn spin_accuracy_check_1_second() {
|
|
let t1 = time::time_manager().uptime();
|
|
time::time_manager().spin_for(Duration::from_secs(1));
|
|
let t2 = time::time_manager().uptime();
|
|
|
|
assert_eq!((t2 - t1).as_secs(), 1)
|
|
}
|