Python CI (#1024)
* Python CI * fix testcase * fix yml * Fixing test * format python * cleanup
This commit is contained in:
parent
fc8c92514f
commit
d73fb92ddf
4
.github/workflows/build_and_test.yml
vendored
4
.github/workflows/build_and_test.yml
vendored
@ -157,7 +157,9 @@ jobs:
|
|||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- name: Run a maturin build
|
- name: Run a maturin build
|
||||||
run: cd ./bindings/pylibafl && maturin build
|
run: cd ./bindings/pylibafl && python3 -m venv .env && . .env/bin/activate && maturin develop && ./test.sh
|
||||||
|
- name: Run python test
|
||||||
|
run: . ./bindings/pylibafl/.env/bin/activate && cd ./fuzzers/baby_fuzzer && python3 baby_fuzzer.py | grep "Bye"
|
||||||
|
|
||||||
fuzzers:
|
fuzzers:
|
||||||
strategy:
|
strategy:
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
from pylibafl.libafl import *
|
from pylibafl.libafl import *
|
||||||
import ctypes
|
import ctypes
|
||||||
|
import platform
|
||||||
|
|
||||||
|
MAP_SIZE = 4096
|
||||||
|
|
||||||
|
|
||||||
class FooObserver(BaseObserver):
|
class FooObserver(BaseObserver):
|
||||||
@ -33,11 +36,16 @@ class FooExecutor(BaseExecutor):
|
|||||||
return (self.h)(input)
|
return (self.h)(input)
|
||||||
|
|
||||||
|
|
||||||
libc = ctypes.cdll.LoadLibrary("libc.so.6")
|
if platform.system() == "Darwin":
|
||||||
|
libc = ctypes.cdll.LoadLibrary("libc.dylib")
|
||||||
|
else:
|
||||||
|
libc = ctypes.cdll.LoadLibrary("libc.so.6")
|
||||||
|
|
||||||
area_ptr = libc.calloc(1, 4096)
|
# Get a buffer to use for our map observer
|
||||||
|
libc.calloc.restype = ctypes.c_void_p
|
||||||
|
area_ptr = libc.calloc(1, MAP_SIZE)
|
||||||
|
|
||||||
observer = StdMapObserverI8("mymap", area_ptr, 4096)
|
observer = StdMapObserverI8("mymap", area_ptr, MAP_SIZE)
|
||||||
|
|
||||||
m = observer.as_map_observer()
|
m = observer.as_map_observer()
|
||||||
|
|
||||||
@ -69,7 +77,12 @@ mgr = SimpleEventManager(monitor.as_monitor())
|
|||||||
|
|
||||||
|
|
||||||
def harness(buf) -> ExitKind:
|
def harness(buf) -> ExitKind:
|
||||||
|
"""
|
||||||
|
The harness fn that the fuzzer will execute in a loop
|
||||||
|
"""
|
||||||
# print(buf)
|
# print(buf)
|
||||||
|
|
||||||
|
# set the observer map byte from python
|
||||||
m[0] = 1
|
m[0] = 1
|
||||||
if len(buf) > 0 and buf[0] == ord("a"):
|
if len(buf) > 0 and buf[0] == ord("a"):
|
||||||
m[1] = 1
|
m[1] = 1
|
||||||
@ -91,4 +104,6 @@ stage_tuple_list = StagesTuple([stage.as_stage()])
|
|||||||
|
|
||||||
fuzzer.add_input(state, executor.as_executor(), mgr.as_manager(), b"\0\0")
|
fuzzer.add_input(state, executor.as_executor(), mgr.as_manager(), b"\0\0")
|
||||||
|
|
||||||
|
print("Starting to fuzz from python!")
|
||||||
|
|
||||||
fuzzer.fuzz_loop(executor.as_executor(), state, mgr.as_manager(), stage_tuple_list)
|
fuzzer.fuzz_loop(executor.as_executor(), state, mgr.as_manager(), stage_tuple_list)
|
||||||
|
11
bindings/pylibafl/test.sh
Executable file
11
bindings/pylibafl/test.sh
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
timeout 10 python3 ./test.py
|
||||||
|
export exit_code=$?
|
||||||
|
if [ $exit_code -eq 124 ]; then
|
||||||
|
# 124 = timeout happened. All good.
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
exit $exit_code
|
||||||
|
fi
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user