mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 18:08:36 +00:00
- passing_tests/loops/: the seven range/while/break/continue/nested tests move over from failing_tests/, joined by rebinding the loop variable, a negative step, loop else-branches, and a helper-bounded loop over a @bpfglobal that survives -O2 as a real loop for the verifier. - failing_tests/loops/: break outside a loop, and a non-literal range step. - for_map_items stays xfail: map iteration needs its own design. - c-form/loops.bpf.c: the clang reference the lowering was checked against.
24 lines
538 B
Python
24 lines
538 B
Python
# Rebinding the loop variable does not change the trip count: range() steps a
|
|
# counter of its own, as in Python. Returns 10.
|
|
from pythonbpf import bpf, section, bpfglobal, compile
|
|
from ctypes import c_void_p, c_int64
|
|
|
|
|
|
@bpf
|
|
@section("tracepoint/syscalls/sys_enter_execve")
|
|
def hello(ctx: c_void_p) -> c_int64:
|
|
total: c_int64 = 0
|
|
for i in range(10):
|
|
total = total + 1
|
|
i = 100 # noqa: F841 -- rebinding is the point of the test
|
|
return total
|
|
|
|
|
|
@bpf
|
|
@bpfglobal
|
|
def LICENSE() -> str:
|
|
return "GPL"
|
|
|
|
|
|
compile()
|