llvm.org GIT mirror llvm / e2f7bf8
Simplify InstrProfRecord tests, eliminating named temporaries in favor of braced init args This will also simplify an API transition and class renaming coming soon. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307236 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 2 years ago
2 changed file(s) with 57 addition(s) and 108 deletion(s). Raw diff Collapse all Expand all
308308 }
309309
310310 TEST_P(CoverageMappingTest, load_coverage_for_more_than_two_files) {
311 InstrProfRecord Record("func", 0x1234, {0});
312 NoError(ProfileWriter.addRecord(std::move(Record)));
311 NoError(ProfileWriter.addRecord({"func", 0x1234, {0}}));
313312
314313 const char *FileNames[] = {"bar", "baz", "foo"};
315314 static const unsigned N = array_lengthof(FileNames);
330329 }
331330
332331 TEST_P(CoverageMappingTest, load_coverage_with_bogus_function_name) {
333 InstrProfRecord RecordFunc1("", 0x1234, {10});
334 NoError(ProfileWriter.addRecord(std::move(RecordFunc1)));
332 NoError(ProfileWriter.addRecord({"", 0x1234, {10}}));
335333 startFunction("", 0x1234);
336334 addCMR(Counter::getCounter(0), "foo", 1, 1, 5, 5);
337335 ErrorEquals(coveragemap_error::malformed, loadCoverageMapping());
338336 }
339337
340338 TEST_P(CoverageMappingTest, load_coverage_for_several_functions) {
341 InstrProfRecord RecordFunc1("func1", 0x1234, {10});
342 NoError(ProfileWriter.addRecord(std::move(RecordFunc1)));
343 InstrProfRecord RecordFunc2("func2", 0x2345, {20});
344 NoError(ProfileWriter.addRecord(std::move(RecordFunc2)));
339 NoError(ProfileWriter.addRecord({"func1", 0x1234, {10}}));
340 NoError(ProfileWriter.addRecord({"func2", 0x2345, {20}}));
345341
346342 startFunction("func1", 0x1234);
347343 addCMR(Counter::getCounter(0), "foo", 1, 1, 5, 5);
385381 }
386382
387383 TEST_P(CoverageMappingTest, basic_coverage_iteration) {
388 InstrProfRecord Record("func", 0x1234, {30, 20, 10, 0});
389 NoError(ProfileWriter.addRecord(std::move(Record)));
384 NoError(ProfileWriter.addRecord({"func", 0x1234, {30, 20, 10, 0}}));
390385
391386 startFunction("func", 0x1234);
392387 addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
434429 }
435430
436431 TEST_P(CoverageMappingTest, combine_regions) {
437 InstrProfRecord Record("func", 0x1234, {10, 20, 30});
438 NoError(ProfileWriter.addRecord(std::move(Record)));
432 NoError(ProfileWriter.addRecord({"func", 0x1234, {10, 20, 30}}));
439433
440434 startFunction("func", 0x1234);
441435 addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
453447 }
454448
455449 TEST_P(CoverageMappingTest, restore_combined_counter_after_nested_region) {
456 InstrProfRecord Record("func", 0x1234, {10, 20, 40});
457 NoError(ProfileWriter.addRecord(std::move(Record)));
450 NoError(ProfileWriter.addRecord({"func", 0x1234, {10, 20, 40}}));
458451
459452 startFunction("func", 0x1234);
460453 addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
474467 // If CodeRegions and ExpansionRegions cover the same area,
475468 // only counts of CodeRegions should be used.
476469 TEST_P(CoverageMappingTest, dont_combine_expansions) {
477 InstrProfRecord Record1("func", 0x1234, {10, 20});
478 InstrProfRecord Record2("func", 0x1234, {0, 0});
479 NoError(ProfileWriter.addRecord(std::move(Record1)));
480 NoError(ProfileWriter.addRecord(std::move(Record2)));
470 NoError(ProfileWriter.addRecord({"func", 0x1234, {10, 20}}));
471 NoError(ProfileWriter.addRecord({"func", 0x1234, {0, 0}}));
481472
482473 startFunction("func", 0x1234);
483474 addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
497488
498489 // If an area is covered only by ExpansionRegions, they should be combinated.
499490 TEST_P(CoverageMappingTest, combine_expansions) {
500 InstrProfRecord Record("func", 0x1234, {2, 3, 7});
501 NoError(ProfileWriter.addRecord(std::move(Record)));
491 NoError(ProfileWriter.addRecord({"func", 0x1234, {2, 3, 7}}));
502492
503493 startFunction("func", 0x1234);
504494 addCMR(Counter::getCounter(1), "include1", 1, 1, 1, 10);
519509 }
520510
521511 TEST_P(CoverageMappingTest, strip_filename_prefix) {
522 InstrProfRecord Record("file1:func", 0x1234, {0});
523 NoError(ProfileWriter.addRecord(std::move(Record)));
512 NoError(ProfileWriter.addRecord({"file1:func", 0x1234, {0}}));
524513
525514 startFunction("file1:func", 0x1234);
526515 addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
534523 }
535524
536525 TEST_P(CoverageMappingTest, strip_unknown_filename_prefix) {
537 InstrProfRecord Record(":func", 0x1234, {0});
538 NoError(ProfileWriter.addRecord(std::move(Record)));
526 NoError(ProfileWriter.addRecord({":func", 0x1234, {0}}));
539527
540528 startFunction(":func", 0x1234);
541529 addCMR(Counter::getCounter(0), "", 1, 1, 9, 9);
549537 }
550538
551539 TEST_P(CoverageMappingTest, dont_detect_false_instantiations) {
552 InstrProfRecord Record1("foo", 0x1234, {10});
553 InstrProfRecord Record2("bar", 0x2345, {20});
554 NoError(ProfileWriter.addRecord(std::move(Record1)));
555 NoError(ProfileWriter.addRecord(std::move(Record2)));
540 NoError(ProfileWriter.addRecord({"foo", 0x1234, {10}}));
541 NoError(ProfileWriter.addRecord({"bar", 0x2345, {20}}));
556542
557543 startFunction("foo", 0x1234);
558544 addCMR(Counter::getCounter(0), "expanded", 1, 1, 1, 10);
570556 }
571557
572558 TEST_P(CoverageMappingTest, load_coverage_for_expanded_file) {
573 InstrProfRecord Record("func", 0x1234, {10});
574 NoError(ProfileWriter.addRecord(std::move(Record)));
559 NoError(ProfileWriter.addRecord({"func", 0x1234, {10}}));
575560
576561 startFunction("func", 0x1234);
577562 addCMR(Counter::getCounter(0), "expanded", 1, 1, 1, 10);
587572 }
588573
589574 TEST_P(CoverageMappingTest, skip_duplicate_function_record) {
590 InstrProfRecord Record("func", 0x1234, {1});
591 NoError(ProfileWriter.addRecord(std::move(Record)));
575 NoError(ProfileWriter.addRecord({"func", 0x1234, {1}}));
592576
593577 startFunction("func", 0x1234);
594578 addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
6969 }
7070
7171 TEST_P(MaybeSparseInstrProfTest, write_and_read_one_function) {
72 InstrProfRecord Record("foo", 0x1234, {1, 2, 3, 4});
73 NoError(Writer.addRecord(std::move(Record)));
72 NoError(Writer.addRecord({"foo", 0x1234, {1, 2, 3, 4}}));
7473 auto Profile = Writer.writeBuffer();
7574 readProfile(std::move(Profile));
7675
8786 }
8887
8988 TEST_P(MaybeSparseInstrProfTest, get_instr_prof_record) {
90 InstrProfRecord Record1("foo", 0x1234, {1, 2});
91 InstrProfRecord Record2("foo", 0x1235, {3, 4});
92 NoError(Writer.addRecord(std::move(Record1)));
93 NoError(Writer.addRecord(std::move(Record2)));
89 NoError(Writer.addRecord({"foo", 0x1234, {1, 2}}));
90 NoError(Writer.addRecord({"foo", 0x1235, {3, 4}}));
9491 auto Profile = Writer.writeBuffer();
9592 readProfile(std::move(Profile));
9693
114111 }
115112
116113 TEST_P(MaybeSparseInstrProfTest, get_function_counts) {
117 InstrProfRecord Record1("foo", 0x1234, {1, 2});
118 InstrProfRecord Record2("foo", 0x1235, {3, 4});
119 NoError(Writer.addRecord(std::move(Record1)));
120 NoError(Writer.addRecord(std::move(Record2)));
114 NoError(Writer.addRecord({"foo", 0x1234, {1, 2}}));
115 NoError(Writer.addRecord({"foo", 0x1235, {3, 4}}));
121116 auto Profile = Writer.writeBuffer();
122117 readProfile(std::move(Profile));
123118
141136
142137 // Profile data is copied from general.proftext
143138 TEST_F(InstrProfTest, get_profile_summary) {
144 InstrProfRecord Record1("func1", 0x1234, {97531});
145 InstrProfRecord Record2("func2", 0x1234, {0, 0});
146 InstrProfRecord Record3("func3", 0x1234,
147 {2305843009213693952, 1152921504606846976,
148 576460752303423488, 288230376151711744,
149 144115188075855872, 72057594037927936});
150 InstrProfRecord Record4("func4", 0x1234, {0});
151 NoError(Writer.addRecord(std::move(Record1)));
152 NoError(Writer.addRecord(std::move(Record2)));
153 NoError(Writer.addRecord(std::move(Record3)));
154 NoError(Writer.addRecord(std::move(Record4)));
139 NoError(Writer.addRecord({"func1", 0x1234, {97531}}));
140 NoError(Writer.addRecord({"func2", 0x1234, {0, 0}}));
141 NoError(Writer.addRecord(
142 {"func3",
143 0x1234,
144 {2305843009213693952, 1152921504606846976, 576460752303423488,
145 288230376151711744, 144115188075855872, 72057594037927936}}));
146 NoError(Writer.addRecord({"func4", 0x1234, {0}}));
155147 auto Profile = Writer.writeBuffer();
156148 readProfile(std::move(Profile));
157149
202194 }
203195
204196 TEST_F(InstrProfTest, test_writer_merge) {
205 InstrProfRecord Record1("func1", 0x1234, {42});
206 NoError(Writer.addRecord(std::move(Record1)));
197 NoError(Writer.addRecord({"func1", 0x1234, {42}}));
207198
208199 InstrProfWriter Writer2;
209 InstrProfRecord Record2("func2", 0x1234, {0, 0});
210 NoError(Writer2.addRecord(std::move(Record2)));
200 NoError(Writer2.addRecord({"func2", 0x1234, {0, 0}}));
211201
212202 NoError(Writer.mergeRecordsFromWriter(std::move(Writer2)));
213203
235225
236226 TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write) {
237227 InstrProfRecord Record1("caller", 0x1234, {1, 2});
238 InstrProfRecord Record2("callee1", 0x1235, {3, 4});
239 InstrProfRecord Record3("callee2", 0x1235, {3, 4});
240 InstrProfRecord Record4("callee3", 0x1235, {3, 4});
241228
242229 // 4 value sites.
243230 Record1.reserveSites(IPVK_IndirectCallTarget, 4);
252239 Record1.addValueData(IPVK_IndirectCallTarget, 3, VD3, 1, nullptr);
253240
254241 NoError(Writer.addRecord(std::move(Record1)));
255 NoError(Writer.addRecord(std::move(Record2)));
256 NoError(Writer.addRecord(std::move(Record3)));
257 NoError(Writer.addRecord(std::move(Record4)));
242 NoError(Writer.addRecord({"callee1", 0x1235, {3, 4}}));
243 NoError(Writer.addRecord({"callee2", 0x1235, {3, 4}}));
244 NoError(Writer.addRecord({"callee3", 0x1235, {3, 4}}));
258245 auto Profile = Writer.writeBuffer();
259246 readProfile(std::move(Profile));
260247
378365
379366 TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write_with_weight) {
380367 InstrProfRecord Record1("caller", 0x1234, {1, 2});
381 InstrProfRecord Record2("callee1", 0x1235, {3, 4});
382 InstrProfRecord Record3("callee2", 0x1235, {3, 4});
383 InstrProfRecord Record4("callee3", 0x1235, {3, 4});
384368
385369 // 4 value sites.
386370 Record1.reserveSites(IPVK_IndirectCallTarget, 4);
395379 Record1.addValueData(IPVK_IndirectCallTarget, 3, VD3, 1, nullptr);
396380
397381 NoError(Writer.addRecord(std::move(Record1), 10));
398 NoError(Writer.addRecord(std::move(Record2)));
399 NoError(Writer.addRecord(std::move(Record3)));
400 NoError(Writer.addRecord(std::move(Record4)));
382 NoError(Writer.addRecord({"callee1", 0x1235, {3, 4}}));
383 NoError(Writer.addRecord({"callee2", 0x1235, {3, 4}}));
384 NoError(Writer.addRecord({"callee3", 0x1235, {3, 4}}));
401385 auto Profile = Writer.writeBuffer();
402386 readProfile(std::move(Profile));
403387
424408
425409 TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write_big_endian) {
426410 InstrProfRecord Record1("caller", 0x1234, {1, 2});
427 InstrProfRecord Record2("callee1", 0x1235, {3, 4});
428 InstrProfRecord Record3("callee2", 0x1235, {3, 4});
429 InstrProfRecord Record4("callee3", 0x1235, {3, 4});
430411
431412 // 4 value sites.
432413 Record1.reserveSites(IPVK_IndirectCallTarget, 4);
441422 Record1.addValueData(IPVK_IndirectCallTarget, 3, VD3, 1, nullptr);
442423
443424 NoError(Writer.addRecord(std::move(Record1)));
444 NoError(Writer.addRecord(std::move(Record2)));
445 NoError(Writer.addRecord(std::move(Record3)));
446 NoError(Writer.addRecord(std::move(Record4)));
425 NoError(Writer.addRecord({"callee1", 0x1235, {3, 4}}));
426 NoError(Writer.addRecord({"callee2", 0x1235, {3, 4}}));
427 NoError(Writer.addRecord({"callee3", 0x1235, {3, 4}}));
447428
448429 // Set big endian output.
449430 Writer.setValueProfDataEndianness(support::big);
476457 static const char caller[] = "caller";
477458 InstrProfRecord Record11(caller, 0x1234, {1, 2});
478459 InstrProfRecord Record12(caller, 0x1234, {1, 2});
479 InstrProfRecord Record2(callee1, 0x1235, {3, 4});
480 InstrProfRecord Record3(callee2, 0x1235, {3, 4});
481 InstrProfRecord Record4(callee3, 0x1235, {3, 4});
482 InstrProfRecord Record5(callee3, 0x1235, {3, 4});
483 InstrProfRecord Record6(callee4, 0x1235, {3, 5});
484460
485461 // 5 value sites.
486462 Record11.reserveSites(IPVK_IndirectCallTarget, 5);
528504 // Merge profile data.
529505 NoError(Writer.addRecord(std::move(Record12)));
530506
531 NoError(Writer.addRecord(std::move(Record2)));
532 NoError(Writer.addRecord(std::move(Record3)));
533 NoError(Writer.addRecord(std::move(Record4)));
534 NoError(Writer.addRecord(std::move(Record5)));
535 NoError(Writer.addRecord(std::move(Record6)));
507 NoError(Writer.addRecord({callee1, 0x1235, {3, 4}}));
508 NoError(Writer.addRecord({callee2, 0x1235, {3, 4}}));
509 NoError(Writer.addRecord({callee3, 0x1235, {3, 4}}));
510 NoError(Writer.addRecord({callee3, 0x1235, {3, 4}}));
511 NoError(Writer.addRecord({callee4, 0x1235, {3, 5}}));
536512 auto Profile = Writer.writeBuffer();
537513 readProfile(std::move(Profile));
538514
587563
588564 const uint64_t Max = std::numeric_limits::max();
589565
590 InstrProfRecord Record1("foo", 0x1234, {1});
591 auto Result1 = Writer.addRecord(std::move(Record1));
566 auto Result1 = Writer.addRecord({"foo", 0x1234, {1}});
592567 ASSERT_EQ(InstrProfError::take(std::move(Result1)),
593568 instrprof_error::success);
594569
595570 // Verify counter overflow.
596 InstrProfRecord Record2("foo", 0x1234, {Max});
597 auto Result2 = Writer.addRecord(std::move(Record2));
571 auto Result2 = Writer.addRecord({"foo", 0x1234, {Max}});
598572 ASSERT_EQ(InstrProfError::take(std::move(Result2)),
599573 instrprof_error::counter_overflow);
600574
601 InstrProfRecord Record3(bar, 0x9012, {8});
602 auto Result3 = Writer.addRecord(std::move(Record3));
575 auto Result3 = Writer.addRecord({bar, 0x9012, {8}});
603576 ASSERT_EQ(InstrProfError::take(std::move(Result3)),
604577 instrprof_error::success);
605578
816789 }
817790
818791 TEST_P(MaybeSparseInstrProfTest, get_max_function_count) {
819 InstrProfRecord Record1("foo", 0x1234, {1ULL << 31, 2});
820 InstrProfRecord Record2("bar", 0, {1ULL << 63});
821 InstrProfRecord Record3("baz", 0x5678, {0, 0, 0, 0});
822 NoError(Writer.addRecord(std::move(Record1)));
823 NoError(Writer.addRecord(std::move(Record2)));
824 NoError(Writer.addRecord(std::move(Record3)));
792 NoError(Writer.addRecord({"foo", 0x1234, {1ULL << 31, 2}}));
793 NoError(Writer.addRecord({"bar", 0, {1ULL << 63}}));
794 NoError(Writer.addRecord({"baz", 0x5678, {0, 0, 0, 0}}));
825795 auto Profile = Writer.writeBuffer();
826796 readProfile(std::move(Profile));
827797
829799 }
830800
831801 TEST_P(MaybeSparseInstrProfTest, get_weighted_function_counts) {
832 InstrProfRecord Record1("foo", 0x1234, {1, 2});
833 InstrProfRecord Record2("foo", 0x1235, {3, 4});
834 NoError(Writer.addRecord(std::move(Record1), 3));
835 NoError(Writer.addRecord(std::move(Record2), 5));
802 NoError(Writer.addRecord({"foo", 0x1234, {1, 2}}, 3));
803 NoError(Writer.addRecord({"foo", 0x1235, {3, 4}}, 5));
836804 auto Profile = Writer.writeBuffer();
837805 readProfile(std::move(Profile));
838806
1014982 }
1015983
1016984 TEST_F(SparseInstrProfTest, preserve_no_records) {
1017 InstrProfRecord Record1("foo", 0x1234, {0});
1018 InstrProfRecord Record2("bar", 0x4321, {0, 0});
1019 InstrProfRecord Record3("bar", 0x4321, {0, 0, 0});
1020
1021 NoError(Writer.addRecord(std::move(Record1)));
1022 NoError(Writer.addRecord(std::move(Record2)));
1023 NoError(Writer.addRecord(std::move(Record3)));
985 NoError(Writer.addRecord({"foo", 0x1234, {0}}));
986 NoError(Writer.addRecord({"bar", 0x4321, {0, 0}}));
987 NoError(Writer.addRecord({"bar", 0x4321, {0, 0, 0}}));
988
1024989 auto Profile = Writer.writeBuffer();
1025990 readProfile(std::move(Profile));
1026991