trusty: Allow fuzzing without coverage

Bug: 171750250
Test: m
Change-Id: I9e4cbf11fd223092f9ad800b35d0502c27f71e8f
This commit is contained in:
Tri Vo 2021-02-10 15:29:57 -08:00
parent ce812a22ca
commit 19eccb4f51
3 changed files with 21 additions and 1 deletions

View File

@ -29,6 +29,7 @@
#include <trusty/coverage/record.h>
#include <trusty/coverage/tipc.h>
#include <trusty/tipc.h>
#include <iostream>
#define COVERAGE_CLIENT_PORT "com.android.trusty.coverage.client"
@ -122,7 +123,9 @@ Result<void> 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<void> CoverageRecord::Open() {
return {};
}
bool CoverageRecord::IsOpen() {
return shm_;
}
void CoverageRecord::ResetFullRecord() {
auto header_region = GetRegionBounds(COV_START);
if (!header_region.ok()) {

View File

@ -47,6 +47,7 @@ class CoverageRecord {
~CoverageRecord();
Result<void> Open();
bool IsOpen();
void ResetFullRecord();
void ResetCounts();
void ResetPCs();

View File

@ -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();
}