Skip to content

Commit 8658143

Browse files
add passing tests to maps and change debug info generation location
1 parent 475e07c commit 8658143

File tree

4 files changed

+63
-5
lines changed

4 files changed

+63
-5
lines changed

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 2
2+
updates:
3+
# Maintain dependencies for GitHub Actions
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
groups:
9+
actions:
10+
patterns:
11+
- "*"

pythonbpf/maps/maps_pass.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ def create_bpf_map(module, map_name, map_params):
4646
map_global.section = ".maps"
4747
map_global.align = 8
4848

49-
# Generate debug info for BTF
50-
create_map_debug_info(module, map_global, map_name, map_params)
51-
5249
logger.info(f"Created BPF map: {map_name} with params {map_params}")
5350
return map_global
5451

@@ -130,7 +127,10 @@ def process_hash_map(map_name, rval, module):
130127
map_params["max_entries"] = const_val
131128

132129
logger.info(f"Map parameters: {map_params}")
133-
return create_bpf_map(module, map_name, map_params)
130+
map_global = create_bpf_map(module, map_name, map_params)
131+
# Generate debug info for BTF
132+
create_map_debug_info(module, map_global, map_name, map_params)
133+
return map_global
134134

135135

136136
@MapProcessorRegistry.register("PerfEventArray")
@@ -152,7 +152,10 @@ def process_perf_event_map(map_name, rval, module):
152152
map_params["value_size"] = keyword.value.id
153153

154154
logger.info(f"Map parameters: {map_params}")
155-
return create_bpf_map(module, map_name, map_params)
155+
map_global = create_bpf_map(module, map_name, map_params)
156+
# Generate debug info for BTF
157+
create_map_debug_info(module, map_global, map_name, map_params)
158+
return map_global
156159

157160

158161
def process_bpf_map(func_node, module):

tests/passing_tests/hash_map.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from pythonbpf import bpf, map, bpfglobal, BPF, section
2+
from pythonbpf.maps import HashMap
3+
from pylibbpf import BpfMap
4+
from ctypes import c_int32, c_uint64, c_void_p
5+
6+
7+
# Define a map
8+
@bpf
9+
@map
10+
def mymap() -> HashMap:
11+
return HashMap(key=c_int32, value=c_uint64, max_entries=16)
12+
13+
@bpf
14+
@section("tracepoint/syscalls/sys_enter_clone")
15+
def testing(ctx: c_void_p) -> c_int32:
16+
return c_int32(0)
17+
18+
@bpf
19+
@bpfglobal
20+
def LICENSE() -> str:
21+
return "GPL"
22+
23+
# Load program (no sections -> nothing attached, just map exists)
24+
b = BPF()
25+
b.load_and_attach()
26+
27+
# Access the map
28+
bpymap = BpfMap(b, mymap)
29+
30+
# Insert values
31+
bpymap.update(1, 100)
32+
bpymap.update(2, 200)
33+
34+
# Read values
35+
print("Key 1 =", bpymap.lookup(1))
36+
print("Key 2 =", bpymap.lookup(2))
37+
38+
# Update again
39+
bpymap.update(1, bpymap.lookup(1) + 50)
40+
print("Key 1 updated =", bpymap.lookup(1))
41+
42+
# Iterate through keys
43+
for k in bpymap.keys():
44+
print("Key:", k, "Value:", bpymap[k])

tests/passing_tests/perf_buffer_map.py

Whitespace-only changes.

0 commit comments

Comments
 (0)