Skip to content

Commit 2f5fdf0

Browse files
committed
Test that boot config is actually loaded (through a sentinel value)
1 parent baec055 commit 2f5fdf0

File tree

8 files changed

+24
-10
lines changed

8 files changed

+24
-10
lines changed

api/src/info.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ pub struct BootInfo {
5656
pub ramdisk_addr: Optional<u64>,
5757
/// Ramdisk image size, set to 0 if addr is None
5858
pub ramdisk_len: u64,
59+
60+
#[doc(hidden)]
61+
pub _test_sentinel: u64,
5962
}
6063

6164
impl BootInfo {
@@ -73,6 +76,7 @@ impl BootInfo {
7376
tls_template: Optional::None,
7477
ramdisk_addr: Optional::None,
7578
ramdisk_len: 0,
79+
_test_sentinel: 0,
7680
}
7781
}
7882
}

bios/stage-4/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ pub extern "C" fn _start(info: &mut BiosInfo) -> ! {
173173
ramdisk_len: info.ramdisk.len,
174174
};
175175

176-
load_and_switch_to_kernel(kernel, frame_allocator, page_tables, system_info);
176+
load_and_switch_to_kernel(kernel, config, frame_allocator, page_tables, system_info);
177177
}
178178

179179
fn init_logger(

common/config/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pub struct BootConfig {
2222
///
2323
/// Enabled by default.
2424
pub serial_logging: bool,
25+
26+
pub _test_sentinel: u64,
2527
}
2628

2729
impl Default for BootConfig {
@@ -31,6 +33,7 @@ impl Default for BootConfig {
3133
log_level: Default::default(),
3234
frame_buffer_logging: true,
3335
serial_logging: true,
36+
_test_sentinel: 0,
3437
}
3538
}
3639
}

common/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use bootloader_api::{
88
info::{FrameBuffer, FrameBufferInfo, MemoryRegion, TlsTemplate},
99
BootInfo, BootloaderConfig,
1010
};
11-
use bootloader_boot_config::LevelFilter;
11+
use bootloader_boot_config::{BootConfig, LevelFilter};
1212
use core::{alloc::Layout, arch::asm, mem::MaybeUninit, slice};
1313
use level_4_entries::UsedLevel4Entries;
1414
use usize_conversions::FromUsize;
@@ -125,6 +125,7 @@ impl<'a> Kernel<'a> {
125125
/// directly to these functions, so see their docs for more info.
126126
pub fn load_and_switch_to_kernel<I, D>(
127127
kernel: Kernel,
128+
boot_config: BootConfig,
128129
mut frame_allocator: LegacyFrameAllocator<I, D>,
129130
mut page_tables: PageTables,
130131
system_info: SystemInfo,
@@ -144,6 +145,7 @@ where
144145
);
145146
let boot_info = create_boot_info(
146147
&config,
148+
&boot_config,
147149
frame_allocator,
148150
&mut page_tables,
149151
&mut mappings,
@@ -435,6 +437,7 @@ pub struct Mappings {
435437
/// are taken from the given `frame_allocator`.
436438
pub fn create_boot_info<I, D>(
437439
config: &BootloaderConfig,
440+
boot_config: &BootConfig,
438441
mut frame_allocator: LegacyFrameAllocator<I, D>,
439442
page_tables: &mut PageTables,
440443
mappings: &mut Mappings,
@@ -539,6 +542,7 @@ where
539542
.map(|addr| addr.as_u64())
540543
.into();
541544
info.ramdisk_len = mappings.ramdisk_slice_len;
545+
info._test_sentinel = boot_config._test_sentinel;
542546
info
543547
});
544548

tests/config_file.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ use bootloader_test_runner::run_test_kernel_internal;
33
use bootloader::BootConfig;
44

55
#[test]
6-
fn basic_boot() {
7-
let config: BootConfig = Default::default();
6+
fn default_config() {
87
run_test_kernel_internal(
9-
env!("CARGO_BIN_FILE_TEST_KERNEL_CONFIG_FILE_basic_boot"),
8+
env!("CARGO_BIN_FILE_TEST_KERNEL_CONFIG_FILE_no_config"),
9+
None,
1010
None,
11-
Some(&config),
1211
);
1312
}
1413

1514
#[test]
16-
fn custom_options_boot() {
15+
fn custom_boot_config() {
1716
let config = BootConfig {
1817
frame_buffer: Default::default(),
1918
log_level: Default::default(),
2019
frame_buffer_logging: false,
2120
serial_logging: true,
21+
_test_sentinel: 0xb001b001b001,
2222
};
2323
run_test_kernel_internal(
24-
env!("CARGO_BIN_FILE_TEST_KERNEL_CONFIG_FILE_basic_boot_broken_config_file"),
24+
env!("CARGO_BIN_FILE_TEST_KERNEL_CONFIG_FILE_custom_config"),
2525
None,
2626
Some(&config),
2727
);

tests/test_kernels/config_file/src/bin/basic_boot_broken_config_file.rs renamed to tests/test_kernels/config_file/src/bin/custom_config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ entry_point!(kernel_main);
99

1010
fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
1111
writeln!(serial(), "Entered kernel with boot info: {boot_info:?}").unwrap();
12+
assert_eq!(boot_info._test_sentinel, 0xb001b001b001);
1213
exit_qemu(QemuExitCode::Success);
1314
}
1415

tests/test_kernels/config_file/src/bin/basic_boot.rs renamed to tests/test_kernels/config_file/src/bin/no_config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ entry_point!(kernel_main);
99

1010
fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
1111
writeln!(serial(), "Entered kernel with boot info: {boot_info:?}").unwrap();
12+
assert_eq!(boot_info._test_sentinel, 0);
1213
exit_qemu(QemuExitCode::Success);
1314
}
1415

uefi/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn main_inner(image: Handle, mut st: SystemTable<Boot>) -> Status {
105105
config.frame_buffer.minimum_framebuffer_width =
106106
kernel.config.frame_buffer.minimum_framebuffer_width;
107107
}
108-
let framebuffer = init_logger(image, &st, config);
108+
let framebuffer = init_logger(image, &st, &config);
109109

110110
unsafe {
111111
*SYSTEM_TABLE.get() = None;
@@ -193,6 +193,7 @@ fn main_inner(image: Handle, mut st: SystemTable<Boot>) -> Status {
193193

194194
bootloader_x86_64_common::load_and_switch_to_kernel(
195195
kernel,
196+
config,
196197
frame_allocator,
197198
page_tables,
198199
system_info,
@@ -473,7 +474,7 @@ fn create_page_tables(
473474
fn init_logger(
474475
image_handle: Handle,
475476
st: &SystemTable<Boot>,
476-
config: BootConfig,
477+
config: &BootConfig,
477478
) -> Option<RawFrameBufferInfo> {
478479
let gop_handle = st
479480
.boot_services()

0 commit comments

Comments
 (0)