@@ -58,9 +58,12 @@ mod bootservices {
5858/// Tests that use [`uefi::allocator::Allocator`], which is configured as the
5959/// global allocator.
6060mod global {
61+ use alloc:: boxed:: Box ;
62+ use uefi_raw:: table:: boot:: PAGE_SIZE ;
63+
6164 /// Simple test to ensure our custom allocator works with the `alloc` crate.
6265 pub fn alloc_vec ( ) {
63- info ! ( "Allocating a vector through the `alloc` crate " ) ;
66+ info ! ( "Allocating a vector using the global allocator " ) ;
6467
6568 #[ allow( clippy:: useless_vec) ]
6669 let mut values = vec ! [ -5 , 16 , 23 , 4 , 0 ] ;
@@ -71,17 +74,27 @@ mod global {
7174 }
7275
7376 /// Simple test to ensure our custom allocator works with correct alignment.
77+ #[ allow( dead_code) ] // Ignore warning due to field not being read.
7478 pub fn alloc_alignment ( ) {
75- info ! ( "Allocating a structure with alignment to 0x100" ) ;
76-
77- #[ repr( align( 0x100 ) ) ]
78- struct Block (
79- // Ignore warning due to field not being read.
80- #[ allow( dead_code) ] [ u8 ; 0x100 ] ,
81- ) ;
79+ {
80+ info ! ( "Allocating a structure with alignment of 0x100 using the global allocator" ) ;
81+ #[ repr( align( 0x100 ) ) ]
82+ struct Block ( [ u8 ; 0x100 ] ) ;
8283
83- let value = vec ! [ Block ( [ 1 ; 0x100 ] ) ] ;
84- assert_eq ! ( value. as_ptr( ) as usize % 0x100 , 0 , "Wrong alignment" ) ;
84+ let value = vec ! [ Block ( [ 1 ; 0x100 ] ) ] ;
85+ assert_eq ! ( value. as_ptr( ) as usize % 0x100 , 0 , "Wrong alignment" ) ;
86+ }
87+ {
88+ info ! ( "Allocating a memory page ({PAGE_SIZE}) using the global allocator" ) ;
89+ #[ repr( align( 4096 ) ) ]
90+ struct Page ( [ u8 ; PAGE_SIZE ] ) ;
91+ let value = Box :: new ( Page ( [ 0 ; PAGE_SIZE ] ) ) ;
92+ assert_eq ! (
93+ value. 0 . as_ptr( ) . align_offset( PAGE_SIZE ) ,
94+ 0 ,
95+ "Wrong alignment"
96+ ) ;
97+ }
8598 }
8699}
87100
0 commit comments