diff options
author | Alan Phipps <a-phipps@ti.com> | 2023-12-13 14:13:56 -0600 |
---|---|---|
committer | Alan Phipps <a-phipps@ti.com> | 2023-12-13 15:10:05 -0600 |
commit | 8ecbb0404d740d1ab173554e47cef39cd5e3ef8c (patch) | |
tree | 93cc0afc02965f5ccc27dc83c7389662ef772661 /llvm/unittests/ProfileData/CoverageMappingTest.cpp | |
parent | 14d7e0bb0f75066da5d2eff718b6d59215a02077 (diff) | |
download | llvm-8ecbb0404d740d1ab173554e47cef39cd5e3ef8c.zip llvm-8ecbb0404d740d1ab173554e47cef39cd5e3ef8c.tar.gz llvm-8ecbb0404d740d1ab173554e47cef39cd5e3ef8c.tar.bz2 |
Reland "[Coverage][llvm-cov] Enable MC/DC Support in LLVM Source-based Code Coverage (2/3)"
Part 2 of 3. This includes the Visualization and Evaluation components.
Differential Revision: https://reviews.llvm.org/D138847
Diffstat (limited to 'llvm/unittests/ProfileData/CoverageMappingTest.cpp')
-rw-r--r-- | llvm/unittests/ProfileData/CoverageMappingTest.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/llvm/unittests/ProfileData/CoverageMappingTest.cpp b/llvm/unittests/ProfileData/CoverageMappingTest.cpp index 873bc05..1cf497cb 100644 --- a/llvm/unittests/ProfileData/CoverageMappingTest.cpp +++ b/llvm/unittests/ProfileData/CoverageMappingTest.cpp @@ -187,6 +187,25 @@ struct CoverageMappingTest : ::testing::TestWithParam<std::tuple<bool, bool>> { : CounterMappingRegion::makeRegion(C, FileID, LS, CS, LE, CE)); } + void addMCDCDecisionCMR(unsigned Mask, unsigned NC, StringRef File, + unsigned LS, unsigned CS, unsigned LE, unsigned CE) { + auto &Regions = InputFunctions.back().Regions; + unsigned FileID = getFileIndexForFunction(File); + Regions.push_back(CounterMappingRegion::makeDecisionRegion( + CounterMappingRegion::MCDCParameters{Mask, NC}, FileID, LS, CS, LE, + CE)); + } + + void addMCDCBranchCMR(Counter C1, Counter C2, unsigned ID, unsigned TrueID, + unsigned FalseID, StringRef File, unsigned LS, + unsigned CS, unsigned LE, unsigned CE) { + auto &Regions = InputFunctions.back().Regions; + unsigned FileID = getFileIndexForFunction(File); + Regions.push_back(CounterMappingRegion::makeBranchRegion( + C1, C2, CounterMappingRegion::MCDCParameters{0, 0, ID, TrueID, FalseID}, + FileID, LS, CS, LE, CE)); + } + void addExpansionCMR(StringRef File, StringRef ExpandedFile, unsigned LS, unsigned CS, unsigned LE, unsigned CE) { InputFunctions.back().Regions.push_back(CounterMappingRegion::makeExpansion( @@ -828,6 +847,33 @@ TEST_P(CoverageMappingTest, non_code_region_counters) { ASSERT_EQ(1U, Names.size()); } +// Test that MCDC bitmasks not associated with any code regions are allowed. +TEST_P(CoverageMappingTest, non_code_region_bitmask) { + // No records in profdata + + startFunction("func", 0x1234); + addCMR(Counter::getCounter(0), "file", 1, 1, 5, 5); + addCMR(Counter::getCounter(1), "file", 1, 1, 5, 5); + addCMR(Counter::getCounter(2), "file", 1, 1, 5, 5); + addCMR(Counter::getCounter(3), "file", 1, 1, 5, 5); + + addMCDCDecisionCMR(0, 2, "file", 7, 1, 7, 6); + addMCDCBranchCMR(Counter::getCounter(0), Counter::getCounter(1), 1, 2, 0, + "file", 7, 2, 7, 3); + addMCDCBranchCMR(Counter::getCounter(2), Counter::getCounter(3), 2, 0, 0, + "file", 7, 4, 7, 5); + + EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded()); + + std::vector<std::string> Names; + for (const auto &Func : LoadedCoverage->getCoveredFunctions()) { + Names.push_back(Func.Name); + ASSERT_EQ(2U, Func.CountedBranchRegions.size()); + ASSERT_EQ(1U, Func.MCDCRecords.size()); + } + ASSERT_EQ(1U, Names.size()); +} + TEST_P(CoverageMappingTest, strip_filename_prefix) { ProfileWriter.addRecord({"file1:func", 0x1234, {0}}, Err); |