diff --git a/dodo.py b/dodo.py index 25c9f34..f59ee5d 100644 --- a/dodo.py +++ b/dodo.py @@ -91,12 +91,14 @@ def task_install_dep(): def task_compile(): """ Compile the sources. """ - return { + task = { 'file_dep': get_build_dep(), 'targets': [f'{consts.WORK_DIR}/target/{consts.TARGET}/release/kernel'], 'actions': [f'RUSTFLAGS="{consts.RUSTC_FLAGS}" cargo rustc --target={consts.TARGET} {consts.CARGO_COMPILE_FLAGS}'], 'clean': [f'cargo clean'] } + print(task) + return task def task_build(): """ Strip the binary from ELF format to raw binary. diff --git a/src/main.rs b/src/main.rs index 3cfe69e..c42e220 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,8 +5,8 @@ //! but it's a project for discovering rust on embedded, so its architecture is less generic and //! I'm trying to reuse knowledge from Telecom-Paris SE203 class as much as I can. -#![no_main] -#![no_std] +#![cfg_attr(not(test), no_main)] +#![cfg_attr(not(test), no_std)] #![feature(format_args_nl)] #![feature(panic_info_message)] @@ -16,19 +16,26 @@ mod traits; mod bsp; mod utils; +#[cfg(not(test))] mod panic; +#[cfg(not(test))] mod print; +#[cfg(not(test))] use core::arch::global_asm; +#[cfg(not(test))] use core::arch::asm; // TODO: handle this with features //use crate::bsp::qemu::console::console; +#[cfg(not(test))] use crate::bsp::rpi3::uart::console; +#[cfg(not(test))] use crate::bsp::rpi3::gpio; // TODO: move this to BSP /// Pause the core with a infinit loop +#[cfg(not(test))] #[inline(always)] pub fn wait_forever() -> ! { loop { @@ -37,9 +44,11 @@ pub fn wait_forever() -> ! { } // TODO: move this to BSP +#[cfg(not(test))] global_asm!(include_str!("boot.s")); /// Start the rust part of the kernel +#[cfg(not(test))] #[no_mangle] pub unsafe fn _start_rust() -> ! { @@ -85,3 +94,6 @@ pub unsafe fn _start_rust() -> ! { panic!("Paniccccccc") */ } + +#[cfg(test)] +fn main() {} diff --git a/src/utils/field.rs b/src/utils/field.rs index 94950e8..4746ae5 100644 --- a/src/utils/field.rs +++ b/src/utils/field.rs @@ -81,3 +81,14 @@ impl Field { self.mask } } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test() { + let f = Field::new(0, 0, 1); + assert_eq!(1, f.get_mask()); + } +}