Skip to content

Commit

Permalink
added intergration test for stack overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Blindspot22 committed May 18, 2024
1 parent 3318cd9 commit 3ea12ea
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ test-timeout = 5 # (in seconds)
[[test]]
name = "should_panic"
harness = false

[[test]]
name = "stack_overflow"
harness = false
2 changes: 1 addition & 1 deletion tests/basic_boot.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![no_std]
#![no_main]
#![feature(custom_test_frameworks)]
#![test_runner(orust_os:test_runner)]
#![test_runner(orust_os::test_runner)]
#![reexport_test_harness_main = "test_main"]

use core::panic::PanicInfo;
Expand Down
57 changes: 57 additions & 0 deletions tests/stack_overflow.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#![feature(abi_x86_interrupt)]
#![no_std]
#![no_main]

use orust_os::{exit_qemu, QemuExitCode, serial_print, serial_println};
use lazy_static::lazy_static;
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};

lazy_static! {
static ref TEST_IDT: InterruptDescriptorTable = {
let mut idt = InterruptDescriptorTable::new();
unsafe {
idt.double_fault
.set_handler_fn(test_double_fault_handler)
.set_stack_index(orust_os::gdt::DOUBLE_FAULT_IST_INDEX);
}

idt
};
}

use core::panic::PanicInfo;

#[no_mangle]
pub extern "C" fn _start() -> ! {
serial_print!("stack_overflow::stack_overflow...\t");

orust_os::gdt::init();
init_test_idt();

stack_overflow();

panic!("Execution continued after stack overflow");
}

extern "x86-interrupt" fn test_double_fault_handler(
_stack_frame: InterruptStackFrame,
_error_code: u64,
) -> ! {
serial_println!("[ok]");
exit_qemu(QemuExitCode::Success);
loop {}
}

pub fn init_test_idt() {
TEST_IDT.load();
}

#[allow(unconditional_recursion)]
fn stack_overflow() {
stack_overflow();
volatile::Volatile::new(0).read();
}
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
orust_os::test_panic_handler(info)
}
14 changes: 14 additions & 0 deletions tests/test-skeleton.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![no_std]
#![no_main]

use core::panic::PanicInfo;

#[no_mangle]
pub extern "C" fn _start() -> ! {
unimplemented!();
}

#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
orust_os::test_panic_handler(info)
}

0 comments on commit 3ea12ea

Please sign in to comment.