mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 09:58:34 +00:00
The selftest spike substituted a one-entry HashMap for every upstream global because PythonBPF had no global variable support. Integer-scalar @bpfglobal support has since landed, so the three affected ports now declare the upstream globals directly: get_cgroup_id reads expected_pid and writes cg_id, autoattach shares prog1_called/prog2_called between two programs, and perf_skip reads ip. perf_skip stays a strict xfail on the nested ctx.regs.ip access. Update the tests README and porting notes accordingly; the WORKAROUND tag no longer exists in the tree. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DLMW3X7opqAPH6bjmTVkr7
66 lines
1.4 KiB
Python
66 lines
1.4 KiB
Python
# Ported from Linux tools/testing/selftests/bpf/progs/test_autoattach.c
|
|
#
|
|
# Two programs on different raw tracepoints, each recording that it ran. The
|
|
# upstream test asserts both fired after bpf_object__attach_skeleton():
|
|
#
|
|
# bool prog1_called = false;
|
|
# bool prog2_called = false;
|
|
#
|
|
# SEC("raw_tp/sys_enter")
|
|
# int prog1(const void *ctx)
|
|
# {
|
|
# prog1_called = true;
|
|
# return 0;
|
|
# }
|
|
#
|
|
# SEC("raw_tp/sys_exit")
|
|
# int prog2(const void *ctx)
|
|
# {
|
|
# prog2_called = true;
|
|
# return 0;
|
|
# }
|
|
#
|
|
# Both flags are @bpfglobal scalars shared by the two programs in one object.
|
|
# They are c_uint64 rather than bool because integer scalars are the only
|
|
# global type today; the driver-side check is the same either way.
|
|
|
|
from pythonbpf import bpf, section, bpfglobal, compile
|
|
from ctypes import c_void_p, c_int64, c_uint64
|
|
|
|
|
|
@bpf
|
|
@bpfglobal
|
|
def prog1_called() -> c_uint64:
|
|
return c_uint64(0)
|
|
|
|
|
|
@bpf
|
|
@bpfglobal
|
|
def prog2_called() -> c_uint64:
|
|
return c_uint64(0)
|
|
|
|
|
|
@bpf
|
|
@section("raw_tp/sys_enter")
|
|
def prog1(ctx: c_void_p) -> c_int64:
|
|
global prog1_called
|
|
prog1_called = 1
|
|
return c_int64(0)
|
|
|
|
|
|
@bpf
|
|
@section("raw_tp/sys_exit")
|
|
def prog2(ctx: c_void_p) -> c_int64:
|
|
global prog2_called
|
|
prog2_called = 1
|
|
return c_int64(0)
|
|
|
|
|
|
@bpf
|
|
@bpfglobal
|
|
def LICENSE() -> str:
|
|
return "GPL"
|
|
|
|
|
|
compile()
|