Skip to content

Commit 51d8628

Browse files
r41k0uclaude
andcommitted
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>
1 parent be1d86d commit 51d8628

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

‎tests/passing_tests/vmlinux/assignment_handling.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
@bpf
88
@section("kprobe/blk_mq_start_request")
99
def example(ctx: c_void_p) -> c_int64:
10-
d = XDP_PASS # This gives an error, but
11-
e = XDP_PASS + 0 # this does not
10+
d = XDP_PASS # bare enum constant: used to be rejected at allocation
11+
e = XDP_PASS + 0 # through a binop: always worked; the two must agree
1212
print(f"test1 {e} test2 {d}")
1313
return c_int64(0)
1414

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# A local initialised from a vmlinux enum constant, the C shape
2+
# `int act = XDP_PASS;`. Reads of a bare name resolve local, then BPF global,
3+
# then vmlinux enum everywhere else; the allocation pass used to stop one step
4+
# short for this shape and reject it, while `act = XDP_PASS + 0` compiled.
5+
from ctypes import c_int64
6+
from pythonbpf import bpf, section, bpfglobal, compile
7+
from vmlinux import struct_xdp_md
8+
from vmlinux import XDP_PASS, XDP_DROP
9+
10+
11+
@bpf
12+
@section("xdp")
13+
def prog(ctx: struct_xdp_md) -> c_int64:
14+
act = XDP_PASS
15+
if ctx.data_end - ctx.data > 1500:
16+
act = XDP_DROP
17+
return c_int64(act)
18+
19+
20+
@bpf
21+
@bpfglobal
22+
def LICENSE() -> str:
23+
return "GPL"
24+
25+
26+
compile()

‎tests/test_config.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
"failing_tests/vmlinux/args_test.py" = {reason = "struct_trace_event_raw_sys_enter args field access not supported", level = "ir"}
3131

32-
"failing_tests/vmlinux/assignment_handling.py" = {reason = "Assigning vmlinux enum value (XDP_PASS) to a local variable not yet supported", level = "ir"}
3332

3433
"failing_tests/xdp_pass.py" = {reason = "XDP program using vmlinux structs (struct_xdp_md) and complex map/struct interaction not yet supported", level = "ir"}
3534

0 commit comments

Comments
 (0)