From a2959b3e027b3ea6ef425b8346ee687faab652b3 Mon Sep 17 00:00:00 2001 From: Xiaobo Liu Date: Sun, 17 Aug 2025 10:01:31 +0800 Subject: [PATCH] tweak Signed-off-by: Xiaobo Liu --- test/integration-ebpf/src/queue_test.rs | 22 +++++++++++----------- test/integration-test/src/tests/queue.rs | 18 ++++++++---------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/test/integration-ebpf/src/queue_test.rs b/test/integration-ebpf/src/queue_test.rs index a8bc146d..968894e9 100644 --- a/test/integration-ebpf/src/queue_test.rs +++ b/test/integration-ebpf/src/queue_test.rs @@ -2,7 +2,7 @@ #![no_main] use aya_ebpf::{ - cty::{c_int, c_long}, + cty::c_long, macros::{map, uprobe}, maps::{Array, Queue}, programs::ProbeContext, @@ -14,33 +14,33 @@ const PEEK_INDEX: u32 = 0; const POP_INDEX: u32 = 1; #[map] -static RESULT: Array = Array::::with_max_entries(10, 0); +static RESULT: Array = Array::::with_max_entries(2, 0); #[map] -static TEST_QUEUE: Queue = Queue::with_max_entries(10, 0); +static TEST_QUEUE: Queue = Queue::with_max_entries(10, 0); #[uprobe] pub fn test_queue_push(ctx: ProbeContext) -> Result<(), c_long> { - let value: c_int = ctx.arg(0).ok_or(-2)?; + let value = ctx.arg(0).ok_or(-1)?; TEST_QUEUE.push(&value, 0)?; Ok(()) } #[uprobe] -pub fn test_queue_peek(_: ProbeContext) -> Result<(), c_long> { - let value = TEST_QUEUE.peek().unwrap_or(-1); - result_set(PEEK_INDEX, value)?; +pub fn test_queue_pop(_: ProbeContext) -> Result<(), c_long> { + let value = TEST_QUEUE.pop().ok_or(-1)?; + result_set(POP_INDEX, value)?; Ok(()) } #[uprobe] -pub fn test_queue_pop(_: ProbeContext) -> Result<(), c_long> { - let value = TEST_QUEUE.pop().unwrap_or(-1); - result_set(POP_INDEX, value)?; +pub fn test_queue_peek(_: ProbeContext) -> Result<(), c_long> { + let value = TEST_QUEUE.peek().ok_or(-1)?; + result_set(PEEK_INDEX, value)?; Ok(()) } -fn result_set(index: u32, value: c_int) -> Result<(), c_long> { +fn result_set(index: u32, value: u64) -> Result<(), c_long> { let ptr = RESULT.get_ptr_mut(index).ok_or(-1)?; let dst = unsafe { ptr.as_mut() }; let dst_res = dst.ok_or(-1)?; diff --git a/test/integration-test/src/tests/queue.rs b/test/integration-test/src/tests/queue.rs index 9014e2ec..858a7253 100644 --- a/test/integration-test/src/tests/queue.rs +++ b/test/integration-test/src/tests/queue.rs @@ -1,5 +1,3 @@ -use std::ffi::c_int; - use aya::{EbpfLoader, maps::Array, programs::UProbe}; const PEEK_INDEX: u32 = 0; @@ -7,7 +5,7 @@ const POP_INDEX: u32 = 1; #[unsafe(no_mangle)] #[inline(never)] -pub extern "C" fn trigger_queue_push(arg: c_int) { +pub extern "C" fn trigger_queue_push(arg: u64) { core::hint::black_box(arg); } @@ -37,33 +35,33 @@ fn queue_basic() { .unwrap(); let prog: &mut UProbe = bpf - .program_mut("test_queue_peek") + .program_mut("test_queue_pop") .unwrap() .try_into() .unwrap(); prog.load().unwrap(); - prog.attach("trigger_queue_peek", "/proc/self/exe", None, None) + prog.attach("trigger_queue_pop", "/proc/self/exe", None, None) .unwrap(); let prog: &mut UProbe = bpf - .program_mut("test_queue_pop") + .program_mut("test_queue_peek") .unwrap() .try_into() .unwrap(); prog.load().unwrap(); - prog.attach("trigger_queue_pop", "/proc/self/exe", None, None) + prog.attach("trigger_queue_peek", "/proc/self/exe", None, None) .unwrap(); let array_map = bpf.map("RESULT").unwrap(); - let array = Array::<_, c_int>::try_from(array_map).unwrap(); + let array = Array::<_, u64>::try_from(array_map).unwrap(); for i in 0..9 { trigger_queue_push(i); trigger_queue_peek(); - assert_eq!(array.get(&PEEK_INDEX, 0).unwrap(), i as c_int); + assert_eq!(array.get(&PEEK_INDEX, 0).unwrap(), i); trigger_queue_pop(); - assert_eq!(array.get(&POP_INDEX, 0).unwrap(), i as c_int); + assert_eq!(array.get(&POP_INDEX, 0).unwrap(), i); } }