diff --git a/aya/src/programs/utils.rs b/aya/src/programs/utils.rs index a32d9f933..0930e62b1 100644 --- a/aya/src/programs/utils.rs +++ b/aya/src/programs/utils.rs @@ -74,7 +74,7 @@ pub(crate) fn boot_time() -> SystemTime { }; let since_boot = get_time(libc::CLOCK_BOOTTIME); 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. diff --git a/test/integration-test/src/tests/load.rs b/test/integration-test/src/tests/load.rs index 4c99a008c..75d8a95c4 100644 --- a/test/integration-test/src/tests/load.rs +++ b/test/integration-test/src/tests/load.rs @@ -1,4 +1,8 @@ -use std::{convert::TryInto as _, thread, time}; +use std::{ + convert::TryInto as _, + thread, + time::{Duration, SystemTime}, +}; use aya::{ maps::Array, @@ -11,7 +15,7 @@ use aya::{ }; const MAX_RETRIES: usize = 100; -const RETRY_DURATION: time::Duration = time::Duration::from_millis(10); +const RETRY_DURATION: Duration = Duration::from_millis(10); #[test] fn long_name() { @@ -145,6 +149,26 @@ fn unload_xdp() { 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 load_time = SystemTime::now(); + prog.load().unwrap(); + assert_loaded("pass"); + + let loaded_at = prog.info().unwrap().loaded_at(); + + // make sure loaded_at() api is correct with a millisecond tolerance. + assert_eq!( + (loaded_at.duration_since(load_time).unwrap()).as_millis(), + 0 + ); + prog.unload().unwrap(); + + assert_unloaded("pass"); +} + #[test] fn unload_kprobe() { let mut bpf = Bpf::load(crate::TEST).unwrap();