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