diff --git a/bazel/setup_configs.sh b/bazel/setup_configs.sh index 8a6524b15..5903a59aa 100755 --- a/bazel/setup_configs.sh +++ b/bazel/setup_configs.sh @@ -42,11 +42,6 @@ cat < #include "gtest/gtest.h" +#include "absl/base/config.h" #include "absl/flags/flag.h" #include "absl/time/clock.h" #include "absl/time/time.h" @@ -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 @@ -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); @@ -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) { diff --git a/centipede/rusage_stats_test.cc b/centipede/rusage_stats_test.cc index 7f5e0580f..2a0e008b7 100644 --- a/centipede/rusage_stats_test.cc +++ b/centipede/rusage_stats_test.cc @@ -21,6 +21,7 @@ #include #include "gtest/gtest.h" +#include "absl/base/config.h" #include "absl/base/nullability.h" #include "absl/flags/flag.h" #include "absl/synchronization/barrier.h" @@ -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. @@ -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. diff --git a/cmake/FuzzTestFlagSetup.cmake b/cmake/FuzzTestFlagSetup.cmake index ac6a24aeb..e900b92e1 100644 --- a/cmake/FuzzTestFlagSetup.cmake +++ b/cmake/FuzzTestFlagSetup.cmake @@ -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 () diff --git a/doc/quickstart-cmake.md b/doc/quickstart-cmake.md index e7f4a7095..1479f6a69 100644 --- a/doc/quickstart-cmake.md +++ b/doc/quickstart-cmake.md @@ -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. @@ -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 diff --git a/e2e_tests/BUILD b/e2e_tests/BUILD index fc0e23f5b..2edd62cd6 100644 --- a/e2e_tests/BUILD +++ b/e2e_tests/BUILD @@ -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", diff --git a/e2e_tests/functional_test.cc b/e2e_tests/functional_test.cc index 613347390..f9d36964d 100644 --- a/e2e_tests/functional_test.cc +++ b/e2e_tests/functional_test.cc @@ -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" @@ -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"); @@ -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"); @@ -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"); @@ -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] = @@ -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] = @@ -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; @@ -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; diff --git a/fuzztest/internal/BUILD b/fuzztest/internal/BUILD index f51559105..c2a2cea1e 100644 --- a/fuzztest/internal/BUILD +++ b/fuzztest/internal/BUILD @@ -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", diff --git a/fuzztest/internal/runtime.cc b/fuzztest/internal/runtime.cc index f03dbaf18..79ea2ff46 100644 --- a/fuzztest/internal/runtime.cc +++ b/fuzztest/internal/runtime.cc @@ -38,6 +38,7 @@ #include #include +#include "absl/base/config.h" #include "absl/functional/bind_front.h" #include "absl/functional/function_ref.h" #include "absl/random/bit_gen_ref.h" @@ -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