Merge changes I9e4cbf11,I41cde13a

* changes:
  trusty: Allow fuzzing without coverage
  trusty: Fix up error messages
This commit is contained in:
Tri Vo 2021-02-11 22:39:29 +00:00 committed by Gerrit Code Review
commit 83e66f792e
4 changed files with 24 additions and 4 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);
@ -130,7 +133,7 @@ Result<void> CoverageRecord::Open() {
req.open_args.uuid = uuid_;
auto ret = Rpc(&req, -1, &resp);
if (!ret.ok()) {
return Error() << "failed to open coverage client: ";
return Error() << "failed to open coverage client: " << ret.error();
}
record_len_ = resp.open_args.record_len;
shm_len_ = RoundPageUp(record_len_);
@ -153,13 +156,17 @@ Result<void> CoverageRecord::Open() {
req.share_record_args.shm_len = shm_len_;
ret = Rpc(&req, dma_buf, &resp);
if (!ret.ok()) {
return Error() << "failed to send shared memory: ";
return Error() << "failed to send shared memory: " << ret.error();
}
shm_ = shm;
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();
}

View file

@ -113,7 +113,7 @@ Result<void> TrustyApp::Write(const void* buf, size_t len) {
int rc = write(ta_fd_, buf, len);
alarm(0);
if (rc < 0) {
return Error() << "failed to read TIPC message from TA: ";
return Error() << "failed to write TIPC message to TA: ";
}
return {};