fix: 🐛 Restore libmachine tests
To make unit tests work we build libmachine as a binary with test-runner.
This commit is contained in:
parent
78a864c433
commit
b1bf9dc09d
|
@ -1,6 +1,7 @@
|
|||
[workspace]
|
||||
members = [
|
||||
"nucleus",
|
||||
"machine",
|
||||
"bin/chainboot",
|
||||
"bin/chainofcommand"
|
||||
]
|
||||
|
|
|
@ -34,3 +34,7 @@ bitflags = "1.3"
|
|||
cfg-if = "1.0"
|
||||
snafu = { version = "0.7", default-features = false }
|
||||
seahash = "4.1"
|
||||
|
||||
[[bin]]
|
||||
name = "chainboot"
|
||||
test = false
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#![no_builtins]
|
||||
|
||||
use {
|
||||
core::{hash::Hasher, panic::PanicInfo},
|
||||
core::hash::Hasher,
|
||||
cortex_a::asm::barrier,
|
||||
machine::{
|
||||
devices::SerialOps,
|
||||
|
@ -147,12 +147,20 @@ fn kernel_main(max_kernel_size: u64) -> ! {
|
|||
|
||||
#[cfg(not(test))]
|
||||
#[panic_handler]
|
||||
fn panicked(info: &PanicInfo) -> ! {
|
||||
fn panicked(info: &core::panic::PanicInfo) -> ! {
|
||||
machine::panic::handler(info)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[panic_handler]
|
||||
fn panicked(info: &PanicInfo) -> ! {
|
||||
#[cfg(test)]
|
||||
fn panicked(info: &core::panic::PanicInfo) -> ! {
|
||||
machine::panic::handler_for_tests(info)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod chainboot_tests {
|
||||
#[test_case]
|
||||
fn nothing() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,3 +39,9 @@ cfg-if = "1.0"
|
|||
snafu = { version = "0.7", default-features = false }
|
||||
buddy-alloc = { git = "https://github.com/metta-systems/buddy-alloc", version = "0.6.0", branch = "feature/allocator-api" }
|
||||
once_cell = { version = "1.14", default-features = false, features = ["unstable"] }
|
||||
|
||||
[lib]
|
||||
name = "machine"
|
||||
test = true
|
||||
|
||||
# For proper testing in libmachine, we build it as a test_runner binary!
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
const LINKER_SCRIPT: &str = "linker/aarch64.ld";
|
||||
const LINKER_SCRIPT_AUX: &str = "linker/aarch64-exceptions.ld";
|
||||
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed={}", LINKER_SCRIPT);
|
||||
println!("cargo:rerun-if-changed={}", LINKER_SCRIPT_AUX);
|
||||
println!("cargo:rustc-link-arg=--script={}", LINKER_SCRIPT);
|
||||
}
|
|
@ -66,3 +66,18 @@ static DMA_ALLOCATOR: sync::NullLock<Lazy<BuddyAlloc>> =
|
|||
|
||||
// 0x00600000 as usize,
|
||||
// 0x007FFFFF as usize,
|
||||
|
||||
#[cfg(test)]
|
||||
mod lib_tests {
|
||||
#[panic_handler]
|
||||
fn panicked(info: &core::panic::PanicInfo) -> ! {
|
||||
crate::panic::handler_for_tests(info)
|
||||
}
|
||||
|
||||
/// Main for running tests.
|
||||
#[no_mangle]
|
||||
pub unsafe fn main() -> ! {
|
||||
crate::test_main();
|
||||
crate::qemu::semihosting::exit_success()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -669,7 +669,7 @@ mod tests {
|
|||
// by the end() fn.
|
||||
#[test_case]
|
||||
fn test_prepare_mailbox() {
|
||||
let mut mailbox = Mailbox::default();
|
||||
let mut mailbox = Mailbox::<8>::default();
|
||||
let index = mailbox.request();
|
||||
let index = mailbox.set_led_on(index, true);
|
||||
let mailbox = mailbox.end(index);
|
||||
|
|
|
@ -442,6 +442,8 @@ mod tests {
|
|||
const BAUD_RATE: u32 = 115_200;
|
||||
|
||||
let divisors = RateDivisors::from_clock_and_rate(CLOCK, BAUD_RATE);
|
||||
assert!(divisors.is_ok());
|
||||
let divisors = divisors.unwrap();
|
||||
assert_eq!(divisors.integer_baud_rate_divisor, 1);
|
||||
assert_eq!(divisors.fractional_baud_rate_divisor, 40);
|
||||
}
|
||||
|
|
|
@ -36,3 +36,7 @@ bit_field = "0.10"
|
|||
bitflags = "1.3"
|
||||
cfg-if = "1.0"
|
||||
snafu = { version = "0.7", default-features = false }
|
||||
|
||||
[[bin]]
|
||||
name = "nucleus"
|
||||
test = false
|
||||
|
|
Loading…
Reference in New Issue