mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 09:58:34 +00:00
Compare commits
9 Commits
kernel-sel
...
fix/ringbu
| Author | SHA1 | Date | |
|---|---|---|---|
| 180c35f83e | |||
| e1b40d2c77 | |||
| fd2412e733 | |||
| d66b468f39 | |||
| 79c8a1e194 | |||
| ecb2774694 | |||
| a7e2bc39ef | |||
| edefe626d0 | |||
| f796338245 |
7
Makefile
7
Makefile
@ -10,12 +10,13 @@ test:
|
||||
pytest tests/ -W ignore::DeprecationWarning -v --tb=short -m "not verifier"
|
||||
|
||||
test-cov:
|
||||
pytest tests/ -v --tb=short -m "not verifier" \
|
||||
pytest tests/ -W ignore::DeprecationWarning -v --tb=short -m "not verifier" \
|
||||
--cov=pythonbpf --cov-report=term-missing --cov-report=html
|
||||
|
||||
test-verifier:
|
||||
@echo "NOTE: verifier tests require sudo and bpftool. Uses sudo .venv/bin/python3."
|
||||
pytest tests/test_verifier.py -v --tb=short -m verifier
|
||||
@echo "NOTE: verifier tests shell out to 'sudo bpftool'; run 'sudo -v' first so"
|
||||
@echo " the timestamp does not lapse mid-run. bpftool must be installed."
|
||||
pytest tests/test_verifier.py -W ignore::DeprecationWarning -v --tb=short -m verifier
|
||||
|
||||
all: clean install
|
||||
|
||||
|
||||
@ -15,8 +15,8 @@ sys.path.insert(0, os.path.abspath(".."))
|
||||
project = "PythonBPF"
|
||||
copyright = "2026, Pragyansh Chaturvedi, Varun Mallya"
|
||||
author = "Pragyansh Chaturvedi, Varun Mallya"
|
||||
release = "0.1.9"
|
||||
version = "0.1.9"
|
||||
release = "0.1.8"
|
||||
version = "0.1.8"
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
||||
|
||||
@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "pythonbpf"
|
||||
version = "0.1.9"
|
||||
version = "0.1.8"
|
||||
description = "Reduced Python frontend for eBPF"
|
||||
authors = [
|
||||
{ name = "r41k0u", email="pragyanshchaturvedi18@gmail.com" },
|
||||
|
||||
@ -26,7 +26,7 @@ import re
|
||||
|
||||
logger: Logger = logging.getLogger(__name__)
|
||||
|
||||
VERSION = "v0.1.9"
|
||||
VERSION = "v0.1.8"
|
||||
|
||||
|
||||
def finalize_module(original_str):
|
||||
|
||||
@ -11,7 +11,7 @@ def deref_to_depth(func, builder, val, target_depth):
|
||||
cur_type = val.type
|
||||
|
||||
for depth in range(target_depth):
|
||||
if not isinstance(cur_type, ir.PointerType):
|
||||
if not isinstance(val.type, ir.PointerType):
|
||||
logger.error("Cannot dereference further, non-pointer type")
|
||||
return None
|
||||
|
||||
|
||||
@ -113,12 +113,7 @@ def bpf_map_lookup_elem_emitter(
|
||||
f"Map lookup expects exactly one argument (key), got {len(call.args)}"
|
||||
)
|
||||
key_ptr = get_or_create_ptr_from_arg(
|
||||
func,
|
||||
compilation_context,
|
||||
call.args[0],
|
||||
builder,
|
||||
local_sym_tab,
|
||||
expected_type=ir.IntType(64),
|
||||
func, compilation_context, call.args[0], builder, local_sym_tab
|
||||
)
|
||||
map_void_ptr = builder.bitcast(map_ptr, ir.PointerType())
|
||||
|
||||
@ -220,20 +215,10 @@ def bpf_map_update_elem_emitter(
|
||||
flags_arg = call.args[2] if len(call.args) > 2 else None
|
||||
|
||||
key_ptr = get_or_create_ptr_from_arg(
|
||||
func,
|
||||
compilation_context,
|
||||
key_arg,
|
||||
builder,
|
||||
local_sym_tab,
|
||||
expected_type=ir.IntType(64),
|
||||
func, compilation_context, key_arg, builder, local_sym_tab
|
||||
)
|
||||
value_ptr = get_or_create_ptr_from_arg(
|
||||
func,
|
||||
compilation_context,
|
||||
value_arg,
|
||||
builder,
|
||||
local_sym_tab,
|
||||
expected_type=ir.IntType(64),
|
||||
func, compilation_context, value_arg, builder, local_sym_tab
|
||||
)
|
||||
flags_val = get_flags_val(flags_arg, builder, local_sym_tab)
|
||||
|
||||
@ -282,12 +267,7 @@ def bpf_map_delete_elem_emitter(
|
||||
f"Map delete expects exactly one argument (key), got {len(call.args)}"
|
||||
)
|
||||
key_ptr = get_or_create_ptr_from_arg(
|
||||
func,
|
||||
compilation_context,
|
||||
call.args[0],
|
||||
builder,
|
||||
local_sym_tab,
|
||||
expected_type=ir.IntType(64),
|
||||
func, compilation_context, call.args[0], builder, local_sym_tab
|
||||
)
|
||||
map_void_ptr = builder.bitcast(map_ptr, ir.PointerType())
|
||||
|
||||
|
||||
@ -6,8 +6,6 @@ from pythonbpf.expr import (
|
||||
eval_expr,
|
||||
access_struct_field,
|
||||
)
|
||||
from pythonbpf.expr.ir_ops import deref_to_depth
|
||||
from pythonbpf.expr.type_normalization import get_base_type_and_depth
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -106,18 +104,6 @@ def get_or_create_ptr_from_arg(
|
||||
if val is None:
|
||||
raise ValueError("Failed to evaluate expression for helper arg.")
|
||||
|
||||
if expected_type and isinstance(val.type, ir.PointerType):
|
||||
_, val_depth = get_base_type_and_depth(val.type)
|
||||
_, expected_depth = get_base_type_and_depth(expected_type)
|
||||
if val_depth > expected_depth:
|
||||
val = deref_to_depth(func, builder, val, val_depth - expected_depth)
|
||||
if val is None:
|
||||
raise ValueError("Failed to dereference pointer to expected depth")
|
||||
else:
|
||||
logger.debug(
|
||||
"Expected Type not known / Not a pointer, skipping dereference"
|
||||
)
|
||||
|
||||
ptr, temp_name = compilation_context.scratch_pool.get_next_temp(
|
||||
local_sym_tab, expected_type
|
||||
)
|
||||
|
||||
@ -1,12 +1,5 @@
|
||||
from .maps import ArrayMap, HashMap, PerfEventArray, RingBuffer
|
||||
from .maps import HashMap, PerfEventArray, RingBuffer
|
||||
from .maps_pass import maps_proc
|
||||
from .map_types import BPFMapType
|
||||
|
||||
__all__ = [
|
||||
"ArrayMap",
|
||||
"HashMap",
|
||||
"PerfEventArray",
|
||||
"maps_proc",
|
||||
"RingBuffer",
|
||||
"BPFMapType",
|
||||
]
|
||||
__all__ = ["HashMap", "PerfEventArray", "maps_proc", "RingBuffer", "BPFMapType"]
|
||||
|
||||
@ -26,26 +26,6 @@ class HashMap:
|
||||
raise KeyError(f"Key {key} not found in map")
|
||||
|
||||
|
||||
class ArrayMap:
|
||||
def __init__(self, key, value, max_entries):
|
||||
self.key = key
|
||||
self.value = value
|
||||
self.max_entries = max_entries
|
||||
self.entries = {}
|
||||
|
||||
def lookup(self, key):
|
||||
return self.entries.get(key)
|
||||
|
||||
def update(self, key, value, flags=None):
|
||||
self.entries[key] = value
|
||||
|
||||
def delete(self, key):
|
||||
if key in self.entries:
|
||||
del self.entries[key]
|
||||
else:
|
||||
raise KeyError(f"Key {key} not found in map")
|
||||
|
||||
|
||||
class PerfEventArray:
|
||||
def __init__(self, key_size, value_size):
|
||||
self.key_type = key_size
|
||||
|
||||
@ -138,14 +138,6 @@ def process_hash_map(map_name, rval, compilation_context):
|
||||
return map_global
|
||||
|
||||
|
||||
@MapProcessorRegistry.register("ArrayMap")
|
||||
def process_array_map(map_name, rval, compilation_context):
|
||||
"""Document the planned BPF_ARRAY map support with an explicit failure."""
|
||||
raise NotImplementedError(
|
||||
"ArrayMap is not implemented yet; add BPF_MAP_TYPE_ARRAY metadata support"
|
||||
)
|
||||
|
||||
|
||||
@MapProcessorRegistry.register("PerfEventArray")
|
||||
def process_perf_event_map(map_name, rval, compilation_context):
|
||||
"""Process a BPF_PERF_EVENT_ARRAY map declaration"""
|
||||
@ -183,10 +175,15 @@ def process_bpf_map(func_node, compilation_context):
|
||||
|
||||
if isinstance(rval, ast.Call) and isinstance(rval.func, ast.Name):
|
||||
handler = MapProcessorRegistry.get_processor(rval.func.id)
|
||||
if handler:
|
||||
return handler(map_name, rval, compilation_context)
|
||||
else:
|
||||
logger.warning(f"Unknown map type {rval.func.id}, defaulting to HashMap")
|
||||
return process_hash_map(map_name, rval, compilation_context)
|
||||
if handler is None:
|
||||
# Raise an exception and fail the build because the
|
||||
# map carried the wrong type. A misspelled map type
|
||||
# is a program error.
|
||||
known = ", ".join(sorted(MapProcessorRegistry.known_types()))
|
||||
raise ValueError(
|
||||
f"Unknown map type '{rval.func.id}' returned by '{map_name}'. "
|
||||
f"Known map types: {known}"
|
||||
)
|
||||
return handler(map_name, rval, compilation_context)
|
||||
else:
|
||||
raise ValueError("Function under @map must return a map")
|
||||
|
||||
@ -33,3 +33,8 @@ class MapProcessorRegistry:
|
||||
def get_processor(cls, map_type_name):
|
||||
"""Get the processor function for a map type"""
|
||||
return cls._processors.get(map_type_name)
|
||||
|
||||
@classmethod
|
||||
def known_types(cls):
|
||||
"""Names of every registered map type, for error messages"""
|
||||
return list(cls._processors.keys())
|
||||
|
||||
@ -69,8 +69,16 @@ Known-broken tests are declared in `tests/test_config.toml`:
|
||||
"failing_tests/my_test.py" = {reason = "...", level = "ir"}
|
||||
```
|
||||
|
||||
- `level = "ir"` — fails during IR generation; both IR and LLC tests are marked xfail.
|
||||
- `level = "llc"` — IR generates fine but `llc` rejects it; only the LLC test is marked xfail.
|
||||
- `level = "ir"` — fails during IR generation.
|
||||
- `level = "llc"` — IR generates fine but `llc` rejects it.
|
||||
- `level = "verifier"` — IR and `llc` both succeed, but the kernel verifier rejects the object.
|
||||
|
||||
A failure at one level implies failure at every later one, so the declared level marks
|
||||
that level **and all later ones** xfail. An `"ir"` entry is xfail at all three levels; a
|
||||
`"verifier"` entry is xfail at level 3 only and must still pass levels 1 and 2.
|
||||
|
||||
Every test file runs at every level, including the ones declared here — level 3 does not
|
||||
skip declared failures, it reports them as expected ones.
|
||||
|
||||
All xfails use `strict = True`: if a test starts **passing** it shows up as **XPASS** and is treated as a test failure. This is intentional — it means the bug was fixed and the test should be promoted to `passing_tests/`.
|
||||
|
||||
@ -80,14 +88,6 @@ All xfails use `strict = True`: if a test starts **passing** it shows up as **XP
|
||||
2. Run `make test` — the file is discovered and tested automatically at all levels.
|
||||
3. If the test is expected to fail, add it to `tests/test_config.toml` instead of `passing_tests/`.
|
||||
|
||||
## Kernel selftest equivalents
|
||||
|
||||
`tests/kernel_selftest_equivalent/` contains PythonBPF versions of important
|
||||
kernel BPF selftests from `bpf-next/tools/testing/selftests/bpf`. These tests
|
||||
describe features PythonBPF should grow next. They are collected by default and
|
||||
must be listed as strict expected failures in `tests/test_config.toml` until the
|
||||
corresponding feature lands.
|
||||
|
||||
## Directory structure
|
||||
|
||||
```
|
||||
@ -104,6 +104,5 @@ tests/
|
||||
│ ├── compiler.py ← wrappers around compile_to_ir() + _run_llc()
|
||||
│ └── verifier.py ← bpftool subprocess wrapper
|
||||
├── passing_tests/ ← programs that should compile and verify cleanly
|
||||
├── failing_tests/ ← programs with known issues (declared in test_config.toml)
|
||||
└── kernel_selftest_equivalent/ ← kernel-selftest-inspired feature roadmap tests
|
||||
└── failing_tests/ ← programs with known issues (declared in test_config.toml)
|
||||
```
|
||||
|
||||
@ -16,24 +16,20 @@ Run the suite:
|
||||
"""
|
||||
|
||||
import logging
|
||||
import warnings
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.framework.bpf_test_case import level_index
|
||||
from tests.framework.collector import collect_all_test_files
|
||||
|
||||
# ── vmlinux availability ────────────────────────────────────────────────────
|
||||
|
||||
try:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", DeprecationWarning)
|
||||
import vmlinux # noqa: F401
|
||||
import vmlinux # noqa: F401
|
||||
|
||||
VMLINUX_AVAILABLE = True
|
||||
VMLINUX_SKIP_REASON = ""
|
||||
except Exception as exc:
|
||||
except ImportError:
|
||||
VMLINUX_AVAILABLE = False
|
||||
VMLINUX_SKIP_REASON = f"vmlinux.py not usable for current kernel: {exc}"
|
||||
|
||||
|
||||
# ── pytest_generate_tests: parametrize on bpf_test_file ───────────────────
|
||||
@ -69,23 +65,25 @@ def pytest_collection_modifyitems(items):
|
||||
# vmlinux skip
|
||||
if case.needs_vmlinux and not VMLINUX_AVAILABLE:
|
||||
item.add_marker(
|
||||
pytest.mark.skip(
|
||||
reason=VMLINUX_SKIP_REASON
|
||||
or "vmlinux.py not available for current kernel"
|
||||
)
|
||||
pytest.mark.skip(reason="vmlinux.py not available for current kernel")
|
||||
)
|
||||
continue
|
||||
|
||||
# xfail (strict: XPASS counts as a test failure, alerting us to fixed bugs)
|
||||
if case.is_expected_fail:
|
||||
# Level "ir" → fails at IR generation: xfail both IR and LLC tests
|
||||
# Level "llc" → IR succeeds but LLC fails: only xfail the LLC test
|
||||
is_llc_test = item.nodeid.startswith("tests/test_llc_compilation.py")
|
||||
# A failure at one level implies failure at every later one, so mark
|
||||
# this item xfail whenever the declared level is at or before it:
|
||||
# "ir" → IR, LLC and verifier
|
||||
# "llc" → LLC and verifier (IR is expected to succeed)
|
||||
# "verifier" → verifier only
|
||||
if item.nodeid.startswith("tests/test_verifier.py"):
|
||||
item_level = "verifier"
|
||||
elif item.nodeid.startswith("tests/test_llc_compilation.py"):
|
||||
item_level = "llc"
|
||||
else:
|
||||
item_level = "ir"
|
||||
|
||||
apply_xfail = (case.xfail_level == "ir") or (
|
||||
case.xfail_level == "llc" and is_llc_test
|
||||
)
|
||||
if apply_xfail:
|
||||
if level_index(case.xfail_level) <= level_index(item_level):
|
||||
item.add_marker(
|
||||
pytest.mark.xfail(
|
||||
reason=case.xfail_reason,
|
||||
|
||||
@ -1,6 +1,20 @@
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
# The three test levels, in pipeline order. A test declared as failing at one
|
||||
# level is also expected to fail at every later level: a program that cannot
|
||||
# generate IR cannot reach llc, and one that llc rejects never reaches the
|
||||
# kernel. Used by conftest to decide which items to mark xfail.
|
||||
LEVELS = ("ir", "llc", "verifier")
|
||||
|
||||
|
||||
def level_index(level: str) -> int:
|
||||
"""Position of a level in the pipeline. Unknown levels sort first ("ir")."""
|
||||
try:
|
||||
return LEVELS.index(level)
|
||||
except ValueError:
|
||||
return 0
|
||||
|
||||
|
||||
@dataclass
|
||||
class BpfTestCase:
|
||||
@ -8,7 +22,7 @@ class BpfTestCase:
|
||||
rel_path: str
|
||||
is_expected_fail: bool = False
|
||||
xfail_reason: str = ""
|
||||
xfail_level: str = "ir" # "ir" or "llc"
|
||||
xfail_level: str = "ir" # one of LEVELS
|
||||
needs_vmlinux: bool = False
|
||||
skip_reason: str = ""
|
||||
|
||||
|
||||
@ -33,7 +33,7 @@ def collect_all_test_files() -> list[BpfTestCase]:
|
||||
xfail_map: dict = config.get("xfail", {})
|
||||
|
||||
cases = []
|
||||
for subdir in ("passing_tests", "failing_tests", "kernel_selftest_equivalent"):
|
||||
for subdir in ("passing_tests", "failing_tests"):
|
||||
for py_file in sorted((TESTS_DIR / subdir).rglob("*.py")):
|
||||
rel = str(py_file.relative_to(TESTS_DIR))
|
||||
needs_vmlinux = _is_vmlinux_test(rel)
|
||||
|
||||
@ -1,35 +0,0 @@
|
||||
# Adapted from bpf-next/tools/testing/selftests/bpf/progs/test_map_ops.c
|
||||
# and bpf-next/tools/testing/selftests/bpf/progs/bpf_iter_bpf_array_map.c.
|
||||
|
||||
from ctypes import c_int32, c_uint64, c_void_p
|
||||
|
||||
from pythonbpf import bpf, bpfglobal, compile, map, section
|
||||
from pythonbpf.maps import ArrayMap
|
||||
|
||||
|
||||
@bpf
|
||||
@map
|
||||
def counters() -> ArrayMap:
|
||||
return ArrayMap(key=c_int32, value=c_uint64, max_entries=8)
|
||||
|
||||
|
||||
@bpf
|
||||
@section("tracepoint/syscalls/sys_enter_getpid")
|
||||
def array_map_lookup_update(ctx: c_void_p) -> c_int32:
|
||||
counters.update(0, 1)
|
||||
|
||||
current = counters.lookup(0)
|
||||
if current:
|
||||
next_value = current + 1
|
||||
counters.update(0, next_value)
|
||||
|
||||
return c_int32(0)
|
||||
|
||||
|
||||
@bpf
|
||||
@bpfglobal
|
||||
def LICENSE() -> str:
|
||||
return "GPL"
|
||||
|
||||
|
||||
compile()
|
||||
@ -1,48 +0,0 @@
|
||||
# Adapted from bpf-next/tools/testing/selftests/bpf/progs/test_ringbuf.c.
|
||||
|
||||
from ctypes import c_int32, c_uint64, c_void_p
|
||||
|
||||
from pythonbpf import bpf, bpfglobal, compile, map, section, struct
|
||||
from pythonbpf.helper import pid
|
||||
from pythonbpf.maps import RingBuffer
|
||||
|
||||
|
||||
@bpf
|
||||
@struct
|
||||
class sample_t:
|
||||
pid: c_uint64
|
||||
seq: c_uint64
|
||||
value: c_uint64
|
||||
|
||||
|
||||
@bpf
|
||||
@map
|
||||
def events() -> RingBuffer:
|
||||
return RingBuffer(max_entries=4096)
|
||||
|
||||
|
||||
@bpf
|
||||
@section("tracepoint/syscalls/sys_enter_getpid")
|
||||
def ringbuf_reserve_submit_discard(ctx: c_void_p) -> c_int32:
|
||||
first = events.reserve(24)
|
||||
if first:
|
||||
sample = sample_t(first)
|
||||
sample.pid = pid()
|
||||
sample.seq = 0
|
||||
sample.value = 7
|
||||
events.submit(first, 0)
|
||||
|
||||
second = events.reserve(24)
|
||||
if second:
|
||||
events.discard(second, 0)
|
||||
|
||||
return c_int32(0)
|
||||
|
||||
|
||||
@bpf
|
||||
@bpfglobal
|
||||
def LICENSE() -> str:
|
||||
return "GPL"
|
||||
|
||||
|
||||
compile()
|
||||
@ -3,7 +3,7 @@ from ctypes import c_void_p, c_int64
|
||||
|
||||
|
||||
@bpf
|
||||
@section("sometag1")
|
||||
@section("tracepoint/syscalls/sys_enter_execve")
|
||||
def sometag(ctx: c_void_p) -> c_int64:
|
||||
if 3 + 2 == 5:
|
||||
return c_int64(5)
|
||||
@ -3,7 +3,7 @@ from ctypes import c_void_p, c_int64
|
||||
|
||||
|
||||
@bpf
|
||||
@section("sometag1")
|
||||
@section("tracepoint/syscalls/sys_enter_execve")
|
||||
def sometag(ctx: c_void_p) -> c_int64:
|
||||
return c_int64(1 - 1)
|
||||
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
from pythonbpf import bpf, BPF, map, bpfglobal, section, compile, compile_to_ir
|
||||
from pythonbpf.maps import RingBuf, HashMap
|
||||
from pythonbpf.maps import RingBuffer, HashMap
|
||||
from ctypes import c_int32, c_void_p
|
||||
|
||||
|
||||
# Define a map
|
||||
@bpf
|
||||
@map
|
||||
def mymap() -> RingBuf:
|
||||
return RingBuf(max_entries=(1024))
|
||||
def mymap() -> RingBuffer:
|
||||
return RingBuffer(max_entries=4096)
|
||||
|
||||
|
||||
@bpf
|
||||
|
||||
@ -5,7 +5,7 @@ from ctypes import c_void_p, c_int64
|
||||
|
||||
|
||||
@bpf
|
||||
@section("sometag1")
|
||||
@section("tracepoint/syscalls/sys_enter_execve")
|
||||
def sometag(ctx: c_void_p) -> c_int64:
|
||||
a = 1 - 1
|
||||
return c_int64(a)
|
||||
|
||||
@ -2,15 +2,27 @@
|
||||
#
|
||||
# [xfail] — tests expected to fail.
|
||||
# key = path relative to tests/
|
||||
# value = {reason = "...", level = "ir" | "llc"}
|
||||
# level "ir" = fails during pythonbpf IR generation (exception or ERROR log)
|
||||
# level "llc" = IR generates but llc rejects it
|
||||
# value = {reason = "...", level = "ir" | "llc" | "verifier"}
|
||||
# level "ir" = fails during pythonbpf IR generation (exception or ERROR log)
|
||||
# level "llc" = IR generates but llc rejects it
|
||||
# level "verifier" = IR and llc both succeed, but the kernel verifier rejects it
|
||||
#
|
||||
# A failure at one level implies failure at every later one, so the declared
|
||||
# level marks that level and all later ones xfail.
|
||||
#
|
||||
|
||||
[xfail]
|
||||
|
||||
"failing_tests/conditionals/struct_ptr.py" = {reason = "Struct pointer used directly as boolean condition not supported", level = "ir"}
|
||||
|
||||
# Compiles cleanly; rejected by the kernel. 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 (it stays r=0) and the later
|
||||
# `iph.saddr` read fails with "invalid access to packet, off=26 size=4" /
|
||||
# "R1 offset is outside of the packet". Direct packet access needs bounds checks
|
||||
# in a form the verifier can follow.
|
||||
"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"}
|
||||
|
||||
"failing_tests/license.py" = {reason = "Missing LICENSE global produces IR that llc rejects — should be caught earlier with a clear error message", level = "llc"}
|
||||
|
||||
"failing_tests/undeclared_values.py" = {reason = "Undeclared variable used in f-string — should raise SyntaxError (correct behaviour, test documents it)", level = "ir"}
|
||||
@ -20,7 +32,3 @@
|
||||
"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"}
|
||||
|
||||
"kernel_selftest_equivalent/maps/array_map_lookup_update.py" = {reason = "ArrayMap / BPF_MAP_TYPE_ARRAY support is planned but not implemented yet", level = "ir"}
|
||||
|
||||
"kernel_selftest_equivalent/ringbuf/reserve_submit_discard.py" = {reason = "RingBuffer reserve/typed record/discard workflow is planned but not implemented yet", level = "ir"}
|
||||
|
||||
@ -24,12 +24,12 @@ from tests.framework.compiler import run_ir_generation, run_llc
|
||||
from tests.framework.verifier import verify_object
|
||||
|
||||
|
||||
def _passing_test_files():
|
||||
return [c.path for c in collect_all_test_files() if not c.is_expected_fail]
|
||||
def _verifier_test_files():
|
||||
return [c.path for c in collect_all_test_files()]
|
||||
|
||||
|
||||
def _passing_test_ids():
|
||||
return [c.rel_path for c in collect_all_test_files() if not c.is_expected_fail]
|
||||
def _verifier_test_ids():
|
||||
return [c.rel_path for c in collect_all_test_files()]
|
||||
|
||||
|
||||
def _get_rejection_reason(verifier_test_file: Path, output) -> str:
|
||||
@ -43,11 +43,16 @@ def _get_rejection_reason(verifier_test_file: Path, output) -> str:
|
||||
return errstr
|
||||
|
||||
|
||||
# Every test file runs at this level, including the ones declared in
|
||||
# test_config.toml. conftest marks those xfail, so an "ir"- or "llc"-level
|
||||
# failure is still reported as an expected failure rather than being silently
|
||||
# dropped from the level-3 run — and a "verifier"-level entry becomes possible
|
||||
# at all.
|
||||
@pytest.mark.verifier
|
||||
@pytest.mark.parametrize(
|
||||
"verifier_test_file",
|
||||
_passing_test_files(),
|
||||
ids=_passing_test_ids(),
|
||||
_verifier_test_files(),
|
||||
ids=_verifier_test_ids(),
|
||||
)
|
||||
def test_kernel_verifier(verifier_test_file: Path, tmp_path, caplog):
|
||||
"""Compile the BPF test and verify it passes the kernel verifier."""
|
||||
|
||||
@ -1,80 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
log() { echo -e "${GREEN}[release]${NC} $1"; }
|
||||
warn() { echo -e "${YELLOW}[release]${NC} $1"; }
|
||||
err() { echo -e "${RED}[release]${NC} $1"; exit 1; }
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
cd "$REPO_ROOT"
|
||||
|
||||
git diff --quiet || err "Working tree is dirty — commit or stash changes first."
|
||||
|
||||
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "none")
|
||||
log "Latest tag: $LATEST_TAG"
|
||||
|
||||
CURRENT_VERSION=$(grep -E '^version\s*=' pyproject.toml | head -1 | sed 's/version\s*=\s*"\([^"]*\)"/\1/')
|
||||
log "Current version in pyproject.toml: $CURRENT_VERSION"
|
||||
|
||||
echo ""
|
||||
read -r -p "Enter new version (e.g. 0.1.9): " NEW_VERSION
|
||||
|
||||
if [[ ! "$NEW_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||
err "Invalid version format — use X.Y.Z (e.g. 0.1.9)"
|
||||
fi
|
||||
|
||||
TAG="v${NEW_VERSION}"
|
||||
|
||||
if git rev-parse "$TAG" >/dev/null 2>&1; then
|
||||
err "Tag $TAG already exists."
|
||||
fi
|
||||
|
||||
# --- Apply version bumps across all files ---
|
||||
|
||||
sed -i "s/^version = \"$CURRENT_VERSION\"/version = \"$NEW_VERSION\"/" pyproject.toml
|
||||
sed -i "s/VERSION = \"v$CURRENT_VERSION\"/VERSION = \"v$NEW_VERSION\"/" pythonbpf/codegen.py
|
||||
sed -i "s/release = \"$CURRENT_VERSION\"/release = \"$NEW_VERSION\"/" docs/conf.py
|
||||
sed -i "s/version = \"$CURRENT_VERSION\"/version = \"$NEW_VERSION\"/" docs/conf.py
|
||||
|
||||
log "Bumped version $CURRENT_VERSION → $NEW_VERSION in:"
|
||||
log " pyproject.toml"
|
||||
log " pythonbpf/codegen.py"
|
||||
log " docs/conf.py"
|
||||
|
||||
# --- Show diff and confirm ---
|
||||
|
||||
echo ""
|
||||
log "Changes to be committed:"
|
||||
git diff --stat
|
||||
echo ""
|
||||
git diff
|
||||
|
||||
echo ""
|
||||
read -r -p "Commit these changes and create tag $TAG? [y/N]: " CONFIRM
|
||||
if [[ ! "$CONFIRM" =~ ^[Yy]$ ]]; then
|
||||
git checkout -- pyproject.toml pythonbpf/codegen.py docs/conf.py
|
||||
warn "Reverted changes. Aborted."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
git add pyproject.toml pythonbpf/codegen.py docs/conf.py
|
||||
git commit -m "Bump version to $NEW_VERSION"
|
||||
log "Committed version bump."
|
||||
|
||||
git tag "$TAG"
|
||||
log "Created tag $TAG."
|
||||
|
||||
echo ""
|
||||
read -r -p "Push commit and tag to origin? [y/N]: " PUSH
|
||||
if [[ "$PUSH" =~ ^[Yy]$ ]]; then
|
||||
git push origin HEAD
|
||||
git push origin "$TAG"
|
||||
log "Pushed commit and tag $TAG. CI will build and publish to PyPI."
|
||||
else
|
||||
warn "Push skipped. Run: git push origin HEAD && git push origin $TAG"
|
||||
fi
|
||||
Reference in New Issue
Block a user