@@ -58,9 +58,12 @@ mod bootservices {
58
58
/// Tests that use [`uefi::allocator::Allocator`], which is configured as the
59
59
/// global allocator.
60
60
mod global {
61
+ use alloc:: boxed:: Box ;
62
+ use uefi_raw:: table:: boot:: PAGE_SIZE ;
63
+
61
64
/// Simple test to ensure our custom allocator works with the `alloc` crate.
62
65
pub fn alloc_vec ( ) {
63
- info ! ( "Allocating a vector through the `alloc` crate " ) ;
66
+ info ! ( "Allocating a vector using the global allocator " ) ;
64
67
65
68
#[ allow( clippy:: useless_vec) ]
66
69
let mut values = vec ! [ -5 , 16 , 23 , 4 , 0 ] ;
@@ -71,17 +74,27 @@ mod global {
71
74
}
72
75
73
76
/// Simple test to ensure our custom allocator works with correct alignment.
77
+ #[ allow( dead_code) ] // Ignore warning due to field not being read.
74
78
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 ] ) ;
82
83
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
+ }
85
98
}
86
99
}
87
100
0 commit comments