diff options
Diffstat (limited to 'unittests/ProfileData/InstrProfTest.cpp')
-rw-r--r-- | unittests/ProfileData/InstrProfTest.cpp | 268 |
1 files changed, 122 insertions, 146 deletions
diff --git a/unittests/ProfileData/InstrProfTest.cpp b/unittests/ProfileData/InstrProfTest.cpp index 13436cc0d5b2..79f880e475c6 100644 --- a/unittests/ProfileData/InstrProfTest.cpp +++ b/unittests/ProfileData/InstrProfTest.cpp @@ -14,20 +14,15 @@ #include "llvm/ProfileData/InstrProfReader.h" #include "llvm/ProfileData/InstrProfWriter.h" #include "llvm/Support/Compression.h" +#include "llvm/Testing/Support/Error.h" +#include "llvm/Testing/Support/SupportHelpers.h" #include "gtest/gtest.h" #include <cstdarg> using namespace llvm; -static ::testing::AssertionResult NoError(Error E) { - if (!E) - return ::testing::AssertionSuccess(); - return ::testing::AssertionFailure() << "error: " << toString(std::move(E)) - << "\n"; -} - -static ::testing::AssertionResult ErrorEquals(instrprof_error Expected, - Error E) { +LLVM_NODISCARD static ::testing::AssertionResult +ErrorEquals(instrprof_error Expected, Error E) { instrprof_error Found; std::string FoundMsg; handleAllErrors(std::move(E), [&](const InstrProfError &IPE) { @@ -49,7 +44,7 @@ struct InstrProfTest : ::testing::Test { void readProfile(std::unique_ptr<MemoryBuffer> Profile) { auto ReaderOrErr = IndexedInstrProfReader::create(std::move(Profile)); - ASSERT_TRUE(NoError(ReaderOrErr.takeError())); + EXPECT_THAT_ERROR(ReaderOrErr.takeError(), Succeeded()); Reader = std::move(ReaderOrErr.get()); } }; @@ -69,9 +64,13 @@ TEST_P(MaybeSparseInstrProfTest, write_and_read_empty_profile) { ASSERT_TRUE(Reader->begin() == Reader->end()); } +static const auto Err = [](Error E) { + consumeError(std::move(E)); + FAIL(); +}; + TEST_P(MaybeSparseInstrProfTest, write_and_read_one_function) { - InstrProfRecord Record("foo", 0x1234, {1, 2, 3, 4}); - NoError(Writer.addRecord(std::move(Record))); + Writer.addRecord({"foo", 0x1234, {1, 2, 3, 4}}, Err); auto Profile = Writer.writeBuffer(); readProfile(std::move(Profile)); @@ -88,21 +87,19 @@ 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))); + Writer.addRecord({"foo", 0x1234, {1, 2}}, Err); + Writer.addRecord({"foo", 0x1235, {3, 4}}, Err); auto Profile = Writer.writeBuffer(); readProfile(std::move(Profile)); Expected<InstrProfRecord> R = Reader->getInstrProfRecord("foo", 0x1234); - ASSERT_TRUE(NoError(R.takeError())); + EXPECT_THAT_ERROR(R.takeError(), Succeeded()); ASSERT_EQ(2U, R->Counts.size()); ASSERT_EQ(1U, R->Counts[0]); ASSERT_EQ(2U, R->Counts[1]); R = Reader->getInstrProfRecord("foo", 0x1235); - ASSERT_TRUE(NoError(R.takeError())); + EXPECT_THAT_ERROR(R.takeError(), Succeeded()); ASSERT_EQ(2U, R->Counts.size()); ASSERT_EQ(3U, R->Counts[0]); ASSERT_EQ(4U, R->Counts[1]); @@ -115,20 +112,20 @@ 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))); + Writer.addRecord({"foo", 0x1234, {1, 2}}, Err); + Writer.addRecord({"foo", 0x1235, {3, 4}}, Err); auto Profile = Writer.writeBuffer(); readProfile(std::move(Profile)); std::vector<uint64_t> Counts; - ASSERT_TRUE(NoError(Reader->getFunctionCounts("foo", 0x1234, Counts))); + EXPECT_THAT_ERROR(Reader->getFunctionCounts("foo", 0x1234, Counts), + Succeeded()); ASSERT_EQ(2U, Counts.size()); ASSERT_EQ(1U, Counts[0]); ASSERT_EQ(2U, Counts[1]); - ASSERT_TRUE(NoError(Reader->getFunctionCounts("foo", 0x1235, Counts))); + EXPECT_THAT_ERROR(Reader->getFunctionCounts("foo", 0x1235, Counts), + Succeeded()); ASSERT_EQ(2U, Counts.size()); ASSERT_EQ(3U, Counts[0]); ASSERT_EQ(4U, Counts[1]); @@ -142,17 +139,15 @@ 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))); + Writer.addRecord({"func1", 0x1234, {97531}}, Err); + Writer.addRecord({"func2", 0x1234, {0, 0}}, Err); + Writer.addRecord( + {"func3", + 0x1234, + {2305843009213693952, 1152921504606846976, 576460752303423488, + 288230376151711744, 144115188075855872, 72057594037927936}}, + Err); + Writer.addRecord({"func4", 0x1234, {0}}, Err); auto Profile = Writer.writeBuffer(); readProfile(std::move(Profile)); @@ -203,25 +198,23 @@ TEST_F(InstrProfTest, get_profile_summary) { } TEST_F(InstrProfTest, test_writer_merge) { - InstrProfRecord Record1("func1", 0x1234, {42}); - NoError(Writer.addRecord(std::move(Record1))); + Writer.addRecord({"func1", 0x1234, {42}}, Err); InstrProfWriter Writer2; - InstrProfRecord Record2("func2", 0x1234, {0, 0}); - NoError(Writer2.addRecord(std::move(Record2))); + Writer2.addRecord({"func2", 0x1234, {0, 0}}, Err); - NoError(Writer.mergeRecordsFromWriter(std::move(Writer2))); + Writer.mergeRecordsFromWriter(std::move(Writer2), Err); auto Profile = Writer.writeBuffer(); readProfile(std::move(Profile)); Expected<InstrProfRecord> R = Reader->getInstrProfRecord("func1", 0x1234); - ASSERT_TRUE(NoError(R.takeError())); + EXPECT_THAT_ERROR(R.takeError(), Succeeded()); ASSERT_EQ(1U, R->Counts.size()); ASSERT_EQ(42U, R->Counts[0]); R = Reader->getInstrProfRecord("func2", 0x1234); - ASSERT_TRUE(NoError(R.takeError())); + EXPECT_THAT_ERROR(R.takeError(), Succeeded()); ASSERT_EQ(2U, R->Counts.size()); ASSERT_EQ(0U, R->Counts[0]); ASSERT_EQ(0U, R->Counts[1]); @@ -235,10 +228,7 @@ static const char callee5[] = "callee5"; 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}); + NamedInstrProfRecord Record1("caller", 0x1234, {1, 2}); // 4 value sites. Record1.reserveSites(IPVK_IndirectCallTarget, 4); @@ -252,15 +242,15 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write) { InstrProfValueData VD3[] = {{(uint64_t)callee1, 1}}; 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))); + Writer.addRecord(std::move(Record1), Err); + Writer.addRecord({"callee1", 0x1235, {3, 4}}, Err); + Writer.addRecord({"callee2", 0x1235, {3, 4}}, Err); + Writer.addRecord({"callee3", 0x1235, {3, 4}}, Err); auto Profile = Writer.writeBuffer(); readProfile(std::move(Profile)); Expected<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234); - ASSERT_TRUE(NoError(R.takeError())); + EXPECT_THAT_ERROR(R.takeError(), Succeeded()); ASSERT_EQ(4U, R->getNumValueSites(IPVK_IndirectCallTarget)); ASSERT_EQ(3U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 0)); ASSERT_EQ(0U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 1)); @@ -282,16 +272,16 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write) { } TEST_P(MaybeSparseInstrProfTest, annotate_vp_data) { - InstrProfRecord Record("caller", 0x1234, {1, 2}); + NamedInstrProfRecord Record("caller", 0x1234, {1, 2}); Record.reserveSites(IPVK_IndirectCallTarget, 1); InstrProfValueData VD0[] = {{1000, 1}, {2000, 2}, {3000, 3}, {5000, 5}, {4000, 4}, {6000, 6}}; Record.addValueData(IPVK_IndirectCallTarget, 0, VD0, 6, nullptr); - NoError(Writer.addRecord(std::move(Record))); + Writer.addRecord(std::move(Record), Err); auto Profile = Writer.writeBuffer(); readProfile(std::move(Profile)); Expected<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234); - ASSERT_TRUE(NoError(R.takeError())); + EXPECT_THAT_ERROR(R.takeError(), Succeeded()); LLVMContext Ctx; std::unique_ptr<Module> M(new Module("MyModule", Ctx)); @@ -378,10 +368,7 @@ 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}); + NamedInstrProfRecord Record1("caller", 0x1234, {1, 2}); // 4 value sites. Record1.reserveSites(IPVK_IndirectCallTarget, 4); @@ -395,15 +382,15 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write_with_weight) { InstrProfValueData VD3[] = {{(uint64_t)callee1, 1}}; 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))); + Writer.addRecord(std::move(Record1), 10, Err); + Writer.addRecord({"callee1", 0x1235, {3, 4}}, Err); + Writer.addRecord({"callee2", 0x1235, {3, 4}}, Err); + Writer.addRecord({"callee3", 0x1235, {3, 4}}, Err); auto Profile = Writer.writeBuffer(); readProfile(std::move(Profile)); Expected<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234); - ASSERT_TRUE(NoError(R.takeError())); + EXPECT_THAT_ERROR(R.takeError(), Succeeded()); ASSERT_EQ(4U, R->getNumValueSites(IPVK_IndirectCallTarget)); ASSERT_EQ(3U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 0)); ASSERT_EQ(0U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 1)); @@ -424,10 +411,7 @@ 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}); + NamedInstrProfRecord Record1("caller", 0x1234, {1, 2}); // 4 value sites. Record1.reserveSites(IPVK_IndirectCallTarget, 4); @@ -441,10 +425,10 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write_big_endian) { InstrProfValueData VD3[] = {{(uint64_t)callee1, 1}}; 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))); + Writer.addRecord(std::move(Record1), Err); + Writer.addRecord({"callee1", 0x1235, {3, 4}}, Err); + Writer.addRecord({"callee2", 0x1235, {3, 4}}, Err); + Writer.addRecord({"callee3", 0x1235, {3, 4}}, Err); // Set big endian output. Writer.setValueProfDataEndianness(support::big); @@ -456,7 +440,7 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write_big_endian) { Reader->setValueProfDataEndianness(support::big); Expected<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234); - ASSERT_TRUE(NoError(R.takeError())); + EXPECT_THAT_ERROR(R.takeError(), Succeeded()); ASSERT_EQ(4U, R->getNumValueSites(IPVK_IndirectCallTarget)); ASSERT_EQ(3U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 0)); ASSERT_EQ(0U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 1)); @@ -475,13 +459,8 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write_big_endian) { 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}); + NamedInstrProfRecord Record11(caller, 0x1234, {1, 2}); + NamedInstrProfRecord Record12(caller, 0x1234, {1, 2}); // 5 value sites. Record11.reserveSites(IPVK_IndirectCallTarget, 5); @@ -525,20 +504,20 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_merge1) { {uint64_t(callee3), 3}}; Record12.addValueData(IPVK_IndirectCallTarget, 4, VD42, 3, nullptr); - NoError(Writer.addRecord(std::move(Record11))); + Writer.addRecord(std::move(Record11), Err); // Merge profile data. - NoError(Writer.addRecord(std::move(Record12))); + Writer.addRecord(std::move(Record12), Err); - 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))); + Writer.addRecord({callee1, 0x1235, {3, 4}}, Err); + Writer.addRecord({callee2, 0x1235, {3, 4}}, Err); + Writer.addRecord({callee3, 0x1235, {3, 4}}, Err); + Writer.addRecord({callee3, 0x1235, {3, 4}}, Err); + Writer.addRecord({callee4, 0x1235, {3, 5}}, Err); auto Profile = Writer.writeBuffer(); readProfile(std::move(Profile)); Expected<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234); - ASSERT_TRUE(NoError(R.takeError())); + EXPECT_THAT_ERROR(R.takeError(), Succeeded()); ASSERT_EQ(5U, R->getNumValueSites(IPVK_IndirectCallTarget)); ASSERT_EQ(4U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 0)); ASSERT_EQ(0U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 1)); @@ -588,38 +567,37 @@ 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)); - ASSERT_EQ(InstrProfError::take(std::move(Result1)), - instrprof_error::success); + instrprof_error Result; + auto Err = [&](Error E) { Result = InstrProfError::take(std::move(E)); }; + Result = instrprof_error::success; + Writer.addRecord({"foo", 0x1234, {1}}, Err); + ASSERT_EQ(Result, instrprof_error::success); // Verify counter overflow. - InstrProfRecord Record2("foo", 0x1234, {Max}); - auto Result2 = Writer.addRecord(std::move(Record2)); - ASSERT_EQ(InstrProfError::take(std::move(Result2)), - instrprof_error::counter_overflow); + Result = instrprof_error::success; + Writer.addRecord({"foo", 0x1234, {Max}}, Err); + ASSERT_EQ(Result, instrprof_error::counter_overflow); - InstrProfRecord Record3(bar, 0x9012, {8}); - auto Result3 = Writer.addRecord(std::move(Record3)); - ASSERT_EQ(InstrProfError::take(std::move(Result3)), - instrprof_error::success); + Result = instrprof_error::success; + Writer.addRecord({bar, 0x9012, {8}}, Err); + ASSERT_EQ(Result, instrprof_error::success); - InstrProfRecord Record4("baz", 0x5678, {3, 4}); + NamedInstrProfRecord Record4("baz", 0x5678, {3, 4}); Record4.reserveSites(IPVK_IndirectCallTarget, 1); InstrProfValueData VD4[] = {{uint64_t(bar), 1}}; Record4.addValueData(IPVK_IndirectCallTarget, 0, VD4, 1, nullptr); - auto Result4 = Writer.addRecord(std::move(Record4)); - ASSERT_EQ(InstrProfError::take(std::move(Result4)), - instrprof_error::success); + Result = instrprof_error::success; + Writer.addRecord(std::move(Record4), Err); + ASSERT_EQ(Result, instrprof_error::success); // Verify value data counter overflow. - InstrProfRecord Record5("baz", 0x5678, {5, 6}); + NamedInstrProfRecord Record5("baz", 0x5678, {5, 6}); Record5.reserveSites(IPVK_IndirectCallTarget, 1); InstrProfValueData VD5[] = {{uint64_t(bar), Max}}; Record5.addValueData(IPVK_IndirectCallTarget, 0, VD5, 1, nullptr); - auto Result5 = Writer.addRecord(std::move(Record5)); - ASSERT_EQ(InstrProfError::take(std::move(Result5)), - instrprof_error::counter_overflow); + Result = instrprof_error::success; + Writer.addRecord(std::move(Record5), Err); + ASSERT_EQ(Result, instrprof_error::counter_overflow); auto Profile = Writer.writeBuffer(); readProfile(std::move(Profile)); @@ -627,7 +605,7 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_merge1_saturation) { // Verify saturation of counts. Expected<InstrProfRecord> ReadRecord1 = Reader->getInstrProfRecord("foo", 0x1234); - ASSERT_TRUE(NoError(ReadRecord1.takeError())); + EXPECT_THAT_ERROR(ReadRecord1.takeError(), Succeeded()); ASSERT_EQ(Max, ReadRecord1->Counts[0]); Expected<InstrProfRecord> ReadRecord2 = @@ -646,8 +624,8 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_merge1_saturation) { TEST_P(MaybeSparseInstrProfTest, get_icall_data_merge_site_trunc) { static const char caller[] = "caller"; - InstrProfRecord Record11(caller, 0x1234, {1, 2}); - InstrProfRecord Record12(caller, 0x1234, {1, 2}); + NamedInstrProfRecord Record11(caller, 0x1234, {1, 2}); + NamedInstrProfRecord Record12(caller, 0x1234, {1, 2}); // 2 value sites. Record11.reserveSites(IPVK_IndirectCallTarget, 2); @@ -670,15 +648,15 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_merge_site_trunc) { Record12.addValueData(IPVK_IndirectCallTarget, 0, VD1, 255, nullptr); Record12.addValueData(IPVK_IndirectCallTarget, 1, nullptr, 0, nullptr); - NoError(Writer.addRecord(std::move(Record11))); + Writer.addRecord(std::move(Record11), Err); // Merge profile data. - NoError(Writer.addRecord(std::move(Record12))); + Writer.addRecord(std::move(Record12), Err); auto Profile = Writer.writeBuffer(); readProfile(std::move(Profile)); Expected<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234); - ASSERT_TRUE(NoError(R.takeError())); + EXPECT_THAT_ERROR(R.takeError(), Succeeded()); std::unique_ptr<InstrProfValueData[]> VD( R->getValueForSite(IPVK_IndirectCallTarget, 0)); ASSERT_EQ(2U, R->getNumValueSites(IPVK_IndirectCallTarget)); @@ -713,12 +691,12 @@ static void addValueProfData(InstrProfRecord &Record) { } TEST_P(MaybeSparseInstrProfTest, value_prof_data_read_write) { - InstrProfRecord SrcRecord("caller", 0x1234, {1ULL << 31, 2}); + InstrProfRecord SrcRecord({1ULL << 31, 2}); addValueProfData(SrcRecord); std::unique_ptr<ValueProfData> VPData = ValueProfData::serializeFrom(SrcRecord); - InstrProfRecord Record("caller", 0x1234, {1ULL << 31, 2}); + InstrProfRecord Record({1ULL << 31, 2}); VPData->deserializeTo(Record, nullptr); // Now read data from Record and sanity check the data @@ -779,12 +757,12 @@ TEST_P(MaybeSparseInstrProfTest, value_prof_data_read_write) { TEST_P(MaybeSparseInstrProfTest, value_prof_data_read_write_mapping) { - InstrProfRecord SrcRecord("caller", 0x1234, {1ULL << 31, 2}); + NamedInstrProfRecord SrcRecord("caller", 0x1234, {1ULL << 31, 2}); addValueProfData(SrcRecord); std::unique_ptr<ValueProfData> VPData = ValueProfData::serializeFrom(SrcRecord); - InstrProfRecord Record("caller", 0x1234, {1ULL << 31, 2}); + NamedInstrProfRecord Record("caller", 0x1234, {1ULL << 31, 2}); InstrProfSymtab Symtab; Symtab.mapAddress(uint64_t(callee1), 0x1000ULL); Symtab.mapAddress(uint64_t(callee2), 0x2000ULL); @@ -817,12 +795,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))); + Writer.addRecord({"foo", 0x1234, {1ULL << 31, 2}}, Err); + Writer.addRecord({"bar", 0, {1ULL << 63}}, Err); + Writer.addRecord({"baz", 0x5678, {0, 0, 0, 0}}, Err); auto Profile = Writer.writeBuffer(); readProfile(std::move(Profile)); @@ -830,20 +805,20 @@ 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)); + Writer.addRecord({"foo", 0x1234, {1, 2}}, 3, Err); + Writer.addRecord({"foo", 0x1235, {3, 4}}, 5, Err); auto Profile = Writer.writeBuffer(); readProfile(std::move(Profile)); std::vector<uint64_t> Counts; - ASSERT_TRUE(NoError(Reader->getFunctionCounts("foo", 0x1234, Counts))); + EXPECT_THAT_ERROR(Reader->getFunctionCounts("foo", 0x1234, Counts), + Succeeded()); ASSERT_EQ(2U, Counts.size()); ASSERT_EQ(3U, Counts[0]); ASSERT_EQ(6U, Counts[1]); - ASSERT_TRUE(NoError(Reader->getFunctionCounts("foo", 0x1235, Counts))); + EXPECT_THAT_ERROR(Reader->getFunctionCounts("foo", 0x1235, Counts), + Succeeded()); ASSERT_EQ(2U, Counts.size()); ASSERT_EQ(15U, Counts[0]); ASSERT_EQ(20U, Counts[1]); @@ -859,7 +834,7 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_test) { FuncNames.push_back("bar2"); FuncNames.push_back("bar3"); InstrProfSymtab Symtab; - NoError(Symtab.create(FuncNames)); + EXPECT_THAT_ERROR(Symtab.create(FuncNames), Succeeded()); StringRef R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("func1")); ASSERT_EQ(StringRef("func1"), R); R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("func2")); @@ -880,9 +855,9 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_test) { ASSERT_EQ(StringRef(), R); // Now incrementally update the symtab - NoError(Symtab.addFuncName("blah_1")); - NoError(Symtab.addFuncName("blah_2")); - NoError(Symtab.addFuncName("blah_3")); + EXPECT_THAT_ERROR(Symtab.addFuncName("blah_1"), Succeeded()); + EXPECT_THAT_ERROR(Symtab.addFuncName("blah_2"), Succeeded()); + EXPECT_THAT_ERROR(Symtab.addFuncName("blah_3"), Succeeded()); // Finalize it Symtab.finalizeSymtab(); @@ -910,7 +885,7 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_test) { // Test that we get an error when creating a bogus symtab. TEST_P(MaybeSparseInstrProfTest, instr_prof_bogus_symtab_empty_func_name) { InstrProfSymtab Symtab; - ErrorEquals(instrprof_error::malformed, Symtab.addFuncName("")); + EXPECT_TRUE(ErrorEquals(instrprof_error::malformed, Symtab.addFuncName(""))); } // Testing symtab creator interface used by value profile transformer. @@ -933,7 +908,7 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_module_test) { Function::Create(FTy, Function::WeakODRLinkage, "Wbar", M.get()); InstrProfSymtab ProfSymtab; - NoError(ProfSymtab.create(*M)); + EXPECT_THAT_ERROR(ProfSymtab.create(*M), Succeeded()); StringRef Funcs[] = {"Gfoo", "Gblah", "Gbar", "Ifoo", "Iblah", "Ibar", "Pfoo", "Pblah", "Pbar", "Wfoo", "Wblah", "Wbar"}; @@ -973,13 +948,17 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_compression_test) { for (bool DoCompression : {false, true}) { // Compressing: std::string FuncNameStrings1; - NoError(collectPGOFuncNameStrings( - FuncNames1, (DoCompression && zlib::isAvailable()), FuncNameStrings1)); + EXPECT_THAT_ERROR(collectPGOFuncNameStrings( + FuncNames1, (DoCompression && zlib::isAvailable()), + FuncNameStrings1), + Succeeded()); // Compressing: std::string FuncNameStrings2; - NoError(collectPGOFuncNameStrings( - FuncNames2, (DoCompression && zlib::isAvailable()), FuncNameStrings2)); + EXPECT_THAT_ERROR(collectPGOFuncNameStrings( + FuncNames2, (DoCompression && zlib::isAvailable()), + FuncNameStrings2), + Succeeded()); for (int Padding = 0; Padding < 2; Padding++) { // Join with paddings : @@ -991,7 +970,7 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_compression_test) { // Now decompress: InstrProfSymtab Symtab; - NoError(Symtab.create(StringRef(FuncNameStrings))); + EXPECT_THAT_ERROR(Symtab.create(StringRef(FuncNameStrings)), Succeeded()); // Now do the checks: // First sampling some data points: @@ -1015,13 +994,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}); + Writer.addRecord({"foo", 0x1234, {0}}, Err); + Writer.addRecord({"bar", 0x4321, {0, 0}}, Err); + Writer.addRecord({"baz", 0x4321, {0, 0, 0}}, Err); - 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)); |