Skip to content

Commit 7d91f88

Browse files
add failing tests
1 parent 44b95b6 commit 7d91f88

File tree

6 files changed

+68
-6
lines changed

6 files changed

+68
-6
lines changed

TODO.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
## Short term
22

33
- Implement enough functionality to port the BCC tutorial examples in PythonBPF
4-
4+
- Static Typing
5+
- Add all maps
6+
- XDP support in pylibbpf
7+
- ringbuf support
8+
- recursive expression resolution
59

610
## Long term
711

pythonbpf/codegen.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,24 @@ def compile_to_ir(filename: str, output: str):
108108
return output
109109

110110

111-
def compile():
111+
def compile() -> bool:
112112
# Look one level up the stack to the caller of this function
113113
caller_frame = inspect.stack()[1]
114114
caller_file = Path(caller_frame.filename).resolve()
115115

116116
ll_file = Path("/tmp") / caller_file.with_suffix(".ll").name
117117
o_file = caller_file.with_suffix(".o")
118118

119-
compile_to_ir(str(caller_file), str(ll_file))
119+
success = True
120+
success = compile_to_ir(str(caller_file), str(ll_file)) and success
120121

121-
subprocess.run([
122+
success = subprocess.run([
122123
"llc", "-march=bpf", "-filetype=obj", "-O2",
123124
str(ll_file), "-o", str(o_file)
124-
], check=True)
125+
], check=True) and success
125126

126-
print(f"Object written to {o_file}, {ll_file} can be removed")
127+
print(f"Object written to {o_file}")
128+
return success
127129

128130

129131
def BPF() -> BpfProgram:

tests/failing_tests/binops.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from pythonbpf import compile, bpf, section, bpfglobal
2+
from ctypes import c_void_p, c_int64
3+
4+
@bpf
5+
@section("sometag1")
6+
def sometag(ctx: c_void_p) -> c_int64:
7+
a = 1 + 2 + 1
8+
return c_int64(0)
9+
10+
@bpf
11+
@bpfglobal
12+
def LICENSE() -> str:
13+
return "GPL"
14+
15+
compile()

tests/failing_tests/if.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from pythonbpf import compile, bpf, section, bpfglobal
2+
from ctypes import c_void_p, c_int64
3+
4+
@bpf
5+
@section("sometag1")
6+
def sometag(ctx: c_void_p) -> c_int64:
7+
if 3 + 2 == 5:
8+
return c_int64(5)
9+
return c_int64(0)
10+
11+
@bpf
12+
@bpfglobal
13+
def LICENSE() -> str:
14+
return "GPL"
15+
16+
compile()

tests/failing_tests/license.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from pythonbpf import compile, bpf, section, bpfglobal
2+
from ctypes import c_void_p, c_int64
3+
4+
# FAILS WHEN THERE IS NO LICENSE. which is wrong.
5+
@bpf
6+
@section("sometag1")
7+
def sometag(ctx: c_void_p) -> c_int64:
8+
a = 1 + 2
9+
return c_int64(0)
10+
11+
compile()

tests/failing_tests/return.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from pythonbpf import compile, bpf, section, bpfglobal
2+
from ctypes import c_void_p, c_int64
3+
4+
@bpf
5+
@section("sometag1")
6+
def sometag(ctx: c_void_p) -> c_int64:
7+
return c_int64(1 - 1)
8+
9+
@bpf
10+
@bpfglobal
11+
def LICENSE() -> str:
12+
return "GPL"
13+
14+
compile()

0 commit comments

Comments
 (0)