X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=unittests%2FProfileData%2FInstrProfTest.cpp;h=1ccc3ca5d69591c8f5e4d5b1a4c433196e975830;hp=8f4db871a92798d76651400a9013a4289cfcd3d7;hb=2401ff6f94b780ecdc36bed9aaf7b4e6f3f983fe;hpb=aee63adab4f7ce3c891dc847906c1afeeba9f246 diff --git a/unittests/ProfileData/InstrProfTest.cpp b/unittests/ProfileData/InstrProfTest.cpp index 8f4db871a92..1ccc3ca5d69 100644 --- a/unittests/ProfileData/InstrProfTest.cpp +++ b/unittests/ProfileData/InstrProfTest.cpp @@ -9,6 +9,7 @@ #include "llvm/ProfileData/InstrProfReader.h" #include "llvm/ProfileData/InstrProfWriter.h" +#include "llvm/Support/Compression.h" #include "gtest/gtest.h" #include @@ -583,4 +584,77 @@ TEST_F(InstrProfTest, instr_prof_symtab_test) { ASSERT_EQ(StringRef("bar3"), R); } +TEST_F(InstrProfTest, instr_prof_symtab_compression_test) { + std::vector FuncNames1; + std::vector FuncNames2; + for (int I = 0; I < 10 * 1024; I++) { + std::string str; + raw_string_ostream OS(str); + OS << "func_" << I; + FuncNames1.push_back(OS.str()); + str.clear(); + OS << "fooooooooooooooo_" << I; + FuncNames1.push_back(OS.str()); + str.clear(); + OS << "BAR_" << I; + FuncNames2.push_back(OS.str()); + str.clear(); + OS << "BlahblahBlahblahBar_" << I; + FuncNames2.push_back(OS.str()); + } + + for (int Padding = 0; Padding < 10; Padding++) { + for (int DoCompression = 0; DoCompression < 2; DoCompression++) { + // Compressing: + std::string FuncNameStrings1; + collectPGOFuncNameStrings(FuncNames1, + (DoCompression != 0 && zlib::isAvailable()), + FuncNameStrings1); + + // Compressing: + std::string FuncNameStrings2; + collectPGOFuncNameStrings(FuncNames2, + (DoCompression != 0 && zlib::isAvailable()), + FuncNameStrings2); + + // Join with paddings: + std::string FuncNameStrings = FuncNameStrings1; + for (int P = 0; P < Padding; P++) { + FuncNameStrings.push_back('\0'); + } + FuncNameStrings += FuncNameStrings2; + + // Now decompress: + InstrProfSymtab Symtab; + Symtab.create(StringRef(FuncNameStrings)); + + // Now do the checks: + // First sampling some data points: + StringRef R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames1[0])); + ASSERT_EQ(StringRef("func_0"), R); + R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames1[1])); + ASSERT_EQ(StringRef("fooooooooooooooo_0"), R); + R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames1[998])); + ASSERT_EQ(StringRef("func_499"), R); + R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames1[999])); + ASSERT_EQ(StringRef("fooooooooooooooo_499"), R); + R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames2[100])); + ASSERT_EQ(StringRef("BAR_50"), R); + R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames2[101])); + ASSERT_EQ(StringRef("BlahblahBlahblahBar_50"), R); + for (int I = 0; I < 10 * 1024; I++) { + std::string N[4]; + N[0] = FuncNames1[2 * I]; + N[1] = FuncNames1[2 * I + 1]; + N[2] = FuncNames2[2 * I]; + N[3] = FuncNames2[2 * I + 1]; + for (int J = 0; J < 4; J++) { + StringRef R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(N[J])); + ASSERT_EQ(StringRef(N[J]), R); + } + } + } + } +} + } // end anonymous namespace