Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add a test that checks boot info values
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
tests/test_kernels/default_settings/src/bin/check_boot_info.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |