mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 09:58:34 +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
27 lines
573 B
Python
27 lines
573 B
Python
# Writing a global's name without `global` must be a loud compile error, not a
|
|
# silently-created shadowing local (real Python) or a silent global store.
|
|
from pythonbpf import bpf, section, bpfglobal, compile
|
|
from ctypes import c_void_p, c_int64, c_uint64
|
|
|
|
|
|
@bpf
|
|
@bpfglobal
|
|
def counter() -> c_uint64:
|
|
return c_uint64(0)
|
|
|
|
|
|
@bpf
|
|
@section("tracepoint/raw_syscalls/sys_enter")
|
|
def prog(ctx: c_void_p) -> c_int64:
|
|
counter = 1 # noqa: F841 -- missing `global counter` on purpose
|
|
return c_int64(0)
|
|
|
|
|
|
@bpf
|
|
@bpfglobal
|
|
def LICENSE() -> str:
|
|
return "GPL"
|
|
|
|
|
|
compile()
|