OLD | NEW |
(Empty) | |
| 1 //===- unittest/IceELFSectionTest.cpp - ELF Section unit tests ------------===// |
| 2 // |
| 3 // The Subzero Code Generator |
| 4 // |
| 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. |
| 7 // |
| 8 //===----------------------------------------------------------------------===// |
| 9 |
| 10 #include "IceDefs.h" |
| 11 #include "IceELFSection.h" |
| 12 #include "gtest/gtest.h" |
| 13 |
| 14 namespace Ice { |
| 15 namespace { |
| 16 |
| 17 // Test string table layout for various permutations. Test that pop, |
| 18 // lollipop, and lipop are able to share data, while the other strings do not. |
| 19 void CheckStringTablePermLayout(const ELFStringTableSection &Strtab) { |
| 20 size_t pop_index = Strtab.getIndex("pop"); |
| 21 size_t lollipop_index = Strtab.getIndex("lollipop"); |
| 22 size_t lipop_index = Strtab.getIndex("lipop"); |
| 23 size_t pops_index = Strtab.getIndex("pops"); |
| 24 size_t unpop_index = Strtab.getIndex("unpop"); |
| 25 size_t popular_index = Strtab.getIndex("popular"); |
| 26 size_t a_index = Strtab.getIndex("a"); |
| 27 |
| 28 EXPECT_EQ(pop_index, lollipop_index + (IceString("lollipop").size() - |
| 29 IceString("pop").size())); |
| 30 EXPECT_EQ(lipop_index, lollipop_index + (IceString("lollipop").size() - |
| 31 IceString("lipop").size())); |
| 32 // The rest happen to be sorted this way. |
| 33 EXPECT_EQ(1U, pops_index); |
| 34 EXPECT_EQ(popular_index, pops_index + IceString("pops").size() + 1); |
| 35 EXPECT_EQ(unpop_index, popular_index + IceString("popular").size() + 1); |
| 36 EXPECT_EQ(lollipop_index, unpop_index + IceString("unpop").size() + 1); |
| 37 EXPECT_EQ(a_index, lollipop_index + IceString("lollipop").size() + 1); |
| 38 } |
| 39 |
| 40 TEST(IceELFSectionTest, StringTableBuilderPerm1) { |
| 41 ELFStringTableSection Strtab(".strtab", SHT_STRTAB, 0, 1, 0); |
| 42 Strtab.add("pop"); |
| 43 Strtab.add("lollipop"); |
| 44 Strtab.add("lipop"); |
| 45 Strtab.add("pops"); |
| 46 Strtab.add("unpop"); |
| 47 Strtab.add("popular"); |
| 48 Strtab.add("a"); |
| 49 Strtab.doLayout(); |
| 50 CheckStringTablePermLayout(Strtab); |
| 51 } |
| 52 |
| 53 TEST(IceELFSectionTest, StringTableBuilderPerm2) { |
| 54 ELFStringTableSection Strtab(".strtab", SHT_STRTAB, 0, 1, 0); |
| 55 Strtab.add("lollipop"); |
| 56 Strtab.add("pop"); |
| 57 Strtab.add("unpop"); |
| 58 Strtab.add("pops"); |
| 59 Strtab.add("popular"); |
| 60 Strtab.add("lipop"); |
| 61 Strtab.add("a"); |
| 62 Strtab.doLayout(); |
| 63 CheckStringTablePermLayout(Strtab); |
| 64 } |
| 65 |
| 66 TEST(IceELFSectionTest, StringTableBuilderPerm3) { |
| 67 ELFStringTableSection Strtab(".strtab", SHT_STRTAB, 0, 1, 0); |
| 68 Strtab.add("pops"); |
| 69 Strtab.add("a"); |
| 70 Strtab.add("lipop"); |
| 71 Strtab.add("popular"); |
| 72 Strtab.add("pop"); |
| 73 Strtab.add("unpop"); |
| 74 Strtab.add("lollipop"); |
| 75 Strtab.doLayout(); |
| 76 CheckStringTablePermLayout(Strtab); |
| 77 } |
| 78 |
| 79 TEST(IceELFSectionTest, StringTableBuilderPerm4) { |
| 80 ELFStringTableSection Strtab(".strtab", SHT_STRTAB, 0, 1, 0); |
| 81 Strtab.add("unpop"); |
| 82 Strtab.add("pop"); |
| 83 Strtab.add("lollipop"); |
| 84 Strtab.add("a"); |
| 85 Strtab.add("popular"); |
| 86 Strtab.add("pops"); |
| 87 Strtab.add("lipop"); |
| 88 Strtab.doLayout(); |
| 89 CheckStringTablePermLayout(Strtab); |
| 90 } |
| 91 |
| 92 // Test that adding duplicate strings is fine. |
| 93 TEST(IceELFSectionTest, StringTableBuilderDuplicates) { |
| 94 ELFStringTableSection Strtab(".strtab", SHT_STRTAB, 0, 1, 0); |
| 95 Strtab.add("unpop"); |
| 96 Strtab.add("pop"); |
| 97 Strtab.add("lollipop"); |
| 98 Strtab.add("a"); |
| 99 Strtab.add("popular"); |
| 100 Strtab.add("pops"); |
| 101 Strtab.add("lipop"); |
| 102 |
| 103 Strtab.add("lipop"); |
| 104 Strtab.add("pops"); |
| 105 Strtab.add("popular"); |
| 106 Strtab.add("a"); |
| 107 Strtab.add("lollipop"); |
| 108 Strtab.add("pop"); |
| 109 Strtab.add("unpop"); |
| 110 |
| 111 Strtab.doLayout(); |
| 112 CheckStringTablePermLayout(Strtab); |
| 113 } |
| 114 |
| 115 } // end of anonymous namespace |
| 116 } // end of namespace Ice |
OLD | NEW |