Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: unittest/IceELFSectionTest.cpp

Issue 1838753002: Subzero: Remove IceString. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Code review changes Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/PNaClTranslator.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- unittest/IceELFSectionTest.cpp - ELF Section unit tests ------------===// 1 //===- unittest/IceELFSectionTest.cpp - ELF Section unit tests ------------===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 9
10 #include <algorithm> 10 #include <algorithm>
11 11
12 #include "gtest/gtest.h" 12 #include "gtest/gtest.h"
13 13
14 #include "IceDefs.h" 14 #include "IceDefs.h"
15 #include "IceELFSection.h" 15 #include "IceELFSection.h"
16 16
17 #include "llvm/Support/raw_os_ostream.h"
18
17 namespace Ice { 19 namespace Ice {
18 namespace { 20 namespace {
19 21
20 // Test string table layout for various permutations. Test that pop, 22 // Test string table layout for various permutations. Test that pop,
21 // lollipop, and lipop are able to share data, while the other strings do not. 23 // lollipop, and lipop are able to share data, while the other strings do not.
22 void CheckStringTablePermLayout(const ELFStringTableSection &Strtab) { 24 void CheckStringTablePermLayout(const ELFStringTableSection &Strtab) {
23 size_t pop_index = Strtab.getIndex("pop"); 25 size_t pop_index = Strtab.getIndex("pop");
24 size_t pop_size = IceString("pop").size(); 26 size_t pop_size = std::string("pop").size();
25 size_t lollipop_index = Strtab.getIndex("lollipop"); 27 size_t lollipop_index = Strtab.getIndex("lollipop");
26 size_t lollipop_size = IceString("lollipop").size(); 28 size_t lollipop_size = std::string("lollipop").size();
27 size_t lipop_index = Strtab.getIndex("lipop"); 29 size_t lipop_index = Strtab.getIndex("lipop");
28 size_t lipop_size = IceString("lipop").size(); 30 size_t lipop_size = std::string("lipop").size();
29 size_t pops_index = Strtab.getIndex("pops"); 31 size_t pops_index = Strtab.getIndex("pops");
30 size_t pops_size = IceString("pops").size(); 32 size_t pops_size = std::string("pops").size();
31 size_t unpop_index = Strtab.getIndex("unpop"); 33 size_t unpop_index = Strtab.getIndex("unpop");
32 size_t unpop_size = IceString("unpop").size(); 34 size_t unpop_size = std::string("unpop").size();
33 size_t popular_index = Strtab.getIndex("popular"); 35 size_t popular_index = Strtab.getIndex("popular");
34 size_t popular_size = IceString("popular").size(); 36 size_t popular_size = std::string("popular").size();
35 size_t strtab_index = Strtab.getIndex(".strtab"); 37 size_t strtab_index = Strtab.getIndex(".strtab");
36 size_t strtab_size = IceString(".strtab").size(); 38 size_t strtab_size = std::string(".strtab").size();
37 size_t shstrtab_index = Strtab.getIndex(".shstrtab"); 39 size_t shstrtab_index = Strtab.getIndex(".shstrtab");
38 size_t shstrtab_size = IceString(".shstrtab").size(); 40 size_t shstrtab_size = std::string(".shstrtab").size();
39 size_t symtab_index = Strtab.getIndex(".symtab"); 41 size_t symtab_index = Strtab.getIndex(".symtab");
40 size_t symtab_size = IceString(".symtab").size(); 42 size_t symtab_size = std::string(".symtab").size();
41 43
42 // Check that some sharing exists. 44 // Check that some sharing exists.
43 EXPECT_EQ(pop_index, lollipop_index + (lollipop_size - pop_size)); 45 EXPECT_EQ(pop_index, lollipop_index + (lollipop_size - pop_size));
44 EXPECT_EQ(lipop_index, lollipop_index + (lollipop_size - lipop_size)); 46 EXPECT_EQ(lipop_index, lollipop_index + (lollipop_size - lipop_size));
45 47
46 // Check that .strtab does not share with .shstrtab (the dot throws it off). 48 // Check that .strtab does not share with .shstrtab (the dot throws it off).
47 EXPECT_NE(strtab_index, shstrtab_index + (shstrtab_size - strtab_size)); 49 EXPECT_NE(strtab_index, shstrtab_index + (shstrtab_size - strtab_size));
48 50
49 // Check contents make sense. 51 // Check contents make sense.
50 EXPECT_EQ(Strtab.getSectionData().slice(pop_index, pop_index + pop_size), 52 EXPECT_EQ(Strtab.getSectionData().slice(pop_index, pop_index + pop_size),
(...skipping 15 matching lines...) Expand all
66 EXPECT_EQ(Strtab.getSectionData().slice(shstrtab_index, 68 EXPECT_EQ(Strtab.getSectionData().slice(shstrtab_index,
67 shstrtab_index + shstrtab_size), 69 shstrtab_index + shstrtab_size),
68 llvm::StringRef(".shstrtab")); 70 llvm::StringRef(".shstrtab"));
69 EXPECT_EQ( 71 EXPECT_EQ(
70 Strtab.getSectionData().slice(symtab_index, symtab_index + symtab_size), 72 Strtab.getSectionData().slice(symtab_index, symtab_index + symtab_size),
71 llvm::StringRef(".symtab")); 73 llvm::StringRef(".symtab"));
72 } 74 }
73 75
74 // Test that the order in which strings are added doesn't matter. 76 // Test that the order in which strings are added doesn't matter.
75 TEST(IceELFSectionTest, StringTableBuilderPermSeveral) { 77 TEST(IceELFSectionTest, StringTableBuilderPermSeveral) {
76 std::vector<IceString> Strings; 78 std::vector<std::string> Strings;
77 Strings.push_back("pop"); 79 Strings.push_back("pop");
78 Strings.push_back("lollipop"); 80 Strings.push_back("lollipop");
79 Strings.push_back("lipop"); 81 Strings.push_back("lipop");
80 Strings.push_back("pops"); 82 Strings.push_back("pops");
81 Strings.push_back("unpop"); 83 Strings.push_back("unpop");
82 Strings.push_back("popular"); 84 Strings.push_back("popular");
83 Strings.push_back("a"); 85 Strings.push_back("a");
84 Strings.push_back("z"); 86 Strings.push_back("z");
85 Strings.push_back("foo"); 87 Strings.push_back("foo");
86 Strings.push_back("bar"); 88 Strings.push_back("bar");
87 Strings.push_back(".text"); 89 Strings.push_back(".text");
88 Strings.push_back(".symtab"); 90 Strings.push_back(".symtab");
89 Strings.push_back(".strtab"); 91 Strings.push_back(".strtab");
90 Strings.push_back(".shstrtab"); 92 Strings.push_back(".shstrtab");
91 Strings.push_back("_start"); 93 Strings.push_back("_start");
92 const SizeT NumTests = 128; 94 const SizeT NumTests = 128;
93 const uint64_t RandomSeed = 12345; // arbitrary value for now 95 const uint64_t RandomSeed = 12345; // arbitrary value for now
94 RandomNumberGenerator R(RandomSeed); 96 RandomNumberGenerator R(RandomSeed);
95 RandomNumberGeneratorWrapper RNG(R); 97 RandomNumberGeneratorWrapper RNG(R);
96 for (SizeT i = 0; i < NumTests; ++i) { 98 for (SizeT i = 0; i < NumTests; ++i) {
99 auto Str = std::unique_ptr<Ostream>(new llvm::raw_os_ostream(std::cout));
97 RandomShuffle(Strings.begin(), Strings.end(), RNG); 100 RandomShuffle(Strings.begin(), Strings.end(), RNG);
98 ELFStringTableSection Strtab(".strtab", SHT_STRTAB, 0, 1, 0); 101 ELFStringTableSection Strtab(".strtab", SHT_STRTAB, 0, 1, 0);
99 for (auto &S : Strings) { 102 for (auto &S : Strings) {
100 Strtab.add(S); 103 Strtab.add(S);
101 } 104 }
102 Strtab.doLayout(); 105 Strtab.doLayout();
103 CheckStringTablePermLayout(Strtab); 106 CheckStringTablePermLayout(Strtab);
104 } 107 }
105 } 108 }
106 109
107 // Test that adding duplicate strings is fine. 110 // Test that adding duplicate strings is fine.
108 TEST(IceELFSectionTest, StringTableBuilderDuplicates) { 111 TEST(IceELFSectionTest, StringTableBuilderDuplicates) {
112 auto Str = std::unique_ptr<Ostream>(new llvm::raw_os_ostream(std::cout));
109 ELFStringTableSection Strtab(".strtab", SHT_STRTAB, 0, 1, 0); 113 ELFStringTableSection Strtab(".strtab", SHT_STRTAB, 0, 1, 0);
110 Strtab.add("unpop"); 114 Strtab.add("unpop");
111 Strtab.add("pop"); 115 Strtab.add("pop");
112 Strtab.add("lollipop"); 116 Strtab.add("lollipop");
113 Strtab.add("a"); 117 Strtab.add("a");
114 Strtab.add("popular"); 118 Strtab.add("popular");
115 Strtab.add("pops"); 119 Strtab.add("pops");
116 Strtab.add("lipop"); 120 Strtab.add("lipop");
117 Strtab.add(".strtab"); 121 Strtab.add(".strtab");
118 Strtab.add(".shstrtab"); 122 Strtab.add(".shstrtab");
119 Strtab.add(".symtab"); 123 Strtab.add(".symtab");
120 124
121 Strtab.add(".symtab"); 125 Strtab.add(".symtab");
122 Strtab.add(".shstrtab"); 126 Strtab.add(".shstrtab");
123 Strtab.add(".strtab"); 127 Strtab.add(".strtab");
124 Strtab.add("lipop"); 128 Strtab.add("lipop");
125 Strtab.add("pops"); 129 Strtab.add("pops");
126 Strtab.add("popular"); 130 Strtab.add("popular");
127 Strtab.add("a"); 131 Strtab.add("a");
128 Strtab.add("lollipop"); 132 Strtab.add("lollipop");
129 Strtab.add("pop"); 133 Strtab.add("pop");
130 Strtab.add("unpop"); 134 Strtab.add("unpop");
131 135
132 Strtab.doLayout(); 136 Strtab.doLayout();
133 CheckStringTablePermLayout(Strtab); 137 CheckStringTablePermLayout(Strtab);
134 } 138 }
135 139
136 } // end of anonymous namespace 140 } // end of anonymous namespace
137 } // end of namespace Ice 141 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/PNaClTranslator.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698