From c143739a040302033393198c3f60b75ffb5e57ba Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Thu, 16 Oct 2025 23:21:55 +0530 Subject: [PATCH] Add passing test struct_field_to_var_str for strings --- .../assign/struct_field_to_var_str.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/passing_tests/assign/struct_field_to_var_str.py diff --git a/tests/passing_tests/assign/struct_field_to_var_str.py b/tests/passing_tests/assign/struct_field_to_var_str.py new file mode 100644 index 0000000..1374b7c --- /dev/null +++ b/tests/passing_tests/assign/struct_field_to_var_str.py @@ -0,0 +1,26 @@ +from pythonbpf import bpf, struct, section, bpfglobal +from pythonbpf.helper import comm + +from ctypes import c_void_p, c_int64 + + +@bpf +@struct +class data_t: + comm: str(16) # type: ignore [valid-type] + + +@bpf +@section("tracepoint/syscalls/sys_enter_clone") +def hello(ctx: c_void_p) -> c_int64: + dataobj = data_t() + comm(dataobj.comm) + strobj = dataobj.comm + print(f"clone called by comm {strobj}") + return 0 + + +@bpf +@bpfglobal +def LICENSE() -> str: + return "GPL"