diff options
author | Dennis Kobert <dennis@kobert.dev> | 2019-11-09 15:11:50 +0100 |
---|---|---|
committer | Dennis Kobert <dennis@kobert.dev> | 2019-11-09 15:11:50 +0100 |
commit | 26a7561196674b39f9adadcb374f36c503361adb (patch) | |
tree | 3031e026feae853f7c46b91975beaa4e20cf755c /kernel/tests | |
parent | b17a0a41bea7789178919f4a0999ea8519e1f897 (diff) |
Add basic tests
Diffstat (limited to 'kernel/tests')
-rw-r--r-- | kernel/tests/boot.rs | 38 | ||||
-rw-r--r-- | kernel/tests/int3.rs (renamed from kernel/tests/test01.rs) | 13 | ||||
-rw-r--r-- | kernel/tests/stack_overflow.rs | 37 |
3 files changed, 85 insertions, 3 deletions
diff --git a/kernel/tests/boot.rs b/kernel/tests/boot.rs new file mode 100644 index 0000000..534199a --- /dev/null +++ b/kernel/tests/boot.rs @@ -0,0 +1,38 @@ +#![no_main] +#![feature(compiler_builtins_lib)] +#![feature(custom_test_frameworks)] +#![feature(abi_x86_interrupt)] +#![feature(panic_info_message)] +#![test_runner(kernel::testing::serial_test_runner)] +#![reexport_test_harness_main = "test_main"] +#![no_std] + +use kernel; +use kernel::io::qemu; + +#[no_mangle] +extern "C" fn _start() -> ! { + kernel::init(); + test_main(); + + loop {} +} + +#[test_case] +fn boot() { + assert!(true) +} + +#[test_case] +fn poweroff() { + qemu::exit_qemu(qemu::QemuExitCode::Success); + panic!("Qemu did not exit"); +} + +#[cfg(test)] +#[panic_handler] +#[no_mangle] +extern "C" fn panic_handler(info: &core::panic::PanicInfo) -> ! { + kernel::testing::serial_panic(info); + loop {} +} diff --git a/kernel/tests/test01.rs b/kernel/tests/int3.rs index 933d689..771c17d 100644 --- a/kernel/tests/test01.rs +++ b/kernel/tests/int3.rs @@ -3,7 +3,8 @@ #![feature(custom_test_frameworks)] #![feature(abi_x86_interrupt)] #![feature(panic_info_message)] -#![test_runner(crate::testing::serial_test_runner)] +#![test_runner(kernel::testing::serial_test_runner)] +#![reexport_test_harness_main = "test_main"] #![no_std] use kernel; @@ -11,15 +12,21 @@ use kernel::io::qemu; #[no_mangle] extern "C" fn _start() -> ! { - kernel::io::panic_screen::show(Some(&format_args!("hey bro"))); - + kernel::init(); + test_main(); loop {} } +#[test_case] +fn breakpoint() { + x86_64::instructions::interrupts::int3(); +} + #[cfg(test)] #[panic_handler] #[no_mangle] extern "C" fn panic_handler(info: &core::panic::PanicInfo) -> ! { + kernel::testing::serial_should_panic(info); loop {} } diff --git a/kernel/tests/stack_overflow.rs b/kernel/tests/stack_overflow.rs new file mode 100644 index 0000000..677a9e1 --- /dev/null +++ b/kernel/tests/stack_overflow.rs @@ -0,0 +1,37 @@ +#![no_main] +#![feature(compiler_builtins_lib)] +#![feature(custom_test_frameworks)] +#![feature(abi_x86_interrupt)] +#![feature(panic_info_message)] +#![test_runner(kernel::testing::serial_test_runner_panic)] +#![no_std] + +use core::fmt::Write; +use kernel; +use kernel::io::qemu; + +#[no_mangle] +extern "C" fn _start() -> ! { + kernel::init(); + _loop(0); + + loop {} +} + +fn _loop(i: u128) -> u128 { + if i > 1u128 << 83 { + return i; + } + let n = i; + let mut stdout = kernel::OStream::new(); + write!(&mut stdout, "{:x}", &n as *const u128 as u128).unwrap(); + _loop(i + 1) +} + +#[cfg(test)] +#[panic_handler] +#[no_mangle] +extern "C" fn panic_handler(info: &core::panic::PanicInfo) -> ! { + kernel::testing::serial_should_panic(info); + loop {} +} |