InstrProfTest.cpp: Don't assume string literals are always merged.
[oota-llvm.git] / unittests / ProfileData / CoverageMappingTest.cpp
index 9fceacbec895573af7b4e3f5273e793dfc920163..35b8626c494a100026d3d117cbb7e0c07b1f1237 100644 (file)
@@ -188,7 +188,8 @@ TEST_F(CoverageMappingTest, expansion_gets_first_counter) {
 }
 
 TEST_F(CoverageMappingTest, basic_coverage_iteration) {
-  ProfileWriter.addFunctionCounts("func", 0x1234, {30, 20, 10, 0});
+  InstrProfRecord Record("func", 0x1234, {30, 20, 10, 0});
+  ProfileWriter.addRecord(std::move(Record));
   readProfCounts();
 
   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
@@ -222,8 +223,24 @@ TEST_F(CoverageMappingTest, uncovered_function) {
   ASSERT_EQ(CoverageSegment(3, 4, false),   Segments[1]);
 }
 
+TEST_F(CoverageMappingTest, uncovered_function_with_mapping) {
+  readProfCounts();
+
+  addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
+  addCMR(Counter::getCounter(1), "file1", 1, 1, 4, 7);
+  loadCoverageMapping("func", 0x1234);
+
+  CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
+  std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
+  ASSERT_EQ(3U, Segments.size());
+  ASSERT_EQ(CoverageSegment(1, 1, 0, true),  Segments[0]);
+  ASSERT_EQ(CoverageSegment(4, 7, 0, false), Segments[1]);
+  ASSERT_EQ(CoverageSegment(9, 9, false),    Segments[2]);
+}
+
 TEST_F(CoverageMappingTest, combine_regions) {
-  ProfileWriter.addFunctionCounts("func", 0x1234, {10, 20, 30});
+  InstrProfRecord Record("func", 0x1234, {10, 20, 30});
+  ProfileWriter.addRecord(std::move(Record));
   readProfCounts();
 
   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
@@ -241,7 +258,8 @@ TEST_F(CoverageMappingTest, combine_regions) {
 }
 
 TEST_F(CoverageMappingTest, dont_combine_expansions) {
-  ProfileWriter.addFunctionCounts("func", 0x1234, {10, 20});
+  InstrProfRecord Record("func", 0x1234, {10, 20});
+  ProfileWriter.addRecord(std::move(Record));
   readProfCounts();
 
   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
@@ -259,4 +277,19 @@ TEST_F(CoverageMappingTest, dont_combine_expansions) {
   ASSERT_EQ(CoverageSegment(9, 9, false), Segments[3]);
 }
 
+TEST_F(CoverageMappingTest, strip_filename_prefix) {
+  InstrProfRecord Record("file1:func", 0x1234, {10});
+  ProfileWriter.addRecord(std::move(Record));
+  readProfCounts();
+
+  addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
+  loadCoverageMapping("file1:func", 0x1234);
+
+  std::vector<std::string> Names;
+  for (const auto &Func : LoadedCoverage->getCoveredFunctions())
+    Names.push_back(Func.Name);
+  ASSERT_EQ(1U, Names.size());
+  ASSERT_EQ("func", Names[0]);
+}
+
 } // end anonymous namespace