Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a test that checks boot info values
  • Loading branch information
phil-opp committed Jan 10, 2021
1 parent 6aaf882 commit dc1267b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/default_settings.rs
Expand Up @@ -10,6 +10,11 @@ fn should_panic() {
run_test_binary("should_panic");
}

#[test]
fn check_boot_info() {
run_test_binary("check_boot_info");
}

fn run_test_binary(bin_name: &str) {
let mut cmd = Command::new(env!("CARGO"));
cmd.current_dir("tests/test_kernels/default_settings");
Expand Down
46 changes: 46 additions & 0 deletions tests/test_kernels/default_settings/src/bin/check_boot_info.rs
@@ -0,0 +1,46 @@
#![no_std] // don't link the Rust standard library
#![no_main] // disable all Rust-level entry points

use bootloader::{boot_info::PixelFormat, entry_point, BootInfo};
use core::panic::PanicInfo;
use kernel::{exit_qemu, QemuExitCode};

entry_point!(kernel_main);

fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
// check memory regions
assert!(boot_info.memory_regions.len() > 4);

// check framebuffer
let framebuffer = boot_info.framebuffer.as_ref().unwrap();
assert_eq!(framebuffer.info().byte_len, framebuffer.buffer().len());
assert_eq!(framebuffer.info().horizontal_resolution, 1024);
assert_eq!(framebuffer.info().vertical_resolution, 768);
assert_eq!(framebuffer.info().bytes_per_pixel, 3);
assert_eq!(framebuffer.info().stride, 1024);
assert_eq!(framebuffer.info().pixel_format, PixelFormat::RGB);
assert_eq!(framebuffer.buffer().len(), 1024 * 768 * 3);

// check defaults for optional features
assert_eq!(boot_info.physical_memory_offset.into_option(), None);
assert_eq!(boot_info.recursive_index.into_option(), None);

// check rsdp_addr
let rsdp = boot_info.rsdp_addr.into_option().unwrap();
assert!(rsdp > 0x000E0000);
assert!(rsdp < 0x000FFFFF);

// the test kernel has no TLS template
assert_eq!(boot_info.tls_template.into_option(), None);

exit_qemu(QemuExitCode::Success);
}

/// This function is called on panic.
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
use core::fmt::Write;

let _ = writeln!(kernel::serial(), "PANIC: {}", info);
exit_qemu(QemuExitCode::Failed);
}

0 comments on commit dc1267b

Please sign in to comment.