From 0a144a0e69bc136fd8c1aa9f3712a37855be545a Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 11 Sep 2023 10:37:57 -0400 Subject: [PATCH] integration-test: remove all sleeps --- test/integration-test/bpf/multimap-btf.bpf.c | 2 +- test/integration-test/src/tests/load.rs | 13 ++++++++++--- test/integration-test/src/tests/rbpf.rs | 2 +- test/integration-test/src/tests/relocations.rs | 4 ---- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/test/integration-test/bpf/multimap-btf.bpf.c b/test/integration-test/bpf/multimap-btf.bpf.c index 2bd7978b..f6d34bcf 100644 --- a/test/integration-test/bpf/multimap-btf.bpf.c +++ b/test/integration-test/bpf/multimap-btf.bpf.c @@ -17,7 +17,7 @@ struct { __uint(max_entries, 1); } map_2 SEC(".maps"); -SEC("tracepoint") +SEC("uprobe") int bpf_prog(void *ctx) { __u32 key = 0; __u64 twenty_four = 24; diff --git a/test/integration-test/src/tests/load.rs b/test/integration-test/src/tests/load.rs index 0b0d1532..4c99a008 100644 --- a/test/integration-test/src/tests/load.rs +++ b/test/integration-test/src/tests/load.rs @@ -36,11 +36,12 @@ fn multiple_btf_maps() { let map_1: Array<_, u64> = bpf.take_map("map_1").unwrap().try_into().unwrap(); let map_2: Array<_, u64> = bpf.take_map("map_2").unwrap().try_into().unwrap(); - let prog: &mut TracePoint = bpf.program_mut("bpf_prog").unwrap().try_into().unwrap(); + let prog: &mut UProbe = bpf.program_mut("bpf_prog").unwrap().try_into().unwrap(); prog.load().unwrap(); - prog.attach("sched", "sched_switch").unwrap(); + prog.attach(Some("trigger_bpf_program"), 0, "/proc/self/exe", None) + .unwrap(); - thread::sleep(time::Duration::from_secs(3)); + trigger_bpf_program(); let key = 0; let val_1 = map_1.get(&key, 0).unwrap(); @@ -50,6 +51,12 @@ fn multiple_btf_maps() { assert_eq!(val_2, 42); } +#[no_mangle] +#[inline(never)] +pub extern "C" fn trigger_bpf_program() { + core::hint::black_box(trigger_bpf_program); +} + fn poll_loaded_program_id(name: &str) -> impl Iterator> + '_ { std::iter::once(true) .chain(std::iter::repeat(false)) diff --git a/test/integration-test/src/tests/rbpf.rs b/test/integration-test/src/tests/rbpf.rs index 0a85adbf..da44863f 100644 --- a/test/integration-test/src/tests/rbpf.rs +++ b/test/integration-test/src/tests/rbpf.rs @@ -40,7 +40,7 @@ fn use_map_with_rbpf() { assert_eq!(object.programs.len(), 1); assert_matches!( object.programs["bpf_prog"].section, - ProgramSection::TracePoint { .. } + ProgramSection::UProbe { .. } ); // Initialize maps: diff --git a/test/integration-test/src/tests/relocations.rs b/test/integration-test/src/tests/relocations.rs index 1b550e9f..9e7d5719 100644 --- a/test/integration-test/src/tests/relocations.rs +++ b/test/integration-test/src/tests/relocations.rs @@ -1,5 +1,3 @@ -use std::time::Duration; - use aya::{programs::UProbe, Bpf}; #[test] @@ -7,7 +5,6 @@ fn relocations() { let bpf = load_and_attach("test_64_32_call_relocs", crate::RELOCATIONS); trigger_relocations_program(); - std::thread::sleep(Duration::from_millis(100)); let m = aya::maps::Array::<_, u64>::try_from(bpf.map("RESULTS").unwrap()).unwrap(); assert_eq!(m.get(&0, 0).unwrap(), 1); @@ -24,7 +21,6 @@ fn text_64_64_reloc() { m.set(1, 2, 0).unwrap(); trigger_relocations_program(); - std::thread::sleep(Duration::from_millis(100)); assert_eq!(m.get(&0, 0).unwrap(), 2); assert_eq!(m.get(&1, 0).unwrap(), 3);