Skip to content

Commit 1766730

Browse files
committed
Add failing tests struct and not for conditionals
1 parent 1d6226d commit 1766730

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
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 ctypes import c_void_p, c_int64, c_uint64
3+
from pythonbpf.maps import HashMap
4+
5+
6+
@bpf
7+
@map
8+
def last() -> HashMap:
9+
return HashMap(key=c_uint64, value=c_uint64, max_entries=3)
10+
11+
12+
@bpf
13+
@section("tracepoint/syscalls/sys_enter_execve")
14+
def hello_world(ctx: c_void_p) -> c_int64:
15+
# last.update(0, 1)
16+
tsp = last.lookup(0)
17+
if not tsp:
18+
print("Hello, World!")
19+
else:
20+
print("Goodbye, World!")
21+
return
22+
23+
24+
@bpf
25+
@bpfglobal
26+
def LICENSE() -> str:
27+
return "GPL"
28+
29+
30+
compile()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from pythonbpf import bpf, struct, section, bpfglobal, compile
2+
from ctypes import c_void_p, c_int64, c_uint64
3+
4+
5+
@bpf
6+
@struct
7+
class data_t:
8+
pid: c_uint64
9+
ts: c_uint64
10+
11+
12+
@bpf
13+
@section("tracepoint/syscalls/sys_enter_execve")
14+
def hello_world(ctx: c_void_p) -> c_int64:
15+
dat = data_t()
16+
if dat.pid:
17+
print("Hello, World!")
18+
else:
19+
print("Goodbye, World!")
20+
return
21+
22+
23+
@bpf
24+
@bpfglobal
25+
def LICENSE() -> str:
26+
return "GPL"
27+
28+
29+
compile()

0 commit comments

Comments
 (0)