mirror of https://github.com/aya-rs/aya
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.2 KiB
Rust
36 lines
1.2 KiB
Rust
2 years ago
|
use object::{Object, ObjectSection, ObjectSymbol, SymbolSection};
|
||
|
|
||
|
#[test]
|
||
|
fn prog_sections() {
|
||
|
let obj_file = object::File::parse(crate::XDP_SEC).unwrap();
|
||
|
|
||
|
ensure_symbol(&obj_file, "xdp", "xdp_plain");
|
||
|
ensure_symbol(&obj_file, "xdp.frags", "xdp_frags");
|
||
|
ensure_symbol(&obj_file, "xdp/cpumap", "xdp_cpumap");
|
||
|
ensure_symbol(&obj_file, "xdp/devmap", "xdp_devmap");
|
||
|
ensure_symbol(&obj_file, "xdp.frags/cpumap", "xdp_frags_cpumap");
|
||
|
ensure_symbol(&obj_file, "xdp.frags/devmap", "xdp_frags_devmap");
|
||
|
}
|
||
|
|
||
|
#[track_caller]
|
||
|
fn ensure_symbol(obj_file: &object::File, sec_name: &str, sym_name: &str) {
|
||
|
let sec = obj_file.section_by_name(sec_name).unwrap_or_else(|| {
|
||
|
let secs = obj_file
|
||
|
.sections()
|
||
|
.flat_map(|sec| sec.name().ok().map(|name| name.to_owned()))
|
||
|
.collect::<Vec<_>>();
|
||
|
panic!("section {sec_name} not found. available sections: {secs:?}");
|
||
|
});
|
||
|
let sec = SymbolSection::Section(sec.index());
|
||
|
|
||
|
let syms = obj_file
|
||
|
.symbols()
|
||
|
.filter(|sym| sym.section() == sec)
|
||
|
.filter_map(|sym| sym.name().ok())
|
||
|
.collect::<Vec<_>>();
|
||
|
assert!(
|
||
|
syms.contains(&sym_name),
|
||
|
"symbol not found. available symbols in section: {syms:?}"
|
||
|
);
|
||
|
}
|