|
|
@ -1,17 +1,17 @@
|
|
|
|
use std::{convert::TryInto as _, process::Command, thread, time};
|
|
|
|
use std::{convert::TryInto as _, thread, time};
|
|
|
|
|
|
|
|
|
|
|
|
use aya::{
|
|
|
|
use aya::{
|
|
|
|
maps::Array,
|
|
|
|
maps::Array,
|
|
|
|
programs::{
|
|
|
|
programs::{
|
|
|
|
links::{FdLink, PinnedLink},
|
|
|
|
links::{FdLink, PinnedLink},
|
|
|
|
loaded_programs, KProbe, TracePoint, UProbe, Xdp, XdpFlags,
|
|
|
|
loaded_links, loaded_programs, KProbe, TracePoint, UProbe, Xdp, XdpFlags,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
util::KernelVersion,
|
|
|
|
util::KernelVersion,
|
|
|
|
Bpf,
|
|
|
|
Bpf,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const MAX_RETRIES: u32 = 100;
|
|
|
|
const MAX_RETRIES: usize = 100;
|
|
|
|
const RETRY_DURATION_MS: u64 = 10;
|
|
|
|
const RETRY_DURATION: time::Duration = time::Duration::from_millis(10);
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
|
fn long_name() {
|
|
|
|
fn long_name() {
|
|
|
@ -50,61 +50,67 @@ fn multiple_btf_maps() {
|
|
|
|
assert_eq!(val_2, 42);
|
|
|
|
assert_eq!(val_2, 42);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn is_linked(prog_id: &u32) -> bool {
|
|
|
|
fn poll_loaded_program_id(name: &str) -> impl Iterator<Item = Option<u32>> + '_ {
|
|
|
|
let output = Command::new("bpftool").args(["link"]).output();
|
|
|
|
std::iter::once(true)
|
|
|
|
let output = output.expect("Failed to run 'bpftool link'");
|
|
|
|
.chain(std::iter::repeat(false))
|
|
|
|
let stdout = String::from_utf8(output.stdout).unwrap();
|
|
|
|
.map(|first| {
|
|
|
|
stdout.contains(&prog_id.to_string())
|
|
|
|
if !first {
|
|
|
|
}
|
|
|
|
thread::sleep(RETRY_DURATION);
|
|
|
|
|
|
|
|
}
|
|
|
|
macro_rules! assert_loaded_and_linked {
|
|
|
|
|
|
|
|
($name:literal, $loaded:expr) => {
|
|
|
|
|
|
|
|
for i in 0..(MAX_RETRIES + 1) {
|
|
|
|
|
|
|
|
// Ignore race failures which can happen when the tests delete a
|
|
|
|
// Ignore race failures which can happen when the tests delete a
|
|
|
|
// program in the middle of a `loaded_programs()` call.
|
|
|
|
// program in the middle of a `loaded_programs()` call.
|
|
|
|
let id = loaded_programs()
|
|
|
|
loaded_programs()
|
|
|
|
.filter_map(|prog| prog.ok())
|
|
|
|
.filter_map(|prog| prog.ok())
|
|
|
|
.find(|prog| prog.name() == $name.as_bytes())
|
|
|
|
.find_map(|prog| (prog.name() == name.as_bytes()).then(|| prog.id()))
|
|
|
|
.map(|prog| Some(prog.id()));
|
|
|
|
})
|
|
|
|
let mut linked = false;
|
|
|
|
|
|
|
|
if let Some(prog_id) = id {
|
|
|
|
|
|
|
|
linked = is_linked(&prog_id.unwrap());
|
|
|
|
|
|
|
|
if linked == $loaded {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if i == MAX_RETRIES {
|
|
|
|
|
|
|
|
panic!(
|
|
|
|
|
|
|
|
"Expected (loaded/linked: {}) but found (id: {}, linked: {}",
|
|
|
|
|
|
|
|
$loaded,
|
|
|
|
|
|
|
|
id.is_some(),
|
|
|
|
|
|
|
|
linked
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
thread::sleep(time::Duration::from_millis(RETRY_DURATION_MS));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
macro_rules! assert_loaded {
|
|
|
|
#[track_caller]
|
|
|
|
($name:literal, $loaded:expr) => {
|
|
|
|
fn assert_loaded_and_linked(name: &str) {
|
|
|
|
for i in 0..(MAX_RETRIES + 1) {
|
|
|
|
let (attempts_used, prog_id) = poll_loaded_program_id(name)
|
|
|
|
|
|
|
|
.take(MAX_RETRIES)
|
|
|
|
|
|
|
|
.enumerate()
|
|
|
|
|
|
|
|
.find_map(|(i, id)| id.map(|id| (i, id)))
|
|
|
|
|
|
|
|
.unwrap_or_else(|| panic!("{name} not loaded after {MAX_RETRIES}"));
|
|
|
|
|
|
|
|
let poll_loaded_link_id = std::iter::once(true)
|
|
|
|
|
|
|
|
.chain(std::iter::repeat(false))
|
|
|
|
|
|
|
|
.map(|first| {
|
|
|
|
|
|
|
|
if !first {
|
|
|
|
|
|
|
|
thread::sleep(RETRY_DURATION);
|
|
|
|
|
|
|
|
}
|
|
|
|
// Ignore race failures which can happen when the tests delete a
|
|
|
|
// Ignore race failures which can happen when the tests delete a
|
|
|
|
// program in the middle of a `loaded_programs()` call.
|
|
|
|
// program in the middle of a `loaded_programs()` call.
|
|
|
|
let state = loaded_programs()
|
|
|
|
loaded_links()
|
|
|
|
.filter_map(|prog| prog.ok())
|
|
|
|
.filter_map(|link| link.ok())
|
|
|
|
.any(|prog| prog.name() == $name.as_bytes());
|
|
|
|
.find_map(|link| (link.prog_id == prog_id).then_some(link.id))
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
assert!(
|
|
|
|
|
|
|
|
poll_loaded_link_id
|
|
|
|
|
|
|
|
.take(MAX_RETRIES)
|
|
|
|
|
|
|
|
.skip(attempts_used)
|
|
|
|
|
|
|
|
.any(|id| id.is_some()),
|
|
|
|
|
|
|
|
"{name} not linked after {MAX_RETRIES}"
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if state == $loaded {
|
|
|
|
#[track_caller]
|
|
|
|
break;
|
|
|
|
fn assert_loaded(name: &str) {
|
|
|
|
}
|
|
|
|
assert!(
|
|
|
|
if i == MAX_RETRIES {
|
|
|
|
poll_loaded_program_id(name)
|
|
|
|
panic!("Expected loaded: {} but was loaded: {}", $loaded, state);
|
|
|
|
.take(MAX_RETRIES)
|
|
|
|
}
|
|
|
|
.any(|id| id.is_some()),
|
|
|
|
thread::sleep(time::Duration::from_millis(RETRY_DURATION_MS));
|
|
|
|
"{name} not loaded after {MAX_RETRIES}"
|
|
|
|
}
|
|
|
|
)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[track_caller]
|
|
|
|
|
|
|
|
fn assert_unloaded(name: &str) {
|
|
|
|
|
|
|
|
assert!(
|
|
|
|
|
|
|
|
poll_loaded_program_id(name)
|
|
|
|
|
|
|
|
.take(MAX_RETRIES)
|
|
|
|
|
|
|
|
.any(|id| id.is_none()),
|
|
|
|
|
|
|
|
"{name} still loaded after {MAX_RETRIES}"
|
|
|
|
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
@ -112,24 +118,24 @@ fn unload_xdp() {
|
|
|
|
let mut bpf = Bpf::load(crate::TEST).unwrap();
|
|
|
|
let mut bpf = Bpf::load(crate::TEST).unwrap();
|
|
|
|
let prog: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap();
|
|
|
|
let prog: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap();
|
|
|
|
prog.load().unwrap();
|
|
|
|
prog.load().unwrap();
|
|
|
|
assert_loaded!("pass", true);
|
|
|
|
assert_loaded("pass");
|
|
|
|
let link = prog.attach("lo", XdpFlags::default()).unwrap();
|
|
|
|
let link = prog.attach("lo", XdpFlags::default()).unwrap();
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let _link_owned = prog.take_link(link).unwrap();
|
|
|
|
let _link_owned = prog.take_link(link).unwrap();
|
|
|
|
prog.unload().unwrap();
|
|
|
|
prog.unload().unwrap();
|
|
|
|
assert_loaded_and_linked!("pass", true);
|
|
|
|
assert_loaded_and_linked("pass");
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
assert_loaded!("pass", false);
|
|
|
|
assert_unloaded("pass");
|
|
|
|
prog.load().unwrap();
|
|
|
|
prog.load().unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
assert_loaded!("pass", true);
|
|
|
|
assert_loaded("pass");
|
|
|
|
prog.attach("lo", XdpFlags::default()).unwrap();
|
|
|
|
prog.attach("lo", XdpFlags::default()).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
assert_loaded!("pass", true);
|
|
|
|
assert_loaded("pass");
|
|
|
|
prog.unload().unwrap();
|
|
|
|
prog.unload().unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
assert_loaded!("pass", false);
|
|
|
|
assert_unloaded("pass");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
@ -137,24 +143,24 @@ fn unload_kprobe() {
|
|
|
|
let mut bpf = Bpf::load(crate::TEST).unwrap();
|
|
|
|
let mut bpf = Bpf::load(crate::TEST).unwrap();
|
|
|
|
let prog: &mut KProbe = bpf.program_mut("test_kprobe").unwrap().try_into().unwrap();
|
|
|
|
let prog: &mut KProbe = bpf.program_mut("test_kprobe").unwrap().try_into().unwrap();
|
|
|
|
prog.load().unwrap();
|
|
|
|
prog.load().unwrap();
|
|
|
|
assert_loaded!("test_kprobe", true);
|
|
|
|
assert_loaded("test_kprobe");
|
|
|
|
let link = prog.attach("try_to_wake_up", 0).unwrap();
|
|
|
|
let link = prog.attach("try_to_wake_up", 0).unwrap();
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let _link_owned = prog.take_link(link).unwrap();
|
|
|
|
let _link_owned = prog.take_link(link).unwrap();
|
|
|
|
prog.unload().unwrap();
|
|
|
|
prog.unload().unwrap();
|
|
|
|
assert_loaded_and_linked!("test_kprobe", true);
|
|
|
|
assert_loaded_and_linked("test_kprobe");
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
assert_loaded!("test_kprobe", false);
|
|
|
|
assert_unloaded("test_kprobe");
|
|
|
|
prog.load().unwrap();
|
|
|
|
prog.load().unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
assert_loaded!("test_kprobe", true);
|
|
|
|
assert_loaded("test_kprobe");
|
|
|
|
prog.attach("try_to_wake_up", 0).unwrap();
|
|
|
|
prog.attach("try_to_wake_up", 0).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
assert_loaded!("test_kprobe", true);
|
|
|
|
assert_loaded("test_kprobe");
|
|
|
|
prog.unload().unwrap();
|
|
|
|
prog.unload().unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
assert_loaded!("test_kprobe", false);
|
|
|
|
assert_unloaded("test_kprobe");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
@ -167,25 +173,25 @@ fn basic_tracepoint() {
|
|
|
|
.unwrap();
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
prog.load().unwrap();
|
|
|
|
prog.load().unwrap();
|
|
|
|
assert_loaded!("test_tracepoint", true);
|
|
|
|
assert_loaded("test_tracepoint");
|
|
|
|
let link = prog.attach("syscalls", "sys_enter_kill").unwrap();
|
|
|
|
let link = prog.attach("syscalls", "sys_enter_kill").unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let _link_owned = prog.take_link(link).unwrap();
|
|
|
|
let _link_owned = prog.take_link(link).unwrap();
|
|
|
|
prog.unload().unwrap();
|
|
|
|
prog.unload().unwrap();
|
|
|
|
assert_loaded_and_linked!("test_tracepoint", true);
|
|
|
|
assert_loaded_and_linked("test_tracepoint");
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
assert_loaded!("test_tracepoint", false);
|
|
|
|
assert_unloaded("test_tracepoint");
|
|
|
|
prog.load().unwrap();
|
|
|
|
prog.load().unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
assert_loaded!("test_tracepoint", true);
|
|
|
|
assert_loaded("test_tracepoint");
|
|
|
|
prog.attach("syscalls", "sys_enter_kill").unwrap();
|
|
|
|
prog.attach("syscalls", "sys_enter_kill").unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
assert_loaded!("test_tracepoint", true);
|
|
|
|
assert_loaded("test_tracepoint");
|
|
|
|
prog.unload().unwrap();
|
|
|
|
prog.unload().unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
assert_loaded!("test_tracepoint", false);
|
|
|
|
assert_unloaded("test_tracepoint");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
@ -194,25 +200,25 @@ fn basic_uprobe() {
|
|
|
|
let prog: &mut UProbe = bpf.program_mut("test_uprobe").unwrap().try_into().unwrap();
|
|
|
|
let prog: &mut UProbe = bpf.program_mut("test_uprobe").unwrap().try_into().unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
prog.load().unwrap();
|
|
|
|
prog.load().unwrap();
|
|
|
|
assert_loaded!("test_uprobe", true);
|
|
|
|
assert_loaded("test_uprobe");
|
|
|
|
let link = prog.attach(Some("sleep"), 0, "libc", None).unwrap();
|
|
|
|
let link = prog.attach(Some("sleep"), 0, "libc", None).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let _link_owned = prog.take_link(link).unwrap();
|
|
|
|
let _link_owned = prog.take_link(link).unwrap();
|
|
|
|
prog.unload().unwrap();
|
|
|
|
prog.unload().unwrap();
|
|
|
|
assert_loaded_and_linked!("test_uprobe", true);
|
|
|
|
assert_loaded_and_linked("test_uprobe");
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
assert_loaded!("test_uprobe", false);
|
|
|
|
assert_unloaded("test_uprobe");
|
|
|
|
prog.load().unwrap();
|
|
|
|
prog.load().unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
assert_loaded!("test_uprobe", true);
|
|
|
|
assert_loaded("test_uprobe");
|
|
|
|
prog.attach(Some("sleep"), 0, "libc", None).unwrap();
|
|
|
|
prog.attach(Some("sleep"), 0, "libc", None).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
assert_loaded!("test_uprobe", true);
|
|
|
|
assert_loaded("test_uprobe");
|
|
|
|
prog.unload().unwrap();
|
|
|
|
prog.unload().unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
assert_loaded!("test_uprobe", false);
|
|
|
|
assert_unloaded("test_uprobe");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
@ -228,22 +234,22 @@ fn pin_link() {
|
|
|
|
prog.load().unwrap();
|
|
|
|
prog.load().unwrap();
|
|
|
|
let link_id = prog.attach("lo", XdpFlags::default()).unwrap();
|
|
|
|
let link_id = prog.attach("lo", XdpFlags::default()).unwrap();
|
|
|
|
let link = prog.take_link(link_id).unwrap();
|
|
|
|
let link = prog.take_link(link_id).unwrap();
|
|
|
|
assert_loaded!("pass", true);
|
|
|
|
assert_loaded("pass");
|
|
|
|
|
|
|
|
|
|
|
|
let fd_link: FdLink = link.try_into().unwrap();
|
|
|
|
let fd_link: FdLink = link.try_into().unwrap();
|
|
|
|
let pinned = fd_link.pin("/sys/fs/bpf/aya-xdp-test-lo").unwrap();
|
|
|
|
let pinned = fd_link.pin("/sys/fs/bpf/aya-xdp-test-lo").unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
// because of the pin, the program is still attached
|
|
|
|
// because of the pin, the program is still attached
|
|
|
|
prog.unload().unwrap();
|
|
|
|
prog.unload().unwrap();
|
|
|
|
assert_loaded!("pass", true);
|
|
|
|
assert_loaded("pass");
|
|
|
|
|
|
|
|
|
|
|
|
// delete the pin, but the program is still attached
|
|
|
|
// delete the pin, but the program is still attached
|
|
|
|
let new_link = pinned.unpin().unwrap();
|
|
|
|
let new_link = pinned.unpin().unwrap();
|
|
|
|
assert_loaded!("pass", true);
|
|
|
|
assert_loaded("pass");
|
|
|
|
|
|
|
|
|
|
|
|
// finally when new_link is dropped we're detached
|
|
|
|
// finally when new_link is dropped we're detached
|
|
|
|
drop(new_link);
|
|
|
|
drop(new_link);
|
|
|
|
assert_loaded!("pass", false);
|
|
|
|
assert_unloaded("pass");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
@ -263,7 +269,7 @@ fn pin_lifecycle() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// should still be loaded since prog was pinned
|
|
|
|
// should still be loaded since prog was pinned
|
|
|
|
assert_loaded!("pass", true);
|
|
|
|
assert_loaded("pass");
|
|
|
|
|
|
|
|
|
|
|
|
// 2. Load program from bpffs but don't attach it
|
|
|
|
// 2. Load program from bpffs but don't attach it
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -271,7 +277,7 @@ fn pin_lifecycle() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// should still be loaded since prog was pinned
|
|
|
|
// should still be loaded since prog was pinned
|
|
|
|
assert_loaded!("pass", true);
|
|
|
|
assert_loaded("pass");
|
|
|
|
|
|
|
|
|
|
|
|
// 3. Load program from bpffs and attach
|
|
|
|
// 3. Load program from bpffs and attach
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -286,7 +292,7 @@ fn pin_lifecycle() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// should still be loaded since link was pinned
|
|
|
|
// should still be loaded since link was pinned
|
|
|
|
assert_loaded_and_linked!("pass", true);
|
|
|
|
assert_loaded_and_linked("pass");
|
|
|
|
|
|
|
|
|
|
|
|
// 4. Load a new version of the program, unpin link, and atomically replace old program
|
|
|
|
// 4. Load a new version of the program, unpin link, and atomically replace old program
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -299,11 +305,11 @@ fn pin_lifecycle() {
|
|
|
|
.unpin()
|
|
|
|
.unpin()
|
|
|
|
.unwrap();
|
|
|
|
.unwrap();
|
|
|
|
prog.attach_to_link(link.try_into().unwrap()).unwrap();
|
|
|
|
prog.attach_to_link(link.try_into().unwrap()).unwrap();
|
|
|
|
assert_loaded!("pass", true);
|
|
|
|
assert_loaded("pass");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// program should be unloaded
|
|
|
|
// program should be unloaded
|
|
|
|
assert_loaded!("pass", false);
|
|
|
|
assert_unloaded("pass");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
@ -321,7 +327,7 @@ fn pin_lifecycle_tracepoint() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// should still be loaded since prog was pinned
|
|
|
|
// should still be loaded since prog was pinned
|
|
|
|
assert_loaded!("test_tracepoint", true);
|
|
|
|
assert_loaded("test_tracepoint");
|
|
|
|
|
|
|
|
|
|
|
|
// 2. Load program from bpffs but don't attach it
|
|
|
|
// 2. Load program from bpffs but don't attach it
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -329,7 +335,7 @@ fn pin_lifecycle_tracepoint() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// should still be loaded since prog was pinned
|
|
|
|
// should still be loaded since prog was pinned
|
|
|
|
assert_loaded!("test_tracepoint", true);
|
|
|
|
assert_loaded("test_tracepoint");
|
|
|
|
|
|
|
|
|
|
|
|
// 3. Load program from bpffs and attach
|
|
|
|
// 3. Load program from bpffs and attach
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -346,7 +352,7 @@ fn pin_lifecycle_tracepoint() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// should still be loaded since link was pinned
|
|
|
|
// should still be loaded since link was pinned
|
|
|
|
assert_loaded_and_linked!("test_tracepoint", true);
|
|
|
|
assert_loaded_and_linked("test_tracepoint");
|
|
|
|
|
|
|
|
|
|
|
|
// 4. unpin link, and make sure everything is unloaded
|
|
|
|
// 4. unpin link, and make sure everything is unloaded
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -357,7 +363,7 @@ fn pin_lifecycle_tracepoint() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// program should be unloaded
|
|
|
|
// program should be unloaded
|
|
|
|
assert_loaded!("test_tracepoint", false);
|
|
|
|
assert_unloaded("test_tracepoint");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
@ -371,7 +377,7 @@ fn pin_lifecycle_kprobe() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// should still be loaded since prog was pinned
|
|
|
|
// should still be loaded since prog was pinned
|
|
|
|
assert_loaded!("test_kprobe", true);
|
|
|
|
assert_loaded("test_kprobe");
|
|
|
|
|
|
|
|
|
|
|
|
// 2. Load program from bpffs but don't attach it
|
|
|
|
// 2. Load program from bpffs but don't attach it
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -383,7 +389,7 @@ fn pin_lifecycle_kprobe() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// should still be loaded since prog was pinned
|
|
|
|
// should still be loaded since prog was pinned
|
|
|
|
assert_loaded!("test_kprobe", true);
|
|
|
|
assert_loaded("test_kprobe");
|
|
|
|
|
|
|
|
|
|
|
|
// 3. Load program from bpffs and attach
|
|
|
|
// 3. Load program from bpffs and attach
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -404,7 +410,7 @@ fn pin_lifecycle_kprobe() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// should still be loaded since link was pinned
|
|
|
|
// should still be loaded since link was pinned
|
|
|
|
assert_loaded_and_linked!("test_kprobe", true);
|
|
|
|
assert_loaded_and_linked("test_kprobe");
|
|
|
|
|
|
|
|
|
|
|
|
// 4. unpin link, and make sure everything is unloaded
|
|
|
|
// 4. unpin link, and make sure everything is unloaded
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -415,7 +421,7 @@ fn pin_lifecycle_kprobe() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// program should be unloaded
|
|
|
|
// program should be unloaded
|
|
|
|
assert_loaded!("test_kprobe", false);
|
|
|
|
assert_unloaded("test_kprobe");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
@ -429,7 +435,7 @@ fn pin_lifecycle_uprobe() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// should still be loaded since prog was pinned
|
|
|
|
// should still be loaded since prog was pinned
|
|
|
|
assert_loaded!("test_uprobe", true);
|
|
|
|
assert_loaded("test_uprobe");
|
|
|
|
|
|
|
|
|
|
|
|
// 2. Load program from bpffs but don't attach it
|
|
|
|
// 2. Load program from bpffs but don't attach it
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -441,7 +447,7 @@ fn pin_lifecycle_uprobe() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// should still be loaded since prog was pinned
|
|
|
|
// should still be loaded since prog was pinned
|
|
|
|
assert_loaded!("test_uprobe", true);
|
|
|
|
assert_loaded("test_uprobe");
|
|
|
|
|
|
|
|
|
|
|
|
// 3. Load program from bpffs and attach
|
|
|
|
// 3. Load program from bpffs and attach
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -462,7 +468,7 @@ fn pin_lifecycle_uprobe() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// should still be loaded since link was pinned
|
|
|
|
// should still be loaded since link was pinned
|
|
|
|
assert_loaded_and_linked!("test_uprobe", true);
|
|
|
|
assert_loaded_and_linked("test_uprobe");
|
|
|
|
|
|
|
|
|
|
|
|
// 4. unpin link, and make sure everything is unloaded
|
|
|
|
// 4. unpin link, and make sure everything is unloaded
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -473,5 +479,5 @@ fn pin_lifecycle_uprobe() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// program should be unloaded
|
|
|
|
// program should be unloaded
|
|
|
|
assert_loaded!("test_uprobe", false);
|
|
|
|
assert_unloaded("test_uprobe");
|
|
|
|
}
|
|
|
|
}
|
|
|
|