- process_stmt now raises NotImplementedError on an unsupported statement
instead of warning: a dropped statement silently changes what the
program means (a for/while loop compiled to nothing).
- failing_tests/loops/: 8 xfail tests for for/while/break/continue/nested
loops and map iteration
- failing_tests/assign/annotated_assign.py: xfail for `x: c_int64 = 0`
(ast.AnnAssign is not handled)
return/map_value.py is the C shape `if (p) return *p;`; return_struct.py
is the type error convert() now raises; vmlinux/enum_rank.py pins the
u32 trunc/zext pair for `XDP_PASS - k`. test_signedness_ir.py takes
paths under passing_tests so it can assert on all three, and skips the
vmlinux case when vmlinux.py is not importable, as the harness does.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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>
Every read of a bare name resolves local, then BPF global, then vmlinux
enum constant, except the allocation pass's variable-to-variable path,
which stopped after the globals and rejected `act = XDP_PASS` with
"source variable not found", while `act = XDP_PASS + 0` compiled through
the binop path. The error text pointed the wrong way: it is the target
that needs a stack slot, and the pass could not type it. An enum
constant is an immediate with no storage of its own, so the target gets
the i64 slot a literal gets, and the constant is folded at the store.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Seven programs under passing_tests/signedness, one per case in
tests/c-form/signedness.bpf.c: unsigned and signed widening, mixed
division and remainder, unsigned comparison, u32 * u32 wrapping before
the widening, right shifts, and literal rank. Levels 1 and 2 compile
them like any other case; test_signedness_ir.py asserts the shape of the
IR against what clang emits for the C (zext vs sext, udiv vs sdiv,
icmp ugt vs sgt, lshr vs ashr, the trunc/zext pair around the wrap).
The XDP xfail note no longer claims the guard is a signed compare.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BSDVsZH5NtoASyxB8FCtGU
Eight cases, each reading operands from .bss globals (so clang cannot fold)
and writing its result to a .bss global (so the runtime proof is a bpftool
map dump). The IR clang emits is the specification for the signedness work:
s64 = u32 zext i32 -> i64 (widening is source-driven)
u64 = s32 sext i32 -> i64
u32 / s32 udiv i32 (usual arithmetic conversions)
u64 > s64 icmp ugt i64
u32 * u32 -> u64 mul i32, then zext (wraps at 32 before widening)
u32 >> 4 lshr i32
s32 >> 4 ashr i32
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BSDVsZH5NtoASyxB8FCtGU
Levels 1 and 2 only prove the globals cases compile; what they are about
is whether a name resolves to the @bpfglobal symbol or to a stack slot
that shadows it. test_globals_ir.py reads the IR of each BPF function
and counts loads and stores per operand, exactly: `global counter` is
load/add/store on @counter with no slot, a read needs no declaration and
hits the symbol, and a write without `global` binds a slot for the whole
body of that function while a second function still reads the symbol.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
globals_shadowing.py asserted the old rule, so it moves to
passing_tests/globals/shadowing.py and asserts the new one: the write
without `global` binds a local, and a second program still reads the
global's initializer. copy_to_local.py covers `x = a_global`, the read
shape that used to fail in the allocation pass.
globals_read_before_shadow.py takes over as the failing case, since a
read above the binding is what Python rejects, and the augassign test
keeps its xfail with the reason reworded to the UnboundLocalError it is.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Assigning a global's name without declaring it `global` was a compile
error. Python makes it a local instead: the name is local for the whole
function body, the global keeps its value, and only a `global` statement
writes through to it. Do that, so the same program means the same thing
in Python and in BPF.
Python's scoping is function-wide and static, which the compiler gets
for free: allocation runs as a pre-pass over the whole body, so a name
bound anywhere is in local_sym_tab before the first statement is
lowered, and reads resolve local-first. What does not come for free is
the read above the binding, which Python answers with UnboundLocalError
rather than the global's value. There is no runtime here in which to
raise that, so the local records where its binding ends and a read above
it is rejected, with the message Python would have given. Silence there
would load an uninitialised stack slot through a name the author
expected to be the global.
`counter += 1` without `global counter` stays an error for the same
reason: it binds a local and reads it in the same statement. Only its
message changes, from a shadowing refusal to the UnboundLocalError it
actually is.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Reads resolve a name local-first (_handle_name_expr, get_operand_value, the
printk formatter), but both write paths checked the declared-global set
before local_sym_tab. Normally harmless because the two tables are disjoint
by construction -- except for a parameter whose name matches a @bpfglobal.
With 'global ctx' in a function taking ctx, the write path stored to the
global while a read of the same name picked the parameter and crashed on its
None slot: the same name resolving to different storage depending on which
side of an assignment it sat.
Python forbids the construct outright, and now so does the compiler, with
Python's own wording: SyntaxError: name 'ctx' is parameter and global. Both
write paths now resolve local-first like the reads, so all name lookups read
the same way; and an augmented assignment to the context parameter itself
gets a clear error instead of a store to None.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BSDVsZH5NtoASyxB8FCtGU
A struct-field test with a non-add operator and a sub-64-bit field (the
narrow-on-store path), and a strict expected failure for counter += 1 without
a global statement, which now fails as loudly as plain assignment does. Ruff
flags that line as F823 (referenced before assignment) -- the same
UnboundLocalError Python itself would raise, which is exactly the semantics
the global statement requirement mirrors.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L1PX8EuP9C3o3veWGA84RF
Two tests locking the shadowing semantics: a local named XDP_PASS returned
from a program (the exact case the return fast path used to hijack), and a
vmlinux-importing program where a local shadows one enum constant while a
@bpfglobal shadows another, read in expressions and f-strings.
The vmlinux test needs noqa on its import and both collision sites: ruff
rightly flags unused imports and redefinitions in normal Python, and this file
is deliberately made of them.
These pin compilation; the value-level proof (ret of 55, not 2) was verified
against the emitted IR and the clang reference for the same collision shapes.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L1PX8EuP9C3o3veWGA84RF
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
Captures the development loop this project has always used for new compiler
features: write a minimal C eBPF program exercising only the feature, compile
it to LLVM IR and read that as the specification, diff against what PythonBPF
currently emits, stop for a human decision on the Python syntax, implement
against the reference, and test at the right tier. Recorded as a project skill
so agents follow it too; the syntax step is an explicit hard stop.
tests/c-form/global_vars.bpf.c is the loop's step 1 for global variables: the
four C global classes and nothing else. Its IR established that every global is
an independent symbol accessed by plain load/store, that llc manufactures the
BTF VAR/DATASEC entries from DIGlobalVariable metadata, and that clang folds
const but not const volatile -- the facts the globals design rests on.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L1PX8EuP9C3o3veWGA84RF
- make test/test-cov/test-verifier now depend on a 'vmlinux' target that
regenerates vmlinux.py from the running kernel's BTF and symlinks it
into every directory under tests/, replacing the stale, duplicated
vmlinux.py fixtures that used to be committed there.
- collector.py now skips the 'vmlinux.py' filename when collecting BPF
test cases, since it's a fixture module, not a test program - it was
previously being mis-collected and compiled as a bogus test.
- functions_pass.py: llvmlite >=0.49 renamed the 'nocapture' argument
attribute to 'captures(none)'.
It generates IR and compiles, and the CO-RE relocations against struct xdp_md
resolve correctly, so it must keep passing levels 1 and 2. The kernel rejects
it: the 'data + 34 < data_end' guard is emitted as a signed compare over values
round-tripped through the stack, so the verifier never narrows the packet range
and the later iph.saddr read fails with
invalid access to packet, off=26 size=4, R1(id=0,off=26,r=0)
R1 offset is outside of the packet
Direct packet access needs bounds checks in a form the verifier can follow.
strict = True, so this flags up if that ever lands.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
It generates IR, compiles, and now passes the kernel verifier, so it is no
longer a failing test. It sat in failing_tests/ with no test_config.toml entry,
which meant the framework already required it to pass at every level -- the
directory was merely misleading.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The map was declared as RingBuf, which is not an exported name -- the class is
RingBuffer. maps_pass has no processor registered under RingBuf, so it fell
through to the 'unknown map type, defaulting to HashMap' path and was emitted
as BPF_MAP_TYPE_HASH with no key or value size. The kernel rejected it:
libbpf: map 'mymap': found type = 1.
libbpf: map 'mymap': failed to create: -EINVAL
Nothing caught this earlier because the test framework compiles the file's AST
and never imports it, so the bogus 'from pythonbpf.maps import RingBuf' never
raised ImportError.
Using the real name also subjects the map to process_ringbuf_map's validation,
which max_entries=1024 does not survive: a ringbuf needs a power of two at
least as large as the page size. Raised to 4096. libbpf now reports
type = 27 with max_entries = 4096.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
test_config.toml could only declare a failure at the "ir" or "llc" level, and
test_verifier.py dropped every declared-xfail case from the level-3 run
outright. A program that generates IR and compiles cleanly but that the kernel
verifier rejects therefore had no way to be declared: it was silently treated
as must-pass at all three levels.
Levels now form an ordered pipeline (ir < llc < verifier) and a declared level
marks that level and every later one xfail, which is what the old
ir-implies-llc special case was expressing. Level 3 runs every test file and
reports declared failures as expected ones rather than skipping them.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
These three declared @section("sometag1"), which is not a section name libbpf
can map to a program type:
libbpf: failed to guess program type from ELF section 'sometag1'
so they were rejected before the kernel verifier ever saw them. They generate
IR and compile fine; only the section was wrong. Switch to
tracepoint/syscalls/sys_enter_execve, matching the other tracepoint tests.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>