summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/unittests/ProfileData/SampleProfTest.cpp
diff options
context:
space:
mode:
authorpatrick <patrick@openbsd.org>2019-06-23 21:36:31 +0000
committerpatrick <patrick@openbsd.org>2019-06-23 21:36:31 +0000
commit23f101f37937a1bd4a29726cab2f76e0fb038b35 (patch)
treef7da7d6b32c2e07114da399150bfa88d72187012 /gnu/llvm/unittests/ProfileData/SampleProfTest.cpp
parentsort previous; ok deraadt (diff)
downloadwireguard-openbsd-23f101f37937a1bd4a29726cab2f76e0fb038b35.tar.xz
wireguard-openbsd-23f101f37937a1bd4a29726cab2f76e0fb038b35.zip
Import LLVM 8.0.0 release including clang, lld and lldb.
Diffstat (limited to 'gnu/llvm/unittests/ProfileData/SampleProfTest.cpp')
-rw-r--r--gnu/llvm/unittests/ProfileData/SampleProfTest.cpp93
1 files changed, 64 insertions, 29 deletions
diff --git a/gnu/llvm/unittests/ProfileData/SampleProfTest.cpp b/gnu/llvm/unittests/ProfileData/SampleProfTest.cpp
index 3ebfd0e500f..f75f10bae90 100644
--- a/gnu/llvm/unittests/ProfileData/SampleProfTest.cpp
+++ b/gnu/llvm/unittests/ProfileData/SampleProfTest.cpp
@@ -36,29 +36,33 @@ static ::testing::AssertionResult NoError(std::error_code EC) {
namespace {
struct SampleProfTest : ::testing::Test {
- std::string Data;
LLVMContext Context;
- std::unique_ptr<raw_ostream> OS;
std::unique_ptr<SampleProfileWriter> Writer;
std::unique_ptr<SampleProfileReader> Reader;
- SampleProfTest()
- : Data(), OS(new raw_string_ostream(Data)), Writer(), Reader() {}
+ SampleProfTest() : Writer(), Reader() {}
- void createWriter(SampleProfileFormat Format) {
+ void createWriter(SampleProfileFormat Format, StringRef Profile) {
+ std::error_code EC;
+ std::unique_ptr<raw_ostream> OS(
+ new raw_fd_ostream(Profile, EC, sys::fs::F_None));
auto WriterOrErr = SampleProfileWriter::create(OS, Format);
ASSERT_TRUE(NoError(WriterOrErr.getError()));
Writer = std::move(WriterOrErr.get());
}
- void readProfile(std::unique_ptr<MemoryBuffer> &Profile) {
+ void readProfile(const Module &M, StringRef Profile) {
auto ReaderOrErr = SampleProfileReader::create(Profile, Context);
ASSERT_TRUE(NoError(ReaderOrErr.getError()));
Reader = std::move(ReaderOrErr.get());
+ Reader->collectFuncsToUse(M);
}
- void testRoundTrip(SampleProfileFormat Format) {
- createWriter(Format);
+ void testRoundTrip(SampleProfileFormat Format, bool Remap) {
+ SmallVector<char, 128> ProfilePath;
+ ASSERT_TRUE(NoError(llvm::sys::fs::createTemporaryFile("profile", "", ProfilePath)));
+ StringRef Profile(ProfilePath.data(), ProfilePath.size());
+ createWriter(Format, Profile);
StringRef FooName("_Z3fooi");
FunctionSamples FooSamples;
@@ -83,6 +87,12 @@ struct SampleProfTest : ::testing::Test {
BarSamples.addCalledTargetSamples(1, 0, MconstructName, 1000);
BarSamples.addCalledTargetSamples(1, 0, StringviewName, 437);
+ Module M("my_module", Context);
+ FunctionType *fn_type =
+ FunctionType::get(Type::getVoidTy(Context), {}, false);
+ M.getOrInsertFunction(FooName, fn_type);
+ M.getOrInsertFunction(BarName, fn_type);
+
StringMap<FunctionSamples> Profiles;
Profiles[FooName] = std::move(FooSamples);
Profiles[BarName] = std::move(BarSamples);
@@ -93,28 +103,46 @@ struct SampleProfTest : ::testing::Test {
Writer->getOutputStream().flush();
- auto Profile = MemoryBuffer::getMemBufferCopy(Data);
- readProfile(Profile);
+ readProfile(M, Profile);
EC = Reader->read();
ASSERT_TRUE(NoError(EC));
- StringMap<FunctionSamples> &ReadProfiles = Reader->getProfiles();
- ASSERT_EQ(2u, ReadProfiles.size());
-
- std::string FooGUID;
- StringRef FooRep = getRepInFormat(FooName, Format, FooGUID);
- FunctionSamples &ReadFooSamples = ReadProfiles[FooRep];
- ASSERT_EQ(7711u, ReadFooSamples.getTotalSamples());
- ASSERT_EQ(610u, ReadFooSamples.getHeadSamples());
-
- std::string BarGUID;
- StringRef BarRep = getRepInFormat(BarName, Format, BarGUID);
- FunctionSamples &ReadBarSamples = ReadProfiles[BarRep];
- ASSERT_EQ(20301u, ReadBarSamples.getTotalSamples());
- ASSERT_EQ(1437u, ReadBarSamples.getHeadSamples());
+ if (Remap) {
+ auto MemBuffer = llvm::MemoryBuffer::getMemBuffer(R"(
+ # Types 'int' and 'long' are equivalent
+ type i l
+ # Function names 'foo' and 'faux' are equivalent
+ name 3foo 4faux
+ )");
+ Reader.reset(new SampleProfileReaderItaniumRemapper(
+ std::move(MemBuffer), Context, std::move(Reader)));
+ FooName = "_Z4fauxi";
+ BarName = "_Z3barl";
+
+ EC = Reader->read();
+ ASSERT_TRUE(NoError(EC));
+ }
+
+ ASSERT_EQ(2u, Reader->getProfiles().size());
+
+ FunctionSamples *ReadFooSamples = Reader->getSamplesFor(FooName);
+ ASSERT_TRUE(ReadFooSamples != nullptr);
+ if (Format != SampleProfileFormat::SPF_Compact_Binary) {
+ ASSERT_EQ("_Z3fooi", ReadFooSamples->getName());
+ }
+ ASSERT_EQ(7711u, ReadFooSamples->getTotalSamples());
+ ASSERT_EQ(610u, ReadFooSamples->getHeadSamples());
+
+ FunctionSamples *ReadBarSamples = Reader->getSamplesFor(BarName);
+ ASSERT_TRUE(ReadBarSamples != nullptr);
+ if (Format != SampleProfileFormat::SPF_Compact_Binary) {
+ ASSERT_EQ("_Z3bari", ReadBarSamples->getName());
+ }
+ ASSERT_EQ(20301u, ReadBarSamples->getTotalSamples());
+ ASSERT_EQ(1437u, ReadBarSamples->getHeadSamples());
ErrorOr<SampleRecord::CallTargetMap> CTMap =
- ReadBarSamples.findCallTargetMapAt(1, 0);
+ ReadBarSamples->findCallTargetMapAt(1, 0);
ASSERT_FALSE(CTMap.getError());
std::string MconstructGUID;
@@ -164,7 +192,6 @@ struct SampleProfTest : ::testing::Test {
delete PS;
// Test that summary can be attached to and read back from module.
- Module M("my_module", Context);
M.setProfileSummary(MD);
MD = M.getProfileSummary();
ASSERT_TRUE(MD);
@@ -176,15 +203,23 @@ struct SampleProfTest : ::testing::Test {
};
TEST_F(SampleProfTest, roundtrip_text_profile) {
- testRoundTrip(SampleProfileFormat::SPF_Text);
+ testRoundTrip(SampleProfileFormat::SPF_Text, false);
}
TEST_F(SampleProfTest, roundtrip_raw_binary_profile) {
- testRoundTrip(SampleProfileFormat::SPF_Binary);
+ testRoundTrip(SampleProfileFormat::SPF_Binary, false);
}
TEST_F(SampleProfTest, roundtrip_compact_binary_profile) {
- testRoundTrip(SampleProfileFormat::SPF_Compact_Binary);
+ testRoundTrip(SampleProfileFormat::SPF_Compact_Binary, false);
+}
+
+TEST_F(SampleProfTest, remap_text_profile) {
+ testRoundTrip(SampleProfileFormat::SPF_Text, true);
+}
+
+TEST_F(SampleProfTest, remap_raw_binary_profile) {
+ testRoundTrip(SampleProfileFormat::SPF_Binary, true);
}
TEST_F(SampleProfTest, sample_overflow_saturation) {