Skip to content

Commit 9dbd794

Browse files
committed
mm: Add unit tests for memory address checks
Add unit tests to evaluate offline correct behavior of valid physical address checking (memory.rs). Signed-off-by: Carlos Bilbao <[email protected]>
1 parent 065e6cd commit 9dbd794

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/mm/memory.rs

+21
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,24 @@ pub fn writable_phys_addr(paddr: PhysAddr) -> bool {
107107

108108
valid_phys_address(paddr)
109109
}
110+
111+
#[cfg(test)]
112+
mod tests {
113+
use super::*;
114+
use crate::address::PhysAddr;
115+
116+
#[test]
117+
fn test_valid_phys_address() {
118+
let region = MemoryRegion {
119+
start: 0x1000,
120+
end: 0x2000,
121+
};
122+
123+
MEMORY_MAP.lock_write().push(region);
124+
125+
// Inside the region
126+
assert!(valid_phys_address(PhysAddr::new(0x1500)));
127+
// Outside the region
128+
assert!(!valid_phys_address(PhysAddr::new(0x3000)));
129+
}
130+
}

0 commit comments

Comments
 (0)