Report errors from the engine worker in a separate error description file.

Errors and findings used to share the failure description file, so they had
to coordinate on who writes it, and an error could be lost or mixed with a
finding. Now the controller passes `error_description_path` to the test
binary, and the engine worker writes the first error there, without touching
the failure description and signature of findings.

On a failed batch, the controller takes the error description and the
failure description and signature: each file is renamed to a temporary path
first, and is read and removed only if the renaming succeeds, so that
nothing written in between is lost. If there is an error description, it is
reported as a setup failure, ignoring any finding. Before starting a new
process of the test binary, the controller removes the files left by a
previous process. Test binaries that write `SETUP FAILURE: ...` to the
failure description keep working.

Note that it is still possible for the worker to leave partially written
failure/error files due to concurrent failures/errors. This would be
addressed in another CL.

Also add tests for how the engine worker reports errors.

PiperOrigin-RevId: 1026818201
8 files changed
tree: 414405d8586d0df43e848b69231d5423f8734008
  1. .github/
  2. bazel/
  3. build_defs/
  4. centipede/
  5. cmake/
  6. codelab/
  7. common/
  8. doc/
  9. domain_tests/
  10. e2e_tests/
  11. fuzztest/
  12. grammar_codegen/
  13. rust/
  14. tools/
  15. .bazelrc
  16. .bazelversion
  17. .clang-format
  18. BUILD
  19. Cargo.Bazel.lock
  20. Cargo.lock
  21. Cargo.toml
  22. CMakeLists.txt
  23. CONTRIBUTING.md
  24. LICENSE
  25. MODULE.bazel
  26. MODULE.bazel.lock
  27. README.md
README.md

FuzzTest

What is FuzzTest?

FuzzTest is a C++ testing framework for writing and executing fuzz tests, which are property-based tests executed using coverage-guided fuzzing under the hood. Fuzz tests are like regular unit tests, but more generic and more powerful. Instead of saying: “for this specific input, we expect this specific output”, we can say: “for these types of input, we expect this generic property to be true”. For example:

void MyApiAlwaysSucceedsOnPositiveIntegers(int i) {
  bool success = MyApi(i);
  EXPECT_TRUE(success);
}
FUZZ_TEST(MyApiTest, MyApiAlwaysSucceedsOnPositiveIntegers)
    .WithDomains(/*i:*/fuzztest::Positive<int>());

It is our latest fuzz testing technology and the successor of previously used fuzzing tools, such as libFuzzer. It allows you to write powerful fuzz tests more easily than with previously used fuzz targets. You can use it together with GoogleTest, or other unit testing frameworks, allowing you to write fuzz test side by side with regular unit tests, and just as easily.

It is a first-of-its-kind tool that bridges the gap between fuzzing and property-based testing, as it is both:

  1. a testing framework with a rich API (akin to property-based testing libraries), and
  2. a coverage-guided fuzzing engine (akin to AFL or libFuzzer).

Who is it for?

FuzzTest is for everyone who writes C++ code. (Currently, only C++ is supported.) Fuzz testing is a proven testing technique that has found tens of thousands of bugs. With the FuzzTest framework writing these tests becomes a breeze. Because fuzz tests are more generic, they are more powerful than regular unit tests. They can find tricky edge cases automatically for us, edge cases that most likely we would never think of.

You can write fuzz tests as easily as you write unit tests using GoogleTest for example. Simply use the FUZZ_TEST macro like you would use GoogleTest's TEST macro.

Who uses it?

At Google, FuzzTest is widely used and software engineers love it. It has replaced the old style of writing fuzz targets.

How do I use it?

To get started, read the Quickstart with Bazel or Quickstart with CMake, then take a look at the Overview and the Codelab.

Once you have a high level understanding about fuzz tests, consider reading the rest of the documentation, including the:

I need help!

If you have a question or encounter a bug, please file an issue on GitHub.