From 8658143b16b43f5ac27a4a6772f4721499a9c303 Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Wed, 1 Oct 2025 00:29:12 +0530 Subject: [PATCH] add passing tests to maps and change debug info generation location --- .github/dependabot.yml | 11 +++++++ pythonbpf/maps/maps_pass.py | 13 +++++--- tests/passing_tests/hash_map.py | 44 ++++++++++++++++++++++++++ tests/passing_tests/perf_buffer_map.py | 0 4 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 tests/passing_tests/hash_map.py create mode 100644 tests/passing_tests/perf_buffer_map.py diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..6c4b369 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +version: 2 +updates: + # Maintain dependencies for GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + groups: + actions: + patterns: + - "*" diff --git a/pythonbpf/maps/maps_pass.py b/pythonbpf/maps/maps_pass.py index 1b232e6..8e7ef1c 100644 --- a/pythonbpf/maps/maps_pass.py +++ b/pythonbpf/maps/maps_pass.py @@ -46,9 +46,6 @@ def create_bpf_map(module, map_name, map_params): map_global.section = ".maps" map_global.align = 8 - # Generate debug info for BTF - create_map_debug_info(module, map_global, map_name, map_params) - logger.info(f"Created BPF map: {map_name} with params {map_params}") return map_global @@ -130,7 +127,10 @@ def process_hash_map(map_name, rval, module): map_params["max_entries"] = const_val logger.info(f"Map parameters: {map_params}") - return create_bpf_map(module, map_name, map_params) + map_global = create_bpf_map(module, map_name, map_params) + # Generate debug info for BTF + create_map_debug_info(module, map_global, map_name, map_params) + return map_global @MapProcessorRegistry.register("PerfEventArray") @@ -152,7 +152,10 @@ def process_perf_event_map(map_name, rval, module): map_params["value_size"] = keyword.value.id logger.info(f"Map parameters: {map_params}") - return create_bpf_map(module, map_name, map_params) + map_global = create_bpf_map(module, map_name, map_params) + # Generate debug info for BTF + create_map_debug_info(module, map_global, map_name, map_params) + return map_global def process_bpf_map(func_node, module): diff --git a/tests/passing_tests/hash_map.py b/tests/passing_tests/hash_map.py new file mode 100644 index 0000000..7cb9ead --- /dev/null +++ b/tests/passing_tests/hash_map.py @@ -0,0 +1,44 @@ +from pythonbpf import bpf, map, bpfglobal, BPF, section +from pythonbpf.maps import HashMap +from pylibbpf import BpfMap +from ctypes import c_int32, c_uint64, c_void_p + + +# Define a map +@bpf +@map +def mymap() -> HashMap: + return HashMap(key=c_int32, value=c_uint64, max_entries=16) + +@bpf +@section("tracepoint/syscalls/sys_enter_clone") +def testing(ctx: c_void_p) -> c_int32: + return c_int32(0) + +@bpf +@bpfglobal +def LICENSE() -> str: + return "GPL" + +# Load program (no sections -> nothing attached, just map exists) +b = BPF() +b.load_and_attach() + +# Access the map +bpymap = BpfMap(b, mymap) + +# Insert values +bpymap.update(1, 100) +bpymap.update(2, 200) + +# Read values +print("Key 1 =", bpymap.lookup(1)) +print("Key 2 =", bpymap.lookup(2)) + +# Update again +bpymap.update(1, bpymap.lookup(1) + 50) +print("Key 1 updated =", bpymap.lookup(1)) + +# Iterate through keys +for k in bpymap.keys(): + print("Key:", k, "Value:", bpymap[k]) diff --git a/tests/passing_tests/perf_buffer_map.py b/tests/passing_tests/perf_buffer_map.py new file mode 100644 index 0000000..e69de29