Skip to content

Commit 3805c5f

Browse files
tests: Add loop and AnnAssign xfail tests
- failing_tests/loops/: 8 xfail tests for for/while/break/continue/nested loops and map iteration - failing_tests/assign/annotated_assign.py: xfail for `x: c_int64 = 0` (ast.AnnAssign is not handled) - failing_tests/globals.py: now declared xfail, since the `global` statement it relied on being skipped now raises
1 parent 5d0b226 commit 3805c5f

11 files changed

Lines changed: 223 additions & 0 deletions

File tree

‎pythonbpf/functions/functions_pass.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ def process_stmt(
290290
did_return = handle_return(
291291
builder, stmt, local_sym_tab, ret_type, compilation_context
292292
)
293+
else:
294+
raise NotImplementedError(f"Unsupported statement: {type(stmt).__name__}")
293295
return did_return
294296

295297

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from pythonbpf import bpf, section, bpfglobal, compile
2+
from ctypes import c_void_p, c_int64
3+
4+
5+
@bpf
6+
@section("tracepoint/syscalls/sys_enter_execve")
7+
def hello(ctx: c_void_p) -> c_int64:
8+
total: c_int64 = 0
9+
return total
10+
11+
12+
@bpf
13+
@bpfglobal
14+
def LICENSE() -> str:
15+
return "GPL"
16+
17+
18+
compile()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from pythonbpf import bpf, section, bpfglobal, compile
2+
from ctypes import c_void_p, c_int64
3+
4+
5+
@bpf
6+
@section("tracepoint/syscalls/sys_enter_execve")
7+
def hello(ctx: c_void_p) -> c_int64:
8+
total: c_int64 = 0
9+
for i in range(10):
10+
if i == 5:
11+
break
12+
total = total + 1
13+
return total
14+
15+
16+
@bpf
17+
@bpfglobal
18+
def LICENSE() -> str:
19+
return "GPL"
20+
21+
22+
compile()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from pythonbpf import bpf, section, bpfglobal, compile
2+
from ctypes import c_void_p, c_int64
3+
4+
5+
@bpf
6+
@section("tracepoint/syscalls/sys_enter_execve")
7+
def hello(ctx: c_void_p) -> c_int64:
8+
total: c_int64 = 0
9+
for i in range(10):
10+
if i % 2 == 0:
11+
continue
12+
total = total + i
13+
return total
14+
15+
16+
@bpf
17+
@bpfglobal
18+
def LICENSE() -> str:
19+
return "GPL"
20+
21+
22+
compile()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from pythonbpf import bpf, map, bpfglobal, section, compile
2+
from pythonbpf.maps import HashMap
3+
from ctypes import c_void_p, c_int64, c_int32, c_uint64
4+
5+
6+
@bpf
7+
@map
8+
def mymap() -> HashMap:
9+
return HashMap(key=c_int32, value=c_uint64, max_entries=16)
10+
11+
12+
# Imagined sugar over the kernel's bpf_for_each_map_elem() callback helper:
13+
# iterating a map's entries directly from a `for` statement.
14+
@bpf
15+
@section("tracepoint/syscalls/sys_enter_execve")
16+
def hello(ctx: c_void_p) -> c_int64:
17+
total: c_int64 = 0
18+
for k, v in mymap.items():
19+
total = total + 1
20+
return total
21+
22+
23+
@bpf
24+
@bpfglobal
25+
def LICENSE() -> str:
26+
return "GPL"
27+
28+
29+
compile()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from pythonbpf import bpf, section, bpfglobal, compile
2+
from ctypes import c_void_p, c_int64
3+
4+
5+
@bpf
6+
@section("tracepoint/syscalls/sys_enter_execve")
7+
def hello(ctx: c_void_p) -> c_int64:
8+
total: c_int64 = 0
9+
for i in range(0, 10, 2):
10+
total = total + i
11+
return total
12+
13+
14+
@bpf
15+
@bpfglobal
16+
def LICENSE() -> str:
17+
return "GPL"
18+
19+
20+
compile()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from pythonbpf import bpf, section, bpfglobal, compile
2+
from ctypes import c_void_p, c_int64
3+
4+
5+
@bpf
6+
@section("tracepoint/syscalls/sys_enter_execve")
7+
def hello(ctx: c_void_p) -> c_int64:
8+
total: c_int64 = 0
9+
for i in range(10):
10+
total = total + 1
11+
return total
12+
13+
14+
@bpf
15+
@bpfglobal
16+
def LICENSE() -> str:
17+
return "GPL"
18+
19+
20+
compile()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from pythonbpf import bpf, section, bpfglobal, compile
2+
from ctypes import c_void_p, c_int64
3+
4+
5+
@bpf
6+
@section("tracepoint/syscalls/sys_enter_execve")
7+
def hello(ctx: c_void_p) -> c_int64:
8+
total: c_int64 = 0
9+
for i in range(3):
10+
for j in range(3):
11+
total = total + 1
12+
return total
13+
14+
15+
@bpf
16+
@bpfglobal
17+
def LICENSE() -> str:
18+
return "GPL"
19+
20+
21+
compile()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from pythonbpf import bpf, section, bpfglobal, compile
2+
from ctypes import c_void_p, c_int64
3+
4+
5+
@bpf
6+
@section("tracepoint/syscalls/sys_enter_execve")
7+
def hello(ctx: c_void_p) -> c_int64:
8+
i: c_int64 = 0
9+
while i < 10:
10+
i = i + 1
11+
return i
12+
13+
14+
@bpf
15+
@bpfglobal
16+
def LICENSE() -> str:
17+
return "GPL"
18+
19+
20+
compile()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from pythonbpf import bpf, section, bpfglobal, compile
2+
from ctypes import c_void_p, c_int64
3+
4+
5+
@bpf
6+
@section("tracepoint/syscalls/sys_enter_execve")
7+
def hello(ctx: c_void_p) -> c_int64:
8+
total: c_int64 = 0
9+
while True:
10+
total = total + 1
11+
if total == 10:
12+
break
13+
return total
14+
15+
16+
@bpf
17+
@bpfglobal
18+
def LICENSE() -> str:
19+
return "GPL"
20+
21+
22+
compile()

0 commit comments

Comments
 (0)