integration-test: fix load time and add test

Time since boot is defined as the UNIX_EPOCH plus the duration
since boot. which is realtime - boottime NOT boottime - realtime.

Add a integration test to ensure this doesn't happen again.

Signed-off-by: astoycos <astoycos@redhat.com>
pull/769/head
astoycos 1 year ago
parent 42fd82e32b
commit dffff1ce6b

@ -74,7 +74,7 @@ pub(crate) fn boot_time() -> SystemTime {
}; };
let since_boot = get_time(libc::CLOCK_BOOTTIME); let since_boot = get_time(libc::CLOCK_BOOTTIME);
let since_epoch = get_time(libc::CLOCK_REALTIME); let since_epoch = get_time(libc::CLOCK_REALTIME);
UNIX_EPOCH + since_boot - since_epoch UNIX_EPOCH + since_epoch - since_boot
} }
/// Get the specified information from a file descriptor's fdinfo. /// Get the specified information from a file descriptor's fdinfo.

@ -1,4 +1,8 @@
use std::{convert::TryInto as _, thread, time}; use std::{
convert::TryInto as _,
thread,
time::{Duration, SystemTime},
};
use aya::{ use aya::{
maps::Array, maps::Array,
@ -11,7 +15,7 @@ use aya::{
}; };
const MAX_RETRIES: usize = 100; const MAX_RETRIES: usize = 100;
const RETRY_DURATION: time::Duration = time::Duration::from_millis(10); const RETRY_DURATION: Duration = Duration::from_millis(10);
#[test] #[test]
fn long_name() { fn long_name() {
@ -145,6 +149,28 @@ fn unload_xdp() {
assert_unloaded("pass"); assert_unloaded("pass");
} }
#[test]
fn test_loaded_at() {
let mut bpf = Bpf::load(crate::TEST).unwrap();
let prog: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap();
let t1 = SystemTime::now();
prog.load().unwrap();
let t2 = SystemTime::now();
assert_loaded("pass");
let loaded_at = prog.info().unwrap().loaded_at();
let range = t1..t2;
assert!(
range.contains(&loaded_at),
"{range:?}.contains({loaded_at:?})"
);
prog.unload().unwrap();
assert_unloaded("pass");
}
#[test] #[test]
fn unload_kprobe() { fn unload_kprobe() {
let mut bpf = Bpf::load(crate::TEST).unwrap(); let mut bpf = Bpf::load(crate::TEST).unwrap();

Loading…
Cancel
Save