summaryrefslogtreecommitdiff
path: root/unittests/ProfileData
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2017-07-06 05:19:17 +0000
committerDavid Blaikie <dblaikie@gmail.com>2017-07-06 05:19:17 +0000
commite2f7bf8c93ce495e3bb1a3891a79a690f7f2016f (patch)
tree8a2dcc31ac60b7d81484bede5e7b33dafb868790 /unittests/ProfileData
parent7e0b3ee2a665587755dc0091d0466573bc730ea9 (diff)
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
Diffstat (limited to 'unittests/ProfileData')
-rw-r--r--unittests/ProfileData/CoverageMappingTest.cpp48
-rw-r--r--unittests/ProfileData/InstrProfTest.cpp115
2 files changed, 56 insertions, 107 deletions
diff --git a/unittests/ProfileData/CoverageMappingTest.cpp b/unittests/ProfileData/CoverageMappingTest.cpp
index 1d621f4060c..a2ffa4dca54 100644
--- a/unittests/ProfileData/CoverageMappingTest.cpp
+++ b/unittests/ProfileData/CoverageMappingTest.cpp
@@ -309,8 +309,7 @@ TEST_P(CoverageMappingTest, correct_deserialize_for_more_than_two_files) {
}
TEST_P(CoverageMappingTest, load_coverage_for_more_than_two_files) {
- InstrProfRecord Record("func", 0x1234, {0});
- NoError(ProfileWriter.addRecord(std::move(Record)));
+ NoError(ProfileWriter.addRecord({"func", 0x1234, {0}}));
const char *FileNames[] = {"bar", "baz", "foo"};
static const unsigned N = array_lengthof(FileNames);
@@ -331,18 +330,15 @@ TEST_P(CoverageMappingTest, load_coverage_for_more_than_two_files) {
}
TEST_P(CoverageMappingTest, load_coverage_with_bogus_function_name) {
- InstrProfRecord RecordFunc1("", 0x1234, {10});
- NoError(ProfileWriter.addRecord(std::move(RecordFunc1)));
+ NoError(ProfileWriter.addRecord({"", 0x1234, {10}}));
startFunction("", 0x1234);
addCMR(Counter::getCounter(0), "foo", 1, 1, 5, 5);
ErrorEquals(coveragemap_error::malformed, loadCoverageMapping());
}
TEST_P(CoverageMappingTest, load_coverage_for_several_functions) {
- InstrProfRecord RecordFunc1("func1", 0x1234, {10});
- NoError(ProfileWriter.addRecord(std::move(RecordFunc1)));
- InstrProfRecord RecordFunc2("func2", 0x2345, {20});
- NoError(ProfileWriter.addRecord(std::move(RecordFunc2)));
+ NoError(ProfileWriter.addRecord({"func1", 0x1234, {10}}));
+ NoError(ProfileWriter.addRecord({"func2", 0x2345, {20}}));
startFunction("func1", 0x1234);
addCMR(Counter::getCounter(0), "foo", 1, 1, 5, 5);
@@ -386,8 +382,7 @@ TEST_P(CoverageMappingTest, expansion_gets_first_counter) {
}
TEST_P(CoverageMappingTest, basic_coverage_iteration) {
- InstrProfRecord Record("func", 0x1234, {30, 20, 10, 0});
- NoError(ProfileWriter.addRecord(std::move(Record)));
+ NoError(ProfileWriter.addRecord({"func", 0x1234, {30, 20, 10, 0}}));
startFunction("func", 0x1234);
addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
@@ -435,8 +430,7 @@ TEST_P(CoverageMappingTest, uncovered_function_with_mapping) {
}
TEST_P(CoverageMappingTest, combine_regions) {
- InstrProfRecord Record("func", 0x1234, {10, 20, 30});
- NoError(ProfileWriter.addRecord(std::move(Record)));
+ NoError(ProfileWriter.addRecord({"func", 0x1234, {10, 20, 30}}));
startFunction("func", 0x1234);
addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
@@ -454,8 +448,7 @@ TEST_P(CoverageMappingTest, combine_regions) {
}
TEST_P(CoverageMappingTest, restore_combined_counter_after_nested_region) {
- InstrProfRecord Record("func", 0x1234, {10, 20, 40});
- NoError(ProfileWriter.addRecord(std::move(Record)));
+ NoError(ProfileWriter.addRecord({"func", 0x1234, {10, 20, 40}}));
startFunction("func", 0x1234);
addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
@@ -475,10 +468,8 @@ TEST_P(CoverageMappingTest, restore_combined_counter_after_nested_region) {
// If CodeRegions and ExpansionRegions cover the same area,
// only counts of CodeRegions should be used.
TEST_P(CoverageMappingTest, dont_combine_expansions) {
- InstrProfRecord Record1("func", 0x1234, {10, 20});
- InstrProfRecord Record2("func", 0x1234, {0, 0});
- NoError(ProfileWriter.addRecord(std::move(Record1)));
- NoError(ProfileWriter.addRecord(std::move(Record2)));
+ NoError(ProfileWriter.addRecord({"func", 0x1234, {10, 20}}));
+ NoError(ProfileWriter.addRecord({"func", 0x1234, {0, 0}}));
startFunction("func", 0x1234);
addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
@@ -498,8 +489,7 @@ TEST_P(CoverageMappingTest, dont_combine_expansions) {
// If an area is covered only by ExpansionRegions, they should be combinated.
TEST_P(CoverageMappingTest, combine_expansions) {
- InstrProfRecord Record("func", 0x1234, {2, 3, 7});
- NoError(ProfileWriter.addRecord(std::move(Record)));
+ NoError(ProfileWriter.addRecord({"func", 0x1234, {2, 3, 7}}));
startFunction("func", 0x1234);
addCMR(Counter::getCounter(1), "include1", 1, 1, 1, 10);
@@ -520,8 +510,7 @@ TEST_P(CoverageMappingTest, combine_expansions) {
}
TEST_P(CoverageMappingTest, strip_filename_prefix) {
- InstrProfRecord Record("file1:func", 0x1234, {0});
- NoError(ProfileWriter.addRecord(std::move(Record)));
+ NoError(ProfileWriter.addRecord({"file1:func", 0x1234, {0}}));
startFunction("file1:func", 0x1234);
addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
@@ -535,8 +524,7 @@ TEST_P(CoverageMappingTest, strip_filename_prefix) {
}
TEST_P(CoverageMappingTest, strip_unknown_filename_prefix) {
- InstrProfRecord Record("<unknown>:func", 0x1234, {0});
- NoError(ProfileWriter.addRecord(std::move(Record)));
+ NoError(ProfileWriter.addRecord({"<unknown>:func", 0x1234, {0}}));
startFunction("<unknown>:func", 0x1234);
addCMR(Counter::getCounter(0), "", 1, 1, 9, 9);
@@ -550,10 +538,8 @@ TEST_P(CoverageMappingTest, strip_unknown_filename_prefix) {
}
TEST_P(CoverageMappingTest, dont_detect_false_instantiations) {
- InstrProfRecord Record1("foo", 0x1234, {10});
- InstrProfRecord Record2("bar", 0x2345, {20});
- NoError(ProfileWriter.addRecord(std::move(Record1)));
- NoError(ProfileWriter.addRecord(std::move(Record2)));
+ NoError(ProfileWriter.addRecord({"foo", 0x1234, {10}}));
+ NoError(ProfileWriter.addRecord({"bar", 0x2345, {20}}));
startFunction("foo", 0x1234);
addCMR(Counter::getCounter(0), "expanded", 1, 1, 1, 10);
@@ -571,8 +557,7 @@ TEST_P(CoverageMappingTest, dont_detect_false_instantiations) {
}
TEST_P(CoverageMappingTest, load_coverage_for_expanded_file) {
- InstrProfRecord Record("func", 0x1234, {10});
- NoError(ProfileWriter.addRecord(std::move(Record)));
+ NoError(ProfileWriter.addRecord({"func", 0x1234, {10}}));
startFunction("func", 0x1234);
addCMR(Counter::getCounter(0), "expanded", 1, 1, 1, 10);
@@ -588,8 +573,7 @@ TEST_P(CoverageMappingTest, load_coverage_for_expanded_file) {
}
TEST_P(CoverageMappingTest, skip_duplicate_function_record) {
- InstrProfRecord Record("func", 0x1234, {1});
- NoError(ProfileWriter.addRecord(std::move(Record)));
+ NoError(ProfileWriter.addRecord({"func", 0x1234, {1}}));
startFunction("func", 0x1234);
addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
diff --git a/unittests/ProfileData/InstrProfTest.cpp b/unittests/ProfileData/InstrProfTest.cpp
index 13436cc0d5b..76f172a21b0 100644
--- a/unittests/ProfileData/InstrProfTest.cpp
+++ b/unittests/ProfileData/InstrProfTest.cpp
@@ -70,8 +70,7 @@ TEST_P(MaybeSparseInstrProfTest, write_and_read_empty_profile) {
}
TEST_P(MaybeSparseInstrProfTest, write_and_read_one_function) {
- InstrProfRecord Record("foo", 0x1234, {1, 2, 3, 4});
- NoError(Writer.addRecord(std::move(Record)));
+ NoError(Writer.addRecord({"foo", 0x1234, {1, 2, 3, 4}}));
auto Profile = Writer.writeBuffer();
readProfile(std::move(Profile));
@@ -88,10 +87,8 @@ TEST_P(MaybeSparseInstrProfTest, write_and_read_one_function) {
}
TEST_P(MaybeSparseInstrProfTest, get_instr_prof_record) {
- InstrProfRecord Record1("foo", 0x1234, {1, 2});
- InstrProfRecord Record2("foo", 0x1235, {3, 4});
- NoError(Writer.addRecord(std::move(Record1)));
- NoError(Writer.addRecord(std::move(Record2)));
+ NoError(Writer.addRecord({"foo", 0x1234, {1, 2}}));
+ NoError(Writer.addRecord({"foo", 0x1235, {3, 4}}));
auto Profile = Writer.writeBuffer();
readProfile(std::move(Profile));
@@ -115,10 +112,8 @@ TEST_P(MaybeSparseInstrProfTest, get_instr_prof_record) {
}
TEST_P(MaybeSparseInstrProfTest, get_function_counts) {
- InstrProfRecord Record1("foo", 0x1234, {1, 2});
- InstrProfRecord Record2("foo", 0x1235, {3, 4});
- NoError(Writer.addRecord(std::move(Record1)));
- NoError(Writer.addRecord(std::move(Record2)));
+ NoError(Writer.addRecord({"foo", 0x1234, {1, 2}}));
+ NoError(Writer.addRecord({"foo", 0x1235, {3, 4}}));
auto Profile = Writer.writeBuffer();
readProfile(std::move(Profile));
@@ -142,17 +137,14 @@ TEST_P(MaybeSparseInstrProfTest, get_function_counts) {
// Profile data is copied from general.proftext
TEST_F(InstrProfTest, get_profile_summary) {
- InstrProfRecord Record1("func1", 0x1234, {97531});
- InstrProfRecord Record2("func2", 0x1234, {0, 0});
- InstrProfRecord Record3("func3", 0x1234,
- {2305843009213693952, 1152921504606846976,
- 576460752303423488, 288230376151711744,
- 144115188075855872, 72057594037927936});
- InstrProfRecord Record4("func4", 0x1234, {0});
- NoError(Writer.addRecord(std::move(Record1)));
- NoError(Writer.addRecord(std::move(Record2)));
- NoError(Writer.addRecord(std::move(Record3)));
- NoError(Writer.addRecord(std::move(Record4)));
+ NoError(Writer.addRecord({"func1", 0x1234, {97531}}));
+ NoError(Writer.addRecord({"func2", 0x1234, {0, 0}}));
+ NoError(Writer.addRecord(
+ {"func3",
+ 0x1234,
+ {2305843009213693952, 1152921504606846976, 576460752303423488,
+ 288230376151711744, 144115188075855872, 72057594037927936}}));
+ NoError(Writer.addRecord({"func4", 0x1234, {0}}));
auto Profile = Writer.writeBuffer();
readProfile(std::move(Profile));
@@ -203,12 +195,10 @@ TEST_F(InstrProfTest, get_profile_summary) {
}
TEST_F(InstrProfTest, test_writer_merge) {
- InstrProfRecord Record1("func1", 0x1234, {42});
- NoError(Writer.addRecord(std::move(Record1)));
+ NoError(Writer.addRecord({"func1", 0x1234, {42}}));
InstrProfWriter Writer2;
- InstrProfRecord Record2("func2", 0x1234, {0, 0});
- NoError(Writer2.addRecord(std::move(Record2)));
+ NoError(Writer2.addRecord({"func2", 0x1234, {0, 0}}));
NoError(Writer.mergeRecordsFromWriter(std::move(Writer2)));
@@ -236,9 +226,6 @@ static const char callee6[] = "callee6";
TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write) {
InstrProfRecord Record1("caller", 0x1234, {1, 2});
- InstrProfRecord Record2("callee1", 0x1235, {3, 4});
- InstrProfRecord Record3("callee2", 0x1235, {3, 4});
- InstrProfRecord Record4("callee3", 0x1235, {3, 4});
// 4 value sites.
Record1.reserveSites(IPVK_IndirectCallTarget, 4);
@@ -253,9 +240,9 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write) {
Record1.addValueData(IPVK_IndirectCallTarget, 3, VD3, 1, nullptr);
NoError(Writer.addRecord(std::move(Record1)));
- NoError(Writer.addRecord(std::move(Record2)));
- NoError(Writer.addRecord(std::move(Record3)));
- NoError(Writer.addRecord(std::move(Record4)));
+ NoError(Writer.addRecord({"callee1", 0x1235, {3, 4}}));
+ NoError(Writer.addRecord({"callee2", 0x1235, {3, 4}}));
+ NoError(Writer.addRecord({"callee3", 0x1235, {3, 4}}));
auto Profile = Writer.writeBuffer();
readProfile(std::move(Profile));
@@ -379,9 +366,6 @@ TEST_P(MaybeSparseInstrProfTest, annotate_vp_data) {
TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write_with_weight) {
InstrProfRecord Record1("caller", 0x1234, {1, 2});
- InstrProfRecord Record2("callee1", 0x1235, {3, 4});
- InstrProfRecord Record3("callee2", 0x1235, {3, 4});
- InstrProfRecord Record4("callee3", 0x1235, {3, 4});
// 4 value sites.
Record1.reserveSites(IPVK_IndirectCallTarget, 4);
@@ -396,9 +380,9 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write_with_weight) {
Record1.addValueData(IPVK_IndirectCallTarget, 3, VD3, 1, nullptr);
NoError(Writer.addRecord(std::move(Record1), 10));
- NoError(Writer.addRecord(std::move(Record2)));
- NoError(Writer.addRecord(std::move(Record3)));
- NoError(Writer.addRecord(std::move(Record4)));
+ NoError(Writer.addRecord({"callee1", 0x1235, {3, 4}}));
+ NoError(Writer.addRecord({"callee2", 0x1235, {3, 4}}));
+ NoError(Writer.addRecord({"callee3", 0x1235, {3, 4}}));
auto Profile = Writer.writeBuffer();
readProfile(std::move(Profile));
@@ -425,9 +409,6 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write_with_weight) {
TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write_big_endian) {
InstrProfRecord Record1("caller", 0x1234, {1, 2});
- InstrProfRecord Record2("callee1", 0x1235, {3, 4});
- InstrProfRecord Record3("callee2", 0x1235, {3, 4});
- InstrProfRecord Record4("callee3", 0x1235, {3, 4});
// 4 value sites.
Record1.reserveSites(IPVK_IndirectCallTarget, 4);
@@ -442,9 +423,9 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write_big_endian) {
Record1.addValueData(IPVK_IndirectCallTarget, 3, VD3, 1, nullptr);
NoError(Writer.addRecord(std::move(Record1)));
- NoError(Writer.addRecord(std::move(Record2)));
- NoError(Writer.addRecord(std::move(Record3)));
- NoError(Writer.addRecord(std::move(Record4)));
+ NoError(Writer.addRecord({"callee1", 0x1235, {3, 4}}));
+ NoError(Writer.addRecord({"callee2", 0x1235, {3, 4}}));
+ NoError(Writer.addRecord({"callee3", 0x1235, {3, 4}}));
// Set big endian output.
Writer.setValueProfDataEndianness(support::big);
@@ -477,11 +458,6 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_merge1) {
static const char caller[] = "caller";
InstrProfRecord Record11(caller, 0x1234, {1, 2});
InstrProfRecord Record12(caller, 0x1234, {1, 2});
- InstrProfRecord Record2(callee1, 0x1235, {3, 4});
- InstrProfRecord Record3(callee2, 0x1235, {3, 4});
- InstrProfRecord Record4(callee3, 0x1235, {3, 4});
- InstrProfRecord Record5(callee3, 0x1235, {3, 4});
- InstrProfRecord Record6(callee4, 0x1235, {3, 5});
// 5 value sites.
Record11.reserveSites(IPVK_IndirectCallTarget, 5);
@@ -529,11 +505,11 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_merge1) {
// Merge profile data.
NoError(Writer.addRecord(std::move(Record12)));
- NoError(Writer.addRecord(std::move(Record2)));
- NoError(Writer.addRecord(std::move(Record3)));
- NoError(Writer.addRecord(std::move(Record4)));
- NoError(Writer.addRecord(std::move(Record5)));
- NoError(Writer.addRecord(std::move(Record6)));
+ NoError(Writer.addRecord({callee1, 0x1235, {3, 4}}));
+ NoError(Writer.addRecord({callee2, 0x1235, {3, 4}}));
+ NoError(Writer.addRecord({callee3, 0x1235, {3, 4}}));
+ NoError(Writer.addRecord({callee3, 0x1235, {3, 4}}));
+ NoError(Writer.addRecord({callee4, 0x1235, {3, 5}}));
auto Profile = Writer.writeBuffer();
readProfile(std::move(Profile));
@@ -588,19 +564,16 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_merge1_saturation) {
const uint64_t Max = std::numeric_limits<uint64_t>::max();
- InstrProfRecord Record1("foo", 0x1234, {1});
- auto Result1 = Writer.addRecord(std::move(Record1));
+ auto Result1 = Writer.addRecord({"foo", 0x1234, {1}});
ASSERT_EQ(InstrProfError::take(std::move(Result1)),
instrprof_error::success);
// Verify counter overflow.
- InstrProfRecord Record2("foo", 0x1234, {Max});
- auto Result2 = Writer.addRecord(std::move(Record2));
+ auto Result2 = Writer.addRecord({"foo", 0x1234, {Max}});
ASSERT_EQ(InstrProfError::take(std::move(Result2)),
instrprof_error::counter_overflow);
- InstrProfRecord Record3(bar, 0x9012, {8});
- auto Result3 = Writer.addRecord(std::move(Record3));
+ auto Result3 = Writer.addRecord({bar, 0x9012, {8}});
ASSERT_EQ(InstrProfError::take(std::move(Result3)),
instrprof_error::success);
@@ -817,12 +790,9 @@ TEST_P(MaybeSparseInstrProfTest, value_prof_data_read_write_mapping) {
}
TEST_P(MaybeSparseInstrProfTest, get_max_function_count) {
- InstrProfRecord Record1("foo", 0x1234, {1ULL << 31, 2});
- InstrProfRecord Record2("bar", 0, {1ULL << 63});
- InstrProfRecord Record3("baz", 0x5678, {0, 0, 0, 0});
- NoError(Writer.addRecord(std::move(Record1)));
- NoError(Writer.addRecord(std::move(Record2)));
- NoError(Writer.addRecord(std::move(Record3)));
+ NoError(Writer.addRecord({"foo", 0x1234, {1ULL << 31, 2}}));
+ NoError(Writer.addRecord({"bar", 0, {1ULL << 63}}));
+ NoError(Writer.addRecord({"baz", 0x5678, {0, 0, 0, 0}}));
auto Profile = Writer.writeBuffer();
readProfile(std::move(Profile));
@@ -830,10 +800,8 @@ TEST_P(MaybeSparseInstrProfTest, get_max_function_count) {
}
TEST_P(MaybeSparseInstrProfTest, get_weighted_function_counts) {
- InstrProfRecord Record1("foo", 0x1234, {1, 2});
- InstrProfRecord Record2("foo", 0x1235, {3, 4});
- NoError(Writer.addRecord(std::move(Record1), 3));
- NoError(Writer.addRecord(std::move(Record2), 5));
+ NoError(Writer.addRecord({"foo", 0x1234, {1, 2}}, 3));
+ NoError(Writer.addRecord({"foo", 0x1235, {3, 4}}, 5));
auto Profile = Writer.writeBuffer();
readProfile(std::move(Profile));
@@ -1015,13 +983,10 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_compression_test) {
}
TEST_F(SparseInstrProfTest, preserve_no_records) {
- InstrProfRecord Record1("foo", 0x1234, {0});
- InstrProfRecord Record2("bar", 0x4321, {0, 0});
- InstrProfRecord Record3("bar", 0x4321, {0, 0, 0});
+ NoError(Writer.addRecord({"foo", 0x1234, {0}}));
+ NoError(Writer.addRecord({"bar", 0x4321, {0, 0}}));
+ NoError(Writer.addRecord({"bar", 0x4321, {0, 0, 0}}));
- NoError(Writer.addRecord(std::move(Record1)));
- NoError(Writer.addRecord(std::move(Record2)));
- NoError(Writer.addRecord(std::move(Record3)));
auto Profile = Writer.writeBuffer();
readProfile(std::move(Profile));