Skip to content

Commit abbf177

Browse files
format chore
1 parent 7c55984 commit abbf177

File tree

11 files changed

+27
-10
lines changed

11 files changed

+27
-10
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ repos:
4141
- id: ruff
4242
args: ["--fix", "--show-fixes"]
4343
- id: ruff-format
44-
exclude: ^(docs)|^(tests)|^(examples)
44+
# exclude: ^(docs)|^(tests)|^(examples)
4545

4646
# Checking static types
4747
- repo: https://github.com/pre-commit/mirrors-mypy

examples/clone-matplotlib.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@
308308
"def hist() -> HashMap:\n",
309309
" return HashMap(key=c_int32, value=c_uint64, max_entries=4096)\n",
310310
"\n",
311+
"\n",
311312
"@bpf\n",
312313
"@section(\"tracepoint/syscalls/sys_enter_clone\")\n",
313314
"def hello(ctx: c_void_p) -> c_int64:\n",
@@ -329,6 +330,7 @@
329330
"def LICENSE() -> str:\n",
330331
" return \"GPL\"\n",
331332
"\n",
333+
"\n",
332334
"b = BPF()"
333335
]
334336
},
@@ -357,7 +359,6 @@
357359
}
358360
],
359361
"source": [
360-
"\n",
361362
"b.load_and_attach()\n",
362363
"hist = BpfMap(b, hist)\n",
363364
"print(\"Recording\")\n",

examples/kprobes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ def hello_world(ctx: c_void_p) -> c_int64:
88
print("Hello, World!")
99
return c_int64(0)
1010

11+
1112
@bpf
1213
@section("kprobe/do_unlinkat")
1314
def hello_world2(ctx: c_void_p) -> c_int64:
1415
print("Hello, World!")
1516
return c_int64(0)
1617

18+
1719
@bpf
1820
@bpfglobal
1921
def LICENSE() -> str:

examples/struct_and_perf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def hello(ctx: c_void_p) -> c_int32:
2727
dataobj.pid = pid()
2828
dataobj.ts = ktime()
2929
# dataobj.comm = strobj
30-
print(f"clone called at {dataobj.ts} by pid" f"{dataobj.pid}, comm {strobj}")
30+
print(f"clone called at {dataobj.ts} by pid{dataobj.pid}, comm {strobj}")
3131
events.output(dataobj)
3232
return c_int32(0)
3333

examples/xdp_pass.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ def hello_world(ctx: c_void_p) -> c_int64:
4040
def LICENSE() -> str:
4141
return "GPL"
4242

43+
4344
compile_to_ir("xdp_pass.py", "xdp_pass.ll")
4445
compile()

pythonbpf/vmlinux_parser/vmlinux_class_handler.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,5 @@ def identify_ctypes_type(t):
9292
elif issubclass(t, ctypes._SimpleCData):
9393
print("Scalar type")
9494
print("Base type:", t)
95-
else:
96-
print("Other ctypes type")
9795
else:
98-
print("Instance, not type")
96+
raise TypeError("Instance sent instead of Class")

tests/failing_tests/globals.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
from pythonbpf import compile, bpf, section, bpfglobal, compile_to_ir
44
from ctypes import c_void_p, c_int64, c_int32
55

6+
67
@bpf
78
@bpfglobal
89
def somevalue() -> c_int32:
910
return c_int32(42)
1011

12+
1113
@bpf
1214
@bpfglobal
1315
def somevalue2() -> c_int64:
1416
return c_int64(69)
1517

18+
1619
@bpf
1720
@bpfglobal
1821
def somevalue1() -> c_int32:
@@ -21,12 +24,14 @@ def somevalue1() -> c_int32:
2124

2225
# --- Passing examples ---
2326

27+
2428
# Simple constant return
2529
@bpf
2630
@bpfglobal
2731
def g1() -> c_int64:
2832
return c_int64(42)
2933

34+
3035
# Constructor with one constant argument
3136
@bpf
3237
@bpfglobal
@@ -62,15 +67,17 @@ def g2() -> c_int64:
6267
# def g6() -> c_int64:
6368
# return c_int64(CONST)
6469

70+
6571
# Constructor with multiple args
66-
#TODO: this is not working. should it work ?
72+
# TODO: this is not working. should it work ?
6773
@bpf
6874
@bpfglobal
6975
def g7() -> c_int64:
7076
return c_int64(1)
7177

78+
7279
# Dataclass call
73-
#TODO: fails with dataclass
80+
# TODO: fails with dataclass
7481
# @dataclass
7582
# class Point:
7683
# x: c_int64
@@ -91,6 +98,7 @@ def sometag(ctx: c_void_p) -> c_int64:
9198
print(f"{somevalue}")
9299
return c_int64(1)
93100

101+
94102
@bpf
95103
@bpfglobal
96104
def LICENSE() -> str:

tests/failing_tests/named_arg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# We cannot allocate space for the intermediate type now.
1212
# We probably need to track the ref/deref chain for each variable.
1313

14+
1415
@bpf
1516
@map
1617
def count() -> HashMap:

tests/failing_tests/undeclared_values.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pythonbpf import compile, bpf, section, bpfglobal, compile_to_ir
44
from ctypes import c_void_p, c_int64
55

6+
67
# This should not pass as somevalue is not declared at all.
78
@bpf
89
@section("tracepoint/syscalls/sys_enter_execve")
@@ -11,6 +12,7 @@ def sometag(ctx: c_void_p) -> c_int64:
1112
print(f"{somevalue}") # noqa: F821
1213
return c_int64(1)
1314

15+
1416
@bpf
1517
@bpfglobal
1618
def LICENSE() -> str:

tests/failing_tests/xdp_pass.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from pythonbpf.maps import HashMap
33
from pythonbpf.helper import XDP_PASS
44
from vmlinux import struct_xdp_md
5+
from vmlinux import struct_ring_buffer_per_cpu # noqa: F401
6+
from vmlinux import struct_xdp_buff # noqa: F401
57
from ctypes import c_int64
68

79
# Instructions to how to run this program
@@ -11,6 +13,7 @@
1113
# 4. Attach object file to any network device with something like ./check.sh xdp examples/xdp_pass.o tailscale0
1214
# 5. send traffic through the device and observe effects
1315

16+
1417
@bpf
1518
@map
1619
def count() -> HashMap:
@@ -39,5 +42,6 @@ def hello_world(ctx: struct_xdp_md) -> c_int64:
3942
def LICENSE() -> str:
4043
return "GPL"
4144

45+
4246
compile_to_ir("xdp_pass.py", "xdp_pass.ll")
4347
compile()

0 commit comments

Comments
 (0)