diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index cbca4ae41e..60aaf51cd9 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -157,7 +157,9 @@ jobs: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v2 - 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: strategy: diff --git a/bindings/pylibafl/test.py b/bindings/pylibafl/test.py index 01e72f7489..ecfe35ec90 100644 --- a/bindings/pylibafl/test.py +++ b/bindings/pylibafl/test.py @@ -1,5 +1,8 @@ from pylibafl.libafl import * import ctypes +import platform + +MAP_SIZE = 4096 class FooObserver(BaseObserver): @@ -33,11 +36,16 @@ class FooExecutor(BaseExecutor): 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() @@ -69,7 +77,12 @@ mgr = SimpleEventManager(monitor.as_monitor()) def harness(buf) -> ExitKind: + """ + The harness fn that the fuzzer will execute in a loop + """ # print(buf) + + # set the observer map byte from python m[0] = 1 if len(buf) > 0 and buf[0] == ord("a"): 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") +print("Starting to fuzz from python!") + fuzzer.fuzz_loop(executor.as_executor(), state, mgr.as_manager(), stage_tuple_list) diff --git a/bindings/pylibafl/test.sh b/bindings/pylibafl/test.sh new file mode 100755 index 0000000000..720488b14c --- /dev/null +++ b/bindings/pylibafl/test.sh @@ -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 +