@ -1577,10 +1577,16 @@ mod tests {
#[ test ]
#[ test ]
fn test_read_btf_type_int ( ) {
fn test_read_btf_type_int ( ) {
let endianness = Endianness ::default ( ) ;
let endianness = Endianness ::default ( ) ;
#[ cfg(target_endian = " little " ) ]
let data : & [ u8 ] = & [
let data : & [ u8 ] = & [
0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x08 , 0x00 , 0x00 , 0x00 , 0x40 , 0x00 ,
0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x08 , 0x00 , 0x00 , 0x00 , 0x40 , 0x00 ,
0x00 , 0x00 ,
0x00 , 0x00 ,
] ;
] ;
#[ cfg(target_endian = " big " ) ]
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x01 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x08 , 0x00 , 0x00 ,
0x00 , 0x40 ,
] ;
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Int ( new @ Int {
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Int ( new @ Int {
name_offset ,
name_offset ,
info : _ ,
info : _ ,
@ -1596,30 +1602,48 @@ mod tests {
#[ test ]
#[ test ]
fn test_write_btf_long_unsigned_int ( ) {
fn test_write_btf_long_unsigned_int ( ) {
#[ cfg(target_endian = " little " ) ]
let data : & [ u8 ] = & [
let data : & [ u8 ] = & [
0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x08 , 0x00 , 0x00 , 0x00 , 0x40 , 0x00 ,
0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x08 , 0x00 , 0x00 , 0x00 , 0x40 , 0x00 ,
0x00 , 0x00 ,
0x00 , 0x00 ,
] ;
] ;
#[ cfg(target_endian = " big " ) ]
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x01 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x08 , 0x00 , 0x00 ,
0x00 , 0x40 ,
] ;
let int = Int ::new ( 1 , 8 , IntEncoding ::None , 0 ) ;
let int = Int ::new ( 1 , 8 , IntEncoding ::None , 0 ) ;
assert_eq! ( int . to_bytes ( ) , data ) ;
assert_eq! ( int . to_bytes ( ) , data ) ;
}
}
#[ test ]
#[ test ]
fn test_write_btf_uchar ( ) {
fn test_write_btf_uchar ( ) {
#[ cfg(target_endian = " little " ) ]
let data : & [ u8 ] = & [
let data : & [ u8 ] = & [
0x13 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x01 , 0x00 , 0x00 , 0x00 , 0x08 , 0x00 ,
0x13 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x01 , 0x00 , 0x00 , 0x00 , 0x08 , 0x00 ,
0x00 , 0x00 ,
0x00 , 0x00 ,
] ;
] ;
#[ cfg(target_endian = " big " ) ]
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x13 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 ,
0x00 , 0x08 ,
] ;
let int = Int ::new ( 0x13 , 1 , IntEncoding ::None , 0 ) ;
let int = Int ::new ( 0x13 , 1 , IntEncoding ::None , 0 ) ;
assert_eq! ( int . to_bytes ( ) , data ) ;
assert_eq! ( int . to_bytes ( ) , data ) ;
}
}
#[ test ]
#[ test ]
fn test_write_btf_signed_short_int ( ) {
fn test_write_btf_signed_short_int ( ) {
#[ cfg(target_endian = " little " ) ]
let data : & [ u8 ] = & [
let data : & [ u8 ] = & [
0x4a , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x02 , 0x00 , 0x00 , 0x00 , 0x10 , 0x00 ,
0x4a , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x02 , 0x00 , 0x00 , 0x00 , 0x10 , 0x00 ,
0x00 , 0x01 ,
0x00 , 0x01 ,
] ;
] ;
#[ cfg(target_endian = " big " ) ]
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x4a , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x02 , 0x01 , 0x00 ,
0x00 , 0x10 ,
] ;
let int = Int ::new ( 0x4a , 2 , IntEncoding ::Signed , 0 ) ;
let int = Int ::new ( 0x4a , 2 , IntEncoding ::Signed , 0 ) ;
assert_eq! ( int . to_bytes ( ) , data ) ;
assert_eq! ( int . to_bytes ( ) , data ) ;
}
}
@ -1627,9 +1651,14 @@ mod tests {
#[ test ]
#[ test ]
fn test_read_btf_type_ptr ( ) {
fn test_read_btf_type_ptr ( ) {
let endianness = Endianness ::default ( ) ;
let endianness = Endianness ::default ( ) ;
#[ cfg(target_endian = " little " ) ]
let data : & [ u8 ] = & [
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x02 , 0x06 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x02 , 0x06 , 0x00 , 0x00 , 0x00 ,
] ;
] ;
#[ cfg(target_endian = " big " ) ]
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , 0x02 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x06 ,
] ;
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Ptr ( got ) = > {
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Ptr ( got ) = > {
assert_eq! ( got . to_bytes ( ) , data ) ;
assert_eq! ( got . to_bytes ( ) , data ) ;
} ) ;
} ) ;
@ -1638,10 +1667,16 @@ mod tests {
#[ test ]
#[ test ]
fn test_read_btf_type_array ( ) {
fn test_read_btf_type_array ( ) {
let endianness = Endianness ::default ( ) ;
let endianness = Endianness ::default ( ) ;
#[ cfg(target_endian = " little " ) ]
let data : & [ u8 ] = & [
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x03 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 ,
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x03 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 ,
0x00 , 0x00 , 0x12 , 0x00 , 0x00 , 0x00 , 0x02 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 , 0x12 , 0x00 , 0x00 , 0x00 , 0x02 , 0x00 , 0x00 , 0x00 ,
] ;
] ;
#[ cfg(target_endian = " big " ) ]
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , 0x03 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x12 , 0x00 , 0x00 , 0x00 , 0x02 ,
] ;
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Array ( got ) = > {
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Array ( got ) = > {
assert_eq! ( got . to_bytes ( ) , data ) ;
assert_eq! ( got . to_bytes ( ) , data ) ;
} ) ;
} ) ;
@ -1650,10 +1685,16 @@ mod tests {
#[ test ]
#[ test ]
fn test_read_btf_type_struct ( ) {
fn test_read_btf_type_struct ( ) {
let endianness = Endianness ::default ( ) ;
let endianness = Endianness ::default ( ) ;
#[ cfg(target_endian = " little " ) ]
let data : & [ u8 ] = & [
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x04 , 0x04 , 0x00 , 0x00 , 0x00 , 0x47 , 0x02 ,
0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x04 , 0x04 , 0x00 , 0x00 , 0x00 , 0x47 , 0x02 ,
0x00 , 0x00 , 0x12 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 , 0x12 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
] ;
] ;
#[ cfg(target_endian = " big " ) ]
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 ,
0x02 , 0x47 , 0x00 , 0x00 , 0x00 , 0x12 , 0x00 , 0x00 , 0x00 , 0x00 ,
] ;
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Struct ( got ) = > {
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Struct ( got ) = > {
assert_eq! ( got . to_bytes ( ) , data ) ;
assert_eq! ( got . to_bytes ( ) , data ) ;
} ) ;
} ) ;
@ -1662,10 +1703,16 @@ mod tests {
#[ test ]
#[ test ]
fn test_read_btf_type_union ( ) {
fn test_read_btf_type_union ( ) {
let endianness = Endianness ::default ( ) ;
let endianness = Endianness ::default ( ) ;
#[ cfg(target_endian = " little " ) ]
let data : & [ u8 ] = & [
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x05 , 0x04 , 0x00 , 0x00 , 0x00 , 0x0d , 0x04 ,
0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x05 , 0x04 , 0x00 , 0x00 , 0x00 , 0x0d , 0x04 ,
0x00 , 0x00 , 0x68 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 , 0x68 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
] ;
] ;
#[ cfg(target_endian = " big " ) ]
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , 0x05 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 ,
0x04 , 0x0d , 0x00 , 0x00 , 0x00 , 0x68 , 0x00 , 0x00 , 0x00 , 0x00 ,
] ;
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Union ( got ) = > {
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Union ( got ) = > {
assert_eq! ( got . to_bytes ( ) , data ) ;
assert_eq! ( got . to_bytes ( ) , data ) ;
} ) ;
} ) ;
@ -1674,10 +1721,16 @@ mod tests {
#[ test ]
#[ test ]
fn test_read_btf_type_enum ( ) {
fn test_read_btf_type_enum ( ) {
let endianness = Endianness ::default ( ) ;
let endianness = Endianness ::default ( ) ;
#[ cfg(target_endian = " little " ) ]
let data : & [ u8 ] = & [
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , 0x02 , 0x00 , 0x00 , 0x06 , 0x04 , 0x00 , 0x00 , 0x00 , 0xc9 , 0x00 ,
0x00 , 0x00 , 0x00 , 0x00 , 0x02 , 0x00 , 0x00 , 0x06 , 0x04 , 0x00 , 0x00 , 0x00 , 0xc9 , 0x00 ,
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0xcf , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0xcf , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 ,
] ;
] ;
#[ cfg(target_endian = " big " ) ]
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , 0x06 , 0x00 , 0x00 , 0x02 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 ,
0x00 , 0xc9 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0xcf , 0x00 , 0x00 , 0x00 , 0x01 ,
] ;
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Enum ( got ) = > {
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Enum ( got ) = > {
assert_eq! ( got . to_bytes ( ) , data ) ;
assert_eq! ( got . to_bytes ( ) , data ) ;
} ) ;
} ) ;
@ -1686,9 +1739,14 @@ mod tests {
#[ test ]
#[ test ]
fn test_read_btf_type_fwd ( ) {
fn test_read_btf_type_fwd ( ) {
let endianness = Endianness ::default ( ) ;
let endianness = Endianness ::default ( ) ;
#[ cfg(target_endian = " little " ) ]
let data : & [ u8 ] = & [
let data : & [ u8 ] = & [
0x0b , 0x55 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x07 , 0x00 , 0x00 , 0x00 , 0x00 ,
0x0b , 0x55 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x07 , 0x00 , 0x00 , 0x00 , 0x00 ,
] ;
] ;
#[ cfg(target_endian = " big " ) ]
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x55 , 0x0b , 0x07 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
] ;
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Fwd ( got ) = > {
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Fwd ( got ) = > {
assert_eq! ( got . to_bytes ( ) , data ) ;
assert_eq! ( got . to_bytes ( ) , data ) ;
} ) ;
} ) ;
@ -1697,9 +1755,14 @@ mod tests {
#[ test ]
#[ test ]
fn test_read_btf_type_typedef ( ) {
fn test_read_btf_type_typedef ( ) {
let endianness = Endianness ::default ( ) ;
let endianness = Endianness ::default ( ) ;
#[ cfg(target_endian = " little " ) ]
let data : & [ u8 ] = & [
let data : & [ u8 ] = & [
0x31 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x08 , 0x0b , 0x00 , 0x00 , 0x00 ,
0x31 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x08 , 0x0b , 0x00 , 0x00 , 0x00 ,
] ;
] ;
#[ cfg(target_endian = " big " ) ]
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x31 , 0x08 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x0b ,
] ;
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Typedef ( got ) = > {
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Typedef ( got ) = > {
assert_eq! ( got . to_bytes ( ) , data ) ;
assert_eq! ( got . to_bytes ( ) , data ) ;
} ) ;
} ) ;
@ -1708,9 +1771,14 @@ mod tests {
#[ test ]
#[ test ]
fn test_read_btf_type_volatile ( ) {
fn test_read_btf_type_volatile ( ) {
let endianness = Endianness ::default ( ) ;
let endianness = Endianness ::default ( ) ;
#[ cfg(target_endian = " little " ) ]
let data : & [ u8 ] = & [
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x09 , 0x24 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x09 , 0x24 , 0x00 , 0x00 , 0x00 ,
] ;
] ;
#[ cfg(target_endian = " big " ) ]
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , 0x09 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x24 ,
] ;
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Volatile ( got ) = > {
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Volatile ( got ) = > {
assert_eq! ( got . to_bytes ( ) , data ) ;
assert_eq! ( got . to_bytes ( ) , data ) ;
} ) ;
} ) ;
@ -1719,9 +1787,14 @@ mod tests {
#[ test ]
#[ test ]
fn test_read_btf_type_const ( ) {
fn test_read_btf_type_const ( ) {
let endianness = Endianness ::default ( ) ;
let endianness = Endianness ::default ( ) ;
#[ cfg(target_endian = " little " ) ]
let data : & [ u8 ] = & [
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x0a , 0x01 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x0a , 0x01 , 0x00 , 0x00 , 0x00 ,
] ;
] ;
#[ cfg(target_endian = " big " ) ]
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , 0x0a , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 ,
] ;
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Const ( got ) = > {
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Const ( got ) = > {
assert_eq! ( got . to_bytes ( ) , data ) ;
assert_eq! ( got . to_bytes ( ) , data ) ;
} ) ;
} ) ;
@ -1730,9 +1803,14 @@ mod tests {
#[ test ]
#[ test ]
fn test_read_btf_type_restrict ( ) {
fn test_read_btf_type_restrict ( ) {
let endianness = Endianness ::default ( ) ;
let endianness = Endianness ::default ( ) ;
#[ cfg(target_endian = " little " ) ]
let data : & [ u8 ] = & [
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x0b , 0x04 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x0b , 0x04 , 0x00 , 0x00 , 0x00 ,
] ;
] ;
#[ cfg(target_endian = " big " ) ]
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , 0x0b , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x04 ,
] ;
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Restrict ( got ) = > {
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Restrict ( got ) = > {
assert_eq! ( got . to_bytes ( ) , data ) ;
assert_eq! ( got . to_bytes ( ) , data ) ;
} ) ;
} ) ;
@ -1741,9 +1819,14 @@ mod tests {
#[ test ]
#[ test ]
fn test_read_btf_type_func ( ) {
fn test_read_btf_type_func ( ) {
let endianness = Endianness ::default ( ) ;
let endianness = Endianness ::default ( ) ;
#[ cfg(target_endian = " little " ) ]
let data : & [ u8 ] = & [
let data : & [ u8 ] = & [
0x17 , 0x8b , 0x0f , 0x00 , 0x00 , 0x00 , 0x00 , 0x0c , 0xf0 , 0xe4 , 0x00 , 0x00 ,
0x17 , 0x8b , 0x0f , 0x00 , 0x00 , 0x00 , 0x00 , 0x0c , 0xf0 , 0xe4 , 0x00 , 0x00 ,
] ;
] ;
#[ cfg(target_endian = " big " ) ]
let data : & [ u8 ] = & [
0x00 , 0x0f , 0x8b , 0x17 , 0x0c , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0xe4 , 0xf0 ,
] ;
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Func ( got ) = > {
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Func ( got ) = > {
assert_eq! ( got . to_bytes ( ) , data ) ;
assert_eq! ( got . to_bytes ( ) , data ) ;
} ) ;
} ) ;
@ -1752,10 +1835,16 @@ mod tests {
#[ test ]
#[ test ]
fn test_read_btf_type_func_proto ( ) {
fn test_read_btf_type_func_proto ( ) {
let endianness = Endianness ::default ( ) ;
let endianness = Endianness ::default ( ) ;
#[ cfg(target_endian = " little " ) ]
let data : & [ u8 ] = & [
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x0d , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x0d , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 , 0x12 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 , 0x12 , 0x00 , 0x00 , 0x00 ,
] ;
] ;
#[ cfg(target_endian = " big " ) ]
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , 0x0d , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x12 ,
] ;
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::FuncProto ( got ) = > {
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::FuncProto ( got ) = > {
assert_eq! ( got . to_bytes ( ) , data ) ;
assert_eq! ( got . to_bytes ( ) , data ) ;
} ) ;
} ) ;
@ -1765,10 +1854,16 @@ mod tests {
fn test_read_btf_type_func_var ( ) {
fn test_read_btf_type_func_var ( ) {
let endianness = Endianness ::default ( ) ;
let endianness = Endianness ::default ( ) ;
// NOTE: There was no data in /sys/kernell/btf/vmlinux for this type
// NOTE: There was no data in /sys/kernell/btf/vmlinux for this type
#[ cfg(target_endian = " little " ) ]
let data : & [ u8 ] = & [
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x0e , 0xf0 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x0e , 0xf0 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 ,
0x00 , 0x00 ,
] ;
] ;
#[ cfg(target_endian = " big " ) ]
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , 0x0e , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0xf0 , 0x00 , 0x00 ,
0x00 , 0x00 ,
] ;
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Var ( got ) = > {
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Var ( got ) = > {
assert_eq! ( got . to_bytes ( ) , data ) ;
assert_eq! ( got . to_bytes ( ) , data ) ;
} ) ;
} ) ;
@ -1777,10 +1872,16 @@ mod tests {
#[ test ]
#[ test ]
fn test_read_btf_type_func_datasec ( ) {
fn test_read_btf_type_func_datasec ( ) {
let endianness = Endianness ::default ( ) ;
let endianness = Endianness ::default ( ) ;
#[ cfg(target_endian = " little " ) ]
let data : & [ u8 ] = & [
let data : & [ u8 ] = & [
0xd9 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x0f , 0x00 , 0x00 , 0x00 , 0x00 , 0x0b , 0x00 ,
0xd9 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x0f , 0x00 , 0x00 , 0x00 , 0x00 , 0x0b , 0x00 ,
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 ,
] ;
] ;
#[ cfg(target_endian = " big " ) ]
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0xd9 , 0x0f , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
0x00 , 0x0b , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x04 ,
] ;
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::DataSec ( DataSec {
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::DataSec ( DataSec {
name_offset : _ ,
name_offset : _ ,
info : _ ,
info : _ ,
@ -1802,9 +1903,14 @@ mod tests {
#[ test ]
#[ test ]
fn test_read_btf_type_float ( ) {
fn test_read_btf_type_float ( ) {
let endianness = Endianness ::default ( ) ;
let endianness = Endianness ::default ( ) ;
#[ cfg(target_endian = " little " ) ]
let data : & [ u8 ] = & [
let data : & [ u8 ] = & [
0x78 , 0xfd , 0x02 , 0x00 , 0x00 , 0x00 , 0x00 , 0x10 , 0x08 , 0x00 , 0x00 , 0x00 ,
0x78 , 0xfd , 0x02 , 0x00 , 0x00 , 0x00 , 0x00 , 0x10 , 0x08 , 0x00 , 0x00 , 0x00 ,
] ;
] ;
#[ cfg(target_endian = " big " ) ]
let data : & [ u8 ] = & [
0x00 , 0x02 , 0xfd , 0x78 , 0x10 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x08 ,
] ;
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Float ( got ) = > {
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Float ( got ) = > {
assert_eq! ( got . to_bytes ( ) , data ) ;
assert_eq! ( got . to_bytes ( ) , data ) ;
} ) ;
} ) ;
@ -1856,6 +1962,7 @@ mod tests {
#[ test ]
#[ test ]
pub fn test_read_btf_type_enum64 ( ) {
pub fn test_read_btf_type_enum64 ( ) {
let endianness = Endianness ::default ( ) ;
let endianness = Endianness ::default ( ) ;
#[ cfg(target_endian = " little " ) ]
let data : & [ u8 ] = & [
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , // name offset
0x00 , 0x00 , 0x00 , 0x00 , // name offset
0x01 , 0x00 , 0x00 , 0x13 , // info: vlen, type_kind
0x01 , 0x00 , 0x00 , 0x13 , // info: vlen, type_kind
@ -1864,6 +1971,15 @@ mod tests {
0xbb , 0xbb , 0xbb , 0xbb , // enum variant low
0xbb , 0xbb , 0xbb , 0xbb , // enum variant low
0xaa , 0xaa , 0xaa , 0xaa , // enum variant high
0xaa , 0xaa , 0xaa , 0xaa , // enum variant high
] ;
] ;
#[ cfg(target_endian = " big " ) ]
let data : & [ u8 ] = & [
0x00 , 0x00 , 0x00 , 0x00 , // name offset
0x13 , 0x00 , 0x00 , 0x01 , // info: vlen, type_kind
0x00 , 0x00 , 0x00 , 0x08 , // size
0x00 , 0x00 , 0x06 , 0xd7 , // enum variant name offset
0xbb , 0xbb , 0xbb , 0xbb , // enum variant low
0xaa , 0xaa , 0xaa , 0xaa , // enum variant high
] ;
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Enum64 ( got ) = > {
assert_matches ! ( unsafe { BtfType ::read ( data , endianness ) } . unwrap ( ) , BtfType ::Enum64 ( got ) = > {
assert_eq! ( got . to_bytes ( ) , data ) ;
assert_eq! ( got . to_bytes ( ) , data ) ;