Skip to content

Commit 3ea12ea

Browse files
committed
added intergration test for stack overflow
1 parent 3318cd9 commit 3ea12ea

4 files changed

Lines changed: 76 additions & 1 deletion

File tree

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ test-timeout = 5 # (in seconds)
2323
[[test]]
2424
name = "should_panic"
2525
harness = false
26+
27+
[[test]]
28+
name = "stack_overflow"
29+
harness = false

tests/basic_boot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![no_std]
22
#![no_main]
33
#![feature(custom_test_frameworks)]
4-
#![test_runner(orust_os:test_runner)]
4+
#![test_runner(orust_os::test_runner)]
55
#![reexport_test_harness_main = "test_main"]
66

77
use core::panic::PanicInfo;

tests/stack_overflow.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#![feature(abi_x86_interrupt)]
2+
#![no_std]
3+
#![no_main]
4+
5+
use orust_os::{exit_qemu, QemuExitCode, serial_print, serial_println};
6+
use lazy_static::lazy_static;
7+
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
8+
9+
lazy_static! {
10+
static ref TEST_IDT: InterruptDescriptorTable = {
11+
let mut idt = InterruptDescriptorTable::new();
12+
unsafe {
13+
idt.double_fault
14+
.set_handler_fn(test_double_fault_handler)
15+
.set_stack_index(orust_os::gdt::DOUBLE_FAULT_IST_INDEX);
16+
}
17+
18+
idt
19+
};
20+
}
21+
22+
use core::panic::PanicInfo;
23+
24+
#[no_mangle]
25+
pub extern "C" fn _start() -> ! {
26+
serial_print!("stack_overflow::stack_overflow...\t");
27+
28+
orust_os::gdt::init();
29+
init_test_idt();
30+
31+
stack_overflow();
32+
33+
panic!("Execution continued after stack overflow");
34+
}
35+
36+
extern "x86-interrupt" fn test_double_fault_handler(
37+
_stack_frame: InterruptStackFrame,
38+
_error_code: u64,
39+
) -> ! {
40+
serial_println!("[ok]");
41+
exit_qemu(QemuExitCode::Success);
42+
loop {}
43+
}
44+
45+
pub fn init_test_idt() {
46+
TEST_IDT.load();
47+
}
48+
49+
#[allow(unconditional_recursion)]
50+
fn stack_overflow() {
51+
stack_overflow();
52+
volatile::Volatile::new(0).read();
53+
}
54+
#[panic_handler]
55+
fn panic(info: &PanicInfo) -> ! {
56+
orust_os::test_panic_handler(info)
57+
}

tests/test-skeleton.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![no_std]
2+
#![no_main]
3+
4+
use core::panic::PanicInfo;
5+
6+
#[no_mangle]
7+
pub extern "C" fn _start() -> ! {
8+
unimplemented!();
9+
}
10+
11+
#[panic_handler]
12+
fn panic(info: &PanicInfo) -> ! {
13+
orust_os::test_panic_handler(info)
14+
}

0 commit comments

Comments
 (0)