Remove relocation test by type

The 'ignore_map_by_type' function has been removed. Also renamed test function and simplified the relocation builder since 'by_name' is the only option now
pull/968/head
martinsoees 2 months ago
parent 787d08b031
commit 492feb2147

@ -1,36 +1,12 @@
use std::collections::HashSet;
use aya::{programs::UProbe, util::KernelVersion, Ebpf, EbpfLoader}; use aya::{programs::UProbe, util::KernelVersion, Ebpf, EbpfLoader};
use aya_obj::generated::bpf_map_type;
use test_log::test; use test_log::test;
enum DisableMapRelocation<'a> {
ByType(bpf_map_type),
ByName(&'a str),
}
#[test] #[test]
fn test_ignored_map_relocation_by_type() { fn ignored_map_relocation_by_name() {
let mut ebpf = relocation_load_and_attach( let mut ebpf = relocation_load_and_attach(
"test_ignored_map_relocation", "test_ignored_map_relocation",
crate::IGNORE_MAP, crate::IGNORE_MAP,
DisableMapRelocation::ByType(bpf_map_type::BPF_MAP_TYPE_RINGBUF), "RINGBUF",
);
let perf = ebpf.take_map("PERFBUF");
let ring = ebpf.take_map("RINGBUF");
assert!(perf.is_some());
assert!(ring.is_none());
}
#[test]
fn test_ignored_map_relocation_by_name() {
let mut ebpf = relocation_load_and_attach(
"test_ignored_map_relocation",
crate::IGNORE_MAP,
DisableMapRelocation::ByName("RINGBUF"),
); );
let perf = ebpf.take_map("PERFBUF"); let perf = ebpf.take_map("PERFBUF");
@ -76,24 +52,13 @@ fn text_64_64_reloc() {
fn relocation_load_and_attach( fn relocation_load_and_attach(
name: &str, name: &str,
bytes: &[u8], bytes: &[u8],
disable_type: DisableMapRelocation, disable_map_name: &str,
) -> Ebpf { ) -> Ebpf {
let mut ebpf = match disable_type { let mut ebpf = EbpfLoader::new()
DisableMapRelocation::ByType(bmt) => { .ignore_maps_by_name(&[disable_map_name])
let mut set = HashSet::new();
set.insert(bmt);
EbpfLoader::new()
.ignore_maps_by_type(set)
.set_global("RINGBUF_SUPPORTED", &0, true) .set_global("RINGBUF_SUPPORTED", &0, true)
.load(bytes) .load(bytes)
.unwrap() .unwrap();
}
DisableMapRelocation::ByName(name) => EbpfLoader::new()
.ignore_maps_by_name(&[name])
.set_global("RINGBUF_SUPPORTED", &0, true)
.load(bytes)
.unwrap(),
};
let prog: &mut UProbe = ebpf.program_mut(name).unwrap().try_into().unwrap(); let prog: &mut UProbe = ebpf.program_mut(name).unwrap().try_into().unwrap();
prog.load().unwrap(); prog.load().unwrap();

Loading…
Cancel
Save