summaryrefslogtreecommitdiff
path: root/kernel/src/testing/panic.rs
blob: 729a45fbdcceb53892b95e261f1617bbd339bee7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use crate::io::{qemu, serial, vga_text};
use core::fmt::Write;
use core::panic::PanicInfo;
use qemu::{exit_qemu, QemuExitCode};
use serial::SerialStream;
use vga_text::OStream;

pub fn serial_should_panic(info: &PanicInfo) -> ! {
    let mut stdout = SerialStream::new();
    write!(stdout, "\nOK\nsuccessfully panicked\n").unwrap();
    exit_qemu(QemuExitCode::Success);
    loop {}
}

pub fn serial_panic(info: &PanicInfo) -> ! {
    crate::io::panic_screen::show(info.message());
    let mut stdout = SerialStream::new();
    write!(
        stdout,
        "\nERR\nPanicked execute without -serial for more details\n{}",
        info
    )
    .unwrap();
    exit_qemu(QemuExitCode::Failed);
    loop {}
}

pub fn should_panic(_info: &PanicInfo) -> ! {
    exit_qemu(QemuExitCode::Success);
    loop {}
}

pub fn panic(info: &PanicInfo) -> ! {
    crate::io::panic_screen::show(info.message());
    loop {}
}