mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 18:08:36 +00:00
Five passing tests: read in condition and print; the get_cgroup_id_kern.c read-one-write-one shape; the counter += 1 idiom; two programs sharing global state (the test_autoattach.c shape); and mixed .bss/.data placement with mixed widths and signedness. Three strict expected failures documenting deliberate errors: assignment without the global statement (shadowing), a global statement naming a non-global, and a non-integer global type. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L1PX8EuP9C3o3veWGA84RF
35 lines
682 B
Python
35 lines
682 B
Python
# Section placement needs no marker: a zero initializer lands the global in
|
|
# .bss, a non-zero one in .data, decided by LLVM exactly as for C. Mixed
|
|
# widths and signedness also exercise the BTF basic-type emission.
|
|
from pythonbpf import bpf, section, bpfglobal, compile
|
|
from ctypes import c_void_p, c_int64, c_uint64, c_int32
|
|
|
|
|
|
@bpf
|
|
@bpfglobal
|
|
def zeroed() -> c_uint64:
|
|
return c_uint64(0)
|
|
|
|
|
|
@bpf
|
|
@bpfglobal
|
|
def preset() -> c_int32:
|
|
return c_int32(42)
|
|
|
|
|
|
@bpf
|
|
@section("tracepoint/raw_syscalls/sys_enter")
|
|
def prog(ctx: c_void_p) -> c_int64:
|
|
global zeroed
|
|
zeroed = preset + 1
|
|
return c_int64(0)
|
|
|
|
|
|
@bpf
|
|
@bpfglobal
|
|
def LICENSE() -> str:
|
|
return "GPL"
|
|
|
|
|
|
compile()
|