mirror of
https://github.com/panpaul/tiny_os
synced 2024-09-20 09:45:19 +08:00
Compare commits
2 Commits
a680907a77
...
a8d3dee80d
Author | SHA1 | Date | |
---|---|---|---|
a8d3dee80d | |||
9b73d703b4 |
@ -21,7 +21,7 @@ impl LowLevel for Hardware {
|
||||
|
||||
#[cfg(feature = "board_virt")]
|
||||
unsafe {
|
||||
TEST_DEVICE.write_volatile(0x0042_3333)
|
||||
TEST_DEVICE.write_volatile(0x0001_3333)
|
||||
}
|
||||
} else {
|
||||
#[cfg(not(feature = "board_virt"))]
|
||||
@ -29,7 +29,7 @@ impl LowLevel for Hardware {
|
||||
|
||||
#[cfg(feature = "board_virt")]
|
||||
unsafe {
|
||||
TEST_DEVICE.write_volatile(0x0042_5555)
|
||||
TEST_DEVICE.write_volatile(0x0000_5555)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,8 @@ use crate::utils::lowlevel::{Hardware, LowLevel};
|
||||
pub extern "C" fn rust_main(hart_id: usize, device_tree_addr: usize) -> ! {
|
||||
crate::logging::init();
|
||||
|
||||
info!("[rust_main] Kernel Started");
|
||||
#[cfg(test)]
|
||||
crate::test_main(); // test_main will exit
|
||||
|
||||
info!("Hello World!");
|
||||
info!("hart_id = {}", hart_id);
|
||||
|
25
src/lib.rs
25
src/lib.rs
@ -1,25 +0,0 @@
|
||||
#![no_std]
|
||||
#![feature(asm_const)]
|
||||
#![feature(naked_functions)]
|
||||
#![feature(panic_info_message)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
|
||||
extern crate static_assertions;
|
||||
|
||||
// arch
|
||||
pub mod arch;
|
||||
|
||||
// rust language runtime
|
||||
pub mod lang;
|
||||
|
||||
// entrypoint
|
||||
pub mod entry;
|
||||
|
||||
// page table
|
||||
pub mod mm;
|
||||
|
||||
// utils
|
||||
pub mod utils;
|
||||
|
||||
// logging
|
||||
pub mod logging;
|
37
src/main.rs
37
src/main.rs
@ -1,6 +1,37 @@
|
||||
// We handle entrypoint in arch
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
// Features
|
||||
#![feature(asm_const)]
|
||||
#![feature(naked_functions)]
|
||||
#![feature(panic_info_message)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
// Test Infrastructure
|
||||
#![feature(custom_test_frameworks)]
|
||||
#![test_runner(test_runner::runner)]
|
||||
#![reexport_test_harness_main = "test_main"]
|
||||
#![cfg_attr(test, allow(dead_code))]
|
||||
|
||||
#[allow(unused_imports)]
|
||||
#[allow(clippy::single_component_path_imports)]
|
||||
use tiny_os;
|
||||
extern crate static_assertions;
|
||||
|
||||
// arch
|
||||
pub mod arch;
|
||||
|
||||
// rust language runtime
|
||||
pub mod lang;
|
||||
|
||||
// entrypoint
|
||||
pub mod entry;
|
||||
|
||||
// page table
|
||||
pub mod mm;
|
||||
|
||||
// utils
|
||||
pub mod utils;
|
||||
|
||||
// logging
|
||||
pub mod logging;
|
||||
|
||||
// test infrastructure
|
||||
#[cfg(test)]
|
||||
mod test_runner;
|
||||
|
29
src/test_runner.rs
Normal file
29
src/test_runner.rs
Normal file
@ -0,0 +1,29 @@
|
||||
use log::info;
|
||||
|
||||
use crate::utils::lowlevel::{Hardware, LowLevel};
|
||||
|
||||
// Reference: https://os.phil-opp.com/testing/
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn runner(tests: &[&dyn Testable]) {
|
||||
info!("[TEST] Running {} tests", tests.len());
|
||||
for test in tests {
|
||||
test.run();
|
||||
}
|
||||
Hardware::shutdown(false);
|
||||
}
|
||||
|
||||
pub trait Testable {
|
||||
fn run(&self);
|
||||
}
|
||||
|
||||
impl<T> Testable for T
|
||||
where
|
||||
T: Fn(),
|
||||
{
|
||||
fn run(&self) {
|
||||
info!("[TEST] [{}] Testing", core::any::type_name::<T>());
|
||||
self();
|
||||
info!("[TEST] [{}] Passed", core::any::type_name::<T>());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user