Skip to content

Commit

Permalink
Add time limit to all-clusters-app-fuzzing
Browse files Browse the repository at this point in the history
Fuzzing binary now searches for environment variable `FUZZ_CAMPAIGN_MINUTES` to automatically limit, halt execution, and dump gcov data once X minutes have elapsed. This was required to extract gcov data from a fuzzing binary as under normal circumstances manually aborting the execution did not produce any gcov data.
google/fuzzing#41
  • Loading branch information
zduthie-unimelb committed May 4, 2023
1 parent afc3490 commit 8af47ef
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/all-clusters-app/linux/fuzzing-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

#include <CommissionableInit.h>

#include <chrono>
#include <iostream>

extern "C" void __gcov_dump();

using namespace chip;
using namespace chip::DeviceLayer;

Expand All @@ -40,6 +45,27 @@ void CleanShutdown()

extern "C" int LLVMFuzzerTestOneInput(const uint8_t * aData, size_t aSize)
{
static auto fuzzCampaignStart = std::chrono::steady_clock::now();
static auto fuzzCampaignMinutes = [](){
char *envString = getenv("FUZZ_CAMPAIGN_MINUTES");

int minutes = (envString == NULL) ? 0 : atoi(envString);
std::cerr << "FUZZ_CAMPAIGN_MINUTES: " << minutes << std::endl;

return minutes;
} ();

// Check elapsed time
if (fuzzCampaignMinutes > 0) {
auto current = std::chrono::steady_clock::now();
if (std::chrono::duration_cast<std::chrono::minutes>(current - fuzzCampaignStart).count() > fuzzCampaignMinutes) {
// Passed scheduled end
std::cerr << "Stopping fuzzing after " << fuzzCampaignMinutes << " minutes" << std::endl;
__gcov_dump();
exit(0);
}
}

static bool matterStackInitialized = false;
if (!matterStackInitialized)
{
Expand Down

0 comments on commit 8af47ef

Please sign in to comment.