Skip to content

Commit

Permalink
maps: avoid retagging in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tamird committed Mar 2, 2025
1 parent 9ba73dd commit fd68b99
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions aya/src/maps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1202,10 +1202,6 @@ mod tests {
}

#[test]
#[cfg_attr(
miri,
ignore = "`let map_info = unsafe { &mut *(attr.info.info as *mut bpf_map_info) }` is trying to retag from <wildcard> for Unique permission, but no exposed tags have suitable permission in the borrow stack for this location"
)]
fn test_name() {
const TEST_NAME: &str = "foo";

Expand All @@ -1222,10 +1218,11 @@ mod tests {
unsafe { attr.info.info_len },
mem::size_of::<bpf_map_info>() as u32
);
let map_info = unsafe { &mut *(attr.info.info as *mut bpf_map_info) };
map_info.name[..TEST_NAME.len()].copy_from_slice(unsafe {
mem::transmute::<&[u8], &[c_char]>(TEST_NAME.as_bytes())
});
unsafe {
let name_bytes = mem::transmute::<&[u8], &[c_char]>(TEST_NAME.as_bytes());
let map_info = attr.info.info as *mut bpf_map_info;
(*map_info).name[..name_bytes.len()].copy_from_slice(name_bytes);
}
Ok(0)
}
_ => Err((-1, io::Error::from_raw_os_error(EFAULT))),
Expand All @@ -1236,10 +1233,6 @@ mod tests {
}

#[test]
#[cfg_attr(
miri,
ignore = "`let map_info = unsafe { &mut *(attr.info.info as *mut bpf_map_info) }` is trying to retag from <wildcard> for Unique permission, but no exposed tags have suitable permission in the borrow stack for this location"
)]
fn test_loaded_maps() {
override_syscall(|call| match call {
Syscall::Ebpf {
Expand All @@ -1264,12 +1257,19 @@ mod tests {
cmd: bpf_cmd::BPF_OBJ_GET_INFO_BY_FD,
attr,
} => {
let map_info = unsafe { &mut *(attr.info.info as *mut bpf_map_info) };
map_info.id = unsafe { attr.info.bpf_fd } - crate::MockableFd::mock_unsigned_fd();
map_info.key_size = 32;
map_info.value_size = 64;
map_info.map_flags = 1234;
map_info.max_entries = 99;
unsafe {
let info = attr.info;
let map_info = info.info as *mut bpf_map_info;
map_info.write({
let mut map_info = map_info.read();
map_info.id = info.bpf_fd - crate::MockableFd::mock_unsigned_fd();
map_info.key_size = 32;
map_info.value_size = 64;
map_info.map_flags = 1234;
map_info.max_entries = 99;
map_info
});
}
Ok(0)
}
_ => Err((-1, io::Error::from_raw_os_error(EFAULT))),
Expand Down

0 comments on commit fd68b99

Please sign in to comment.