proxygen
ElfTests.cpp File Reference

Go to the source code of this file.

Classes

class  ElfTest
 

Functions

 TEST_F (ElfTest, IntegerValue)
 
 TEST_F (ElfTest, PointerValue)
 
 TEST_F (ElfTest, iterateProgramHeaders)
 
 TEST_F (ElfTest, TinyNonElfFile)
 
 TEST_F (ElfTest, NonElfScript)
 

Variables

uint64_t kIntegerValue = 1234567890UL
 
const char * kStringValue = "coconuts"
 

Function Documentation

TEST_F ( ElfTest  ,
IntegerValue   
)

Definition at line 34 of file ElfTests.cpp.

References ElfTest::elfFile_, EXPECT_EQ, EXPECT_NE, folly::symbolizer::ElfFile::getSymbolByName(), folly::symbolizer::ElfFile::getSymbolValue(), kIntegerValue, and uint64_t.

34  {
35  auto sym = elfFile_.getSymbolByName("kIntegerValue");
36  EXPECT_NE(nullptr, sym.first) << "Failed to look up symbol kIntegerValue";
37  EXPECT_EQ(kIntegerValue, elfFile_.getSymbolValue<uint64_t>(sym.second));
38 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
uint64_t kIntegerValue
Definition: ElfTests.cpp:26
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
TEST_F ( ElfTest  ,
PointerValue   
)

Definition at line 40 of file ElfTests.cpp.

References addr, ElfTest::elfFile_, EXPECT_NE, EXPECT_STREQ, folly::symbolizer::ElfFile::getAddressValue(), folly::symbolizer::ElfFile::getSymbolByName(), folly::symbolizer::ElfFile::getSymbolValue(), and kStringValue.

40  {
41  auto sym = elfFile_.getSymbolByName("kStringValue");
42  EXPECT_NE(nullptr, sym.first) << "Failed to look up symbol kStringValue";
43  ElfW(Addr) addr = elfFile_.getSymbolValue<ElfW(Addr)>(sym.second);
44  const char* str = &elfFile_.getAddressValue<const char>(addr);
46 }
const char * kStringValue
Definition: ElfTests.cpp:27
#define EXPECT_STREQ(s1, s2)
Definition: gtest.h:1995
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
const
Definition: upload.py:398
ThreadPoolListHook * addr
TEST_F ( ElfTest  ,
iterateProgramHeaders   
)

Definition at line 48 of file ElfTests.cpp.

References ElfTest::elfFile_, EXPECT_GE, EXPECT_NE, h, and folly::symbolizer::ElfFile::iterateProgramHeaders().

48  {
49  auto phdr = elfFile_.iterateProgramHeaders(
50  [](auto& h) { return h.p_type == PT_LOAD; });
51  EXPECT_NE(nullptr, phdr);
52  EXPECT_GE(phdr->p_filesz, 0);
53 }
*than *hazptr_holder h
Definition: Hazptr.h:116
#define EXPECT_GE(val1, val2)
Definition: gtest.h:1932
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
TEST_F ( ElfTest  ,
TinyNonElfFile   
)

Definition at line 55 of file ElfTests.cpp.

References folly::Range< Iter >::data(), EXPECT_EQ, EXPECT_STREQ, folly::test::TemporaryFile::fd(), folly::symbolizer::ElfFile::openNoThrow(), folly::test::TemporaryFile::path(), folly::Range< Iter >::size(), and folly::writeFull().

55  {
57  const static folly::StringPiece contents = "!";
58  folly::writeFull(tmpFile.fd(), contents.data(), contents.size());
59 
60  ElfFile elfFile;
61  const char* msg = nullptr;
62  auto res = elfFile.openNoThrow(tmpFile.path().c_str(), true, &msg);
63  EXPECT_EQ(ElfFile::kInvalidElfFile, res);
64  EXPECT_STREQ("not an ELF file (too short)", msg);
65 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr size_type size() const
Definition: Range.h:431
#define EXPECT_STREQ(s1, s2)
Definition: gtest.h:1995
int openNoThrow(const char *name, bool readOnly=true, const char **msg=nullptr) noexcept
Definition: Elf.cpp:63
constexpr Iter data() const
Definition: Range.h:446
ssize_t writeFull(int fd, const void *buf, size_t count)
Definition: FileUtil.cpp:134
const fs::path & path() const
Definition: TestUtil.cpp:85
TEST_F ( ElfTest  ,
NonElfScript   
)

Definition at line 67 of file ElfTests.cpp.

References folly::Range< Iter >::data(), EXPECT_EQ, EXPECT_STREQ, folly::test::TemporaryFile::fd(), folly::symbolizer::ElfFile::openNoThrow(), folly::test::TemporaryFile::path(), folly::Range< Iter >::size(), and folly::writeFull().

67  {
69  const static folly::StringPiece contents =
70  "#!/bin/sh\necho I'm small non-ELF executable\n";
71  folly::writeFull(tmpFile.fd(), contents.data(), contents.size());
72 
73  ElfFile elfFile;
74  const char* msg = nullptr;
75  auto res = elfFile.openNoThrow(tmpFile.path().c_str(), true, &msg);
76  EXPECT_EQ(ElfFile::kInvalidElfFile, res);
77  EXPECT_STREQ("invalid ELF magic", msg);
78 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr size_type size() const
Definition: Range.h:431
#define EXPECT_STREQ(s1, s2)
Definition: gtest.h:1995
int openNoThrow(const char *name, bool readOnly=true, const char **msg=nullptr) noexcept
Definition: Elf.cpp:63
constexpr Iter data() const
Definition: Range.h:446
ssize_t writeFull(int fd, const void *buf, size_t count)
Definition: FileUtil.cpp:134
const fs::path & path() const
Definition: TestUtil.cpp:85

Variable Documentation

uint64_t kIntegerValue = 1234567890UL

Definition at line 26 of file ElfTests.cpp.

Referenced by TEST_F().

const char* kStringValue = "coconuts"

Definition at line 27 of file ElfTests.cpp.

Referenced by TEST_F().