@@ -19,7 +19,7 @@ pub const PAGE_SIZE: u64 = 1 << 12;
1919pub const PAGE_SIZE_USIZE : usize = 1 << 12 ;
2020
2121/// A memory region in the guest address space
22- #[ derive( Debug , Clone , Copy ) ]
22+ #[ derive( Debug , Clone , Copy , PartialEq , bytemuck :: Pod , bytemuck :: Zeroable ) ]
2323#[ repr( C ) ]
2424pub struct GuestMemoryRegion {
2525 /// The size of the memory region
@@ -65,7 +65,7 @@ impl Default for FileMappingInfo {
6565 }
6666}
6767
68- #[ derive( Debug , Clone , Copy ) ]
68+ #[ derive( Debug , Clone , Copy , PartialEq , bytemuck :: Pod , bytemuck :: Zeroable ) ]
6969#[ repr( C ) ]
7070pub struct HyperlightPEB {
7171 pub input_stack : GuestMemoryRegion ,
@@ -80,3 +80,40 @@ pub struct HyperlightPEB {
8080 #[ cfg( feature = "nanvix-unstable" ) ]
8181 pub file_mappings : GuestMemoryRegion ,
8282}
83+
84+ #[ cfg( test) ]
85+ mod tests {
86+ use super :: * ;
87+
88+ #[ test]
89+ fn peb_round_trip ( ) {
90+ let peb = HyperlightPEB {
91+ input_stack : GuestMemoryRegion {
92+ size : 0x1111 ,
93+ ptr : 0x2222 ,
94+ } ,
95+ output_stack : GuestMemoryRegion {
96+ size : 0x3333 ,
97+ ptr : 0x4444 ,
98+ } ,
99+ init_data : GuestMemoryRegion {
100+ size : 0x5555 ,
101+ ptr : 0x6666 ,
102+ } ,
103+ guest_heap : GuestMemoryRegion {
104+ size : 0x7777 ,
105+ ptr : 0x8888 ,
106+ } ,
107+ #[ cfg( feature = "nanvix-unstable" ) ]
108+ file_mappings : GuestMemoryRegion {
109+ size : 0x9999 ,
110+ ptr : 0xaaaa ,
111+ } ,
112+ } ;
113+ let bytes = bytemuck:: bytes_of ( & peb) ;
114+ let peb2 = * bytemuck:: from_bytes :: < HyperlightPEB > ( bytes) ;
115+ let peb2_bytes = bytemuck:: bytes_of ( & peb2) ;
116+ assert_eq ! ( peb, peb2) ;
117+ assert_eq ! ( bytes, peb2_bytes) ;
118+ }
119+ }
0 commit comments