You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We think property-based testing is great, but sometimes you might want to point a traditional fuzzer at your code, such as `python-afl <https://github.com/jwilk/python-afl>`__ or Google's :pypi:`atheris` (which instruments both Python and native extensions).
5
5
6
-
If you're looking to fuzz property-based tests, `HypoFuzz <https://hypofuzz.com/>`_ is a coverage-guided fuzzer built for Hypothesis.
6
+
You might also want to use Hypothesis strategies to describe your input data, and our world-class shrinking and observability tools to wrangle the results. That's exactly what this how-to guide is about!
7
7
8
-
In a standard Hypothesis test run, Hypothesis is responsible for generating each test case. However, you might instead want to point a traditional fuzzer at your code, such as `python-afl <https://github.com/jwilk/python-afl>`__ or Google's :pypi:`atheris` (which instruments both Python and native extensions).
8
+
.. note::
9
+
10
+
This page is about writing traditional 'fuzz harnesses' for an external fuzzer, using parts of Hypothesis.
11
+
If you already have Hypothesis tests and want to fuzz them, we strongly recommend the purpose-built `HypoFuzz <https://hypofuzz.com/>`_.
9
12
10
13
In order to support this workflow, Hypothesis exposes the |fuzz_one_input| method. |fuzz_one_input| takes a bytestring, parses it into a test case, and executes the corresponding test once. This means you can treat each of your Hypothesis tests as a traditional fuzz target, by pointing the fuzzer at |fuzz_one_input|.
11
14
@@ -27,10 +30,10 @@ Note that |fuzz_one_input| bypasses the standard test lifecycle. In a standard t
27
30
28
31
See the documentation of |fuzz_one_input| for details of how it interacts with other features of Hypothesis, such as |@settings|.
29
32
30
-
Using Atheris with |fuzz_one_input|
31
-
-----------------------------------
33
+
Worked example: using Atheris
34
+
-----------------------------
32
35
33
-
Here is an example that uses the `Atheris <https://github.com/google/atheris>`__ coverage-guided fuzzer (which is built on top of `libFuzzer <https://llvm.org/docs/LibFuzzer.html>`_) with |fuzz_one_input|:
36
+
Here is an example that uses |fuzz_one_input| with the `Atheris <https://github.com/google/atheris>`__ coverage-guided fuzzer (which is built on top of `libFuzzer <https://llvm.org/docs/LibFuzzer.html>`_):
34
37
35
38
.. code-block:: python
36
39
@@ -41,28 +44,18 @@ Here is an example that uses the `Atheris <https://github.com/google/atheris>`__
You may also want to use ``atheris.instrument_all`` or ``atheris.instrument_imports`` in order to add coverage instrumentation to Atheris. For example, to instrument the ``json`` module for coverage:
55
-
56
-
57
-
.. code-block:: python
58
-
59
-
...
60
-
61
-
import atheris
62
-
63
-
with atheris.instrument_imports():
64
-
import json # fmt: off
65
-
66
-
...
59
+
Generating valid JSON objects based only on Atheris' ``FuzzDataProvider`` interface would be considerably more difficult.
67
60
68
-
See the `Atheris <https://github.com/google/atheris>`__ documentation for full details.
61
+
You may also want to use ``atheris.instrument_all`` or ``atheris.instrument_imports`` in order to add coverage instrumentation to Atheris. See the `Atheris <https://github.com/google/atheris>`__ documentation for full details.
0 commit comments