From 6d92119fbc7b3339b1b135bcf8f3de747242442f Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Mon, 24 Jul 2023 19:04:19 +0100 Subject: [PATCH] integration-test: Add test for 2 progs in same section Signed-off-by: Dave Tucker --- test/integration-ebpf/Cargo.toml | 4 ++++ test/integration-ebpf/src/two_progs.rs | 21 +++++++++++++++++++++ test/integration-test/src/lib.rs | 1 + test/integration-test/src/tests/smoke.rs | 24 +++++++++++++++++++++++- 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 test/integration-ebpf/src/two_progs.rs diff --git a/test/integration-ebpf/Cargo.toml b/test/integration-ebpf/Cargo.toml index bb179c59..38c097f3 100644 --- a/test/integration-ebpf/Cargo.toml +++ b/test/integration-ebpf/Cargo.toml @@ -38,3 +38,7 @@ path = "src/relocations.rs" [[bin]] name = "bpf_probe_read" path = "src/bpf_probe_read.rs" + +[[bin]] +name = "two_progs" +path = "src/two_progs.rs" diff --git a/test/integration-ebpf/src/two_progs.rs b/test/integration-ebpf/src/two_progs.rs new file mode 100644 index 00000000..0e4b1f9a --- /dev/null +++ b/test/integration-ebpf/src/two_progs.rs @@ -0,0 +1,21 @@ +// Two programs in the same ELF section + +#![no_std] +#![no_main] + +use aya_bpf::{macros::tracepoint, programs::TracePointContext}; + +#[tracepoint] +pub fn test_tracepoint_one(_ctx: TracePointContext) -> u32 { + 0 +} +#[tracepoint] +pub fn test_tracepoint_two(_ctx: TracePointContext) -> u32 { + 0 +} + +#[cfg(not(test))] +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + loop {} +} diff --git a/test/integration-test/src/lib.rs b/test/integration-test/src/lib.rs index b8e5120d..043b0cff 100644 --- a/test/integration-test/src/lib.rs +++ b/test/integration-test/src/lib.rs @@ -13,6 +13,7 @@ pub const NAME_TEST: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/n pub const PASS: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/pass")); pub const TEST: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/test")); pub const RELOCATIONS: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/relocations")); +pub const TWO_PROGS: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/two_progs")); pub const BPF_PROBE_READ: &[u8] = include_bytes_aligned!(concat!(env!("OUT_DIR"), "/bpf_probe_read")); diff --git a/test/integration-test/src/tests/smoke.rs b/test/integration-test/src/tests/smoke.rs index 89f7d0a1..78614bd9 100644 --- a/test/integration-test/src/tests/smoke.rs +++ b/test/integration-test/src/tests/smoke.rs @@ -1,5 +1,5 @@ use aya::{ - programs::{Extension, Xdp, XdpFlags}, + programs::{Extension, TracePoint, Xdp, XdpFlags}, util::KernelVersion, Bpf, BpfLoader, }; @@ -22,6 +22,28 @@ fn xdp() { dispatcher.attach("lo", XdpFlags::default()).unwrap(); } +#[test] +fn two_progs() { + let mut bpf = Bpf::load(crate::TWO_PROGS).unwrap(); + + let prog_one: &mut TracePoint = bpf + .program_mut("test_tracepoint_one") + .unwrap() + .try_into() + .unwrap(); + + prog_one.load().unwrap(); + prog_one.attach("sched", "sched_switch").unwrap(); + + let prog_two: &mut TracePoint = bpf + .program_mut("test_tracepoint_two") + .unwrap() + .try_into() + .unwrap(); + prog_two.load().unwrap(); + prog_two.attach("sched", "sched_switch").unwrap(); +} + #[test] fn extension() { let _netns = NetNsGuard::new();