From 59579108a78256149b9ed15152606599da97995a Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 25 Jan 2019 13:45:38 +0100 Subject: [PATCH] Add test-basic-boot and test-panic integration tests --- src/bin/test-basic-boot.rs | 33 +++++++++++++++++++++++++++++++++ src/bin/test-panic.rs | 23 +++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/bin/test-basic-boot.rs create mode 100644 src/bin/test-panic.rs diff --git a/src/bin/test-basic-boot.rs b/src/bin/test-basic-boot.rs new file mode 100644 index 00000000..f77d4a02 --- /dev/null +++ b/src/bin/test-basic-boot.rs @@ -0,0 +1,33 @@ +#![cfg_attr(not(test), no_std)] +#![cfg_attr(not(test), no_main)] // disable all Rust-level entry points +#![cfg_attr(test, allow(unused_imports))] + +use blog_os::{exit_qemu, serial_println}; +use core::panic::PanicInfo; + +/// This function is the entry point, since the linker looks for a function +/// named `_start` by default. +#[cfg(not(test))] +#[no_mangle] // don't mangle the name of this function +pub extern "C" fn _start() -> ! { + serial_println!("ok"); + + unsafe { + exit_qemu(); + } + loop {} +} + +/// This function is called on panic. +#[cfg(not(test))] +#[panic_handler] +fn panic(info: &PanicInfo) -> ! { + serial_println!("failed"); + + serial_println!("{}", info); + + unsafe { + exit_qemu(); + } + loop {} +} diff --git a/src/bin/test-panic.rs b/src/bin/test-panic.rs new file mode 100644 index 00000000..c68ac51d --- /dev/null +++ b/src/bin/test-panic.rs @@ -0,0 +1,23 @@ +#![cfg_attr(not(test), no_std)] +#![cfg_attr(not(test), no_main)] +#![cfg_attr(test, allow(unused_imports))] + +use blog_os::{exit_qemu, serial_println}; +use core::panic::PanicInfo; + +#[cfg(not(test))] +#[no_mangle] +pub extern "C" fn _start() -> ! { + panic!(); +} + +#[cfg(not(test))] +#[panic_handler] +fn panic(_info: &PanicInfo) -> ! { + serial_println!("ok"); + + unsafe { + exit_qemu(); + } + loop {} +}