From f9ee43e7ef41e5b75d3981420616426af6805643 Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Sat, 1 Nov 2025 14:13:52 +0530 Subject: [PATCH] Add passing test smp_processor_id.py for helpers --- .../passing_tests/helpers/smp_processor_id.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/passing_tests/helpers/smp_processor_id.py diff --git a/tests/passing_tests/helpers/smp_processor_id.py b/tests/passing_tests/helpers/smp_processor_id.py new file mode 100644 index 0000000..8c17a75 --- /dev/null +++ b/tests/passing_tests/helpers/smp_processor_id.py @@ -0,0 +1,40 @@ +from pythonbpf import bpf, section, bpfglobal, compile, struct +from ctypes import c_void_p, c_int64, c_uint32, c_uint64 +from pythonbpf.helper import smp_processor_id, ktime + + +@bpf +@struct +class cpu_event_t: + cpu_id: c_uint32 + timestamp: c_uint64 + + +@bpf +@section("tracepoint/syscalls/sys_enter_execve") +def trace_with_cpu(ctx: c_void_p) -> c_int64: + """Test bpf_get_smp_processor_id helper function""" + + # Get the current CPU ID + cpu = smp_processor_id() + + # Print it + print(f"Running on CPU {cpu}") + + # Use it in a struct + event = cpu_event_t() + event.cpu_id = smp_processor_id() + event.timestamp = ktime() + + print(f"Event on CPU {event.cpu_id} at time {event.timestamp}") + + return 0 + + +@bpf +@bpfglobal +def LICENSE() -> str: + return "GPL" + + +compile()