Răsfoiți Sursa

integration-test: Add test for 2 progs in same section

Signed-off-by: Dave Tucker <[email protected]>
Dave Tucker 1 an în urmă
părinte
comite
6d92119fbc

+ 4 - 0
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"

+ 21 - 0
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 {}
+}

+ 1 - 0
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"));
 

+ 23 - 1
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();