summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2016-05-13 20:09:39 +0000
committerVedant Kumar <vsk@apple.com>2016-05-13 20:09:39 +0000
commit8007bdd41fa4e8095a170ba9d7cc9bbcc7b50a4f (patch)
treeb19c1a5c22604d53ff8c8e468013fbda453ef0d2 /unittests
parent5b34ed81912658b6228917a436e7c566b801b809 (diff)
Revert "(HEAD -> master, origin/master, origin/HEAD) [ProfileData] (llvm) Use Error in InstrProf and Coverage, NFC"
This reverts commit r269462. It fails two llvm-profdata tests. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269466 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ProfileData/CoverageMappingTest.cpp18
-rw-r--r--unittests/ProfileData/InstrProfTest.cpp88
2 files changed, 48 insertions, 58 deletions
diff --git a/unittests/ProfileData/CoverageMappingTest.cpp b/unittests/ProfileData/CoverageMappingTest.cpp
index 53b40ebae85..81e9cb13233 100644
--- a/unittests/ProfileData/CoverageMappingTest.cpp
+++ b/unittests/ProfileData/CoverageMappingTest.cpp
@@ -20,11 +20,11 @@
using namespace llvm;
using namespace coverage;
-static ::testing::AssertionResult NoError(Error E) {
- if (!E)
+static ::testing::AssertionResult NoError(std::error_code EC) {
+ if (!EC)
return ::testing::AssertionSuccess();
- return ::testing::AssertionFailure() << "error: " << toString(std::move(E))
- << "\n";
+ return ::testing::AssertionFailure() << "error " << EC.value()
+ << ": " << EC.message();
}
namespace llvm {
@@ -70,14 +70,14 @@ struct CoverageMappingReaderMock : CoverageMappingReader {
CoverageMappingReaderMock(ArrayRef<OutputFunctionCoverageData> Functions)
: Functions(Functions) {}
- Error readNextRecord(CoverageMappingRecord &Record) override {
+ std::error_code readNextRecord(CoverageMappingRecord &Record) override {
if (Functions.empty())
- return make_error<CoverageMapError>(coveragemap_error::eof);
+ return coveragemap_error::eof;
Functions.front().fillCoverageMappingRecord(Record);
Functions = Functions.slice(1);
- return Error::success();
+ return coveragemap_error::success;
}
};
@@ -190,7 +190,7 @@ struct CoverageMappingTest : ::testing::Test {
void readProfCounts() {
auto Profile = ProfileWriter.writeBuffer();
auto ReaderOrErr = IndexedInstrProfReader::create(std::move(Profile));
- ASSERT_TRUE(NoError(ReaderOrErr.takeError()));
+ ASSERT_TRUE(NoError(ReaderOrErr.getError()));
ProfileReader = std::move(ReaderOrErr.get());
}
@@ -200,7 +200,7 @@ struct CoverageMappingTest : ::testing::Test {
CoverageMappingReaderMock CovReader(OutputFunctions);
auto CoverageOrErr = CoverageMapping::load(CovReader, *ProfileReader);
- ASSERT_TRUE(NoError(CoverageOrErr.takeError()));
+ ASSERT_TRUE(NoError(CoverageOrErr.getError()));
LoadedCoverage = std::move(CoverageOrErr.get());
}
};
diff --git a/unittests/ProfileData/InstrProfTest.cpp b/unittests/ProfileData/InstrProfTest.cpp
index 9ef3487ba18..2d9a2218e55 100644
--- a/unittests/ProfileData/InstrProfTest.cpp
+++ b/unittests/ProfileData/InstrProfTest.cpp
@@ -19,24 +19,19 @@
using namespace llvm;
-static ::testing::AssertionResult NoError(Error E) {
- if (!E)
+static ::testing::AssertionResult NoError(std::error_code EC) {
+ if (!EC)
return ::testing::AssertionSuccess();
- return ::testing::AssertionFailure() << "error: " << toString(std::move(E))
- << "\n";
+ return ::testing::AssertionFailure() << "error " << EC.value()
+ << ": " << EC.message();
}
-static ::testing::AssertionResult ErrorEquals(instrprof_error Expected,
- Error E) {
- instrprof_error Found;
- std::string FoundMsg;
- handleAllErrors(std::move(E), [&](const InstrProfError &IPE) {
- Found = IPE.get();
- FoundMsg = IPE.message();
- });
+static ::testing::AssertionResult ErrorEquals(std::error_code Expected,
+ std::error_code Found) {
if (Expected == Found)
return ::testing::AssertionSuccess();
- return ::testing::AssertionFailure() << "error: " << FoundMsg << "\n";
+ return ::testing::AssertionFailure() << "error " << Found.value()
+ << ": " << Found.message();
}
namespace {
@@ -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()));
+ ASSERT_TRUE(NoError(ReaderOrErr.getError()));
Reader = std::move(ReaderOrErr.get());
}
};
@@ -95,23 +90,23 @@ TEST_P(MaybeSparseInstrProfTest, get_instr_prof_record) {
auto Profile = Writer.writeBuffer();
readProfile(std::move(Profile));
- Expected<InstrProfRecord> R = Reader->getInstrProfRecord("foo", 0x1234);
- ASSERT_TRUE(NoError(R.takeError()));
+ ErrorOr<InstrProfRecord> R = Reader->getInstrProfRecord("foo", 0x1234);
+ ASSERT_TRUE(NoError(R.getError()));
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()));
+ ASSERT_TRUE(NoError(R.getError()));
ASSERT_EQ(2U, R->Counts.size());
ASSERT_EQ(3U, R->Counts[0]);
ASSERT_EQ(4U, R->Counts[1]);
R = Reader->getInstrProfRecord("foo", 0x5678);
- ASSERT_TRUE(ErrorEquals(instrprof_error::hash_mismatch, R.takeError()));
+ ASSERT_TRUE(ErrorEquals(instrprof_error::hash_mismatch, R.getError()));
R = Reader->getInstrProfRecord("bar", 0x1234);
- ASSERT_TRUE(ErrorEquals(instrprof_error::unknown_function, R.takeError()));
+ ASSERT_TRUE(ErrorEquals(instrprof_error::unknown_function, R.getError()));
}
TEST_P(MaybeSparseInstrProfTest, get_function_counts) {
@@ -133,11 +128,12 @@ TEST_P(MaybeSparseInstrProfTest, get_function_counts) {
ASSERT_EQ(3U, Counts[0]);
ASSERT_EQ(4U, Counts[1]);
- Error E1 = Reader->getFunctionCounts("foo", 0x5678, Counts);
- ASSERT_TRUE(ErrorEquals(instrprof_error::hash_mismatch, std::move(E1)));
+ std::error_code EC;
+ EC = Reader->getFunctionCounts("foo", 0x5678, Counts);
+ ASSERT_TRUE(ErrorEquals(instrprof_error::hash_mismatch, EC));
- Error E2 = Reader->getFunctionCounts("bar", 0x1234, Counts);
- ASSERT_TRUE(ErrorEquals(instrprof_error::unknown_function, std::move(E2)));
+ EC = Reader->getFunctionCounts("bar", 0x1234, Counts);
+ ASSERT_TRUE(ErrorEquals(instrprof_error::unknown_function, EC));
}
// Profile data is copied from general.proftext
@@ -239,8 +235,8 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write) {
auto Profile = Writer.writeBuffer();
readProfile(std::move(Profile));
- Expected<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);
- ASSERT_TRUE(NoError(R.takeError()));
+ ErrorOr<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);
+ ASSERT_TRUE(NoError(R.getError()));
ASSERT_EQ(4U, R->getNumValueSites(IPVK_IndirectCallTarget));
ASSERT_EQ(3U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 0));
ASSERT_EQ(0U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 1));
@@ -270,8 +266,8 @@ TEST_P(MaybeSparseInstrProfTest, annotate_vp_data) {
NoError(Writer.addRecord(std::move(Record)));
auto Profile = Writer.writeBuffer();
readProfile(std::move(Profile));
- Expected<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);
- ASSERT_TRUE(NoError(R.takeError()));
+ ErrorOr<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);
+ ASSERT_TRUE(NoError(R.getError()));
LLVMContext Ctx;
std::unique_ptr<Module> M(new Module("MyModule", Ctx));
@@ -382,8 +378,8 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write_with_weight) {
auto Profile = Writer.writeBuffer();
readProfile(std::move(Profile));
- Expected<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);
- ASSERT_TRUE(NoError(R.takeError()));
+ ErrorOr<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);
+ ASSERT_TRUE(NoError(R.getError()));
ASSERT_EQ(4U, R->getNumValueSites(IPVK_IndirectCallTarget));
ASSERT_EQ(3U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 0));
ASSERT_EQ(0U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 1));
@@ -435,8 +431,8 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write_big_endian) {
// Set big endian input.
Reader->setValueProfDataEndianness(support::big);
- Expected<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);
- ASSERT_TRUE(NoError(R.takeError()));
+ ErrorOr<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);
+ ASSERT_TRUE(NoError(R.getError()));
ASSERT_EQ(4U, R->getNumValueSites(IPVK_IndirectCallTarget));
ASSERT_EQ(3U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 0));
ASSERT_EQ(0U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 1));
@@ -517,8 +513,8 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_merge1) {
auto Profile = Writer.writeBuffer();
readProfile(std::move(Profile));
- Expected<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);
- ASSERT_TRUE(NoError(R.takeError()));
+ ErrorOr<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);
+ ASSERT_TRUE(NoError(R.getError()));
ASSERT_EQ(5U, R->getNumValueSites(IPVK_IndirectCallTarget));
ASSERT_EQ(4U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 0));
ASSERT_EQ(0U, R->getNumValueDataForSite(IPVK_IndirectCallTarget, 1));
@@ -570,27 +566,23 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_merge1_saturation) {
InstrProfRecord Record1("foo", 0x1234, {1});
auto Result1 = Writer.addRecord(std::move(Record1));
- ASSERT_EQ(InstrProfError::take(std::move(Result1)),
- instrprof_error::success);
+ ASSERT_EQ(Result1, 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);
+ ASSERT_EQ(Result2, 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);
+ ASSERT_EQ(Result3, instrprof_error::success);
InstrProfRecord 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);
+ ASSERT_EQ(Result4, instrprof_error::success);
// Verify value data counter overflow.
InstrProfRecord Record5("baz", 0x5678, {5, 6});
@@ -598,21 +590,19 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_merge1_saturation) {
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);
+ ASSERT_EQ(Result5, instrprof_error::counter_overflow);
auto Profile = Writer.writeBuffer();
readProfile(std::move(Profile));
// Verify saturation of counts.
- Expected<InstrProfRecord> ReadRecord1 =
+ ErrorOr<InstrProfRecord> ReadRecord1 =
Reader->getInstrProfRecord("foo", 0x1234);
- ASSERT_TRUE(NoError(ReadRecord1.takeError()));
+ ASSERT_TRUE(NoError(ReadRecord1.getError()));
ASSERT_EQ(Max, ReadRecord1->Counts[0]);
- Expected<InstrProfRecord> ReadRecord2 =
+ ErrorOr<InstrProfRecord> ReadRecord2 =
Reader->getInstrProfRecord("baz", 0x5678);
- ASSERT_TRUE(bool(ReadRecord2));
ASSERT_EQ(1U, ReadRecord2->getNumValueSites(IPVK_IndirectCallTarget));
std::unique_ptr<InstrProfValueData[]> VD =
ReadRecord2->getValueForSite(IPVK_IndirectCallTarget, 0);
@@ -657,8 +647,8 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_merge_site_trunc) {
auto Profile = Writer.writeBuffer();
readProfile(std::move(Profile));
- Expected<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);
- ASSERT_TRUE(NoError(R.takeError()));
+ ErrorOr<InstrProfRecord> R = Reader->getInstrProfRecord("caller", 0x1234);
+ ASSERT_TRUE(NoError(R.getError()));
std::unique_ptr<InstrProfValueData[]> VD(
R->getValueForSite(IPVK_IndirectCallTarget, 0));
ASSERT_EQ(2U, R->getNumValueSites(IPVK_IndirectCallTarget));