summaryrefslogtreecommitdiff
path: root/trusty/coverage/coverage_test.cpp
diff options
context:
space:
mode:
authorStephen Crane <sjc@immunant.com>2020-11-16 18:00:53 -0800
committerStephen Crane <sjc@immunant.com>2020-12-14 22:06:13 -0800
commite962930d19efd198920df2f77b95f78f3b394751 (patch)
treebdd8b656e76f06e92e37ed0a3fb8689bb329b3e7 /trusty/coverage/coverage_test.cpp
parent5a611cb8346877493929582855d8bcbbfd8f3dbf (diff)
trusty: Retrieve coverage PCs from coverage record
Adds the ability to retrieve and save program counter information from the trusty coverage record data. PC information is saved to a .sancov file, parseable by the LLVM sancov tool. Sancov can then symbolize and display this coverage information for consumption by humans. Adds a sancov dump to the libtrusty_coverage_test for testing. Bug: 175221942 Test: atest libtrusty_coverage_test Test: Retrieve sancov file and manually symbolize with sancov Change-Id: I342ea2ca9abb87986b2904ff69415544ee6070fc
Diffstat (limited to 'trusty/coverage/coverage_test.cpp')
-rw-r--r--trusty/coverage/coverage_test.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/trusty/coverage/coverage_test.cpp b/trusty/coverage/coverage_test.cpp
index d8df7a46f..c1efca63b 100644
--- a/trusty/coverage/coverage_test.cpp
+++ b/trusty/coverage/coverage_test.cpp
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+#include <android-base/stringprintf.h>
#include <gtest/gtest.h>
#include <trusty/coverage/coverage.h>
#include <trusty/tipc.h>
@@ -27,6 +28,7 @@ using std::unique_ptr;
#define TIPC_DEV "/dev/trusty-ipc-dev0"
#define TEST_SRV_PORT "com.android.trusty.sancov.test.srv"
+#define TEST_SRV_MODULE "srv.syms.elf"
namespace android {
namespace trusty {
@@ -54,8 +56,8 @@ class CoverageTest : public ::testing::Test {
};
TEST_F(CoverageTest, CoverageReset) {
- record_->Reset();
- auto counter = record_->CountEdges();
+ record_->ResetFullRecord();
+ auto counter = record_->TotalEdgeCounts();
ASSERT_EQ(counter, 0);
}
@@ -69,7 +71,7 @@ TEST_F(CoverageTest, TestServerCoverage) {
for (size_t i = 1; i < sizeof(magic) * 8; i++) {
/* Reset coverage */
- record_->Reset();
+ record_->ResetCounts();
/* Send message to test server */
uint32_t msg = magic & ~(mask << i);
@@ -81,10 +83,15 @@ TEST_F(CoverageTest, TestServerCoverage) {
ASSERT_EQ(rc, sizeof(msg));
/* Count number of non-unique blocks executed */
- auto counter = record_->CountEdges();
+ auto counter = record_->TotalEdgeCounts();
/* Each consecutive input should exercise more or same blocks */
ASSERT_GE(counter, high_watermark);
high_watermark = counter;
+
+ auto sancov_filename = android::base::StringPrintf(
+ "/data/local/tmp/" TEST_SRV_MODULE ".%d.sancov", getpid());
+ auto res = record_->SaveSancovFile(sancov_filename);
+ ASSERT_TRUE(res.ok());
}
ASSERT_GT(high_watermark, 0);