diff options
author | Hana Dusíková <hanicka@hanicka.net> | 2024-01-22 12:50:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-22 12:50:20 +0100 |
commit | 865e4a1f33bd3be42ff256c6839aff0860610a5a (patch) | |
tree | 88d4dd44b81c2a951553cacdc45c690f0ce9799d /llvm/unittests/ProfileData/CoverageMappingTest.cpp | |
parent | 1a5eeade161beddf9c8b2fabad56af3081cd3629 (diff) | |
download | llvm-865e4a1f33bd3be42ff256c6839aff0860610a5a.zip llvm-865e4a1f33bd3be42ff256c6839aff0860610a5a.tar.gz llvm-865e4a1f33bd3be42ff256c6839aff0860610a5a.tar.bz2 |
[coverage] skipping code coverage for 'if constexpr' and 'if consteval' (#78033)
`if constexpr` and `if consteval` conditional statements code coverage
should behave more like a preprocesor `#if`-s than normal
ConditionalStmt. This PR should fix that.
---------
Co-authored-by: cor3ntin <corentinjabot@gmail.com>
Diffstat (limited to 'llvm/unittests/ProfileData/CoverageMappingTest.cpp')
-rw-r--r-- | llvm/unittests/ProfileData/CoverageMappingTest.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/llvm/unittests/ProfileData/CoverageMappingTest.cpp b/llvm/unittests/ProfileData/CoverageMappingTest.cpp index 1cf497cb..23f66a0 100644 --- a/llvm/unittests/ProfileData/CoverageMappingTest.cpp +++ b/llvm/unittests/ProfileData/CoverageMappingTest.cpp @@ -187,6 +187,11 @@ struct CoverageMappingTest : ::testing::TestWithParam<std::tuple<bool, bool>> { : CounterMappingRegion::makeRegion(C, FileID, LS, CS, LE, CE)); } + void addSkipped(StringRef File, unsigned LS, unsigned CS, unsigned LE, + unsigned CE) { + addCMR(Counter::getZero(), File, LS, CS, LE, CE, true); + } + void addMCDCDecisionCMR(unsigned Mask, unsigned NC, StringRef File, unsigned LS, unsigned CS, unsigned LE, unsigned CE) { auto &Regions = InputFunctions.back().Regions; @@ -700,22 +705,33 @@ TEST_P(CoverageMappingTest, test_line_coverage_iterator) { startFunction("func", 0x1234); addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9); + addSkipped("file1", 1, 3, 1, 8); // skipped region inside previous block addCMR(Counter::getCounter(1), "file1", 1, 1, 4, 7); + addSkipped("file1", 4, 1, 4, 20); // skipped line addCMR(Counter::getCounter(2), "file1", 5, 8, 9, 1); + addSkipped("file1", 10, 1, 12, + 20); // skipped region which contains next region addCMR(Counter::getCounter(3), "file1", 10, 10, 11, 11); EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded()); - CoverageData Data = LoadedCoverage->getCoverageForFile("file1"); unsigned Line = 0; - unsigned LineCounts[] = {20, 20, 20, 20, 30, 10, 10, 10, 10, 0, 0}; + const unsigned LineCounts[] = {20, 20, 20, 0, 30, 10, 10, 10, 10, 0, 0, 0, 0}; + const bool MappedLines[] = {1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0}; + ASSERT_EQ(std::size(LineCounts), std::size(MappedLines)); + for (const auto &LCS : getLineCoverageStats(Data)) { + ASSERT_LT(Line, std::size(LineCounts)); + ASSERT_LT(Line, std::size(MappedLines)); + ASSERT_EQ(Line + 1, LCS.getLine()); - errs() << "Line: " << Line + 1 << ", count = " << LCS.getExecutionCount() << "\n"; + errs() << "Line: " << Line + 1 << ", count = " << LCS.getExecutionCount() + << ", mapped = " << LCS.isMapped() << "\n"; ASSERT_EQ(LineCounts[Line], LCS.getExecutionCount()); + ASSERT_EQ(MappedLines[Line], LCS.isMapped()); ++Line; } - ASSERT_EQ(11U, Line); + ASSERT_EQ(12U, Line); // Check that operator->() works / compiles. ASSERT_EQ(1U, LineCoverageIterator(Data)->getLine()); |