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.
aya/test/integration-test/src/tests/iter.rs

29 lines
966 B
Rust

use std::io::BufRead as _;
use aya::{Btf, Ebpf, programs::Iter};
use test_log::test;
#[test]
fn iter_task() {
let mut ebpf = Ebpf::load(crate::ITER_TASK).unwrap();
let btf = Btf::from_sys_fs().unwrap();
let prog: &mut Iter = ebpf.program_mut("iter_task").unwrap().try_into().unwrap();
prog.load("task", &btf).unwrap();
let link_id = prog.attach().unwrap();
let link = prog.take_link(link_id).unwrap();
let file = link.into_file().unwrap();
let reader = std::io::BufReader::new(file);
let mut lines = reader.lines();
let line_title = lines.next().unwrap().unwrap();
let line_init = lines.next().unwrap().unwrap();
assert_eq!(line_title, "tgid pid name");
let expected_values = ["1 1 init", "1 1 systemd"];
assert!(
expected_values.contains(&line_init.as_str()),
"Unexpected line_init value: '{line_init}', expected one of: {expected_values:?}"
);
}