aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorted.mielczarek@gmail.com <ted.mielczarek@gmail.com@4c0a9323-5329-0410-9bdc-e9ce6186880e>2013-03-29 15:06:37 +0000
committerted.mielczarek@gmail.com <ted.mielczarek@gmail.com@4c0a9323-5329-0410-9bdc-e9ce6186880e>2013-03-29 15:06:37 +0000
commit8de2cd2d22d1f37624ef988911a596b736bcf632 (patch)
tree538cb190624799ee0d4b4364d4c749ab8cc01619 /src
parentDefer adding sections until ELF::Finish in synth_elf (diff)
downloadbreakpad-8de2cd2d22d1f37624ef988911a596b736bcf632.tar.xz
Refactor BasicElf synth_elf unitest
A=Mike Hommey <mh@glandium.org> R=ted at https://breakpad.appspot.com/544002/ git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1136 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src')
-rw-r--r--src/common/linux/synth_elf_unittest.cc72
1 files changed, 23 insertions, 49 deletions
diff --git a/src/common/linux/synth_elf_unittest.cc b/src/common/linux/synth_elf_unittest.cc
index 34a00cab..7aa252e3 100644
--- a/src/common/linux/synth_elf_unittest.cc
+++ b/src/common/linux/synth_elf_unittest.cc
@@ -35,9 +35,12 @@
#include <elf.h>
#include "breakpad_googletest_includes.h"
+#include "common/linux/elfutils.h"
#include "common/linux/synth_elf.h"
#include "common/using_std_string.h"
+using google_breakpad::ElfClass32;
+using google_breakpad::ElfClass64;
using google_breakpad::synth_elf::ELF;
using google_breakpad::synth_elf::StringTable;
using google_breakpad::synth_elf::SymbolTable;
@@ -46,6 +49,7 @@ using google_breakpad::test_assembler::kBigEndian;
using google_breakpad::test_assembler::kLittleEndian;
using google_breakpad::test_assembler::Label;
using ::testing::Test;
+using ::testing::Types;
class StringTableTest : public Test {
public:
@@ -178,86 +182,56 @@ TEST_F(SymbolTableTest, Simple32) {
symbol_contents.size()));
}
+template<typename ElfClass>
class BasicElf : public Test {};
// Doesn't seem worthwhile writing the tests to be endian-independent
// when they're unlikely to ever be run on big-endian systems.
#if defined(__i386__) || defined(__x86_64__)
-TEST_F(BasicElf, EmptyLE32) {
- const size_t kStringTableSize = sizeof("\0.shstrtab");
- const size_t kStringTableAlign = 4 - kStringTableSize % 4;
- const size_t kExpectedSize = sizeof(Elf32_Ehdr) +
- // Two sections, SHT_NULL + the section header string table.
- 2 * sizeof(Elf32_Shdr) +
- kStringTableSize + kStringTableAlign;
+typedef Types<ElfClass32, ElfClass64> ElfClasses;
- ELF elf(EM_386, ELFCLASS32, kLittleEndian);
- elf.Finish();
- EXPECT_EQ(kExpectedSize, elf.Size());
+TYPED_TEST_CASE(BasicElf, ElfClasses);
- string contents;
- ASSERT_TRUE(elf.GetContents(&contents));
- ASSERT_EQ(kExpectedSize, contents.size());
- const Elf32_Ehdr* header =
- reinterpret_cast<const Elf32_Ehdr*>(contents.data());
- const uint8_t kIdent[] = {
- ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3,
- ELFCLASS32, ELFDATA2LSB, EV_CURRENT, ELFOSABI_SYSV,
- 0, 0, 0, 0, 0, 0, 0, 0
- };
- EXPECT_EQ(0, memcmp(kIdent, header->e_ident, sizeof(kIdent)));
- EXPECT_EQ(ET_EXEC, header->e_type);
- EXPECT_EQ(EM_386, header->e_machine);
- EXPECT_EQ(static_cast<unsigned int>(EV_CURRENT), header->e_version);
- EXPECT_EQ(0U, header->e_entry);
- EXPECT_EQ(0U, header->e_phoff);
- EXPECT_EQ(sizeof(Elf32_Ehdr) + kStringTableSize + kStringTableAlign,
- header->e_shoff);
- EXPECT_EQ(0U, header->e_flags);
- EXPECT_EQ(sizeof(Elf32_Ehdr), header->e_ehsize);
- EXPECT_EQ(sizeof(Elf32_Phdr), header->e_phentsize);
- EXPECT_EQ(0, header->e_phnum);
- EXPECT_EQ(sizeof(Elf32_Shdr), header->e_shentsize);
- EXPECT_EQ(2, header->e_shnum);
- EXPECT_EQ(1, header->e_shstrndx);
-}
-
-TEST_F(BasicElf, EmptyLE64) {
+TYPED_TEST(BasicElf, EmptyLE) {
+ typedef typename TypeParam::Ehdr Ehdr;
+ typedef typename TypeParam::Phdr Phdr;
+ typedef typename TypeParam::Shdr Shdr;
const size_t kStringTableSize = sizeof("\0.shstrtab");
const size_t kStringTableAlign = 4 - kStringTableSize % 4;
- const size_t kExpectedSize = sizeof(Elf64_Ehdr) +
+ const size_t kExpectedSize = sizeof(Ehdr) +
// Two sections, SHT_NULL + the section header string table.
- 2 * sizeof(Elf64_Shdr) +
+ 2 * sizeof(Shdr) +
kStringTableSize + kStringTableAlign;
- ELF elf(EM_X86_64, ELFCLASS64, kLittleEndian);
+ // It doesn't really matter that the machine type is right for the class.
+ ELF elf(EM_386, TypeParam::kClass, kLittleEndian);
elf.Finish();
EXPECT_EQ(kExpectedSize, elf.Size());
string contents;
ASSERT_TRUE(elf.GetContents(&contents));
ASSERT_EQ(kExpectedSize, contents.size());
- const Elf64_Ehdr* header =
- reinterpret_cast<const Elf64_Ehdr*>(contents.data());
+ const Ehdr* header =
+ reinterpret_cast<const Ehdr*>(contents.data());
const uint8_t kIdent[] = {
ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3,
- ELFCLASS64, ELFDATA2LSB, EV_CURRENT, ELFOSABI_SYSV,
+ TypeParam::kClass, ELFDATA2LSB, EV_CURRENT, ELFOSABI_SYSV,
0, 0, 0, 0, 0, 0, 0, 0
};
EXPECT_EQ(0, memcmp(kIdent, header->e_ident, sizeof(kIdent)));
EXPECT_EQ(ET_EXEC, header->e_type);
- EXPECT_EQ(EM_X86_64, header->e_machine);
+ EXPECT_EQ(EM_386, header->e_machine);
EXPECT_EQ(static_cast<unsigned int>(EV_CURRENT), header->e_version);
EXPECT_EQ(0U, header->e_entry);
EXPECT_EQ(0U, header->e_phoff);
- EXPECT_EQ(sizeof(Elf64_Ehdr) + kStringTableSize + kStringTableAlign,
+ EXPECT_EQ(sizeof(Ehdr) + kStringTableSize + kStringTableAlign,
header->e_shoff);
EXPECT_EQ(0U, header->e_flags);
- EXPECT_EQ(sizeof(Elf64_Ehdr), header->e_ehsize);
- EXPECT_EQ(sizeof(Elf64_Phdr), header->e_phentsize);
+ EXPECT_EQ(sizeof(Ehdr), header->e_ehsize);
+ EXPECT_EQ(sizeof(Phdr), header->e_phentsize);
EXPECT_EQ(0, header->e_phnum);
- EXPECT_EQ(sizeof(Elf64_Shdr), header->e_shentsize);
+ EXPECT_EQ(sizeof(Shdr), header->e_shentsize);
EXPECT_EQ(2, header->e_shnum);
EXPECT_EQ(1, header->e_shstrndx);
}