From 8ecbb0404d740d1ab173554e47cef39cd5e3ef8c Mon Sep 17 00:00:00 2001 From: Alan Phipps Date: Wed, 13 Dec 2023 14:13:56 -0600 Subject: 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 --- llvm/unittests/ProfileData/CoverageMappingTest.cpp | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'llvm/unittests/ProfileData/CoverageMappingTest.cpp') 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> { : 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 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); -- cgit v1.1