xref: /llvm-project/llvm/unittests/ProfileData/CoverageMappingTest.cpp (revision 80f329bcd0281c11062879025761d0657167fe8b)
1 //===- unittest/ProfileData/CoverageMappingTest.cpp -------------------------=//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/ProfileData/Coverage/CoverageMapping.h"
10 #include "llvm/ProfileData/Coverage/CoverageMappingReader.h"
11 #include "llvm/ProfileData/Coverage/CoverageMappingWriter.h"
12 #include "llvm/ProfileData/InstrProfReader.h"
13 #include "llvm/ProfileData/InstrProfWriter.h"
14 #include "llvm/Support/raw_ostream.h"
15 #include "llvm/Testing/Support/Error.h"
16 #include "llvm/Testing/Support/SupportHelpers.h"
17 #include "gtest/gtest.h"
18 
19 #include <ostream>
20 #include <utility>
21 
22 using namespace llvm;
23 using namespace coverage;
24 
25 LLVM_NODISCARD static ::testing::AssertionResult
26 ErrorEquals(coveragemap_error Expected, Error E) {
27   coveragemap_error Found;
28   std::string FoundMsg;
29   handleAllErrors(std::move(E), [&](const CoverageMapError &CME) {
30     Found = CME.get();
31     FoundMsg = CME.message();
32   });
33   if (Expected == Found)
34     return ::testing::AssertionSuccess();
35   return ::testing::AssertionFailure() << "error: " << FoundMsg << "\n";
36 }
37 
38 namespace llvm {
39 namespace coverage {
40 void PrintTo(const Counter &C, ::std::ostream *os) {
41   if (C.isZero())
42     *os << "Zero";
43   else if (C.isExpression())
44     *os << "Expression " << C.getExpressionID();
45   else
46     *os << "Counter " << C.getCounterID();
47 }
48 
49 void PrintTo(const CoverageSegment &S, ::std::ostream *os) {
50   *os << "CoverageSegment(" << S.Line << ", " << S.Col << ", ";
51   if (S.HasCount)
52     *os << S.Count << ", ";
53   *os << (S.IsRegionEntry ? "true" : "false") << ")";
54 }
55 }
56 }
57 
58 namespace {
59 
60 struct OutputFunctionCoverageData {
61   StringRef Name;
62   uint64_t Hash;
63   std::vector<StringRef> Filenames;
64   std::vector<CounterMappingRegion> Regions;
65 
66   OutputFunctionCoverageData() : Hash(0) {}
67 
68   OutputFunctionCoverageData(OutputFunctionCoverageData &&OFCD)
69       : Name(OFCD.Name), Hash(OFCD.Hash), Filenames(std::move(OFCD.Filenames)),
70         Regions(std::move(OFCD.Regions)) {}
71 
72   OutputFunctionCoverageData(const OutputFunctionCoverageData &) = delete;
73   OutputFunctionCoverageData &
74   operator=(const OutputFunctionCoverageData &) = delete;
75   OutputFunctionCoverageData &operator=(OutputFunctionCoverageData &&) = delete;
76 
77   void fillCoverageMappingRecord(CoverageMappingRecord &Record) const {
78     Record.FunctionName = Name;
79     Record.FunctionHash = Hash;
80     Record.Filenames = Filenames;
81     Record.Expressions = {};
82     Record.MappingRegions = Regions;
83   }
84 };
85 
86 struct CoverageMappingReaderMock : CoverageMappingReader {
87   ArrayRef<OutputFunctionCoverageData> Functions;
88 
89   CoverageMappingReaderMock(ArrayRef<OutputFunctionCoverageData> Functions)
90       : Functions(Functions) {}
91 
92   Error readNextRecord(CoverageMappingRecord &Record) override {
93     if (Functions.empty())
94       return make_error<CoverageMapError>(coveragemap_error::eof);
95 
96     Functions.front().fillCoverageMappingRecord(Record);
97     Functions = Functions.slice(1);
98 
99     return Error::success();
100   }
101 };
102 
103 struct InputFunctionCoverageData {
104   // Maps the global file index from CoverageMappingTest.Files
105   // to the index of that file within this function. We can't just use
106   // global file indexes here because local indexes have to be dense.
107   // This map is used during serialization to create the virtual file mapping
108   // (from local fileId to global Index) in the head of the per-function
109   // coverage mapping data.
110   SmallDenseMap<unsigned, unsigned> ReverseVirtualFileMapping;
111   std::string Name;
112   uint64_t Hash;
113   std::vector<CounterMappingRegion> Regions;
114 
115   InputFunctionCoverageData(std::string Name, uint64_t Hash)
116       : Name(std::move(Name)), Hash(Hash) {}
117 
118   InputFunctionCoverageData(InputFunctionCoverageData &&IFCD)
119       : ReverseVirtualFileMapping(std::move(IFCD.ReverseVirtualFileMapping)),
120         Name(std::move(IFCD.Name)), Hash(IFCD.Hash),
121         Regions(std::move(IFCD.Regions)) {}
122 
123   InputFunctionCoverageData(const InputFunctionCoverageData &) = delete;
124   InputFunctionCoverageData &
125   operator=(const InputFunctionCoverageData &) = delete;
126   InputFunctionCoverageData &operator=(InputFunctionCoverageData &&) = delete;
127 };
128 
129 struct CoverageMappingTest : ::testing::TestWithParam<std::pair<bool, bool>> {
130   bool UseMultipleReaders;
131   StringMap<unsigned> Files;
132   std::vector<std::string> Filenames;
133   std::vector<InputFunctionCoverageData> InputFunctions;
134   std::vector<OutputFunctionCoverageData> OutputFunctions;
135 
136   InstrProfWriter ProfileWriter;
137   std::unique_ptr<IndexedInstrProfReader> ProfileReader;
138 
139   std::unique_ptr<CoverageMapping> LoadedCoverage;
140 
141   void SetUp() override {
142     ProfileWriter.setOutputSparse(GetParam().first);
143     UseMultipleReaders = GetParam().second;
144   }
145 
146   unsigned getGlobalFileIndex(StringRef Name) {
147     auto R = Files.find(Name);
148     if (R != Files.end()) {
149       assert(R->second > 0 && "got index of compilation dir");
150       return R->second;
151     }
152     unsigned Index = Files.size() + 1;
153     Files.try_emplace(Name, Index);
154     return Index;
155   }
156 
157   // Return the file index of file 'Name' for the current function.
158   // Add the file into the global map if necessary.
159   // See also InputFunctionCoverageData::ReverseVirtualFileMapping
160   // for additional comments.
161   unsigned getFileIndexForFunction(StringRef Name) {
162     unsigned GlobalIndex = getGlobalFileIndex(Name);
163     auto &CurrentFunctionFileMapping =
164         InputFunctions.back().ReverseVirtualFileMapping;
165     auto R = CurrentFunctionFileMapping.find(GlobalIndex);
166     if (R != CurrentFunctionFileMapping.end()) {
167       assert(R->second > 0 && "got index of compilation dir");
168       return R->second;
169     }
170     unsigned IndexInFunction = CurrentFunctionFileMapping.size();
171     CurrentFunctionFileMapping.insert(
172         std::make_pair(GlobalIndex, IndexInFunction));
173     return IndexInFunction;
174   }
175 
176   void startFunction(StringRef FuncName, uint64_t Hash) {
177     InputFunctions.emplace_back(FuncName.str(), Hash);
178   }
179 
180   void addCMR(Counter C, StringRef File, unsigned LS, unsigned CS, unsigned LE,
181               unsigned CE, bool Skipped = false) {
182     auto &Regions = InputFunctions.back().Regions;
183     unsigned FileID = getFileIndexForFunction(File);
184     Regions.push_back(
185         Skipped ? CounterMappingRegion::makeSkipped(FileID, LS, CS, LE, CE)
186                 : CounterMappingRegion::makeRegion(C, FileID, LS, CS, LE, CE));
187   }
188 
189   void addExpansionCMR(StringRef File, StringRef ExpandedFile, unsigned LS,
190                        unsigned CS, unsigned LE, unsigned CE) {
191     InputFunctions.back().Regions.push_back(CounterMappingRegion::makeExpansion(
192         getFileIndexForFunction(File), getFileIndexForFunction(ExpandedFile),
193         LS, CS, LE, CE));
194   }
195 
196   std::string writeCoverageRegions(InputFunctionCoverageData &Data) {
197     SmallVector<unsigned, 8> FileIDs(Data.ReverseVirtualFileMapping.size());
198     for (const auto &E : Data.ReverseVirtualFileMapping)
199       FileIDs[E.second] = E.first;
200     std::string Coverage;
201     llvm::raw_string_ostream OS(Coverage);
202     CoverageMappingWriter(FileIDs, None, Data.Regions).write(OS);
203     return OS.str();
204   }
205 
206   void readCoverageRegions(const std::string &Coverage,
207                            OutputFunctionCoverageData &Data) {
208     // We will re-use the StringRef in duplicate tests, clear it to avoid
209     // clobber previous ones.
210     Filenames.clear();
211     Filenames.resize(Files.size() + 1);
212     for (const auto &E : Files)
213       Filenames[E.getValue()] = E.getKey().str();
214     std::vector<CounterExpression> Expressions;
215     ArrayRef<std::string> FilenameRefs = llvm::makeArrayRef(Filenames);
216     RawCoverageMappingReader Reader(Coverage, FilenameRefs, Data.Filenames,
217                                     Expressions, Data.Regions);
218     EXPECT_THAT_ERROR(Reader.read(), Succeeded());
219   }
220 
221   void writeAndReadCoverageRegions(bool EmitFilenames = true) {
222     OutputFunctions.resize(InputFunctions.size());
223     for (unsigned I = 0; I < InputFunctions.size(); ++I) {
224       std::string Regions = writeCoverageRegions(InputFunctions[I]);
225       readCoverageRegions(Regions, OutputFunctions[I]);
226       OutputFunctions[I].Name = InputFunctions[I].Name;
227       OutputFunctions[I].Hash = InputFunctions[I].Hash;
228       if (!EmitFilenames)
229         OutputFunctions[I].Filenames.clear();
230     }
231   }
232 
233   void readProfCounts() {
234     auto Profile = ProfileWriter.writeBuffer();
235     auto ReaderOrErr = IndexedInstrProfReader::create(std::move(Profile));
236     EXPECT_THAT_ERROR(ReaderOrErr.takeError(), Succeeded());
237     ProfileReader = std::move(ReaderOrErr.get());
238   }
239 
240   Expected<std::unique_ptr<CoverageMapping>> readOutputFunctions() {
241     std::vector<std::unique_ptr<CoverageMappingReader>> CoverageReaders;
242     if (UseMultipleReaders) {
243       for (const auto &OF : OutputFunctions) {
244         ArrayRef<OutputFunctionCoverageData> Funcs(OF);
245         CoverageReaders.push_back(
246             std::make_unique<CoverageMappingReaderMock>(Funcs));
247       }
248     } else {
249       ArrayRef<OutputFunctionCoverageData> Funcs(OutputFunctions);
250       CoverageReaders.push_back(
251           std::make_unique<CoverageMappingReaderMock>(Funcs));
252     }
253     return CoverageMapping::load(CoverageReaders, *ProfileReader);
254   }
255 
256   Error loadCoverageMapping(bool EmitFilenames = true) {
257     readProfCounts();
258     writeAndReadCoverageRegions(EmitFilenames);
259     auto CoverageOrErr = readOutputFunctions();
260     if (!CoverageOrErr)
261       return CoverageOrErr.takeError();
262     LoadedCoverage = std::move(CoverageOrErr.get());
263     return Error::success();
264   }
265 };
266 
267 TEST_P(CoverageMappingTest, basic_write_read) {
268   startFunction("func", 0x1234);
269   addCMR(Counter::getCounter(0), "foo", 1, 1, 1, 1);
270   addCMR(Counter::getCounter(1), "foo", 2, 1, 2, 2);
271   addCMR(Counter::getZero(),     "foo", 3, 1, 3, 4);
272   addCMR(Counter::getCounter(2), "foo", 4, 1, 4, 8);
273   addCMR(Counter::getCounter(3), "bar", 1, 2, 3, 4);
274 
275   writeAndReadCoverageRegions();
276   ASSERT_EQ(1u, InputFunctions.size());
277   ASSERT_EQ(1u, OutputFunctions.size());
278   InputFunctionCoverageData &Input = InputFunctions.back();
279   OutputFunctionCoverageData &Output = OutputFunctions.back();
280 
281   size_t N = makeArrayRef(Input.Regions).size();
282   ASSERT_EQ(N, Output.Regions.size());
283   for (size_t I = 0; I < N; ++I) {
284     ASSERT_EQ(Input.Regions[I].Count, Output.Regions[I].Count);
285     ASSERT_EQ(Input.Regions[I].FileID, Output.Regions[I].FileID);
286     ASSERT_EQ(Input.Regions[I].startLoc(), Output.Regions[I].startLoc());
287     ASSERT_EQ(Input.Regions[I].endLoc(), Output.Regions[I].endLoc());
288     ASSERT_EQ(Input.Regions[I].Kind, Output.Regions[I].Kind);
289   }
290 }
291 
292 TEST_P(CoverageMappingTest, correct_deserialize_for_more_than_two_files) {
293   const char *FileNames[] = {"bar", "baz", "foo"};
294   static const unsigned N = array_lengthof(FileNames);
295 
296   startFunction("func", 0x1234);
297   for (unsigned I = 0; I < N; ++I)
298     // Use LineStart to hold the index of the file name
299     // in order to preserve that information during possible sorting of CMRs.
300     addCMR(Counter::getCounter(0), FileNames[I], I, 1, I, 1);
301 
302   writeAndReadCoverageRegions();
303   ASSERT_EQ(1u, OutputFunctions.size());
304   OutputFunctionCoverageData &Output = OutputFunctions.back();
305 
306   ASSERT_EQ(N, Output.Regions.size());
307   ASSERT_EQ(N, Output.Filenames.size());
308 
309   for (unsigned I = 0; I < N; ++I) {
310     ASSERT_GT(N, Output.Regions[I].FileID);
311     ASSERT_GT(N, Output.Regions[I].LineStart);
312     EXPECT_EQ(FileNames[Output.Regions[I].LineStart],
313               Output.Filenames[Output.Regions[I].FileID]);
314   }
315 }
316 
317 static const auto Err = [](Error E) { FAIL(); };
318 
319 TEST_P(CoverageMappingTest, load_coverage_for_more_than_two_files) {
320   ProfileWriter.addRecord({"func", 0x1234, {0}}, Err);
321 
322   const char *FileNames[] = {"bar", "baz", "foo"};
323   static const unsigned N = array_lengthof(FileNames);
324 
325   startFunction("func", 0x1234);
326   for (unsigned I = 0; I < N; ++I)
327     // Use LineStart to hold the index of the file name
328     // in order to preserve that information during possible sorting of CMRs.
329     addCMR(Counter::getCounter(0), FileNames[I], I, 1, I, 1);
330 
331   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
332 
333   for (unsigned I = 0; I < N; ++I) {
334     CoverageData Data = LoadedCoverage->getCoverageForFile(FileNames[I]);
335     ASSERT_TRUE(!Data.empty());
336     EXPECT_EQ(I, Data.begin()->Line);
337   }
338 }
339 
340 TEST_P(CoverageMappingTest, load_coverage_with_bogus_function_name) {
341   ProfileWriter.addRecord({"", 0x1234, {10}}, Err);
342   startFunction("", 0x1234);
343   addCMR(Counter::getCounter(0), "foo", 1, 1, 5, 5);
344   EXPECT_TRUE(ErrorEquals(coveragemap_error::malformed, loadCoverageMapping()));
345 }
346 
347 TEST_P(CoverageMappingTest, load_coverage_for_several_functions) {
348   ProfileWriter.addRecord({"func1", 0x1234, {10}}, Err);
349   ProfileWriter.addRecord({"func2", 0x2345, {20}}, Err);
350 
351   startFunction("func1", 0x1234);
352   addCMR(Counter::getCounter(0), "foo", 1, 1, 5, 5);
353 
354   startFunction("func2", 0x2345);
355   addCMR(Counter::getCounter(0), "bar", 2, 2, 6, 6);
356 
357   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
358 
359   const auto FunctionRecords = LoadedCoverage->getCoveredFunctions();
360   EXPECT_EQ(2, std::distance(FunctionRecords.begin(), FunctionRecords.end()));
361   for (const auto &FunctionRecord : FunctionRecords) {
362     CoverageData Data = LoadedCoverage->getCoverageForFunction(FunctionRecord);
363     std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
364     ASSERT_EQ(2U, Segments.size());
365     if (FunctionRecord.Name == "func1") {
366       EXPECT_EQ(CoverageSegment(1, 1, 10, true), Segments[0]);
367       EXPECT_EQ(CoverageSegment(5, 5, false), Segments[1]);
368     } else {
369       ASSERT_EQ("func2", FunctionRecord.Name);
370       EXPECT_EQ(CoverageSegment(2, 2, 20, true), Segments[0]);
371       EXPECT_EQ(CoverageSegment(6, 6, false), Segments[1]);
372     }
373   }
374 }
375 
376 TEST_P(CoverageMappingTest, create_combined_regions) {
377   ProfileWriter.addRecord({"func1", 0x1234, {1, 2, 3}}, Err);
378   startFunction("func1", 0x1234);
379 
380   // Given regions which start at the same location, emit a segment for the
381   // last region.
382   addCMR(Counter::getCounter(0), "file1", 1, 1, 2, 2);
383   addCMR(Counter::getCounter(1), "file1", 1, 1, 2, 2);
384   addCMR(Counter::getCounter(2), "file1", 1, 1, 2, 2);
385 
386   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
387   const auto FunctionRecords = LoadedCoverage->getCoveredFunctions();
388   const auto &FunctionRecord = *FunctionRecords.begin();
389   CoverageData Data = LoadedCoverage->getCoverageForFunction(FunctionRecord);
390   std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
391 
392   ASSERT_EQ(2U, Segments.size());
393   EXPECT_EQ(CoverageSegment(1, 1, 6, true), Segments[0]);
394   EXPECT_EQ(CoverageSegment(2, 2, false), Segments[1]);
395 }
396 
397 TEST_P(CoverageMappingTest, skipped_segments_have_no_count) {
398   ProfileWriter.addRecord({"func1", 0x1234, {1}}, Err);
399   startFunction("func1", 0x1234);
400 
401   addCMR(Counter::getCounter(0), "file1", 1, 1, 5, 5);
402   addCMR(Counter::getCounter(0), "file1", 5, 1, 5, 5, /*Skipped=*/true);
403 
404   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
405   const auto FunctionRecords = LoadedCoverage->getCoveredFunctions();
406   const auto &FunctionRecord = *FunctionRecords.begin();
407   CoverageData Data = LoadedCoverage->getCoverageForFunction(FunctionRecord);
408   std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
409 
410   ASSERT_EQ(3U, Segments.size());
411   EXPECT_EQ(CoverageSegment(1, 1, 1, true), Segments[0]);
412   EXPECT_EQ(CoverageSegment(5, 1, true), Segments[1]);
413   EXPECT_EQ(CoverageSegment(5, 5, false), Segments[2]);
414 }
415 
416 TEST_P(CoverageMappingTest, multiple_regions_end_after_parent_ends) {
417   ProfileWriter.addRecord({"func1", 0x1234, {1, 0}}, Err);
418   startFunction("func1", 0x1234);
419 
420   // 1| F{ a{
421   // 2|
422   // 3|    a} b{ c{
423   // 4|
424   // 5|    b}
425   // 6|
426   // 7| c} d{   e{
427   // 8|
428   // 9| d}      e} F}
429   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9); // < F
430   addCMR(Counter::getCounter(0), "file1", 1, 1, 3, 5); // < a
431   addCMR(Counter::getCounter(0), "file1", 3, 5, 5, 4); // < b
432   addCMR(Counter::getCounter(1), "file1", 3, 5, 7, 3); // < c
433   addCMR(Counter::getCounter(1), "file1", 7, 3, 9, 2); // < d
434   addCMR(Counter::getCounter(1), "file1", 7, 7, 9, 7); // < e
435 
436   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
437   const auto FunctionRecords = LoadedCoverage->getCoveredFunctions();
438   const auto &FunctionRecord = *FunctionRecords.begin();
439   CoverageData Data = LoadedCoverage->getCoverageForFunction(FunctionRecord);
440   std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
441 
442   // Old output (not sorted or unique):
443   //   Segment at 1:1 with count 1
444   //   Segment at 1:1 with count 1
445   //   Segment at 3:5 with count 1
446   //   Segment at 3:5 with count 0
447   //   Segment at 3:5 with count 1
448   //   Segment at 5:4 with count 0
449   //   Segment at 7:3 with count 1
450   //   Segment at 7:3 with count 0
451   //   Segment at 7:7 with count 0
452   //   Segment at 9:7 with count 0
453   //   Segment at 9:2 with count 1
454   //   Top level segment at 9:9
455 
456   // New output (sorted and unique):
457   //   Segment at 1:1 (count = 1), RegionEntry
458   //   Segment at 3:5 (count = 1), RegionEntry
459   //   Segment at 5:4 (count = 0)
460   //   Segment at 7:3 (count = 0), RegionEntry
461   //   Segment at 7:7 (count = 0), RegionEntry
462   //   Segment at 9:2 (count = 0)
463   //   Segment at 9:7 (count = 1)
464   //   Segment at 9:9 (count = 0), Skipped
465 
466   ASSERT_EQ(8U, Segments.size());
467   EXPECT_EQ(CoverageSegment(1, 1, 1, true), Segments[0]);
468   EXPECT_EQ(CoverageSegment(3, 5, 1, true), Segments[1]);
469   EXPECT_EQ(CoverageSegment(5, 4, 0, false), Segments[2]);
470   EXPECT_EQ(CoverageSegment(7, 3, 0, true), Segments[3]);
471   EXPECT_EQ(CoverageSegment(7, 7, 0, true), Segments[4]);
472   EXPECT_EQ(CoverageSegment(9, 2, 0, false), Segments[5]);
473   EXPECT_EQ(CoverageSegment(9, 7, 1, false), Segments[6]);
474   EXPECT_EQ(CoverageSegment(9, 9, false), Segments[7]);
475 }
476 
477 TEST_P(CoverageMappingTest, multiple_completed_segments_at_same_loc) {
478   ProfileWriter.addRecord({"func1", 0x1234, {0, 1, 2}}, Err);
479   startFunction("func1", 0x1234);
480 
481   // PR35495
482   addCMR(Counter::getCounter(1), "file1", 2, 1, 18, 2);
483   addCMR(Counter::getCounter(0), "file1", 8, 10, 14, 6);
484   addCMR(Counter::getCounter(0), "file1", 8, 12, 14, 6);
485   addCMR(Counter::getCounter(1), "file1", 9, 1, 14, 6);
486   addCMR(Counter::getCounter(2), "file1", 11, 13, 11, 14);
487 
488   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
489   const auto FunctionRecords = LoadedCoverage->getCoveredFunctions();
490   const auto &FunctionRecord = *FunctionRecords.begin();
491   CoverageData Data = LoadedCoverage->getCoverageForFunction(FunctionRecord);
492   std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
493 
494   ASSERT_EQ(7U, Segments.size());
495   EXPECT_EQ(CoverageSegment(2, 1, 1, true), Segments[0]);
496   EXPECT_EQ(CoverageSegment(8, 10, 0, true), Segments[1]);
497   EXPECT_EQ(CoverageSegment(8, 12, 0, true), Segments[2]);
498   EXPECT_EQ(CoverageSegment(9, 1, 1, true), Segments[3]);
499   EXPECT_EQ(CoverageSegment(11, 13, 2, true), Segments[4]);
500   // Use count=1 (from 9:1 -> 14:6), not count=0 (from 8:12 -> 14:6).
501   EXPECT_EQ(CoverageSegment(11, 14, 1, false), Segments[5]);
502   EXPECT_EQ(CoverageSegment(18, 2, false), Segments[6]);
503 }
504 
505 TEST_P(CoverageMappingTest, dont_emit_redundant_segments) {
506   ProfileWriter.addRecord({"func1", 0x1234, {1, 1}}, Err);
507   startFunction("func1", 0x1234);
508 
509   addCMR(Counter::getCounter(0), "file1", 1, 1, 4, 4);
510   addCMR(Counter::getCounter(1), "file1", 2, 2, 5, 5);
511   addCMR(Counter::getCounter(0), "file1", 3, 3, 6, 6);
512 
513   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
514   const auto FunctionRecords = LoadedCoverage->getCoveredFunctions();
515   const auto &FunctionRecord = *FunctionRecords.begin();
516   CoverageData Data = LoadedCoverage->getCoverageForFunction(FunctionRecord);
517   std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
518 
519   ASSERT_EQ(5U, Segments.size());
520   EXPECT_EQ(CoverageSegment(1, 1, 1, true), Segments[0]);
521   EXPECT_EQ(CoverageSegment(2, 2, 1, true), Segments[1]);
522   EXPECT_EQ(CoverageSegment(3, 3, 1, true), Segments[2]);
523   EXPECT_EQ(CoverageSegment(4, 4, 1, false), Segments[3]);
524   // A closing segment starting at 5:5 would be redundant: it would have the
525   // same count as the segment starting at 4:4, and has all the same metadata.
526   EXPECT_EQ(CoverageSegment(6, 6, false), Segments[4]);
527 }
528 
529 TEST_P(CoverageMappingTest, dont_emit_closing_segment_at_new_region_start) {
530   ProfileWriter.addRecord({"func1", 0x1234, {1}}, Err);
531   startFunction("func1", 0x1234);
532 
533   addCMR(Counter::getCounter(0), "file1", 1, 1, 6, 5);
534   addCMR(Counter::getCounter(0), "file1", 2, 2, 6, 5);
535   addCMR(Counter::getCounter(0), "file1", 3, 3, 6, 5);
536   addCMR(Counter::getCounter(0), "file1", 6, 5, 7, 7);
537 
538   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
539   const auto FunctionRecords = LoadedCoverage->getCoveredFunctions();
540   const auto &FunctionRecord = *FunctionRecords.begin();
541   CoverageData Data = LoadedCoverage->getCoverageForFunction(FunctionRecord);
542   std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
543 
544   ASSERT_EQ(5U, Segments.size());
545   EXPECT_EQ(CoverageSegment(1, 1, 1, true), Segments[0]);
546   EXPECT_EQ(CoverageSegment(2, 2, 1, true), Segments[1]);
547   EXPECT_EQ(CoverageSegment(3, 3, 1, true), Segments[2]);
548   EXPECT_EQ(CoverageSegment(6, 5, 1, true), Segments[3]);
549   // The old segment builder would get this wrong by emitting multiple segments
550   // which start at 6:5 (a few of which were skipped segments). We should just
551   // get a segment for the region entry.
552   EXPECT_EQ(CoverageSegment(7, 7, false), Segments[4]);
553 }
554 
555 TEST_P(CoverageMappingTest, handle_consecutive_regions_with_zero_length) {
556   ProfileWriter.addRecord({"func1", 0x1234, {1, 2}}, Err);
557   startFunction("func1", 0x1234);
558 
559   addCMR(Counter::getCounter(0), "file1", 1, 1, 1, 1);
560   addCMR(Counter::getCounter(1), "file1", 1, 1, 1, 1);
561   addCMR(Counter::getCounter(0), "file1", 1, 1, 1, 1);
562   addCMR(Counter::getCounter(1), "file1", 1, 1, 1, 1);
563   addCMR(Counter::getCounter(0), "file1", 1, 1, 1, 1);
564 
565   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
566   const auto FunctionRecords = LoadedCoverage->getCoveredFunctions();
567   const auto &FunctionRecord = *FunctionRecords.begin();
568   CoverageData Data = LoadedCoverage->getCoverageForFunction(FunctionRecord);
569   std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
570 
571   ASSERT_EQ(1U, Segments.size());
572   EXPECT_EQ(CoverageSegment(1, 1, true), Segments[0]);
573   // We need to get a skipped segment starting at 1:1. In this case there is
574   // also a region entry at 1:1.
575 }
576 
577 TEST_P(CoverageMappingTest, handle_sandwiched_zero_length_region) {
578   ProfileWriter.addRecord({"func1", 0x1234, {2, 1}}, Err);
579   startFunction("func1", 0x1234);
580 
581   addCMR(Counter::getCounter(0), "file1", 1, 5, 4, 4);
582   addCMR(Counter::getCounter(1), "file1", 1, 9, 1, 50);
583   addCMR(Counter::getCounter(1), "file1", 2, 7, 2, 34);
584   addCMR(Counter::getCounter(1), "file1", 3, 5, 3, 21);
585   addCMR(Counter::getCounter(1), "file1", 3, 21, 3, 21);
586   addCMR(Counter::getCounter(1), "file1", 4, 12, 4, 17);
587 
588   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
589   const auto FunctionRecords = LoadedCoverage->getCoveredFunctions();
590   const auto &FunctionRecord = *FunctionRecords.begin();
591   CoverageData Data = LoadedCoverage->getCoverageForFunction(FunctionRecord);
592   std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
593 
594   ASSERT_EQ(10U, Segments.size());
595   EXPECT_EQ(CoverageSegment(1, 5, 2, true), Segments[0]);
596   EXPECT_EQ(CoverageSegment(1, 9, 1, true), Segments[1]);
597   EXPECT_EQ(CoverageSegment(1, 50, 2, false), Segments[2]);
598   EXPECT_EQ(CoverageSegment(2, 7, 1, true), Segments[3]);
599   EXPECT_EQ(CoverageSegment(2, 34, 2, false), Segments[4]);
600   EXPECT_EQ(CoverageSegment(3, 5, 1, true), Segments[5]);
601   EXPECT_EQ(CoverageSegment(3, 21, 2, true), Segments[6]);
602   // Handle the zero-length region by creating a segment with its predecessor's
603   // count (i.e the count from 1:5 -> 4:4).
604   EXPECT_EQ(CoverageSegment(4, 4, false), Segments[7]);
605   // The area between 4:4 and 4:12 is skipped.
606   EXPECT_EQ(CoverageSegment(4, 12, 1, true), Segments[8]);
607   EXPECT_EQ(CoverageSegment(4, 17, false), Segments[9]);
608 }
609 
610 TEST_P(CoverageMappingTest, handle_last_completed_region) {
611   ProfileWriter.addRecord({"func1", 0x1234, {1, 2, 3, 4}}, Err);
612   startFunction("func1", 0x1234);
613 
614   addCMR(Counter::getCounter(0), "file1", 1, 1, 8, 8);
615   addCMR(Counter::getCounter(1), "file1", 2, 2, 5, 5);
616   addCMR(Counter::getCounter(2), "file1", 3, 3, 4, 4);
617   addCMR(Counter::getCounter(3), "file1", 6, 6, 7, 7);
618 
619   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
620   const auto FunctionRecords = LoadedCoverage->getCoveredFunctions();
621   const auto &FunctionRecord = *FunctionRecords.begin();
622   CoverageData Data = LoadedCoverage->getCoverageForFunction(FunctionRecord);
623   std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
624 
625   ASSERT_EQ(8U, Segments.size());
626   EXPECT_EQ(CoverageSegment(1, 1, 1, true), Segments[0]);
627   EXPECT_EQ(CoverageSegment(2, 2, 2, true), Segments[1]);
628   EXPECT_EQ(CoverageSegment(3, 3, 3, true), Segments[2]);
629   EXPECT_EQ(CoverageSegment(4, 4, 2, false), Segments[3]);
630   EXPECT_EQ(CoverageSegment(5, 5, 1, false), Segments[4]);
631   EXPECT_EQ(CoverageSegment(6, 6, 4, true), Segments[5]);
632   EXPECT_EQ(CoverageSegment(7, 7, 1, false), Segments[6]);
633   EXPECT_EQ(CoverageSegment(8, 8, false), Segments[7]);
634 }
635 
636 TEST_P(CoverageMappingTest, expansion_gets_first_counter) {
637   startFunction("func", 0x1234);
638   addCMR(Counter::getCounter(1), "foo", 10, 1, 10, 2);
639   // This starts earlier in "foo", so the expansion should get its counter.
640   addCMR(Counter::getCounter(2), "foo", 1, 1, 20, 1);
641   addExpansionCMR("bar", "foo", 3, 3, 3, 3);
642 
643   writeAndReadCoverageRegions();
644   ASSERT_EQ(1u, OutputFunctions.size());
645   OutputFunctionCoverageData &Output = OutputFunctions.back();
646 
647   ASSERT_EQ(CounterMappingRegion::ExpansionRegion, Output.Regions[2].Kind);
648   ASSERT_EQ(Counter::getCounter(2), Output.Regions[2].Count);
649   ASSERT_EQ(3U, Output.Regions[2].LineStart);
650 }
651 
652 TEST_P(CoverageMappingTest, basic_coverage_iteration) {
653   ProfileWriter.addRecord({"func", 0x1234, {30, 20, 10, 0}}, Err);
654 
655   startFunction("func", 0x1234);
656   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
657   addCMR(Counter::getCounter(1), "file1", 1, 1, 4, 7);
658   addCMR(Counter::getCounter(2), "file1", 5, 8, 9, 1);
659   addCMR(Counter::getCounter(3), "file1", 10, 10, 11, 11);
660   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
661 
662   CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
663   std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
664   ASSERT_EQ(7U, Segments.size());
665   ASSERT_EQ(CoverageSegment(1, 1, 20, true),  Segments[0]);
666   ASSERT_EQ(CoverageSegment(4, 7, 30, false), Segments[1]);
667   ASSERT_EQ(CoverageSegment(5, 8, 10, true),  Segments[2]);
668   ASSERT_EQ(CoverageSegment(9, 1, 30, false), Segments[3]);
669   ASSERT_EQ(CoverageSegment(9, 9, false),     Segments[4]);
670   ASSERT_EQ(CoverageSegment(10, 10, 0, true), Segments[5]);
671   ASSERT_EQ(CoverageSegment(11, 11, false),   Segments[6]);
672 }
673 
674 TEST_P(CoverageMappingTest, test_line_coverage_iterator) {
675   ProfileWriter.addRecord({"func", 0x1234, {30, 20, 10, 0}}, Err);
676 
677   startFunction("func", 0x1234);
678   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
679   addCMR(Counter::getCounter(1), "file1", 1, 1, 4, 7);
680   addCMR(Counter::getCounter(2), "file1", 5, 8, 9, 1);
681   addCMR(Counter::getCounter(3), "file1", 10, 10, 11, 11);
682   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
683 
684   CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
685 
686   unsigned Line = 0;
687   unsigned LineCounts[] = {20, 20, 20, 20, 10, 10, 10, 10, 10, 0, 0};
688   for (const auto &LCS : getLineCoverageStats(Data)) {
689     ASSERT_EQ(Line + 1, LCS.getLine());
690     errs() << "Line: " << Line + 1 << ", count = " << LCS.getExecutionCount() << "\n";
691     ASSERT_EQ(LineCounts[Line], LCS.getExecutionCount());
692     ++Line;
693   }
694   ASSERT_EQ(11U, Line);
695 }
696 
697 TEST_P(CoverageMappingTest, uncovered_function) {
698   startFunction("func", 0x1234);
699   addCMR(Counter::getZero(), "file1", 1, 2, 3, 4);
700   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
701 
702   CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
703   std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
704   ASSERT_EQ(2U, Segments.size());
705   ASSERT_EQ(CoverageSegment(1, 2, 0, true), Segments[0]);
706   ASSERT_EQ(CoverageSegment(3, 4, false),   Segments[1]);
707 }
708 
709 TEST_P(CoverageMappingTest, uncovered_function_with_mapping) {
710   startFunction("func", 0x1234);
711   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
712   addCMR(Counter::getCounter(1), "file1", 1, 1, 4, 7);
713   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
714 
715   CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
716   std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
717   ASSERT_EQ(3U, Segments.size());
718   ASSERT_EQ(CoverageSegment(1, 1, 0, true),  Segments[0]);
719   ASSERT_EQ(CoverageSegment(4, 7, 0, false), Segments[1]);
720   ASSERT_EQ(CoverageSegment(9, 9, false),    Segments[2]);
721 }
722 
723 TEST_P(CoverageMappingTest, combine_regions) {
724   ProfileWriter.addRecord({"func", 0x1234, {10, 20, 30}}, Err);
725 
726   startFunction("func", 0x1234);
727   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
728   addCMR(Counter::getCounter(1), "file1", 3, 3, 4, 4);
729   addCMR(Counter::getCounter(2), "file1", 3, 3, 4, 4);
730   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
731 
732   CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
733   std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
734   ASSERT_EQ(4U, Segments.size());
735   ASSERT_EQ(CoverageSegment(1, 1, 10, true), Segments[0]);
736   ASSERT_EQ(CoverageSegment(3, 3, 50, true), Segments[1]);
737   ASSERT_EQ(CoverageSegment(4, 4, 10, false), Segments[2]);
738   ASSERT_EQ(CoverageSegment(9, 9, false), Segments[3]);
739 }
740 
741 TEST_P(CoverageMappingTest, restore_combined_counter_after_nested_region) {
742   ProfileWriter.addRecord({"func", 0x1234, {10, 20, 40}}, Err);
743 
744   startFunction("func", 0x1234);
745   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
746   addCMR(Counter::getCounter(1), "file1", 1, 1, 9, 9);
747   addCMR(Counter::getCounter(2), "file1", 3, 3, 5, 5);
748   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
749 
750   CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
751   std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
752   ASSERT_EQ(4U, Segments.size());
753   EXPECT_EQ(CoverageSegment(1, 1, 30, true), Segments[0]);
754   EXPECT_EQ(CoverageSegment(3, 3, 40, true), Segments[1]);
755   EXPECT_EQ(CoverageSegment(5, 5, 30, false), Segments[2]);
756   EXPECT_EQ(CoverageSegment(9, 9, false), Segments[3]);
757 }
758 
759 // If CodeRegions and ExpansionRegions cover the same area,
760 // only counts of CodeRegions should be used.
761 TEST_P(CoverageMappingTest, dont_combine_expansions) {
762   ProfileWriter.addRecord({"func", 0x1234, {10, 20}}, Err);
763   ProfileWriter.addRecord({"func", 0x1234, {0, 0}}, Err);
764 
765   startFunction("func", 0x1234);
766   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
767   addCMR(Counter::getCounter(1), "file1", 3, 3, 4, 4);
768   addCMR(Counter::getCounter(1), "include1", 6, 6, 7, 7);
769   addExpansionCMR("file1", "include1", 3, 3, 4, 4);
770   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
771 
772   CoverageData Data = LoadedCoverage->getCoverageForFile("file1");
773   std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
774   ASSERT_EQ(4U, Segments.size());
775   ASSERT_EQ(CoverageSegment(1, 1, 10, true), Segments[0]);
776   ASSERT_EQ(CoverageSegment(3, 3, 20, true), Segments[1]);
777   ASSERT_EQ(CoverageSegment(4, 4, 10, false), Segments[2]);
778   ASSERT_EQ(CoverageSegment(9, 9, false), Segments[3]);
779 }
780 
781 // If an area is covered only by ExpansionRegions, they should be combinated.
782 TEST_P(CoverageMappingTest, combine_expansions) {
783   ProfileWriter.addRecord({"func", 0x1234, {2, 3, 7}}, Err);
784 
785   startFunction("func", 0x1234);
786   addCMR(Counter::getCounter(1), "include1", 1, 1, 1, 10);
787   addCMR(Counter::getCounter(2), "include2", 1, 1, 1, 10);
788   addCMR(Counter::getCounter(0), "file", 1, 1, 5, 5);
789   addExpansionCMR("file", "include1", 3, 1, 3, 5);
790   addExpansionCMR("file", "include2", 3, 1, 3, 5);
791 
792   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
793 
794   CoverageData Data = LoadedCoverage->getCoverageForFile("file");
795   std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
796   ASSERT_EQ(4U, Segments.size());
797   EXPECT_EQ(CoverageSegment(1, 1, 2, true), Segments[0]);
798   EXPECT_EQ(CoverageSegment(3, 1, 10, true), Segments[1]);
799   EXPECT_EQ(CoverageSegment(3, 5, 2, false), Segments[2]);
800   EXPECT_EQ(CoverageSegment(5, 5, false), Segments[3]);
801 }
802 
803 TEST_P(CoverageMappingTest, strip_filename_prefix) {
804   ProfileWriter.addRecord({"file1:func", 0x1234, {0}}, Err);
805 
806   startFunction("file1:func", 0x1234);
807   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
808   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
809 
810   std::vector<std::string> Names;
811   for (const auto &Func : LoadedCoverage->getCoveredFunctions())
812     Names.push_back(Func.Name);
813   ASSERT_EQ(1U, Names.size());
814   ASSERT_EQ("func", Names[0]);
815 }
816 
817 TEST_P(CoverageMappingTest, strip_unknown_filename_prefix) {
818   ProfileWriter.addRecord({"<unknown>:func", 0x1234, {0}}, Err);
819 
820   startFunction("<unknown>:func", 0x1234);
821   addCMR(Counter::getCounter(0), "", 1, 1, 9, 9);
822   EXPECT_THAT_ERROR(loadCoverageMapping(/*EmitFilenames=*/false), Succeeded());
823 
824   std::vector<std::string> Names;
825   for (const auto &Func : LoadedCoverage->getCoveredFunctions())
826     Names.push_back(Func.Name);
827   ASSERT_EQ(1U, Names.size());
828   ASSERT_EQ("func", Names[0]);
829 }
830 
831 TEST_P(CoverageMappingTest, dont_detect_false_instantiations) {
832   ProfileWriter.addRecord({"foo", 0x1234, {10}}, Err);
833   ProfileWriter.addRecord({"bar", 0x2345, {20}}, Err);
834 
835   startFunction("foo", 0x1234);
836   addCMR(Counter::getCounter(0), "expanded", 1, 1, 1, 10);
837   addExpansionCMR("main", "expanded", 4, 1, 4, 5);
838 
839   startFunction("bar", 0x2345);
840   addCMR(Counter::getCounter(0), "expanded", 1, 1, 1, 10);
841   addExpansionCMR("main", "expanded", 9, 1, 9, 5);
842 
843   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
844 
845   std::vector<InstantiationGroup> InstantiationGroups =
846       LoadedCoverage->getInstantiationGroups("expanded");
847   ASSERT_TRUE(InstantiationGroups.empty());
848 }
849 
850 TEST_P(CoverageMappingTest, load_coverage_for_expanded_file) {
851   ProfileWriter.addRecord({"func", 0x1234, {10}}, Err);
852 
853   startFunction("func", 0x1234);
854   addCMR(Counter::getCounter(0), "expanded", 1, 1, 1, 10);
855   addExpansionCMR("main", "expanded", 4, 1, 4, 5);
856 
857   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
858 
859   CoverageData Data = LoadedCoverage->getCoverageForFile("expanded");
860   std::vector<CoverageSegment> Segments(Data.begin(), Data.end());
861   ASSERT_EQ(2U, Segments.size());
862   EXPECT_EQ(CoverageSegment(1, 1, 10, true), Segments[0]);
863   EXPECT_EQ(CoverageSegment(1, 10, false), Segments[1]);
864 }
865 
866 TEST_P(CoverageMappingTest, skip_duplicate_function_record) {
867   ProfileWriter.addRecord({"func", 0x1234, {1}}, Err);
868 
869   // This record should be loaded.
870   startFunction("func", 0x1234);
871   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
872 
873   // This record should be loaded.
874   startFunction("func", 0x1234);
875   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
876   addCMR(Counter::getCounter(0), "file2", 1, 1, 9, 9);
877 
878   // This record should be skipped.
879   startFunction("func", 0x1234);
880   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
881 
882   // This record should be loaded.
883   startFunction("func", 0x1234);
884   addCMR(Counter::getCounter(0), "file2", 1, 1, 9, 9);
885   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
886 
887   // This record should be skipped.
888   startFunction("func", 0x1234);
889   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
890   addCMR(Counter::getCounter(0), "file2", 1, 1, 9, 9);
891 
892   EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
893 
894   auto Funcs = LoadedCoverage->getCoveredFunctions();
895   unsigned NumFuncs = std::distance(Funcs.begin(), Funcs.end());
896   ASSERT_EQ(3U, NumFuncs);
897 }
898 
899 // FIXME: Use ::testing::Combine() when llvm updates its copy of googletest.
900 INSTANTIATE_TEST_CASE_P(ParameterizedCovMapTest, CoverageMappingTest,
901                         ::testing::Values(std::pair<bool, bool>({false, false}),
902                                           std::pair<bool, bool>({false, true}),
903                                           std::pair<bool, bool>({true, false}),
904                                           std::pair<bool, bool>({true, true})),);
905 
906 TEST(CoverageMappingTest, filename_roundtrip) {
907   std::vector<std::string> Paths({"", "a", "b", "c", "d", "e"});
908 
909   for (bool Compress : {false, true}) {
910     std::string EncodedFilenames;
911     {
912       raw_string_ostream OS(EncodedFilenames);
913       CoverageFilenamesSectionWriter Writer(Paths);
914       Writer.write(OS, Compress);
915     }
916 
917     std::vector<std::string> ReadFilenames;
918     RawCoverageFilenamesReader Reader(EncodedFilenames, ReadFilenames);
919     EXPECT_THAT_ERROR(Reader.read(CovMapVersion::CurrentVersion), Succeeded());
920 
921     ASSERT_EQ(ReadFilenames.size(), Paths.size());
922     for (unsigned I = 1; I < Paths.size(); ++I)
923       ASSERT_TRUE(ReadFilenames[I] == Paths[I]);
924   }
925 }
926 
927 } // end anonymous namespace
928