Lines Matching +full:unit +full:- +full:tests
1 .. _module-pw_fuzzer-guides-using_fuzztest:
6 .. pigweed-module-subpage::
13 .. _module-pw_fuzzer-guides-using_fuzztest-toolchain:
15 ----------------------------------------
17 ----------------------------------------
26 * :ref:`module-pw_third_party_abseil_cpp-using_upstream`
27 * :ref:`module-pw_third_party_fuzztest-using_upstream`
28 * :ref:`module-pw_third_party_googletest-using_upstream`
30 .. tab-set::
32 .. tab-item:: GN
39 .. code-block::
54 .. tab-item:: CMake
60 and set the unit test backend to use FuzzTest.
64 .. code-block::
73 # before any fuzz tests.
77 ``-DFUZZTEST_FUZZING_MODE`` flag to ``cmake`` when building.
79 .. tab-item:: Bazel
82 Include Abseil-C++ and GoogleTest in your ``WORKSPACE`` file. For example:
84 .. code-block::
89 strip_prefix = "abseil-cpp-20240116.0",
90 …url = "https://github.com/abseil/abseil-cpp/releases/download/20240116.0/abseil-cpp-20240116.0.tar…
102 .. code-block::
105 try-import %workspace%/path/to/pigweed/pw_fuzzer/fuzztest.bazelrc
107 ----------------------------------------
108 Step 1: Write a unit test for the target
109 ----------------------------------------
115 Once identified, it is useful to start from a unit test. You may already have a
116 unit test writtern, but if not it is likely still be helpful to write one first.
117 Many developers are more familiar with writing unit tests, and there are
132 :start-after: [pwfuzzer_examples_fuzztest-metrics_h]
133 :end-before: [pwfuzzer_examples_fuzztest-metrics_h]
135 Unit tests for this class might attempt to deserialize previously serialized
141 :start-after: [pwfuzzer_examples_fuzztest-metrics_unittest]
142 :end-before: [pwfuzzer_examples_fuzztest-metrics_unittest]
144 --------------------------------------------
145 Step 2: Convert your unit test to a function
146 --------------------------------------------
148 Examine your unit tests and identify any places you have fixed values that could
149 vary. Turn your unit test into a function that takes those values as parameters.
150 Since fuzzing may not occur on all targets, you should preserve your unit test
156 :start-after: [pwfuzzer_examples_fuzztest-metrics_fuzztest1]
157 :end-before: [pwfuzzer_examples_fuzztest-metrics_fuzztest1]
162 :start-after: [pwfuzzer_examples_fuzztest-metrics_fuzztest3]
163 :end-before: [pwfuzzer_examples_fuzztest-metrics_fuzztest3]
167 to make similar modifications to your unit tests if constraints on parameters
172 --------------------------------------------
174 --------------------------------------------
184 :start-after: [pwfuzzer_examples_fuzztest-metrics_fuzztest2]
185 :end-before: [pwfuzzer_examples_fuzztest-metrics_fuzztest2]
190 :start-after: [pwfuzzer_examples_fuzztest-metrics_fuzztest4]
191 :end-before: [pwfuzzer_examples_fuzztest-metrics_fuzztest4]
196 the comments of the examples, it is recommended to include a unit test with the
207 * Refer to the `Test Fixtures`_ reference for how to create fuzz tests from unit
208 tests that use GoogleTest fixtures.
210 ------------------------------------
212 ------------------------------------
213 Next, indicate that the unit test includes one or more fuzz tests.
215 .. tab-set::
217 .. tab-item:: GN
227 :start-after: [pwfuzzer_examples_fuzztest-gn]
228 :end-before: [pwfuzzer_examples_fuzztest-gn]
230 .. tab-item:: CMake
233 Unit tests can support fuzz tests by simply adding a dependency on
240 :start-after: [pwfuzzer_examples_fuzztest-cmake]
241 :end-before: [pwfuzzer_examples_fuzztest-cmake]
243 .. tab-item:: Bazel
246 Unit tests can support fuzz tests by simply adding a dependency on
253 :start-after: [pwfuzzer_examples_fuzztest-bazel]
254 :end-before: [pwfuzzer_examples_fuzztest-bazel]
256 ------------------------
258 ------------------------
259 .. tab-set::
261 .. tab-item:: GN
265 :ref:`fuzzing toolchain<module-pw_fuzzer-guides-using_fuzztest-toolchain>`.
267 Pigweed includes a ``//:fuzzers`` target that builds all tests, including
269 similar top-level to your project. For example:
271 .. code-block::
277 .. tab-item:: CMake
283 .. code-block::
286 -Ddir_pw_third_party_fuzztest=path/to/fuzztest \
287 -Ddir_pw_third_party_googletest=path/to/googletest \
288 -Dpw_unit_test_BACKEND=pw_third_party.fuzztest
291 .. tab-item:: Bazel
294 By default, ``bazel`` will simply omit the fuzz tests and build unit
295 tests. To build these tests as fuzz tests, specify the ``fuzztest``
298 .. code-block:: console
300 $ bazel build //... --config=fuzztest
302 ----------------------------------
304 ----------------------------------
305 .. TODO: b/281138993 - Add tooling to make it easier to find and run fuzzers.
307 .. tab-set::
309 .. tab-item:: GN
312 When building. Most toolchains will simply omit the fuzz tests and build
313 and run unit tests. A
314 :ref:`fuzzing toolchain<module-pw_fuzzer-guides-using_fuzztest-toolchain>`
318 If you used the top-level ``//:fuzzers`` described in the previous
322 .. code-block:: console
331 .. code-block:: console
334 > --fuzz=MetricsTest.Roundtrip
338 .. tab-item:: CMake
349 .. code-block:: console
351 $ build/my_module/metrics_test --fuzz=MetricsTest.Roundtrip
353 .. tab-item:: Bazel
356 By default, ``bazel`` will simply omit the fuzz tests and build and run
357 unit tests. To build these tests as fuzz tests, specify the "fuzztest"
360 .. code-block:: console
362 $ bazel test //... --config=fuzztest
364 This will build the tests as fuzz tests, but only run them for a limited
370 .. code-block:: console
372 $ bazel run //my_module:metrics_test --config=fuzztest \
373 > --fuzz=MetricsTest.Roundtrip
377 .. code-block::
382 [----------] Global test environment set-up.
383 [----------] 1 test from MetricsTest
391 .. TODO: b/282560789 - Add guides/improve_fuzzers.rst
392 .. TODO: b/281139237 - Add guides/continuous_fuzzing.rst
393 .. ----------
395 .. ----------
402 .. _FuzzTest Domain Reference: https://github.com/google/fuzztest/blob/main/doc/domains-reference.md
403 .. _FuzzTest Use Cases: https://github.com/google/fuzztest/blob/main/doc/use-cases.md
406 .. _The FUZZ_TEST Macro: https://github.com/google/fuzztest/blob/main/doc/fuzz-test-macro.md
408 .. _seeds: https://github.com/google/fuzztest/blob/main/doc/fuzz-test-macro.md#initial-seeds