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

Unified 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: cleanup Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« src/IceMemoryRegion.h ('K') | « tests_lit/llvm2ice_tests/elf_container.ll ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: unittest/IceELFSectionTest.cpp
diff --git a/unittest/IceELFSectionTest.cpp b/unittest/IceELFSectionTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d4716905dc72031cb0b1a7ed08478870bfbe89bb
--- /dev/null
+++ b/unittest/IceELFSectionTest.cpp
@@ -0,0 +1,116 @@
+//===- unittest/IceELFSectionTest.cpp - ELF Section unit tests ------------===//
+//
+// The Subzero Code Generator
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "IceDefs.h"
+#include "IceELFSection.h"
+#include "gtest/gtest.h"
+
+namespace Ice {
+namespace {
+
+// Test string table layout for various permutations. Test that pop,
+// lollipop, and lipop are able to share data, while the other strings do not.
+void CheckStringTablePermLayout(const ELFStringTableSection &Strtab) {
+ size_t pop_index = Strtab.getIndex("pop");
+ size_t lollipop_index = Strtab.getIndex("lollipop");
+ size_t lipop_index = Strtab.getIndex("lipop");
+ size_t pops_index = Strtab.getIndex("pops");
+ size_t unpop_index = Strtab.getIndex("unpop");
+ size_t popular_index = Strtab.getIndex("popular");
+ size_t a_index = Strtab.getIndex("a");
+
+ EXPECT_EQ(pop_index, lollipop_index + (IceString("lollipop").size() -
+ IceString("pop").size()));
+ EXPECT_EQ(lipop_index, lollipop_index + (IceString("lollipop").size() -
+ IceString("lipop").size()));
+ // The rest happen to be sorted this way.
+ EXPECT_EQ(1U, pops_index);
+ EXPECT_EQ(popular_index, pops_index + IceString("pops").size() + 1);
+ EXPECT_EQ(unpop_index, popular_index + IceString("popular").size() + 1);
+ EXPECT_EQ(lollipop_index, unpop_index + IceString("unpop").size() + 1);
+ EXPECT_EQ(a_index, lollipop_index + IceString("lollipop").size() + 1);
+}
+
+TEST(IceELFSectionTest, StringTableBuilderPerm1) {
+ ELFStringTableSection Strtab(".strtab", SHT_STRTAB, 0, 1, 0);
+ Strtab.add("pop");
+ Strtab.add("lollipop");
+ Strtab.add("lipop");
+ Strtab.add("pops");
+ Strtab.add("unpop");
+ Strtab.add("popular");
+ Strtab.add("a");
+ Strtab.doLayout();
+ CheckStringTablePermLayout(Strtab);
+}
+
+TEST(IceELFSectionTest, StringTableBuilderPerm2) {
+ ELFStringTableSection Strtab(".strtab", SHT_STRTAB, 0, 1, 0);
+ Strtab.add("lollipop");
+ Strtab.add("pop");
+ Strtab.add("unpop");
+ Strtab.add("pops");
+ Strtab.add("popular");
+ Strtab.add("lipop");
+ Strtab.add("a");
+ Strtab.doLayout();
+ CheckStringTablePermLayout(Strtab);
+}
+
+TEST(IceELFSectionTest, StringTableBuilderPerm3) {
+ ELFStringTableSection Strtab(".strtab", SHT_STRTAB, 0, 1, 0);
+ Strtab.add("pops");
+ Strtab.add("a");
+ Strtab.add("lipop");
+ Strtab.add("popular");
+ Strtab.add("pop");
+ Strtab.add("unpop");
+ Strtab.add("lollipop");
+ Strtab.doLayout();
+ CheckStringTablePermLayout(Strtab);
+}
+
+TEST(IceELFSectionTest, StringTableBuilderPerm4) {
+ ELFStringTableSection Strtab(".strtab", SHT_STRTAB, 0, 1, 0);
+ Strtab.add("unpop");
+ Strtab.add("pop");
+ Strtab.add("lollipop");
+ Strtab.add("a");
+ Strtab.add("popular");
+ Strtab.add("pops");
+ Strtab.add("lipop");
+ Strtab.doLayout();
+ CheckStringTablePermLayout(Strtab);
+}
+
+// Test that adding duplicate strings is fine.
+TEST(IceELFSectionTest, StringTableBuilderDuplicates) {
+ ELFStringTableSection Strtab(".strtab", SHT_STRTAB, 0, 1, 0);
+ Strtab.add("unpop");
+ Strtab.add("pop");
+ Strtab.add("lollipop");
+ Strtab.add("a");
+ Strtab.add("popular");
+ Strtab.add("pops");
+ Strtab.add("lipop");
+
+ Strtab.add("lipop");
+ Strtab.add("pops");
+ Strtab.add("popular");
+ Strtab.add("a");
+ Strtab.add("lollipop");
+ Strtab.add("pop");
+ Strtab.add("unpop");
+
+ Strtab.doLayout();
+ CheckStringTablePermLayout(Strtab);
+}
+
+} // end of anonymous namespace
+} // end of namespace Ice
« src/IceMemoryRegion.h ('K') | « 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