summaryrefslogtreecommitdiff
path: root/kernel/src/testing/runner.rs
blob: 63b40134b61723346a4672c1982ab1efbe7e252d (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
37
38
39
40
41
42
43
44
45
46
47
48
49
use crate::io::{qemu, serial};
use core::fmt::Write;
use qemu::{exit_qemu, QemuExitCode};
use serial::SerialStream;

pub fn serial_test_runner_panic(tests: &[&dyn Fn()]) {
    let mut stdout = SerialStream::new();
    write!(stdout, "\nRunning {} tests\n", tests.len()).unwrap();
    for test in tests {
        test();
        write!(stdout, "\n[test did not panic]\n\n").unwrap();
        exit_qemu(QemuExitCode::Failed);
    }
    exit_qemu(QemuExitCode::Success);
}

pub fn serial_test_runner(tests: &[&dyn Fn()]) {
    let mut stdout = SerialStream::new();
    write!(stdout, "\nRunning {} tests\n", tests.len()).unwrap();
    for test in tests {
        test();
        write!(stdout, "\n[OK]\n").unwrap();
    }
    exit_qemu(QemuExitCode::Success);
}

pub fn test_runner_panic(tests: &[&dyn Fn()]) {
    crate::vga_println!();
    crate::vga_println!("Running {} tests", tests.len());
    for test in tests {
        test();
        crate::vga_println!();
        crate::vga_println!("[test did not panic]");
        crate::vga_println!();
        exit_qemu(QemuExitCode::Failed);
    }
    exit_qemu(QemuExitCode::Success);
}

pub fn test_runner(tests: &[&dyn Fn()]) {
    crate::vga_println!();
    crate::vga_println!("Running {} tests", tests.len());
    for test in tests {
        test();
        crate::vga_println!();
        crate::vga_println!("[OK]");
    }
    exit_qemu(QemuExitCode::Success);
}