From 3e68d6df4f757dedd5269112a0024a6ae92c8ec5 Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Mon, 6 Oct 2025 04:57:04 +0530 Subject: [PATCH] Add passing test examples for return statements --- tests/passing_tests/return/binop_const.py | 18 +++++++++++++++++ tests/passing_tests/return/binop_var.py | 19 ++++++++++++++++++ tests/passing_tests/return/int.py | 18 +++++++++++++++++ tests/passing_tests/return/null.py | 18 +++++++++++++++++ tests/passing_tests/return/typecast_binops.py | 20 +++++++++++++++++++ tests/passing_tests/return/typecast_const.py | 18 +++++++++++++++++ tests/passing_tests/return/typecast_var.py | 19 ++++++++++++++++++ tests/passing_tests/return/var.py | 19 ++++++++++++++++++ 8 files changed, 149 insertions(+) create mode 100644 tests/passing_tests/return/binop_const.py create mode 100644 tests/passing_tests/return/binop_var.py create mode 100644 tests/passing_tests/return/int.py create mode 100644 tests/passing_tests/return/null.py create mode 100644 tests/passing_tests/return/typecast_binops.py create mode 100644 tests/passing_tests/return/typecast_const.py create mode 100644 tests/passing_tests/return/typecast_var.py create mode 100644 tests/passing_tests/return/var.py diff --git a/tests/passing_tests/return/binop_const.py b/tests/passing_tests/return/binop_const.py new file mode 100644 index 0000000..faafd1f --- /dev/null +++ b/tests/passing_tests/return/binop_const.py @@ -0,0 +1,18 @@ +from pythonbpf import bpf, section, bpfglobal, compile +from ctypes import c_void_p, c_int64 + + +@bpf +@section("tracepoint/syscalls/sys_enter_execve") +def hello_world(ctx: c_void_p) -> c_int64: + print("Hello, World!") + return 1 + 1 - 2 + + +@bpf +@bpfglobal +def LICENSE() -> str: + return "GPL" + + +compile() diff --git a/tests/passing_tests/return/binop_var.py b/tests/passing_tests/return/binop_var.py new file mode 100644 index 0000000..32b5784 --- /dev/null +++ b/tests/passing_tests/return/binop_var.py @@ -0,0 +1,19 @@ +from pythonbpf import bpf, section, bpfglobal, compile +from ctypes import c_void_p, c_int64 + + +@bpf +@section("tracepoint/syscalls/sys_enter_execve") +def hello_world(ctx: c_void_p) -> c_int64: + print("Hello, World!") + a = 2 + return a - 2 + + +@bpf +@bpfglobal +def LICENSE() -> str: + return "GPL" + + +compile() diff --git a/tests/passing_tests/return/int.py b/tests/passing_tests/return/int.py new file mode 100644 index 0000000..b20b4a0 --- /dev/null +++ b/tests/passing_tests/return/int.py @@ -0,0 +1,18 @@ +from pythonbpf import bpf, section, bpfglobal, compile +from ctypes import c_void_p, c_int64 + + +@bpf +@section("tracepoint/syscalls/sys_enter_execve") +def hello_world(ctx: c_void_p) -> c_int64: + print("Hello, World!") + return 1 + + +@bpf +@bpfglobal +def LICENSE() -> str: + return "GPL" + + +compile() diff --git a/tests/passing_tests/return/null.py b/tests/passing_tests/return/null.py new file mode 100644 index 0000000..34a1492 --- /dev/null +++ b/tests/passing_tests/return/null.py @@ -0,0 +1,18 @@ +from pythonbpf import bpf, section, bpfglobal, compile +from ctypes import c_void_p, c_int64 + + +@bpf +@section("tracepoint/syscalls/sys_enter_execve") +def hello_world(ctx: c_void_p) -> c_int64: + print("Hello, World!") + return + + +@bpf +@bpfglobal +def LICENSE() -> str: + return "GPL" + + +compile() diff --git a/tests/passing_tests/return/typecast_binops.py b/tests/passing_tests/return/typecast_binops.py new file mode 100644 index 0000000..c58ba41 --- /dev/null +++ b/tests/passing_tests/return/typecast_binops.py @@ -0,0 +1,20 @@ +from pythonbpf import bpf, section, bpfglobal, compile +from ctypes import c_void_p, c_int32 + + +@bpf +@section("tracepoint/syscalls/sys_enter_execve") +def hello_world(ctx: c_void_p) -> c_int32: + print("Hello, World!") + a = 1 # int64 + x = 1 # int64 + return c_int32(a - x) # typecast to int32 + + +@bpf +@bpfglobal +def LICENSE() -> str: + return "GPL" + + +compile() diff --git a/tests/passing_tests/return/typecast_const.py b/tests/passing_tests/return/typecast_const.py new file mode 100644 index 0000000..50cc26f --- /dev/null +++ b/tests/passing_tests/return/typecast_const.py @@ -0,0 +1,18 @@ +from pythonbpf import bpf, section, bpfglobal, compile +from ctypes import c_void_p, c_int32 + + +@bpf +@section("tracepoint/syscalls/sys_enter_execve") +def hello_world(ctx: c_void_p) -> c_int32: + print("Hello, World!") + return c_int32(1) + + +@bpf +@bpfglobal +def LICENSE() -> str: + return "GPL" + + +compile() diff --git a/tests/passing_tests/return/typecast_var.py b/tests/passing_tests/return/typecast_var.py new file mode 100644 index 0000000..1960edd --- /dev/null +++ b/tests/passing_tests/return/typecast_var.py @@ -0,0 +1,19 @@ +from pythonbpf import bpf, section, bpfglobal, compile +from ctypes import c_void_p, c_int32 + + +@bpf +@section("tracepoint/syscalls/sys_enter_execve") +def hello_world(ctx: c_void_p) -> c_int32: + print("Hello, World!") + a = 1 # int64 + return c_int32(a) # typecast to int32 + + +@bpf +@bpfglobal +def LICENSE() -> str: + return "GPL" + + +compile() diff --git a/tests/passing_tests/return/var.py b/tests/passing_tests/return/var.py new file mode 100644 index 0000000..26fb34d --- /dev/null +++ b/tests/passing_tests/return/var.py @@ -0,0 +1,19 @@ +from pythonbpf import bpf, section, bpfglobal, compile +from ctypes import c_void_p, c_int64 + + +@bpf +@section("tracepoint/syscalls/sys_enter_execve") +def hello_world(ctx: c_void_p) -> c_int64: + print("Hello, World!") + a = 1 + return a + + +@bpf +@bpfglobal +def LICENSE() -> str: + return "GPL" + + +compile()