diff --git a/trusty/coverage/coverage.cpp b/trusty/coverage/coverage.cpp index 9613d0fb5..3c6b5c510 100644 --- a/trusty/coverage/coverage.cpp +++ b/trusty/coverage/coverage.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #define COVERAGE_CLIENT_PORT "com.android.trusty.coverage.client" @@ -122,7 +123,9 @@ Result CoverageRecord::Open() { int fd = tipc_connect(tipc_dev_.c_str(), COVERAGE_CLIENT_PORT); if (fd < 0) { - return ErrnoError() << "failed to connect to Trusty coverarge server: "; + // Don't error out to support fuzzing builds without coverage, e.g. for repros. + std::cerr << "WARNING!!! Failed to connect to Trusty coverarge server." << std::endl; + return {}; } coverage_srv_fd_.reset(fd); @@ -160,6 +163,10 @@ Result CoverageRecord::Open() { return {}; } +bool CoverageRecord::IsOpen() { + return shm_; +} + void CoverageRecord::ResetFullRecord() { auto header_region = GetRegionBounds(COV_START); if (!header_region.ok()) { diff --git a/trusty/coverage/include/trusty/coverage/coverage.h b/trusty/coverage/include/trusty/coverage/coverage.h index 5da68dad2..9ccc9813a 100644 --- a/trusty/coverage/include/trusty/coverage/coverage.h +++ b/trusty/coverage/include/trusty/coverage/coverage.h @@ -47,6 +47,7 @@ class CoverageRecord { ~CoverageRecord(); Result Open(); + bool IsOpen(); void ResetFullRecord(); void ResetCounts(); void ResetPCs(); diff --git a/trusty/fuzz/counters.cpp b/trusty/fuzz/counters.cpp index 1e863acaf..4d340596c 100644 --- a/trusty/fuzz/counters.cpp +++ b/trusty/fuzz/counters.cpp @@ -41,6 +41,10 @@ namespace trusty { namespace fuzz { ExtraCounters::ExtraCounters(coverage::CoverageRecord* record) : record_(record) { + if (!record_->IsOpen()) { + return; + } + assert(fuzzer::ExtraCountersBegin()); assert(fuzzer::ExtraCountersEnd()); @@ -51,10 +55,18 @@ ExtraCounters::ExtraCounters(coverage::CoverageRecord* record) : record_(record) } ExtraCounters::~ExtraCounters() { + if (!record_->IsOpen()) { + return; + } + Flush(); } void ExtraCounters::Reset() { + if (!record_->IsOpen()) { + return; + } + record_->ResetCounts(); fuzzer::ClearExtraCounters(); }