Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions bazel/setup_configs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ cat <<EOF
build:asan --linkopt=-fsanitize=address
build:asan --copt=-fsanitize=address

# We rely on the following flag instead of the compiler provided
# __has_feature(address_sanitizer) to know that we have an ASAN build even in
# the uninstrumented runtime.
build:asan --copt=-DADDRESS_SANITIZER

EOF

cat <<EOF
Expand Down
2 changes: 2 additions & 0 deletions centipede/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,7 @@ cc_test(
deps = [
":rusage_stats",
":thread_pool",
"@abseil-cpp//absl/base:config",
"@abseil-cpp//absl/base:nullability",
"@abseil-cpp//absl/flags:flag",
"@abseil-cpp//absl/synchronization",
Expand Down Expand Up @@ -1467,6 +1468,7 @@ cc_test(
deps = [
":rusage_profiler",
":rusage_stats",
"@abseil-cpp//absl/base:config",
"@abseil-cpp//absl/flags:flag",
"@abseil-cpp//absl/time",
"@com_google_fuzztest//common:logging",
Expand Down
13 changes: 8 additions & 5 deletions centipede/rusage_profiler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <string_view>

#include "gtest/gtest.h"
#include "absl/base/config.h"
#include "absl/flags/flag.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
Expand Down Expand Up @@ -106,7 +107,7 @@ TEST(RUsageProfilerTest, TimelapseSnapshots) {
// and skews the test's memory measurements. 2) The test allocates large
// memory blocks to fight small number volatility of the system allocator, but
// MSAN's custom allocator can't cope and intermittently OOMs.
#if !defined(MEMORY_SANITIZER)
#if !defined(ABSL_HAVE_MEMORY_SANITIZER)
// Compare RUsageProfiler's manually taken snapshots against raw RUsageTiming
// and RUsageMemory numbers acquired approximately at the same time.
// "Approximately the same" is still not *the same*, so some discrepancies are
Expand Down Expand Up @@ -168,8 +169,9 @@ TEST(RUsageProfilerTest, ValidateManualSnapshots) {
// well as the delta timing partially determined by it, from validation.
// 2) All *SANs slow down execution, so skip timing checks under them.
// However, still run RUsageProfiler under them to catch any respective bugs.
#if !defined(MEMORY_SANITIZER) && !defined(ADDRESS_SANITIZER) && \
!defined(THREAD_SANITIZER)
#if !defined(ABSL_HAVE_MEMORY_SANITIZER) && \
!defined(ABSL_HAVE_ADDRESS_SANITIZER) && \
!defined(ABSL_HAVE_THREAD_SANITIZER)
// EXPECT_SYS_TIMING_NEAR(before_snapshot.timing, before_timing);
EXPECT_SYS_TIMING_NEAR(after_snapshot.timing, after_timing);
// EXPECT_SYS_TIMING_NEAR(after_snapshot.delta_timing, delta_timing);
Expand Down Expand Up @@ -202,8 +204,9 @@ TEST(RUsageProfilerTest, ValidateTimelapseSnapshots) {

// NOTE: The sanitizers heavily instrument the code and skew any time
// measurements.
#if !defined(ADDRESS_SANITIZER) && !defined(THREAD_SANITIZER) && \
!defined(MEMORY_SANITIZER)
#if !defined(ABSL_HAVE_ADDRESS_SANITIZER) && \
!defined(ABSL_HAVE_THREAD_SANITIZER) && \
!defined(ABSL_HAVE_MEMORY_SANITIZER)
const auto& snapshots = rprof.GetSnapshots();
ASSERT_NEAR(snapshots.size(), absl::FDivDuration(kWasteTime, kInterval), 1);
for (int i = 1; i < snapshots.size(); ++i) {
Expand Down
11 changes: 7 additions & 4 deletions centipede/rusage_stats_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <vector>

#include "gtest/gtest.h"
#include "absl/base/config.h"
#include "absl/base/nullability.h"
#include "absl/flags/flag.h"
#include "absl/synchronization/barrier.h"
Expand Down Expand Up @@ -266,8 +267,9 @@ TEST(RUsageMemoryTest, Accuracy) {

// NOTE: The sanitizers heavily instrument the code and skew any time
// measurements.
#if !defined(ADDRESS_SANITIZER) && !defined(THREAD_SANITIZER) && \
!defined(MEMORY_SANITIZER)
#if !defined(ABSL_HAVE_ADDRESS_SANITIZER) && \
!defined(ABSL_HAVE_THREAD_SANITIZER) && \
!defined(ABSL_HAVE_MEMORY_SANITIZER)
EXPECT_EQ(delta.mem_rss, after.mem_rss - before.mem_rss);
EXPECT_EQ(delta.mem_data, after.mem_data - before.mem_data);
// VPeak can only grow. VSize may grow to fit BigThing or fit it as-is.
Expand All @@ -293,8 +295,9 @@ TEST(RUsageMemoryTest, Accuracy) {

// NOTE: The sanitizers heavily instrument the code and skew any time
// measurements.
#if !defined(ADDRESS_SANITIZER) && !defined(THREAD_SANITIZER) && \
!defined(MEMORY_SANITIZER)
#if !defined(ABSL_HAVE_ADDRESS_SANITIZER) && \
!defined(ABSL_HAVE_THREAD_SANITIZER) && \
!defined(ABSL_HAVE_MEMORY_SANITIZER)
EXPECT_NEAR(mem_rss_histo.Average(), kBytes, kRssLeeway) << mem_rss_histo;
#ifdef __APPLE__
// `data` is not supported.
Expand Down
4 changes: 2 additions & 2 deletions cmake/FuzzTestFlagSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ macro(fuzztest_setup_fuzzing_flags)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=fuzzer-no-link -DFUZZTEST_COMPATIBILITY_MODE")
endif ()
if (FUZZTEST_FUZZING_MODE OR (FUZZTEST_COMPATIBILITY_MODE STREQUAL "libfuzzer"))
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-coverage=inline-8bit-counters -fsanitize-coverage=trace-cmp -fsanitize=address -DADDRESS_SANITIZER")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-coverage=inline-8bit-counters -fsanitize-coverage=trace-cmp -fsanitize=address -DADDRESS_SANITIZER")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-coverage=inline-8bit-counters -fsanitize-coverage=trace-cmp -fsanitize=address")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-coverage=inline-8bit-counters -fsanitize-coverage=trace-cmp -fsanitize=address")
endif ()
endmacro ()
22 changes: 11 additions & 11 deletions doc/quickstart-cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ special way.

* `-g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -UNDEBUG`
* `-fsanitize-coverage=inline-8bit-counters -fsanitize-coverage=trace-cmp`
* `-fsanitize=address -DADDRESS_SANITIZER` (optionally enabling sanitizer)
* `-fsanitize=address` (optionally enabling sanitizer)

The FuzzTest framework doesn't need to be built with these flags, only the target project.

Expand Down Expand Up @@ -233,18 +233,18 @@ INFO: found LLVMFuzzerCustomMutator (0x55edfe61cac0). Disabling -len_control by
INFO: libFuzzer ignores flags that start with '--'
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 1109364873
INFO: Loaded 1 modules (18692 inline 8-bit counters): 18692 [0x55edfe975548, 0x55edfe979e4c),
INFO: Loaded 1 PC tables (18692 PCs): 18692 [0x55edfe979e50,0x55edfe9c2e90),
INFO: Loaded 1 modules (18692 inline 8-bit counters): 18692 [0x55edfe975548, 0x55edfe979e4c),
INFO: Loaded 1 PC tables (18692 PCs): 18692 [0x55edfe979e50,0x55edfe9c2e90),
INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 4096 bytes
INFO: A corpus is not provided, starting from an empty corpus
#2 INITED cov: 17 ft: 18 corp: 1/1b exec/s: 0 rss: 38Mb
#3 NEW cov: 104 ft: 108 corp: 2/66b lim: 4096 exec/s: 0 rss: 38Mb L: 65/65 MS: 1 Custom-
#4 NEW cov: 105 ft: 112 corp: 3/121b lim: 4096 exec/s: 0 rss: 38Mb L: 55/65 MS: 1 Custom-
#5 NEW cov: 105 ft: 113 corp: 4/196b lim: 4096 exec/s: 0 rss: 38Mb L: 75/75 MS: 1 Custom-
#16 REDUCE cov: 105 ft: 113 corp: 4/195b lim: 4096 exec/s: 0 rss: 38Mb L: 54/75 MS: 1 Custom-
#41 NEW cov: 105 ft: 114 corp: 5/247b lim: 4096 exec/s: 0 rss: 38Mb L: 52/75 MS: 5 Custom-Custom-Custom-Custom-Custom-
#65 NEW cov: 106 ft: 115 corp: 6/312b lim: 4096 exec/s: 0 rss: 38Mb L: 65/75 MS: 4 Custom-Custom-Custom-Custom-
#69 NEW cov: 108 ft: 119 corp: 7/365b lim: 4096 exec/s: 0 rss: 38Mb L: 53/75 MS: 4 Custom-Custom-Custom-Custom-
#2 INITED cov: 17 ft: 18 corp: 1/1b exec/s: 0 rss: 38Mb
#3 NEW cov: 104 ft: 108 corp: 2/66b lim: 4096 exec/s: 0 rss: 38Mb L: 65/65 MS: 1 Custom-
#4 NEW cov: 105 ft: 112 corp: 3/121b lim: 4096 exec/s: 0 rss: 38Mb L: 55/65 MS: 1 Custom-
#5 NEW cov: 105 ft: 113 corp: 4/196b lim: 4096 exec/s: 0 rss: 38Mb L: 75/75 MS: 1 Custom-
#16 REDUCE cov: 105 ft: 113 corp: 4/195b lim: 4096 exec/s: 0 rss: 38Mb L: 54/75 MS: 1 Custom-
#41 NEW cov: 105 ft: 114 corp: 5/247b lim: 4096 exec/s: 0 rss: 38Mb L: 52/75 MS: 5 Custom-Custom-Custom-Custom-Custom-
#65 NEW cov: 106 ft: 115 corp: 6/312b lim: 4096 exec/s: 0 rss: 38Mb L: 65/75 MS: 4 Custom-Custom-Custom-Custom-
#69 NEW cov: 108 ft: 119 corp: 7/365b lim: 4096 exec/s: 0 rss: 38Mb L: 53/75 MS: 4 Custom-Custom-Custom-Custom-
```

## Next steps
Expand Down
1 change: 1 addition & 0 deletions e2e_tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ cc_test(
],
deps = [
":test_binary_util",
"@abseil-cpp//absl/base:config",
"@abseil-cpp//absl/container:flat_hash_map",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:str_format",
Expand Down
15 changes: 8 additions & 7 deletions e2e_tests/functional_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/base/config.h"
#include "absl/container/flat_hash_map.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
Expand Down Expand Up @@ -1603,7 +1604,7 @@ class FuzzingModeCrashFindingTest

TEST_P(FuzzingModeCrashFindingTest,
BufferOverflowIsDetectedWithStringViewInFuzzingMode) {
#ifndef ADDRESS_SANITIZER
#ifndef ABSL_HAVE_ADDRESS_SANITIZER
GTEST_SKIP() << "Skipping crash finding test for ASAN errors without ASAN";
#endif
auto [status, std_out, std_err] = Run("MySuite.BufferOverreadWithStringView");
Expand All @@ -1616,7 +1617,7 @@ TEST_P(FuzzingModeCrashFindingTest,

TEST_P(FuzzingModeCrashFindingTest,
UninitializedReadIsDetectedWithStringInFuzzingMode) {
#ifndef MEMORY_SANITIZER
#ifndef ABSL_HAVE_MEMORY_SANITIZER
GTEST_SKIP() << "Skipping crash finding test for MSAN errors without MSAN";
#endif
auto [status, std_out, std_err] = Run("MySuite.UninitializedReadWithString");
Expand All @@ -1639,7 +1640,7 @@ TEST_P(FuzzingModeCrashFindingTest,

TEST_P(FuzzingModeCrashFindingTest,
BufferOverflowIsDetectedWithStringInFuzzingMode) {
#ifndef ADDRESS_SANITIZER
#ifndef ABSL_HAVE_ADDRESS_SANITIZER
GTEST_SKIP() << "Skipping crash finding test for ASAN errors without ASAN";
#endif
auto [status, std_out, std_err] = Run("MySuite.BufferOverreadWithString");
Expand All @@ -1650,7 +1651,7 @@ TEST_P(FuzzingModeCrashFindingTest,

TEST_P(FuzzingModeCrashFindingTest,
BufferOverflowIsDetectedWithStringAndLvalueStringViewRef) {
#ifndef ADDRESS_SANITIZER
#ifndef ABSL_HAVE_ADDRESS_SANITIZER
GTEST_SKIP() << "Skipping crash finding test for ASAN errors without ASAN";
#endif
auto [status, std_out, std_err] =
Expand All @@ -1662,7 +1663,7 @@ TEST_P(FuzzingModeCrashFindingTest,

TEST_P(FuzzingModeCrashFindingTest,
BufferOverflowIsDetectedWithStringAndRvalueStringViewRef) {
#ifndef ADDRESS_SANITIZER
#ifndef ABSL_HAVE_ADDRESS_SANITIZER
GTEST_SKIP() << "Skipping crash finding test for ASAN errors without ASAN";
#endif
auto [status, std_out, std_err] =
Expand All @@ -1675,7 +1676,7 @@ TEST_P(FuzzingModeCrashFindingTest,
TEST_P(FuzzingModeCrashFindingTest, DivByZeroTestFindsAbortInFuzzingMode) {
auto [status, std_out, std_err] = Run("MySuite.DivByZero");
EXPECT_THAT_LOG(std_err, HasSubstr("argument 1: 0"));
#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER)
#if defined(ABSL_HAVE_ADDRESS_SANITIZER) || defined(ABSL_HAVE_MEMORY_SANITIZER)
EXPECT_THAT(status, Ne(ExitCode(0))) << std_err;
#else
EXPECT_THAT(status, Eq(Signal(SIGFPE))) << std_err;
Expand Down Expand Up @@ -1996,7 +1997,7 @@ TEST_P(FuzzingModeCrashFindingTest, InputsAreSkippedWhenRequestedInTests) {
}

TEST_P(FuzzingModeCrashFindingTest, AsanCrashMetadataIsDumpedIfEnvVarIsSet) {
#ifndef ADDRESS_SANITIZER
#ifndef ABSL_HAVE_ADDRESS_SANITIZER
GTEST_SKIP() << "Skipping crash finding test for ASAN errors without ASAN";
#endif
TempDir out_dir;
Expand Down
1 change: 1 addition & 0 deletions fuzztest/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ cc_library(
":seed_seq",
":serialization",
":status",
"@abseil-cpp//absl/base:config",
"@abseil-cpp//absl/base:core_headers",
"@abseil-cpp//absl/functional:any_invocable",
"@abseil-cpp//absl/functional:bind_front",
Expand Down
3 changes: 2 additions & 1 deletion fuzztest/internal/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <utility>
#include <vector>

#include "absl/base/config.h"
#include "absl/functional/bind_front.h"
#include "absl/functional/function_ref.h"
#include "absl/random/bit_gen_ref.h"
Expand Down Expand Up @@ -71,7 +72,7 @@
#include "./fuzztest/internal/serialization.h"
#include "./fuzztest/internal/status.h"

#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER)
#if defined(ABSL_HAVE_ADDRESS_SANITIZER) || defined(ABSL_HAVE_MEMORY_SANITIZER)
#define FUZZTEST_HAS_SANITIZER
#include <sanitizer/common_interface_defs.h>

Expand Down
Loading