From 73bbf00e7cd865826704381d2c6b7865c94b5f1e Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Thu, 13 Nov 2025 09:29:53 +0530 Subject: [PATCH] add tests --- .../vmlinux/assignment_handling.py | 22 +++++++++++++++++++ tests/failing_tests/vmlinux/requests.py | 9 ++++---- tests/failing_tests/vmlinux/requests2.py | 12 +++++----- 3 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 tests/failing_tests/vmlinux/assignment_handling.py diff --git a/tests/failing_tests/vmlinux/assignment_handling.py b/tests/failing_tests/vmlinux/assignment_handling.py new file mode 100644 index 0000000..5ba1a6e --- /dev/null +++ b/tests/failing_tests/vmlinux/assignment_handling.py @@ -0,0 +1,22 @@ +from vmlinux import XDP_PASS +from pythonbpf import bpf, section, bpfglobal, compile_to_ir +import logging +from ctypes import c_int64, c_void_p + + +@bpf +@section("kprobe/blk_mq_start_request") +def example(ctx: c_void_p) -> c_int64: + d = XDP_PASS # This gives an error, but + e = XDP_PASS + 0 # this does not + print(f"test1 {e} test2 {d}") + return c_int64(0) + + +@bpf +@bpfglobal +def LICENSE() -> str: + return "GPL" + + +compile_to_ir("assignment_handling.py", "assignment_handling.ll", loglevel=logging.INFO) diff --git a/tests/failing_tests/vmlinux/requests.py b/tests/failing_tests/vmlinux/requests.py index f19256b..3c5907e 100644 --- a/tests/failing_tests/vmlinux/requests.py +++ b/tests/failing_tests/vmlinux/requests.py @@ -1,15 +1,16 @@ -from vmlinux import struct_request, struct_pt_regs, XDP_PASS +from vmlinux import struct_request, struct_pt_regs from pythonbpf import bpf, section, bpfglobal, compile_to_ir import logging +from ctypes import c_int64, c_void_p @bpf @section("kprobe/blk_mq_start_request") -def example(ctx: struct_pt_regs): +def example(ctx: struct_pt_regs) -> c_int64: req = struct_request(ctx.di) c = req.__data_len - d = XDP_PASS - print(f"data length {c} and test {d}") + print(f"data length {c}") + return c_int64(0) @bpf diff --git a/tests/failing_tests/vmlinux/requests2.py b/tests/failing_tests/vmlinux/requests2.py index 0f17e30..46ccdcb 100644 --- a/tests/failing_tests/vmlinux/requests2.py +++ b/tests/failing_tests/vmlinux/requests2.py @@ -1,13 +1,15 @@ -from vmlinux import struct_kobj_type +from vmlinux import struct_request, struct_pt_regs, XDP_PASS from pythonbpf import bpf, section, bpfglobal, compile_to_ir import logging -from ctypes import c_void_p +from ctypes import c_int64 @bpf @section("kprobe/blk_mq_start_request") -def example(ctx: c_void_p): - print(f"data lengt") +def example(ctx: struct_pt_regs) -> c_int64: + req = ctx.di + print(f"data length {req}") + return c_int64(0) @bpf @@ -16,4 +18,4 @@ def LICENSE() -> str: return "GPL" -compile_to_ir("requests.py", "requests.ll", loglevel=logging.INFO) +compile_to_ir("requests2.py", "requests2.ll", loglevel=logging.INFO)