Merge changes I9e4cbf11,I41cde13a
* changes:
trusty: Allow fuzzing without coverage
trusty: Fix up error messages
diff --git a/trusty/coverage/coverage.cpp b/trusty/coverage/coverage.cpp
index 5eccdc5..3c6b5c5 100644
--- a/trusty/coverage/coverage.cpp
+++ b/trusty/coverage/coverage.cpp
@@ -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 @@
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 @@
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 @@
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()) {
diff --git a/trusty/coverage/include/trusty/coverage/coverage.h b/trusty/coverage/include/trusty/coverage/coverage.h
index 5da68da..9ccc981 100644
--- a/trusty/coverage/include/trusty/coverage/coverage.h
+++ b/trusty/coverage/include/trusty/coverage/coverage.h
@@ -47,6 +47,7 @@
~CoverageRecord();
Result<void> Open();
+ bool IsOpen();
void ResetFullRecord();
void ResetCounts();
void ResetPCs();
diff --git a/trusty/fuzz/counters.cpp b/trusty/fuzz/counters.cpp
index 1e863ac..4d34059 100644
--- a/trusty/fuzz/counters.cpp
+++ b/trusty/fuzz/counters.cpp
@@ -41,6 +41,10 @@
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() {
+ if (!record_->IsOpen()) {
+ return;
+ }
+
Flush();
}
void ExtraCounters::Reset() {
+ if (!record_->IsOpen()) {
+ return;
+ }
+
record_->ResetCounts();
fuzzer::ClearExtraCounters();
}
diff --git a/trusty/fuzz/utils.cpp b/trusty/fuzz/utils.cpp
index f4cf0b6..3526337 100644
--- a/trusty/fuzz/utils.cpp
+++ b/trusty/fuzz/utils.cpp
@@ -113,7 +113,7 @@
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 {};