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

Side by Side Diff: unittest/IceELFSectionTest.cpp

Issue 678533005: Subzero: Add basic ELFObjectWriter (text section, symtab, strtab, headers) (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: minor cleanup Created 6 years 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 | « tests_lit/llvm2ice_tests/elf_container.ll ('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
(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 <algorithm>
11
12 #include "gtest/gtest.h"
13
14 #include "IceDefs.h"
15 #include "IceELFSection.h"
16
17 namespace Ice {
18 namespace {
19
20 // 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.
22 void CheckStringTablePermLayout(const ELFStringTableSection &Strtab) {
23 size_t pop_index = Strtab.getIndex("pop");
24 size_t pop_size = IceString("pop").size();
25 size_t lollipop_index = Strtab.getIndex("lollipop");
26 size_t lollipop_size = IceString("lollipop").size();
27 size_t lipop_index = Strtab.getIndex("lipop");
28 size_t lipop_size = IceString("lipop").size();
29 size_t pops_index = Strtab.getIndex("pops");
30 size_t pops_size = IceString("pops").size();
31 size_t unpop_index = Strtab.getIndex("unpop");
32 size_t unpop_size = IceString("unpop").size();
33 size_t popular_index = Strtab.getIndex("popular");
34 size_t popular_size = IceString("popular").size();
35 size_t strtab_index = Strtab.getIndex(".strtab");
36 size_t strtab_size = IceString(".strtab").size();
37 size_t shstrtab_index = Strtab.getIndex(".shstrtab");
38 size_t shstrtab_size = IceString(".shstrtab").size();
39 size_t symtab_index = Strtab.getIndex(".symtab");
40 size_t symtab_size = IceString(".symtab").size();
41
42 // Check that some sharing exists.
43 EXPECT_EQ(pop_index, lollipop_index + (lollipop_size - pop_size));
44 EXPECT_EQ(lipop_index, lollipop_index + (lollipop_size - lipop_size));
45
46 // Check that .strtab does not share with .shstrtab (the dot throws it off).
47 EXPECT_NE(strtab_index, shstrtab_index + (shstrtab_size - strtab_size));
48
49 // Check contents make sense.
50 EXPECT_EQ(Strtab.getSectionData().slice(pop_index, pop_index + pop_size),
51 llvm::StringRef("pop"));
52 EXPECT_EQ(Strtab.getSectionData().slice(lollipop_index,
53 lollipop_index + lollipop_size),
54 llvm::StringRef("lollipop"));
55 EXPECT_EQ(Strtab.getSectionData().slice(pops_index, pops_index + pops_size),
56 llvm::StringRef("pops"));
57 EXPECT_EQ(
58 Strtab.getSectionData().slice(unpop_index, unpop_index + unpop_size),
59 llvm::StringRef("unpop"));
60 EXPECT_EQ(Strtab.getSectionData().slice(popular_index,
61 popular_index + popular_size),
62 llvm::StringRef("popular"));
63 EXPECT_EQ(
64 Strtab.getSectionData().slice(strtab_index, strtab_index + strtab_size),
65 llvm::StringRef(".strtab"));
66 EXPECT_EQ(Strtab.getSectionData().slice(shstrtab_index,
67 shstrtab_index + shstrtab_size),
68 llvm::StringRef(".shstrtab"));
69 EXPECT_EQ(
70 Strtab.getSectionData().slice(symtab_index, symtab_index + symtab_size),
71 llvm::StringRef(".symtab"));
72 }
73
74 // Test that the order in which strings are added doesn't matter.
75 TEST(IceELFSectionTest, StringTableBuilderPermSeveral) {
76 std::vector<IceString> Strings;
77 Strings.push_back("pop");
78 Strings.push_back("lollipop");
79 Strings.push_back("lipop");
80 Strings.push_back("pops");
81 Strings.push_back("unpop");
82 Strings.push_back("popular");
83 Strings.push_back("a");
84 Strings.push_back("z");
85 Strings.push_back("foo");
86 Strings.push_back("bar");
87 Strings.push_back(".text");
88 Strings.push_back(".symtab");
89 Strings.push_back(".strtab");
90 Strings.push_back(".shstrtab");
91 Strings.push_back("_start");
92 const SizeT NumTests = 128;
93 for (SizeT i = 0; i < NumTests; ++i) {
94 std::random_shuffle(Strings.begin(), Strings.end());
95 ELFStringTableSection Strtab(".strtab", SHT_STRTAB, 0, 1, 0);
96 for (auto &S : Strings) {
97 Strtab.add(S);
98 }
99 Strtab.doLayout();
100 CheckStringTablePermLayout(Strtab);
101 }
102 }
103
104 // Test that adding duplicate strings is fine.
105 TEST(IceELFSectionTest, StringTableBuilderDuplicates) {
106 ELFStringTableSection Strtab(".strtab", SHT_STRTAB, 0, 1, 0);
107 Strtab.add("unpop");
108 Strtab.add("pop");
109 Strtab.add("lollipop");
110 Strtab.add("a");
111 Strtab.add("popular");
112 Strtab.add("pops");
113 Strtab.add("lipop");
114 Strtab.add(".strtab");
115 Strtab.add(".shstrtab");
116 Strtab.add(".symtab");
117
118 Strtab.add(".symtab");
119 Strtab.add(".shstrtab");
120 Strtab.add(".strtab");
121 Strtab.add("lipop");
122 Strtab.add("pops");
123 Strtab.add("popular");
124 Strtab.add("a");
125 Strtab.add("lollipop");
126 Strtab.add("pop");
127 Strtab.add("unpop");
128
129 Strtab.doLayout();
130 CheckStringTablePermLayout(Strtab);
131 }
132
133 } // end of anonymous namespace
134 } // end of namespace Ice
OLDNEW
« no previous file with comments | « tests_lit/llvm2ice_tests/elf_container.ll ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698