mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 01:48:35 +00:00
Tests: Enum-constant locals pass now
failing_tests/vmlinux/assignment_handling.py pinned exactly this gap
("This gives an error, but / this does not"); it moves to the passing
suite and its xfail entry goes. enum_to_local.py adds the C shape
`int act = XDP_PASS; if (...) act = XDP_DROP; return act;`.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@ -7,8 +7,8 @@ from ctypes import c_int64, c_void_p
|
||||
@bpf
|
||||
@section("kprobe/blk_mq_start_request")
|
||||
def example(ctx: c_void_p) -> c_int64:
|
||||
d = XDP_PASS # This gives an error, but
|
||||
e = XDP_PASS + 0 # this does not
|
||||
d = XDP_PASS # bare enum constant: used to be rejected at allocation
|
||||
e = XDP_PASS + 0 # through a binop: always worked; the two must agree
|
||||
print(f"test1 {e} test2 {d}")
|
||||
return c_int64(0)
|
||||
|
||||
|
||||
26
tests/passing_tests/vmlinux/enum_to_local.py
Normal file
26
tests/passing_tests/vmlinux/enum_to_local.py
Normal file
@ -0,0 +1,26 @@
|
||||
# A local initialised from a vmlinux enum constant, the C shape
|
||||
# `int act = XDP_PASS;`. Reads of a bare name resolve local, then BPF global,
|
||||
# then vmlinux enum everywhere else; the allocation pass used to stop one step
|
||||
# short for this shape and reject it, while `act = XDP_PASS + 0` compiled.
|
||||
from ctypes import c_int64
|
||||
from pythonbpf import bpf, section, bpfglobal, compile
|
||||
from vmlinux import struct_xdp_md
|
||||
from vmlinux import XDP_PASS, XDP_DROP
|
||||
|
||||
|
||||
@bpf
|
||||
@section("xdp")
|
||||
def prog(ctx: struct_xdp_md) -> c_int64:
|
||||
act = XDP_PASS
|
||||
if ctx.data_end - ctx.data > 1500:
|
||||
act = XDP_DROP
|
||||
return c_int64(act)
|
||||
|
||||
|
||||
@bpf
|
||||
@bpfglobal
|
||||
def LICENSE() -> str:
|
||||
return "GPL"
|
||||
|
||||
|
||||
compile()
|
||||
@ -29,7 +29,6 @@
|
||||
|
||||
"failing_tests/vmlinux/args_test.py" = {reason = "struct_trace_event_raw_sys_enter args field access not supported", level = "ir"}
|
||||
|
||||
"failing_tests/vmlinux/assignment_handling.py" = {reason = "Assigning vmlinux enum value (XDP_PASS) to a local variable not yet supported", level = "ir"}
|
||||
|
||||
"failing_tests/xdp_pass.py" = {reason = "XDP program using vmlinux structs (struct_xdp_md) and complex map/struct interaction not yet supported", level = "ir"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user