summaryrefslogtreecommitdiffstats
path: root/llvm/unittests
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2017-10-18 23:58:28 +0000
committerVedant Kumar <vsk@apple.com>2017-10-18 23:58:28 +0000
commit821160d5efc38b84cd51efc4d94acd3948e22873 (patch)
treec54a57109398ecdb5e33ca063a2ddf80bce2ca3c /llvm/unittests
parente955f6183749410992ef358b2d49b8cae2acaae1 (diff)
downloadbcm5719-llvm-821160d5efc38b84cd51efc4d94acd3948e22873.tar.gz
bcm5719-llvm-821160d5efc38b84cd51efc4d94acd3948e22873.zip
[llvm-cov] Move LineCoverageIterator to libCoverage. NFC.
LineCoverageIterator makes it easy for clients of coverage data to determine line execution counts for a file or function. The coverage iteration logic is tricky enough that it really pays not to have multiple copies of it. Hopefully having just one implementation in LLVM will make the iteration logic easier to test, reuse, and update. This commit is NFC but I've added a unit test to go along with it just because it's easy to do now. llvm-svn: 316141
Diffstat (limited to 'llvm/unittests')
-rw-r--r--llvm/unittests/ProfileData/CoverageMappingTest.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/llvm/unittests/ProfileData/CoverageMappingTest.cpp b/llvm/unittests/ProfileData/CoverageMappingTest.cpp
index 8c9c8c48234..ad0a0cfb873 100644
--- a/llvm/unittests/ProfileData/CoverageMappingTest.cpp
+++ b/llvm/unittests/ProfileData/CoverageMappingTest.cpp
@@ -635,6 +635,63 @@ TEST_P(CoverageMappingTest, basic_coverage_iteration) {
ASSERT_EQ(CoverageSegment(11, 11, false), Segments[6]);
}
+TEST_P(CoverageMappingTest, test_line_coverage_iterator) {
+ ProfileWriter.addRecord({"func", 0x1234, {30, 20, 10, 0}}, Err);
+
+ startFunction("func", 0x1234);
+ addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
+ addCMR(Counter::getCounter(1), "file1", 1, 1, 4, 7);
+ addCMR(Counter::getCounter(2), "file1", 5, 8, 9, 1);
+ addCMR(Counter::getCounter(3), "file1", 10, 10, 11, 11);
+ EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
+
+ CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
+
+ unsigned NumLineStats = 0;
+ for (const auto &LCS : getLineCoverageStats(Data)) {
+ ++NumLineStats;
+ (void)LCS;
+ }
+ ASSERT_EQ(11U, NumLineStats);
+
+ LineCoverageIterator LCI{Data};
+
+ ASSERT_EQ(1U, LCI->getLine());
+ ASSERT_EQ(20ULL, LCI->getExecutionCount());
+ ++LCI;
+ ASSERT_EQ(2U, LCI->getLine());
+ ASSERT_EQ(20ULL, LCI->getExecutionCount());
+ ++LCI;
+ ASSERT_EQ(3U, LCI->getLine());
+ ASSERT_EQ(20ULL, LCI->getExecutionCount());
+ ++LCI;
+ ASSERT_EQ(4U, LCI->getLine());
+ ASSERT_EQ(20ULL, LCI->getExecutionCount());
+ ++LCI;
+ ASSERT_EQ(5U, LCI->getLine());
+ ASSERT_EQ(10ULL, LCI->getExecutionCount());
+ ++LCI;
+ ASSERT_EQ(6U, LCI->getLine());
+ ASSERT_EQ(10ULL, LCI->getExecutionCount());
+ ++LCI;
+ ASSERT_EQ(7U, LCI->getLine());
+ ASSERT_EQ(10ULL, LCI->getExecutionCount());
+ ++LCI;
+ ASSERT_EQ(8U, LCI->getLine());
+ ASSERT_EQ(10ULL, LCI->getExecutionCount());
+ ++LCI;
+ ASSERT_EQ(9U, LCI->getLine());
+ ASSERT_EQ(10ULL, LCI->getExecutionCount());
+ ++LCI;
+ ASSERT_EQ(10U, LCI->getLine());
+ ASSERT_EQ(0ULL, LCI->getExecutionCount());
+ ++LCI;
+ ASSERT_EQ(11U, LCI->getLine());
+ ASSERT_EQ(0ULL, LCI->getExecutionCount());
+ ++LCI;
+ ASSERT_EQ(LCI, LCI.getEnd());
+}
+
TEST_P(CoverageMappingTest, uncovered_function) {
startFunction("func", 0x1234);
addCMR(Counter::getZero(), "file1", 1, 2, 3, 4);
OpenPOWER on IntegriCloud