Skip to content

test-runner: Drop the memory map OOM loop #1254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 24 additions & 28 deletions uefi-test-runner/src/boot/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,41 +63,37 @@ fn alloc_alignment() {
fn memory_map(bt: &BootServices) {
info!("Testing memory map functions");

// Ensure that the memory map is freed after each iteration (on drop).
// Otherwise, we will have an OOM.
for _ in 0..200000 {
let mut memory_map = bt
.memory_map(MemoryType::LOADER_DATA)
.expect("Failed to retrieve UEFI memory map");
let mut memory_map = bt
.memory_map(MemoryType::LOADER_DATA)
.expect("Failed to retrieve UEFI memory map");

memory_map.sort();
memory_map.sort();

// Collect the descriptors into a vector
let descriptors = memory_map.entries().copied().collect::<Vec<_>>();
// Collect the descriptors into a vector
let descriptors = memory_map.entries().copied().collect::<Vec<_>>();

// Ensured we have at least one entry.
// Real memory maps usually have dozens of entries.
assert!(!descriptors.is_empty(), "Memory map is empty");
// Ensured we have at least one entry.
// Real memory maps usually have dozens of entries.
assert!(!descriptors.is_empty(), "Memory map is empty");

let mut curr_value = descriptors[0];
let mut curr_value = descriptors[0];

for value in descriptors.iter().skip(1) {
if value.phys_start <= curr_value.phys_start {
panic!("memory map sorting failed");
}
curr_value = *value;
for value in descriptors.iter().skip(1) {
if value.phys_start <= curr_value.phys_start {
panic!("memory map sorting failed");
}
curr_value = *value;
}

// This is pretty much a basic sanity test to ensure returned memory
// isn't filled with random values.
let first_desc = descriptors[0];
// This is pretty much a basic sanity test to ensure returned memory
// isn't filled with random values.
let first_desc = descriptors[0];

#[cfg(target_arch = "x86_64")]
{
let phys_start = first_desc.phys_start;
assert_eq!(phys_start, 0, "Memory does not start at address 0");
}
let page_count = first_desc.page_count;
assert!(page_count != 0, "Memory map entry has size zero");
#[cfg(target_arch = "x86_64")]
{
let phys_start = first_desc.phys_start;
assert_eq!(phys_start, 0, "Memory does not start at address 0");
}
let page_count = first_desc.page_count;
assert!(page_count != 0, "Memory map entry has size zero");
}