mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
add passing tests to maps and change debug info generation location
This commit is contained in:
11
.github/dependabot.yml
vendored
Normal file
11
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
# Maintain dependencies for GitHub Actions
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
groups:
|
||||||
|
actions:
|
||||||
|
patterns:
|
||||||
|
- "*"
|
||||||
@ -46,9 +46,6 @@ def create_bpf_map(module, map_name, map_params):
|
|||||||
map_global.section = ".maps"
|
map_global.section = ".maps"
|
||||||
map_global.align = 8
|
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}")
|
logger.info(f"Created BPF map: {map_name} with params {map_params}")
|
||||||
return map_global
|
return map_global
|
||||||
|
|
||||||
@ -130,7 +127,10 @@ def process_hash_map(map_name, rval, module):
|
|||||||
map_params["max_entries"] = const_val
|
map_params["max_entries"] = const_val
|
||||||
|
|
||||||
logger.info(f"Map parameters: {map_params}")
|
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")
|
@MapProcessorRegistry.register("PerfEventArray")
|
||||||
@ -152,7 +152,10 @@ def process_perf_event_map(map_name, rval, module):
|
|||||||
map_params["value_size"] = keyword.value.id
|
map_params["value_size"] = keyword.value.id
|
||||||
|
|
||||||
logger.info(f"Map parameters: {map_params}")
|
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):
|
def process_bpf_map(func_node, module):
|
||||||
|
|||||||
44
tests/passing_tests/hash_map.py
Normal file
44
tests/passing_tests/hash_map.py
Normal file
@ -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])
|
||||||
0
tests/passing_tests/perf_buffer_map.py
Normal file
0
tests/passing_tests/perf_buffer_map.py
Normal file
Reference in New Issue
Block a user