Skip to content

Commit 30c0e6b

Browse files
authored
Merge pull request #92 from pythonbpf/fix/ringbuf-map-type
Fix auto testing by adding the verifier testing mode as well, suppress deperacation warnings
2 parents 9462431 + 180c35f commit 30c0e6b

5 files changed

Lines changed: 33 additions & 11 deletions

File tree

pythonbpf/maps/maps_pass.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,15 @@ def process_bpf_map(func_node, compilation_context):
175175

176176
if isinstance(rval, ast.Call) and isinstance(rval.func, ast.Name):
177177
handler = MapProcessorRegistry.get_processor(rval.func.id)
178-
if handler:
179-
return handler(map_name, rval, compilation_context)
180-
else:
181-
logger.warning(f"Unknown map type {rval.func.id}, defaulting to HashMap")
182-
return process_hash_map(map_name, rval, compilation_context)
178+
if handler is None:
179+
# Raise an exception and fail the build because the
180+
# map carried the wrong type. A misspelled map type
181+
# is a program error.
182+
known = ", ".join(sorted(MapProcessorRegistry.known_types()))
183+
raise ValueError(
184+
f"Unknown map type '{rval.func.id}' returned by '{map_name}'. "
185+
f"Known map types: {known}"
186+
)
187+
return handler(map_name, rval, compilation_context)
183188
else:
184189
raise ValueError("Function under @map must return a map")

pythonbpf/maps/maps_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ def decorator(func):
3333
def get_processor(cls, map_type_name):
3434
"""Get the processor function for a map type"""
3535
return cls._processors.get(map_type_name)
36+
37+
@classmethod
38+
def known_types(cls):
39+
"""Names of every registered map type, for error messages"""
40+
return list(cls._processors.keys())

tests/passing_tests/ringbuf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from pythonbpf import bpf, BPF, map, bpfglobal, section, compile, compile_to_ir
2-
from pythonbpf.maps import RingBuf, HashMap
2+
from pythonbpf.maps import RingBuffer, HashMap
33
from ctypes import c_int32, c_void_p
44

55

66
# Define a map
77
@bpf
88
@map
9-
def mymap() -> RingBuf:
10-
return RingBuf(max_entries=(1024))
9+
def mymap() -> RingBuffer:
10+
return RingBuffer(max_entries=4096)
1111

1212

1313
@bpf

tests/test_config.toml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,27 @@
22
#
33
# [xfail] — tests expected to fail.
44
# key = path relative to tests/
5-
# value = {reason = "...", level = "ir" | "llc"}
6-
# level "ir" = fails during pythonbpf IR generation (exception or ERROR log)
7-
# level "llc" = IR generates but llc rejects it
5+
# value = {reason = "...", level = "ir" | "llc" | "verifier"}
6+
# level "ir" = fails during pythonbpf IR generation (exception or ERROR log)
7+
# level "llc" = IR generates but llc rejects it
8+
# level "verifier" = IR and llc both succeed, but the kernel verifier rejects it
9+
#
10+
# A failure at one level implies failure at every later one, so the declared
11+
# level marks that level and all later ones xfail.
812
#
913

1014
[xfail]
1115

1216
"failing_tests/conditionals/struct_ptr.py" = {reason = "Struct pointer used directly as boolean condition not supported", level = "ir"}
1317

18+
# Compiles cleanly; rejected by the kernel. The `data + 34 < data_end` guard is
19+
# emitted as a signed compare over values round-tripped through the stack, so the
20+
# verifier never narrows the packet range (it stays r=0) and the later
21+
# `iph.saddr` read fails with "invalid access to packet, off=26 size=4" /
22+
# "R1 offset is outside of the packet". Direct packet access needs bounds checks
23+
# in a form the verifier can follow.
24+
"failing_tests/xdp/xdp_test_1.py" = {reason = "XDP direct packet access: the data/data_end guard does not establish a packet range the verifier can use", level = "verifier"}
25+
1426
"failing_tests/license.py" = {reason = "Missing LICENSE global produces IR that llc rejects — should be caught earlier with a clear error message", level = "llc"}
1527

1628
"failing_tests/undeclared_values.py" = {reason = "Undeclared variable used in f-string — should raise SyntaxError (correct behaviour, test documents it)", level = "ir"}

0 commit comments

Comments
 (0)