@@ -2161,7 +2161,7 @@ impl<'a> HandleBuffer<'a> {
21612161pub struct ProtocolSearchKey ( NonNull < c_void > ) ;
21622162
21632163#[ cfg( test) ]
2164- mod tests {
2164+ mod tests_mmap_artificial {
21652165 use core:: mem:: { size_of, size_of_val} ;
21662166
21672167 use crate :: table:: boot:: { MemoryAttribute , MemoryMap , MemoryType } ;
@@ -2292,3 +2292,138 @@ mod tests {
22922292 true
22932293 }
22942294}
2295+
2296+ #[ cfg( test) ]
2297+ mod tests_mmap_real {
2298+ use super :: * ;
2299+ use core:: mem:: size_of;
2300+
2301+ const MMAP_META : MemoryMapMeta = MemoryMapMeta {
2302+ map_size : MMAP_RAW . len ( ) * size_of :: < u64 > ( ) ,
2303+ desc_size : 48 ,
2304+ map_key : MemoryMapKey ( 0 ) ,
2305+ desc_version : 1 ,
2306+ } ;
2307+ /// Sample with 10 entries of a real UEFI memory map extracted from our
2308+ /// UEFI test runner.
2309+ const MMAP_RAW : [ u64 ; 60 ] = [
2310+ 3 , 0 , 0 , 1 , 15 , 0 , 7 , 4096 , 0 , 134 , 15 , 0 , 4 , 552960 , 0 , 1 , 15 , 0 , 7 , 557056 , 0 , 24 , 15 , 0 ,
2311+ 7 , 1048576 , 0 , 1792 , 15 , 0 , 10 , 8388608 , 0 , 8 , 15 , 0 , 7 , 8421376 , 0 , 3 , 15 , 0 , 10 , 8433664 ,
2312+ 0 , 1 , 15 , 0 , 7 , 8437760 , 0 , 4 , 15 , 0 , 10 , 8454144 , 0 , 240 , 15 , 0 ,
2313+ ] ;
2314+ extern crate std;
2315+ #[ test]
2316+ fn basic_functionality ( ) {
2317+ let mut buf = MMAP_RAW ;
2318+ let buf =
2319+ unsafe { slice:: from_raw_parts_mut ( buf. as_mut_ptr ( ) . cast :: < u8 > ( ) , MMAP_META . map_size ) } ;
2320+ let mut mmap = MemoryMap :: from_raw ( buf, MMAP_META . desc_size ) ;
2321+ mmap. sort ( ) ;
2322+
2323+ let entries = mmap. entries ( ) . copied ( ) . collect :: < Vec < _ > > ( ) ;
2324+
2325+ let expected = [
2326+ MemoryDescriptor {
2327+ ty : MemoryType :: BOOT_SERVICES_CODE ,
2328+ phys_start : 0x0 ,
2329+ virt_start : 0x0 ,
2330+ page_count : 0x1 ,
2331+ att : MemoryAttribute :: UNCACHEABLE
2332+ | MemoryAttribute :: WRITE_COMBINE
2333+ | MemoryAttribute :: WRITE_THROUGH
2334+ | MemoryAttribute :: WRITE_BACK ,
2335+ } ,
2336+ MemoryDescriptor {
2337+ ty : MemoryType :: CONVENTIONAL ,
2338+ phys_start : 0x1000 ,
2339+ virt_start : 0x0 ,
2340+ page_count : 0x86 ,
2341+ att : MemoryAttribute :: UNCACHEABLE
2342+ | MemoryAttribute :: WRITE_COMBINE
2343+ | MemoryAttribute :: WRITE_THROUGH
2344+ | MemoryAttribute :: WRITE_BACK ,
2345+ } ,
2346+ MemoryDescriptor {
2347+ ty : MemoryType :: BOOT_SERVICES_DATA ,
2348+ phys_start : 0x87000 ,
2349+ virt_start : 0x0 ,
2350+ page_count : 0x1 ,
2351+ att : MemoryAttribute :: UNCACHEABLE
2352+ | MemoryAttribute :: WRITE_COMBINE
2353+ | MemoryAttribute :: WRITE_THROUGH
2354+ | MemoryAttribute :: WRITE_BACK ,
2355+ } ,
2356+ MemoryDescriptor {
2357+ ty : MemoryType :: CONVENTIONAL ,
2358+ phys_start : 0x88000 ,
2359+ virt_start : 0x0 ,
2360+ page_count : 0x18 ,
2361+ att : MemoryAttribute :: UNCACHEABLE
2362+ | MemoryAttribute :: WRITE_COMBINE
2363+ | MemoryAttribute :: WRITE_THROUGH
2364+ | MemoryAttribute :: WRITE_BACK ,
2365+ } ,
2366+ MemoryDescriptor {
2367+ ty : MemoryType :: CONVENTIONAL ,
2368+ phys_start : 0x100000 ,
2369+ virt_start : 0x0 ,
2370+ page_count : 0x700 ,
2371+ att : MemoryAttribute :: UNCACHEABLE
2372+ | MemoryAttribute :: WRITE_COMBINE
2373+ | MemoryAttribute :: WRITE_THROUGH
2374+ | MemoryAttribute :: WRITE_BACK ,
2375+ } ,
2376+ MemoryDescriptor {
2377+ ty : MemoryType :: ACPI_NON_VOLATILE ,
2378+ phys_start : 0x800000 ,
2379+ virt_start : 0x0 ,
2380+ page_count : 0x8 ,
2381+ att : MemoryAttribute :: UNCACHEABLE
2382+ | MemoryAttribute :: WRITE_COMBINE
2383+ | MemoryAttribute :: WRITE_THROUGH
2384+ | MemoryAttribute :: WRITE_BACK ,
2385+ } ,
2386+ MemoryDescriptor {
2387+ ty : MemoryType :: CONVENTIONAL ,
2388+ phys_start : 0x808000 ,
2389+ virt_start : 0x0 ,
2390+ page_count : 0x3 ,
2391+ att : MemoryAttribute :: UNCACHEABLE
2392+ | MemoryAttribute :: WRITE_COMBINE
2393+ | MemoryAttribute :: WRITE_THROUGH
2394+ | MemoryAttribute :: WRITE_BACK ,
2395+ } ,
2396+ MemoryDescriptor {
2397+ ty : MemoryType :: ACPI_NON_VOLATILE ,
2398+ phys_start : 0x80b000 ,
2399+ virt_start : 0x0 ,
2400+ page_count : 0x1 ,
2401+ att : MemoryAttribute :: UNCACHEABLE
2402+ | MemoryAttribute :: WRITE_COMBINE
2403+ | MemoryAttribute :: WRITE_THROUGH
2404+ | MemoryAttribute :: WRITE_BACK ,
2405+ } ,
2406+ MemoryDescriptor {
2407+ ty : MemoryType :: CONVENTIONAL ,
2408+ phys_start : 0x80c000 ,
2409+ virt_start : 0x0 ,
2410+ page_count : 0x4 ,
2411+ att : MemoryAttribute :: UNCACHEABLE
2412+ | MemoryAttribute :: WRITE_COMBINE
2413+ | MemoryAttribute :: WRITE_THROUGH
2414+ | MemoryAttribute :: WRITE_BACK ,
2415+ } ,
2416+ MemoryDescriptor {
2417+ ty : MemoryType :: ACPI_NON_VOLATILE ,
2418+ phys_start : 0x810000 ,
2419+ virt_start : 0x0 ,
2420+ page_count : 0xf0 ,
2421+ att : MemoryAttribute :: UNCACHEABLE
2422+ | MemoryAttribute :: WRITE_COMBINE
2423+ | MemoryAttribute :: WRITE_THROUGH
2424+ | MemoryAttribute :: WRITE_BACK ,
2425+ } ,
2426+ ] ;
2427+ assert_eq ! ( entries. as_slice( ) , & expected) ;
2428+ }
2429+ }
0 commit comments