Skip to content

Commit

Permalink
Enable FuzzTest on macOS (experimental) with documentation.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 714132065
  • Loading branch information
xinhaoyuan authored and copybara-github committed Jan 13, 2025
1 parent 87fffb7 commit 410927d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
7 changes: 6 additions & 1 deletion doc/quickstart-bazel.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ more extensive showcase of the FuzzTest framework, consider doing the

To use FuzzTest, you'll need:

* A Linux-based operating system
* A Linux-based operating system or macOS (experimental)
* [Clang](https://clang.llvm.org/)
* [Bazel](https://bazel.build/)

Expand Down Expand Up @@ -52,6 +52,8 @@ Next, create a [Bazel configuration file](https://bazel.build/run/bazelrc) named
`.bazelrc` to configure the build flags:

```
common --enable_platform_specific_config
# Force the use of Clang for all builds. FuzzTest relies on Clang for sanitizer
# coverage (https://clang.llvm.org/docs/SanitizerCoverage.html).
build --action_env=CC=clang
Expand All @@ -63,6 +65,9 @@ build --cxxopt=-std=c++17
# Show everything when running tests.
test --test_output=streamed
build:macos --macos_minimum_os=10.15
build:macos --no@fuzztest//fuzztest:use_riegeli
# To create this file, please run:
#
# bazel run @fuzztest//bazel:setup_configs > fuzztest.bazelrc
Expand Down
2 changes: 1 addition & 1 deletion e2e_tests/testdata/fuzz_tests_for_functional_testing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ FUZZ_TEST(MySuite, FailsWhenOneofFieldDoesntHaveOneofValue)
.WithDomains(Arbitrary<TestProtobuf>()
.WithOneofAlwaysSet("oneof_field")
.WithFieldUnset("oneof_u32")
.WithInt64Field("oneof_i64", fuzztest::Just(1l)));
.WithInt64Field("oneof_i64", fuzztest::Just(int64_t{1})));

void FailsIfProtobufEnumEqualsLabel4(TestProtobuf::Enum e) {
if (e == TestProtobuf::Enum::TestProtobuf_Enum_Label4) {
Expand Down
17 changes: 12 additions & 5 deletions fuzztest/internal/coverage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,16 @@ void ExecutionCoverage::UpdateMaxStack(uintptr_t PC) {
}
}

// Coverage only available in Clang, but only for Linux.
// iOS and Windows and Android might not have what we need.
#if defined(__clang__) && defined(__linux__) && !defined(__ANDROID__)
// Coverage only available in Clang, but only for Linux and macOS.
// Windows and Android might not have what we need.
#if /* Supported compilers */ \
defined(__clang__) && \
(/* Supported platforms */ \
(defined(__linux__) && !defined(__ANDROID__)) || defined(__APPLE__))
#define FUZZTEST_COVERAGE_IS_AVAILABLE
#endif

#ifdef FUZZTEST_COVERAGE_IS_AVAILABLE
namespace {
// Use clang's vector extensions. This way it will implement with whatever the
// platform supports.
Expand Down Expand Up @@ -315,7 +322,7 @@ bool CorpusCoverage::Update(ExecutionCoverage* execution_coverage) {
return new_coverage || execution_coverage->NewCoverageFound();
}

#else // __clang__ && __linux__
#else // FUZZTEST_COVERAGE_IS_AVAILABLE

// On other compilers we just need it to build, but we know we don't have any
// instrumentation.
Expand All @@ -326,7 +333,7 @@ bool CorpusCoverage::Update(ExecutionCoverage* execution_coverage) {
return false;
}

#endif // __clang__ && __linux__
#endif // FUZZTEST_COVERAGE_IS_AVAILABLE

} // namespace fuzztest::internal

Expand Down
6 changes: 3 additions & 3 deletions fuzztest/internal/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ void Runtime::OnTestIterationEnd() {
watchdog_spinlock_.clear();
}

#if defined(__linux__)
#if defined(__linux__) || defined(__APPLE__)

struct OldSignalHandler {
int signum;
Expand Down Expand Up @@ -554,14 +554,14 @@ void Runtime::PrintReportOnDefaultSink() const {
PrintReport(&signal_out_sink);
}

#else // __linux__
#else // __linux__ || __APPLE__
// TODO(sbenzaquen): We should still install signal handlers in other systems.
void InstallSignalHandlers(FILE* out) {}

void Runtime::PrintFinalStatsOnDefaultSink() const {}

void Runtime::PrintReportOnDefaultSink() const {}
#endif // __linux__
#endif // __linux__ || __APPLE__

using corpus_type = GenericDomainCorpusType;

Expand Down

0 comments on commit 410927d

Please sign in to comment.