Skip to content

Commit

Permalink
Increase crash reporting limit when running with FuzzTest.
Browse files Browse the repository at this point in the history
Also adjust the e2e test to reduce flakiness.

PiperOrigin-RevId: 724367942
  • Loading branch information
xinhaoyuan authored and copybara-github committed Feb 7, 2025
1 parent 7a55888 commit af84f4c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/bazel_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/bazel_test_centipede.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/cmake_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions centipede/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
12 changes: 8 additions & 4 deletions e2e_tests/corpus_database_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 8 additions & 4 deletions e2e_tests/testdata/fuzz_tests_for_corpus_database_testing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>& 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);

Expand Down

0 comments on commit af84f4c

Please sign in to comment.