Skip to content

Commit 3e68d6d

Browse files
committed
Add passing test examples for return statements
1 parent b75dc82 commit 3e68d6d

File tree

8 files changed

+149
-0
lines changed

8 files changed

+149
-0
lines changed
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_world(ctx: c_void_p) -> c_int64:
8+
print("Hello, World!")
9+
return 1 + 1 - 2
10+
11+
12+
@bpf
13+
@bpfglobal
14+
def LICENSE() -> str:
15+
return "GPL"
16+
17+
18+
compile()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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_world(ctx: c_void_p) -> c_int64:
8+
print("Hello, World!")
9+
a = 2
10+
return a - 2
11+
12+
13+
@bpf
14+
@bpfglobal
15+
def LICENSE() -> str:
16+
return "GPL"
17+
18+
19+
compile()

tests/passing_tests/return/int.py

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_world(ctx: c_void_p) -> c_int64:
8+
print("Hello, World!")
9+
return 1
10+
11+
12+
@bpf
13+
@bpfglobal
14+
def LICENSE() -> str:
15+
return "GPL"
16+
17+
18+
compile()

tests/passing_tests/return/null.py

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_world(ctx: c_void_p) -> c_int64:
8+
print("Hello, World!")
9+
return
10+
11+
12+
@bpf
13+
@bpfglobal
14+
def LICENSE() -> str:
15+
return "GPL"
16+
17+
18+
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_int32
3+
4+
5+
@bpf
6+
@section("tracepoint/syscalls/sys_enter_execve")
7+
def hello_world(ctx: c_void_p) -> c_int32:
8+
print("Hello, World!")
9+
a = 1 # int64
10+
x = 1 # int64
11+
return c_int32(a - x) # typecast to int32
12+
13+
14+
@bpf
15+
@bpfglobal
16+
def LICENSE() -> str:
17+
return "GPL"
18+
19+
20+
compile()
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_int32
3+
4+
5+
@bpf
6+
@section("tracepoint/syscalls/sys_enter_execve")
7+
def hello_world(ctx: c_void_p) -> c_int32:
8+
print("Hello, World!")
9+
return c_int32(1)
10+
11+
12+
@bpf
13+
@bpfglobal
14+
def LICENSE() -> str:
15+
return "GPL"
16+
17+
18+
compile()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from pythonbpf import bpf, section, bpfglobal, compile
2+
from ctypes import c_void_p, c_int32
3+
4+
5+
@bpf
6+
@section("tracepoint/syscalls/sys_enter_execve")
7+
def hello_world(ctx: c_void_p) -> c_int32:
8+
print("Hello, World!")
9+
a = 1 # int64
10+
return c_int32(a) # typecast to int32
11+
12+
13+
@bpf
14+
@bpfglobal
15+
def LICENSE() -> str:
16+
return "GPL"
17+
18+
19+
compile()

tests/passing_tests/return/var.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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_world(ctx: c_void_p) -> c_int64:
8+
print("Hello, World!")
9+
a = 1
10+
return a
11+
12+
13+
@bpf
14+
@bpfglobal
15+
def LICENSE() -> str:
16+
return "GPL"
17+
18+
19+
compile()

0 commit comments

Comments
 (0)