Skip to content

Commit e1fb5bf

Browse files
committed
uefi-test-runner: test that BootService::memory_map memory is freed
This is now a benefit compared to the old API. This wasn't possible.
1 parent c3d3ed3 commit e1fb5bf

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

uefi-test-runner/src/boot/memory.rs

+34-23
Original file line numberDiff line numberDiff line change
@@ -63,36 +63,47 @@ fn alloc_alignment() {
6363
fn memory_map(bt: &BootServices) {
6464
info!("Testing memory map functions");
6565

66-
let mut memory_map = bt
67-
.memory_map(MemoryType::LOADER_DATA)
68-
.expect("Failed to retrieve UEFI memory map");
66+
/*
67+
// Useful to check of OOM happens.
68+
let mut maps = Vec::new();
69+
for _ in 0..100000_u64 {
70+
maps.push(bt.memory_map(MemoryType::LOADER_DATA).unwrap())
71+
}
72+
let _a = maps;*/
73+
74+
// Ensure that the memory of the UEFI memory map is always freed again.
75+
for _ in 0..100000 {
76+
let mut memory_map = bt
77+
.memory_map(MemoryType::LOADER_DATA)
78+
.expect("Failed to retrieve UEFI memory map");
6979

70-
memory_map.sort();
80+
memory_map.sort();
7181

72-
// Collect the descriptors into a vector
73-
let descriptors = memory_map.entries().copied().collect::<Vec<_>>();
82+
// Collect the descriptors into a vector
83+
let descriptors = memory_map.entries().copied().collect::<Vec<_>>();
7484

75-
// Ensured we have at least one entry.
76-
// Real memory maps usually have dozens of entries.
77-
assert!(!descriptors.is_empty(), "Memory map is empty");
85+
// Ensured we have at least one entry.
86+
// Real memory maps usually have dozens of entries.
87+
assert!(!descriptors.is_empty(), "Memory map is empty");
7888

79-
let mut curr_value = descriptors[0];
89+
let mut curr_value = descriptors[0];
8090

81-
for value in descriptors.iter().skip(1) {
82-
if value.phys_start <= curr_value.phys_start {
83-
panic!("memory map sorting failed");
91+
for value in descriptors.iter().skip(1) {
92+
if value.phys_start <= curr_value.phys_start {
93+
panic!("memory map sorting failed");
94+
}
95+
curr_value = *value;
8496
}
85-
curr_value = *value;
86-
}
8797

88-
// This is pretty much a sanity test to ensure returned memory isn't filled with random values.
89-
let first_desc = descriptors[0];
98+
// This is pretty much a sanity test to ensure returned memory isn't filled with random values.
99+
let first_desc = descriptors[0];
90100

91-
#[cfg(target_arch = "x86_64")]
92-
{
93-
let phys_start = first_desc.phys_start;
94-
assert_eq!(phys_start, 0, "Memory does not start at address 0");
101+
#[cfg(target_arch = "x86_64")]
102+
{
103+
let phys_start = first_desc.phys_start;
104+
assert_eq!(phys_start, 0, "Memory does not start at address 0");
105+
}
106+
let page_count = first_desc.page_count;
107+
assert!(page_count != 0, "Memory map entry has zero size");
95108
}
96-
let page_count = first_desc.page_count;
97-
assert!(page_count != 0, "Memory map entry has zero size");
98109
}

0 commit comments

Comments
 (0)