Skip to content

Commit dc1267b

Browse files
committed
Add a test that checks boot info values
1 parent 6aaf882 commit dc1267b

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

tests/default_settings.rs

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ fn should_panic() {
1010
run_test_binary("should_panic");
1111
}
1212

13+
#[test]
14+
fn check_boot_info() {
15+
run_test_binary("check_boot_info");
16+
}
17+
1318
fn run_test_binary(bin_name: &str) {
1419
let mut cmd = Command::new(env!("CARGO"));
1520
cmd.current_dir("tests/test_kernels/default_settings");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#![no_std] // don't link the Rust standard library
2+
#![no_main] // disable all Rust-level entry points
3+
4+
use bootloader::{boot_info::PixelFormat, entry_point, BootInfo};
5+
use core::panic::PanicInfo;
6+
use kernel::{exit_qemu, QemuExitCode};
7+
8+
entry_point!(kernel_main);
9+
10+
fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
11+
// check memory regions
12+
assert!(boot_info.memory_regions.len() > 4);
13+
14+
// check framebuffer
15+
let framebuffer = boot_info.framebuffer.as_ref().unwrap();
16+
assert_eq!(framebuffer.info().byte_len, framebuffer.buffer().len());
17+
assert_eq!(framebuffer.info().horizontal_resolution, 1024);
18+
assert_eq!(framebuffer.info().vertical_resolution, 768);
19+
assert_eq!(framebuffer.info().bytes_per_pixel, 3);
20+
assert_eq!(framebuffer.info().stride, 1024);
21+
assert_eq!(framebuffer.info().pixel_format, PixelFormat::RGB);
22+
assert_eq!(framebuffer.buffer().len(), 1024 * 768 * 3);
23+
24+
// check defaults for optional features
25+
assert_eq!(boot_info.physical_memory_offset.into_option(), None);
26+
assert_eq!(boot_info.recursive_index.into_option(), None);
27+
28+
// check rsdp_addr
29+
let rsdp = boot_info.rsdp_addr.into_option().unwrap();
30+
assert!(rsdp > 0x000E0000);
31+
assert!(rsdp < 0x000FFFFF);
32+
33+
// the test kernel has no TLS template
34+
assert_eq!(boot_info.tls_template.into_option(), None);
35+
36+
exit_qemu(QemuExitCode::Success);
37+
}
38+
39+
/// This function is called on panic.
40+
#[panic_handler]
41+
fn panic(info: &PanicInfo) -> ! {
42+
use core::fmt::Write;
43+
44+
let _ = writeln!(kernel::serial(), "PANIC: {}", info);
45+
exit_qemu(QemuExitCode::Failed);
46+
}

0 commit comments

Comments
 (0)