From b089696fe633511573fa22e7662fdd8ea84bdc80 Mon Sep 17 00:00:00 2001 From: Xinhao Yuan Date: Mon, 3 Feb 2025 11:51:33 -0800 Subject: [PATCH] Increase crash reporting limit when running with FuzzTest. Also adjust the e2e test to reduce flakiness. PiperOrigin-RevId: 722741758 --- .github/workflows/bazel_test.yml | 3 +++ .github/workflows/bazel_test_centipede.yml | 3 +++ .github/workflows/cmake_test.yml | 3 +++ centipede/environment.cc | 10 ++++++++++ e2e_tests/corpus_database_test.cc | 12 ++++++++---- .../fuzz_tests_for_corpus_database_testing.cc | 12 ++++++++---- 6 files changed, 35 insertions(+), 8 deletions(-) diff --git a/.github/workflows/bazel_test.yml b/.github/workflows/bazel_test.yml index c2208576..a83bee7c 100644 --- a/.github/workflows/bazel_test.yml +++ b/.github/workflows/bazel_test.yml @@ -36,6 +36,9 @@ jobs: config: ['default', 'fuzztest'] compilation_mode: ['fastbuild', 'opt', 'dbg'] steps: + - name: Disable core dumping and piping due to slowness + run: | + sudo sysctl -w kernel.core_pattern="" - name: Checkout repository uses: actions/checkout@v4 - name: Install dependencies diff --git a/.github/workflows/bazel_test_centipede.yml b/.github/workflows/bazel_test_centipede.yml index b39e778e..d6674814 100644 --- a/.github/workflows/bazel_test_centipede.yml +++ b/.github/workflows/bazel_test_centipede.yml @@ -35,6 +35,9 @@ jobs: matrix: config: ['default', 'noriegeli', 'asan'] steps: + - name: Disable core dumping and piping due to slowness + run: | + sudo sysctl -w kernel.core_pattern="" - name: Checkout repository uses: actions/checkout@v4 - name: Install dependencies diff --git a/.github/workflows/cmake_test.yml b/.github/workflows/cmake_test.yml index f64d68be..d23c692c 100644 --- a/.github/workflows/cmake_test.yml +++ b/.github/workflows/cmake_test.yml @@ -38,6 +38,9 @@ jobs: matrix: mode: ['default', 'fuzzing', 'codelab'] steps: + - name: Disable core dumping and piping due to slowness + run: | + sudo sysctl -w kernel.core_pattern="" - name: Checkout repository uses: actions/checkout@v4 - name: Install dependencies diff --git a/centipede/environment.cc b/centipede/environment.cc index 3b2a7f38..98a593fb 100644 --- a/centipede/environment.cc +++ b/centipede/environment.cc @@ -238,6 +238,16 @@ void Environment::ReadKnobsFileIfSpecified() { void Environment::UpdateWithTargetConfig( const fuzztest::internal::Configuration &config) { + // Allow more crashes to be reported when running with FuzzTest. This allows + // more unique crashes to collected after deduplication. But we don't want to + // make the limit too large to stress the filesystem, so this is not a perfect + // solution. Currently we just increase the default to be seemingly large + // enough. + if (max_num_crash_reports == Default().max_num_crash_reports) { + max_num_crash_reports = 20; + LOG(INFO) << "Overriding the default max_num_crash_reports to " + << max_num_crash_reports << " for FuzzTest."; + } if (config.jobs != 0) { CHECK(j == Default().j || j == config.jobs) << "Value for --j is inconsistent with the value for jobs in the " diff --git a/e2e_tests/corpus_database_test.cc b/e2e_tests/corpus_database_test.cc index bcfd1f32..608a9c60 100644 --- a/e2e_tests/corpus_database_test.cc +++ b/e2e_tests/corpus_database_test.cc @@ -150,19 +150,23 @@ TEST_P(UpdateCorpusDatabaseTest, RunsFuzzTests) { } TEST_P(UpdateCorpusDatabaseTest, UsesMultipleShardsForFuzzingAndDistillation) { + const auto &std_err = GetUpdateCorpusDatabaseStdErr(); EXPECT_THAT( - GetUpdateCorpusDatabaseStdErr(), + std_err, AllOf(HasSubstr("[S0.0] begin-fuzz"), HasSubstr("[S1.0] begin-fuzz"), HasSubstr("DISTILL[S.0]: Distilling to output shard 0"), - HasSubstr("DISTILL[S.1]: Distilling to output shard 1"))); + HasSubstr("DISTILL[S.1]: Distilling to output shard 1"))) + << std_err; } TEST_P(UpdateCorpusDatabaseTest, FindsAllCrashes) { + const auto &std_err = GetUpdateCorpusDatabaseStdErr(); EXPECT_THAT( - GetUpdateCorpusDatabaseStdErr(), + std_err, AllOf(ContainsRegex(R"re(Failure\s*: GoogleTest assertion failure)re"), ContainsRegex(R"re(Failure\s*: heap-buffer-overflow)re"), - ContainsRegex(R"re(Failure\s*: stack-limit-exceeded)re"))); + ContainsRegex(R"re(Failure\s*: stack-limit-exceeded)re"))) + << std_err; } TEST_P(UpdateCorpusDatabaseTest, ResumedFuzzTestRunsForRemainingTime) { diff --git a/e2e_tests/testdata/fuzz_tests_for_corpus_database_testing.cc b/e2e_tests/testdata/fuzz_tests_for_corpus_database_testing.cc index 8d97055a..6600776e 100644 --- a/e2e_tests/testdata/fuzz_tests_for_corpus_database_testing.cc +++ b/e2e_tests/testdata/fuzz_tests_for_corpus_database_testing.cc @@ -22,12 +22,16 @@ namespace { volatile int force_write = 0; // This test fails in two ways: -// 1. It fails with an assertion failure, e.g., when `v == {2025}`. -// 2. It fails with a heap buffer overflow, e.g., when `v == {4050}`. +// 1. It fails with an assertion failure, e.g., when `v == {1}`. +// 2. It fails with a heap buffer overflow, e.g., when `v == {2}`. void FailsInTwoWays(const std::vector& v) { if (v.size() % 7 != 1) return; - ASSERT_NE(v[0], 2025); - if (v[0] == 2 * 2025) force_write = v.data()[v.size()]; + // Compare A - B and 0 instead of A and B to not rely on auto-dictionary for + // flipping the branches. Otherwise due to the current auto-dictionary + // implementation sometimes the branches are not flipped evenly, causing test + // flakiness. + ASSERT_NE(v[0] % 3 - 1, 0); + if (v[0] % 3 - 2 == 0) force_write = v.data()[v.size()]; } FUZZ_TEST(FuzzTest, FailsInTwoWays);