Skip to content

Commit 1847d96

Browse files
improve import and add failing test
1 parent 430617d commit 1847d96

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

pythonbpf/codegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from llvmlite import ir
33
from .license_pass import license_processing
44
from .functions_pass import func_proc
5-
from pythonbpf.maps import maps_proc
5+
from .maps import maps_proc
66
from .structs import structs_proc
77
from .globals_pass import globals_processing
88
from .debuginfo import DW_LANG_C11, DwarfBehaviorEnum
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from pythonbpf import bpf, map, section, bpfglobal, compile
2+
from pythonbpf.helpers import XDP_PASS
3+
from pythonbpf.maps import HashMap
4+
5+
from ctypes import c_void_p, c_int64
6+
7+
@bpf
8+
@map
9+
def count() -> HashMap:
10+
return HashMap(key=c_int64, value=c_int64, max_entries=1)
11+
12+
13+
@bpf
14+
@section("xdp")
15+
def hello_world(ctx: c_void_p) -> c_int64:
16+
prev = count().lookup(0)
17+
if prev:
18+
count().update(0, prev + 1)
19+
return XDP_PASS
20+
else:
21+
count().update(0, 1)
22+
23+
return XDP_PASS
24+
25+
@bpf
26+
@bpfglobal
27+
def LICENSE() -> str:
28+
return "GPL"
29+
30+
compile()

0 commit comments

Comments
 (0)