Skip to content

Commit

Permalink
Insert comparison entries into integer dictionaries.
Browse files Browse the repository at this point in the history
This is for using them in integer value mutations.

PiperOrigin-RevId: 609770760
  • Loading branch information
xinhaoyuan authored and copybara-github committed Feb 23, 2024
1 parent a6a6e66 commit a4c6283
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
7 changes: 7 additions & 0 deletions e2e_tests/functional_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,13 @@ TEST_P(FuzzingModeCrashFindingTest, DivByZeroTestFindsAbortInFuzzingMode) {
#endif
}

TEST_P(FuzzingModeCrashFindingTest, Int32ValueTestFindsAbortInFuzzingMode) {
auto [status, std_out, std_err] = Run("MySuite.Int32ValueTest");
// -559038737 is 0xdeadbeef in int32_t.
EXPECT_THAT(std_err, HasSubstr("argument 0: -559038737"));
ExpectTargetAbort(status, std_err);
}

TEST_P(FuzzingModeCrashFindingTest, CoverageTestFindsAbortInFuzzingMode) {
auto [status, std_out, std_err] = Run("MySuite.Coverage");
EXPECT_THAT(std_err, HasSubstr("argument 0: 'F'"));
Expand Down
22 changes: 20 additions & 2 deletions fuzztest/internal/centipede_adaptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,19 @@ class CentipedeAdaptorRunnerCallbacks : public centipede::RunnerCallbacks {
}

private:
template <typename T>
static void InsertCmpEntryIntoIntegerDictionary(const uint8_t* a,
const uint8_t* b) {
T a_int;
T b_int;
memcpy(&a_int, a, sizeof(T));
memcpy(&b_int, b, sizeof(T));
GetExecutionCoverage()
->GetTablesOfRecentCompares()
.GetMutable<sizeof(T)>()
.Insert(a_int, b_int);
}

void SetMetadata(const centipede::ExecutionMetadata* metadata) {
if (metadata == nullptr) return;
metadata->ForEachCmpEntry([](centipede::ByteSpan a, centipede::ByteSpan b) {
Expand All @@ -244,8 +257,13 @@ class CentipedeAdaptorRunnerCallbacks : public centipede::RunnerCallbacks {
const size_t size = a.size();
if (size < kMinCmpEntrySize) return;
if (size > kMaxCmpEntrySize) return;
// TODO(xinhaoyuan): Consider handling integer comparison and
// memcmp entries differently.
if (size == 2) {
InsertCmpEntryIntoIntegerDictionary<uint16_t>(a.data(), b.data());
} else if (size == 4) {
InsertCmpEntryIntoIntegerDictionary<uint32_t>(a.data(), b.data());
} else if (size == 8) {
InsertCmpEntryIntoIntegerDictionary<uint64_t>(a.data(), b.data());
}
GetExecutionCoverage()
->GetTablesOfRecentCompares()
.GetMutable<0>()
Expand Down

0 comments on commit a4c6283

Please sign in to comment.