Most of the tests are passing

This commit is contained in:
Serge Lamikhov-Center 2022-02-11 23:15:39 +02:00
parent 090444309f
commit 068cb76a3f
6 changed files with 450 additions and 423 deletions

4
.vscode/launch.json vendored
View File

@ -8,13 +8,13 @@
"name": "Run ELFIO Tests", "name": "Run ELFIO Tests",
"type": "cppdbg", "type": "cppdbg",
"request": "launch", "request": "launch",
"program": "${workspaceFolder}/tests/ELFIOTest", "program": "${workspaceFolder}/build/tests/ELFIOTest",
"args": [ "args": [
"-r", "-r",
"short" "short"
], ],
"stopAtEntry": false, "stopAtEntry": false,
"cwd": "${workspaceFolder}/tests", "cwd": "${workspaceFolder}/build/tests",
"environment": [], "environment": [],
"externalConsole": false, "externalConsole": false,
"MIMode": "gdb", "MIMode": "gdb",

26
.vscode/settings.json vendored
View File

@ -73,5 +73,29 @@
"typeinfo": "cpp", "typeinfo": "cpp",
"variant": "cpp" "variant": "cpp"
}, },
"svn.ignoreMissingSvnWarning": true "svn.ignoreMissingSvnWarning": true,
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "googletest.failed",
"settings": {
"foreground": "#f00"
}
},
{
"scope": "googletest.passed",
"settings": {
"foreground": "#0f0"
}
},
{
"scope": "googletest.run",
"settings": {
"foreground": "#0f0"
}
}
]
},
"gtest-adapter.debugConfig": "Run ELFIO Tests",
"gtest-adapter.supportLocation": true
} }

View File

@ -1,5 +1,16 @@
# Unit tests are written using the Boost unit test framework include(FetchContent)
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/9a32aee22d771387c494be2d8519fbdf46a713b2.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
enable_testing()
# Find all the binary files used for testing and copy them into the build # Find all the binary files used for testing and copy them into the build
# directory. This allows the test to be run from the build directory # directory. This allows the test to be run from the build directory
@ -33,7 +44,7 @@ target_link_libraries(
ELFIOTest ELFIOTest
PRIVATE PRIVATE
elfio::elfio elfio::elfio
Boost::unit_test_framework) gtest_main)
add_test( add_test(
NAME NAME
@ -44,3 +55,6 @@ add_test(
${CMAKE_CURRENT_BINARY_DIR}) ${CMAKE_CURRENT_BINARY_DIR})
add_dependencies(check ELFIOTest) add_dependencies(check ELFIOTest)
include(GoogleTest)
gtest_discover_tests(ELFIOTest)

View File

@ -24,8 +24,7 @@ THE SOFTWARE.
#define _SCL_SECURE_NO_WARNINGS #define _SCL_SECURE_NO_WARNINGS
#endif #endif
#define BOOST_TEST_MODULE ELFIO_Test #include <gtest/gtest.h>
#include <boost/test/included/unit_test.hpp>
#include <elfio/elfio.hpp> #include <elfio/elfio.hpp>
@ -46,18 +45,18 @@ void checkHeader( elfio& reader,
unsigned char OSABI, unsigned char OSABI,
unsigned char ABIVersion ) unsigned char ABIVersion )
{ {
BOOST_CHECK_EQUAL( reader.get_class(), nClass ); EXPECT_EQ( reader.get_class(), nClass );
BOOST_CHECK_EQUAL( reader.get_encoding(), encoding ); EXPECT_EQ( reader.get_encoding(), encoding );
BOOST_CHECK_EQUAL( reader.get_elf_version(), elfVersion ); EXPECT_EQ( reader.get_elf_version(), elfVersion );
BOOST_CHECK_EQUAL( reader.get_os_abi(), OSABI ); EXPECT_EQ( reader.get_os_abi(), OSABI );
BOOST_CHECK_EQUAL( reader.get_abi_version(), ABIVersion ); EXPECT_EQ( reader.get_abi_version(), ABIVersion );
BOOST_CHECK_EQUAL( reader.get_type(), type ); EXPECT_EQ( reader.get_type(), type );
BOOST_CHECK_EQUAL( reader.get_machine(), machine ); EXPECT_EQ( reader.get_machine(), machine );
BOOST_CHECK_EQUAL( reader.get_version(), version ); EXPECT_EQ( reader.get_version(), version );
BOOST_CHECK_EQUAL( reader.get_entry(), entry ); EXPECT_EQ( reader.get_entry(), entry );
BOOST_CHECK_EQUAL( reader.get_flags(), flags ); EXPECT_EQ( reader.get_flags(), flags );
BOOST_CHECK_EQUAL( reader.sections.size(), secNum ); EXPECT_EQ( reader.sections.size(), secNum );
BOOST_CHECK_EQUAL( reader.segments.size(), segNum ); EXPECT_EQ( reader.segments.size(), segNum );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -73,16 +72,16 @@ void checkSection( const section* sec,
Elf_Xword addrAlign, Elf_Xword addrAlign,
Elf_Xword entrySize ) Elf_Xword entrySize )
{ {
BOOST_CHECK_EQUAL( sec->get_index(), index ); EXPECT_EQ( sec->get_index(), index );
BOOST_CHECK_EQUAL( sec->get_name(), name ); EXPECT_EQ( sec->get_name(), name );
BOOST_CHECK_EQUAL( sec->get_type(), type ); EXPECT_EQ( sec->get_type(), type );
BOOST_CHECK_EQUAL( sec->get_flags(), flags ); EXPECT_EQ( sec->get_flags(), flags );
BOOST_CHECK_EQUAL( sec->get_address(), address ); EXPECT_EQ( sec->get_address(), address );
BOOST_CHECK_EQUAL( sec->get_size(), size ); EXPECT_EQ( sec->get_size(), size );
BOOST_CHECK_EQUAL( sec->get_link(), link ); EXPECT_EQ( sec->get_link(), link );
BOOST_CHECK_EQUAL( sec->get_info(), info ); EXPECT_EQ( sec->get_info(), info );
BOOST_CHECK_EQUAL( sec->get_addr_align(), addrAlign ); EXPECT_EQ( sec->get_addr_align(), addrAlign );
BOOST_CHECK_EQUAL( sec->get_entry_size(), entrySize ); EXPECT_EQ( sec->get_entry_size(), entrySize );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -111,13 +110,13 @@ void checkSegment( const segment* seg,
Elf_Word flags, Elf_Word flags,
Elf_Xword align ) Elf_Xword align )
{ {
BOOST_CHECK_EQUAL( seg->get_type(), type ); EXPECT_EQ( seg->get_type(), type );
BOOST_CHECK_EQUAL( seg->get_virtual_address(), vaddr ); EXPECT_EQ( seg->get_virtual_address(), vaddr );
BOOST_CHECK_EQUAL( seg->get_physical_address(), paddr ); EXPECT_EQ( seg->get_physical_address(), paddr );
BOOST_CHECK_EQUAL( seg->get_file_size(), fsize ); EXPECT_EQ( seg->get_file_size(), fsize );
BOOST_CHECK_EQUAL( seg->get_memory_size(), msize ); EXPECT_EQ( seg->get_memory_size(), msize );
BOOST_CHECK_EQUAL( seg->get_flags(), flags ); EXPECT_EQ( seg->get_flags(), flags );
BOOST_CHECK_EQUAL( seg->get_align(), align ); EXPECT_EQ( seg->get_align(), align );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -139,16 +138,16 @@ void checkSymbol( const symbol_section_accessor& sr,
Elf_Half section; Elf_Half section;
unsigned char other; unsigned char other;
BOOST_REQUIRE_EQUAL( ASSERT_EQ(
sr.get_symbol( index, name, value, size, bind, type, section, other ), sr.get_symbol( index, name, value, size, bind, type, section, other ),
true ); true );
BOOST_CHECK_EQUAL( name, name_ ); EXPECT_EQ( name, name_ );
BOOST_CHECK_EQUAL( value, value_ ); EXPECT_EQ( value, value_ );
BOOST_CHECK_EQUAL( size, size_ ); EXPECT_EQ( size, size_ );
BOOST_CHECK_EQUAL( bind, bind_ ); EXPECT_EQ( bind, bind_ );
BOOST_CHECK_EQUAL( type, type_ ); EXPECT_EQ( type, type_ );
BOOST_CHECK_EQUAL( section, section_ ); EXPECT_EQ( section, section_ );
BOOST_CHECK_EQUAL( other, other_ ); EXPECT_EQ( other, other_ );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -168,15 +167,15 @@ void checkRelocation( const relocation_section_accessor* pRT,
Elf_Sxword addend; Elf_Sxword addend;
Elf_Sxword calcValue; Elf_Sxword calcValue;
BOOST_REQUIRE_EQUAL( pRT->get_entry( index, offset, symbolValue, symbolName, ASSERT_EQ( pRT->get_entry( index, offset, symbolValue, symbolName, type,
type, addend, calcValue ), addend, calcValue ),
true ); true );
BOOST_CHECK_EQUAL( offset, offset_ ); EXPECT_EQ( offset, offset_ );
BOOST_CHECK_EQUAL( symbolValue, symbolValue_ ); EXPECT_EQ( symbolValue, symbolValue_ );
BOOST_CHECK_EQUAL( symbolName, symbolName_ ); EXPECT_EQ( symbolName, symbolName_ );
BOOST_CHECK_EQUAL( type, type_ ); EXPECT_EQ( type, type_ );
BOOST_CHECK_EQUAL( addend, addend_ ); EXPECT_EQ( addend, addend_ );
BOOST_CHECK_EQUAL( calcValue, calcValue_ ); EXPECT_EQ( calcValue, calcValue_ );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -191,18 +190,17 @@ void checkNote( const note_section_accessor& notes,
void* desc; void* desc;
Elf_Word descSize; Elf_Word descSize;
BOOST_REQUIRE_EQUAL( notes.get_note( index, type, name, desc, descSize ), ASSERT_EQ( notes.get_note( index, type, name, desc, descSize ), true );
true ); EXPECT_EQ( type, type_ );
BOOST_CHECK_EQUAL( type, type_ ); EXPECT_EQ( name, name_ );
BOOST_CHECK_EQUAL( name, name_ ); EXPECT_EQ( descSize, descSize_ );
BOOST_CHECK_EQUAL( descSize, descSize_ );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( load32 ) TEST( ELFIOTest, load32 )
{ {
elfio reader; elfio reader;
BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/hello_32" ), true ); ASSERT_EQ( reader.load( "elf_examples/hello_32" ), true );
checkHeader( reader, ELFCLASS32, ELFDATA2LSB, EV_CURRENT, ET_EXEC, EM_386, checkHeader( reader, ELFCLASS32, ELFDATA2LSB, EV_CURRENT, ET_EXEC, EM_386,
1, 0x80482b0, 0, 28, 7, 0, 0 ); 1, 0x80482b0, 0, 28, 7, 0, 0 );
@ -227,7 +225,7 @@ BOOST_AUTO_TEST_CASE( load32 )
checkSection( sec, 27, ".strtab", SHT_STRTAB, 0, 0x0, 0x259, 0, 0, 1, 0 ); checkSection( sec, 27, ".strtab", SHT_STRTAB, 0, 0x0, 0x259, 0, 0, 1, 0 );
const section* sec1 = reader.sections[".strtab"]; const section* sec1 = reader.sections[".strtab"];
BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); EXPECT_EQ( sec->get_index(), sec1->get_index() );
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Check segments // Check segments
@ -248,7 +246,7 @@ BOOST_AUTO_TEST_CASE( load32 )
symbol_section_accessor sr( reader, sec ); symbol_section_accessor sr( reader, sec );
BOOST_CHECK_EQUAL( sr.get_symbols_num(), 68 ); EXPECT_EQ( sr.get_symbols_num(), 68 );
checkSymbol( sr, 0, "", 0x00000000, 0, STB_LOCAL, STT_NOTYPE, STN_UNDEF, checkSymbol( sr, 0, "", 0x00000000, 0, STB_LOCAL, STT_NOTYPE, STN_UNDEF,
ELF_ST_VISIBILITY( STV_DEFAULT ) ); ELF_ST_VISIBILITY( STV_DEFAULT ) );
checkSymbol( sr, 1, "", 0x08048114, 0, STB_LOCAL, STT_SECTION, 1, checkSymbol( sr, 1, "", 0x08048114, 0, STB_LOCAL, STT_SECTION, 1,
@ -267,7 +265,7 @@ BOOST_AUTO_TEST_CASE( load32 )
sec = reader.sections[".rel.dyn"]; sec = reader.sections[".rel.dyn"];
relocation_section_accessor reloc( reader, sec ); relocation_section_accessor reloc( reader, sec );
BOOST_CHECK_EQUAL( reloc.get_entries_num(), 1 ); EXPECT_EQ( reloc.get_entries_num(), 1 );
checkRelocation( &reloc, 0, 0x08049568, 0x0, "__gmon_start__", checkRelocation( &reloc, 0, 0x08049568, 0x0, "__gmon_start__",
R_386_GLOB_DAT, 0, 0 ); R_386_GLOB_DAT, 0, 0 );
@ -275,7 +273,7 @@ BOOST_AUTO_TEST_CASE( load32 )
sec = reader.sections[".rel.plt"]; sec = reader.sections[".rel.plt"];
relocation_section_accessor reloc1( reader, sec ); relocation_section_accessor reloc1( reader, sec );
BOOST_CHECK_EQUAL( reloc1.get_entries_num(), 3 ); EXPECT_EQ( reloc1.get_entries_num(), 3 );
checkRelocation( &reloc1, 0, 0x08049578, 0x0, "__gmon_start__", checkRelocation( &reloc1, 0, 0x08049578, 0x0, "__gmon_start__",
R_X86_64_JUMP_SLOT, 0, 0 ); R_X86_64_JUMP_SLOT, 0, 0 );
@ -289,17 +287,17 @@ BOOST_AUTO_TEST_CASE( load32 )
sec = reader.sections[".note.ABI-tag"]; sec = reader.sections[".note.ABI-tag"];
note_section_accessor notes( reader, sec ); note_section_accessor notes( reader, sec );
BOOST_CHECK_EQUAL( notes.get_notes_num(), 1u ); EXPECT_EQ( notes.get_notes_num(), 1u );
checkNote( notes, 0, 1, std::string( "GNU" ), 16 ); checkNote( notes, 0, 1, std::string( "GNU" ), 16 );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( load64 ) TEST( ELFIOTest, load64 )
{ {
elfio reader; elfio reader;
BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/hello_64" ), true ); ASSERT_EQ( reader.load( "elf_examples/hello_64" ), true );
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Check ELF header // Check ELF header
@ -332,7 +330,7 @@ BOOST_AUTO_TEST_CASE( load64 )
checkSection( sec, 28, ".strtab", SHT_STRTAB, 0, 0x0, 0x23f, 0, 0, 1, 0 ); checkSection( sec, 28, ".strtab", SHT_STRTAB, 0, 0x0, 0x23f, 0, 0, 1, 0 );
const section* sec1 = reader.sections[".strtab"]; const section* sec1 = reader.sections[".strtab"];
BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); EXPECT_EQ( sec->get_index(), sec1->get_index() );
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Check segments // Check segments
@ -354,7 +352,7 @@ BOOST_AUTO_TEST_CASE( load64 )
symbol_section_accessor sr( reader, sec ); symbol_section_accessor sr( reader, sec );
BOOST_CHECK_EQUAL( sr.get_symbols_num(), 67 ); EXPECT_EQ( sr.get_symbols_num(), 67 );
checkSymbol( sr, 0, "", 0x00000000, 0, STB_LOCAL, STT_NOTYPE, STN_UNDEF, checkSymbol( sr, 0, "", 0x00000000, 0, STB_LOCAL, STT_NOTYPE, STN_UNDEF,
ELF_ST_VISIBILITY( STV_DEFAULT ) ); ELF_ST_VISIBILITY( STV_DEFAULT ) );
checkSymbol( sr, 1, "", 0x00400200, 0, STB_LOCAL, STT_SECTION, 1, checkSymbol( sr, 1, "", 0x00400200, 0, STB_LOCAL, STT_SECTION, 1,
@ -375,7 +373,7 @@ BOOST_AUTO_TEST_CASE( load64 )
sec = reader.sections[".rela.dyn"]; sec = reader.sections[".rela.dyn"];
relocation_section_accessor reloc( reader, sec ); relocation_section_accessor reloc( reader, sec );
BOOST_CHECK_EQUAL( reloc.get_entries_num(), 1 ); EXPECT_EQ( reloc.get_entries_num(), 1 );
checkRelocation( &reloc, 0, 0x00600828, 0x0, "__gmon_start__", checkRelocation( &reloc, 0, 0x00600828, 0x0, "__gmon_start__",
R_X86_64_GLOB_DAT, 0, 0 ); R_X86_64_GLOB_DAT, 0, 0 );
@ -383,7 +381,7 @@ BOOST_AUTO_TEST_CASE( load64 )
sec = reader.sections[".rela.plt"]; sec = reader.sections[".rela.plt"];
relocation_section_accessor reloc1( reader, sec ); relocation_section_accessor reloc1( reader, sec );
BOOST_CHECK_EQUAL( reloc1.get_entries_num(), 2 ); EXPECT_EQ( reloc1.get_entries_num(), 2 );
checkRelocation( &reloc1, 0, 0x00600848, 0x0, "puts", R_X86_64_JUMP_SLOT, 0, checkRelocation( &reloc1, 0, 0x00600848, 0x0, "puts", R_X86_64_JUMP_SLOT, 0,
0 ); 0 );
@ -395,17 +393,17 @@ BOOST_AUTO_TEST_CASE( load64 )
sec = reader.sections[".note.ABI-tag"]; sec = reader.sections[".note.ABI-tag"];
note_section_accessor notes( reader, sec ); note_section_accessor notes( reader, sec );
BOOST_CHECK_EQUAL( notes.get_notes_num(), 1u ); EXPECT_EQ( notes.get_notes_num(), 1u );
checkNote( notes, 0, 1, std::string( "GNU" ), 16 ); checkNote( notes, 0, 1, std::string( "GNU" ), 16 );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( hello_64_o ) TEST( ELFIOTest, hello_64_o )
{ {
elfio reader; elfio reader;
BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/hello_64.o" ), true ); ASSERT_EQ( reader.load( "elf_examples/hello_64.o" ), true );
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Check ELF header // Check ELF header
@ -424,13 +422,13 @@ BOOST_AUTO_TEST_CASE( hello_64_o )
0x15, 0, 0, 4, 0 ); 0x15, 0, 0, 4, 0 );
section* sec1 = reader.sections[".text"]; section* sec1 = reader.sections[".text"];
BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); EXPECT_EQ( sec->get_index(), sec1->get_index() );
sec = reader.sections[12]; sec = reader.sections[12];
checkSection( sec, 12, ".strtab", SHT_STRTAB, 0, 0x0, 0x13, 0, 0, 1, 0 ); checkSection( sec, 12, ".strtab", SHT_STRTAB, 0, 0x0, 0x13, 0, 0, 1, 0 );
sec1 = reader.sections[".strtab"]; sec1 = reader.sections[".strtab"];
BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); EXPECT_EQ( sec->get_index(), sec1->get_index() );
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Check symbol table // Check symbol table
@ -438,7 +436,7 @@ BOOST_AUTO_TEST_CASE( hello_64_o )
symbol_section_accessor sr( reader, sec ); symbol_section_accessor sr( reader, sec );
BOOST_CHECK_EQUAL( sr.get_symbols_num(), 11 ); EXPECT_EQ( sr.get_symbols_num(), 11 );
checkSymbol( sr, 9, "main", 0x00000000, 21, STB_GLOBAL, STT_FUNC, 1, checkSymbol( sr, 9, "main", 0x00000000, 21, STB_GLOBAL, STT_FUNC, 1,
ELF_ST_VISIBILITY( STV_DEFAULT ) ); ELF_ST_VISIBILITY( STV_DEFAULT ) );
@ -447,7 +445,7 @@ BOOST_AUTO_TEST_CASE( hello_64_o )
sec = reader.sections[".rela.text"]; sec = reader.sections[".rela.text"];
relocation_section_accessor reloc( reader, sec ); relocation_section_accessor reloc( reader, sec );
BOOST_CHECK_EQUAL( reloc.get_entries_num(), 2 ); EXPECT_EQ( reloc.get_entries_num(), 2 );
checkRelocation( &reloc, 0, 0x00000005, 0x0, "", R_X86_64_32, 0, 0 ); checkRelocation( &reloc, 0, 0x00000005, 0x0, "", R_X86_64_32, 0, 0 );
checkRelocation( &reloc, 1, 0x0000000A, 0x0, "puts", R_X86_64_PC32, checkRelocation( &reloc, 1, 0x0000000A, 0x0, "puts", R_X86_64_PC32,
@ -456,17 +454,17 @@ BOOST_AUTO_TEST_CASE( hello_64_o )
sec = reader.sections[".rela.eh_frame"]; sec = reader.sections[".rela.eh_frame"];
relocation_section_accessor reloc1( reader, sec ); relocation_section_accessor reloc1( reader, sec );
BOOST_CHECK_EQUAL( reloc1.get_entries_num(), 1 ); EXPECT_EQ( reloc1.get_entries_num(), 1 );
checkRelocation( &reloc1, 0, 0x00000020, 0x0, "", R_X86_64_32, 0, 0 ); checkRelocation( &reloc1, 0, 0x00000020, 0x0, "", R_X86_64_32, 0, 0 );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( hello_32_o ) TEST( ELFIOTest, hello_32_o )
{ {
elfio reader; elfio reader;
BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/hello_32.o" ), true ); ASSERT_EQ( reader.load( "elf_examples/hello_32.o" ), true );
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Check ELF header // Check ELF header
@ -485,14 +483,14 @@ BOOST_AUTO_TEST_CASE( hello_32_o )
0x2b, 0, 0, 4, 0 ); 0x2b, 0, 0, 4, 0 );
section* sec1 = reader.sections[".text"]; section* sec1 = reader.sections[".text"];
BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); EXPECT_EQ( sec->get_index(), sec1->get_index() );
sec = reader.sections[10]; sec = reader.sections[10];
checkSection( sec, 10, ".strtab", SHT_STRTAB, 0, 0x0, 0x13, 0, 0, 1, 0 ); checkSection( sec, 10, ".strtab", SHT_STRTAB, 0, 0x0, 0x13, 0, 0, 1, 0 );
sec1 = reader.sections[".strtab"]; sec1 = reader.sections[".strtab"];
BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); EXPECT_EQ( sec->get_index(), sec1->get_index() );
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Check symbol table // Check symbol table
@ -500,7 +498,7 @@ BOOST_AUTO_TEST_CASE( hello_32_o )
symbol_section_accessor sr( reader, sec ); symbol_section_accessor sr( reader, sec );
BOOST_CHECK_EQUAL( sr.get_symbols_num(), 10 ); EXPECT_EQ( sr.get_symbols_num(), 10 );
checkSymbol( sr, 8, "main", 0x00000000, 43, STB_GLOBAL, STT_FUNC, 1, checkSymbol( sr, 8, "main", 0x00000000, 43, STB_GLOBAL, STT_FUNC, 1,
ELF_ST_VISIBILITY( STV_DEFAULT ) ); ELF_ST_VISIBILITY( STV_DEFAULT ) );
@ -509,18 +507,18 @@ BOOST_AUTO_TEST_CASE( hello_32_o )
sec = reader.sections[".rel.text"]; sec = reader.sections[".rel.text"];
relocation_section_accessor reloc( reader, sec ); relocation_section_accessor reloc( reader, sec );
BOOST_CHECK_EQUAL( reloc.get_entries_num(), 2 ); EXPECT_EQ( reloc.get_entries_num(), 2 );
checkRelocation( &reloc, 0, 0x00000014, 0x0, "", R_386_32, 0, 0 ); checkRelocation( &reloc, 0, 0x00000014, 0x0, "", R_386_32, 0, 0 );
checkRelocation( &reloc, 1, 0x00000019, 0x0, "puts", R_386_PC32, 0x0, -25 ); checkRelocation( &reloc, 1, 0x00000019, 0x0, "puts", R_386_PC32, 0x0, -25 );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( test_ppc_o ) TEST( ELFIOTest, test_ppc_o )
{ {
elfio reader; elfio reader;
BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/test_ppc.o" ), true ); ASSERT_EQ( reader.load( "elf_examples/test_ppc.o" ), true );
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Check ELF header // Check ELF header
@ -539,14 +537,14 @@ BOOST_AUTO_TEST_CASE( test_ppc_o )
0x118, 0, 0, 4, 0 ); 0x118, 0, 0, 4, 0 );
section* sec1 = reader.sections[".text"]; section* sec1 = reader.sections[".text"];
BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); EXPECT_EQ( sec->get_index(), sec1->get_index() );
sec = reader.sections[15]; sec = reader.sections[15];
checkSection( sec, 15, ".strtab", SHT_STRTAB, 0, 0x0, 0x14f, 0, 0, 1, 0 ); checkSection( sec, 15, ".strtab", SHT_STRTAB, 0, 0x0, 0x14f, 0, 0, 1, 0 );
sec1 = reader.sections[".strtab"]; sec1 = reader.sections[".strtab"];
BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); EXPECT_EQ( sec->get_index(), sec1->get_index() );
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Check symbol table // Check symbol table
@ -554,7 +552,7 @@ BOOST_AUTO_TEST_CASE( test_ppc_o )
symbol_section_accessor sr( reader, sec ); symbol_section_accessor sr( reader, sec );
BOOST_CHECK_EQUAL( sr.get_symbols_num(), 24 ); EXPECT_EQ( sr.get_symbols_num(), 24 );
checkSymbol( sr, 14, "main", 0x00000000, 92, STB_GLOBAL, STT_FUNC, 1, checkSymbol( sr, 14, "main", 0x00000000, 92, STB_GLOBAL, STT_FUNC, 1,
ELF_ST_VISIBILITY( STV_DEFAULT ) ); ELF_ST_VISIBILITY( STV_DEFAULT ) );
checkSymbol( sr, 8, "_GLOBAL__I_main", 0x000000DC, 60, STB_LOCAL, STT_FUNC, checkSymbol( sr, 8, "_GLOBAL__I_main", 0x000000DC, 60, STB_LOCAL, STT_FUNC,
@ -565,7 +563,7 @@ BOOST_AUTO_TEST_CASE( test_ppc_o )
sec = reader.sections[".rela.text"]; sec = reader.sections[".rela.text"];
relocation_section_accessor reloc( reader, sec ); relocation_section_accessor reloc( reader, sec );
BOOST_CHECK_EQUAL( reloc.get_entries_num(), 18 ); EXPECT_EQ( reloc.get_entries_num(), 18 );
checkRelocation( &reloc, 0, 0x00000016, 0x0, "_ZSt4cout", 6, 0, 0 ); checkRelocation( &reloc, 0, 0x00000016, 0x0, "_ZSt4cout", 6, 0, 0 );
checkRelocation( &reloc, 1, 0x0000001a, 0x0, "_ZSt4cout", 4, 0x0, 0 ); checkRelocation( &reloc, 1, 0x0000001a, 0x0, "_ZSt4cout", 4, 0x0, 0 );
@ -574,24 +572,24 @@ BOOST_AUTO_TEST_CASE( test_ppc_o )
sec = reader.sections[".rela.ctors"]; sec = reader.sections[".rela.ctors"];
relocation_section_accessor reloc1( reader, sec ); relocation_section_accessor reloc1( reader, sec );
BOOST_CHECK_EQUAL( reloc1.get_entries_num(), 1 ); EXPECT_EQ( reloc1.get_entries_num(), 1 );
checkRelocation( &reloc1, 0, 0x00000000, 0x0, "", 1, 0xDC, 0xDC ); checkRelocation( &reloc1, 0, 0x00000000, 0x0, "", 1, 0xDC, 0xDC );
sec = reader.sections[".rela.eh_frame"]; sec = reader.sections[".rela.eh_frame"];
relocation_section_accessor reloc2( reader, sec ); relocation_section_accessor reloc2( reader, sec );
BOOST_CHECK_EQUAL( reloc2.get_entries_num(), 3 ); EXPECT_EQ( reloc2.get_entries_num(), 3 );
checkRelocation( &reloc2, 1, 0x00000020, 0x0, "", 1, 0x0, 0x0 ); checkRelocation( &reloc2, 1, 0x00000020, 0x0, "", 1, 0x0, 0x0 );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( test_ppc ) TEST( ELFIOTest, test_ppc )
{ {
elfio reader; elfio reader;
BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/test_ppc" ), true ); ASSERT_EQ( reader.load( "elf_examples/test_ppc" ), true );
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Check ELF header // Check ELF header
@ -624,7 +622,7 @@ BOOST_AUTO_TEST_CASE( test_ppc )
checkSection( sec, 28, ".shstrtab", SHT_STRTAB, 0, 0x0, 0x101, 0, 0, 1, 0 ); checkSection( sec, 28, ".shstrtab", SHT_STRTAB, 0, 0x0, 0x101, 0, 0, 1, 0 );
const section* sec1 = reader.sections[".shstrtab"]; const section* sec1 = reader.sections[".shstrtab"];
BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); EXPECT_EQ( sec->get_index(), sec1->get_index() );
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Check segments // Check segments
@ -645,7 +643,7 @@ BOOST_AUTO_TEST_CASE( test_ppc )
symbol_section_accessor sr( reader, sec ); symbol_section_accessor sr( reader, sec );
BOOST_CHECK_EQUAL( sr.get_symbols_num(), 80 ); EXPECT_EQ( sr.get_symbols_num(), 80 );
checkSymbol( sr, 0, "", 0x00000000, 0, STB_LOCAL, STT_NOTYPE, STN_UNDEF, checkSymbol( sr, 0, "", 0x00000000, 0, STB_LOCAL, STT_NOTYPE, STN_UNDEF,
ELF_ST_VISIBILITY( STV_DEFAULT ) ); ELF_ST_VISIBILITY( STV_DEFAULT ) );
checkSymbol( sr, 1, "", 0x10000134, 0, STB_LOCAL, STT_SECTION, 1, checkSymbol( sr, 1, "", 0x10000134, 0, STB_LOCAL, STT_SECTION, 1,
@ -667,14 +665,14 @@ BOOST_AUTO_TEST_CASE( test_ppc )
sec = reader.sections[".rela.dyn"]; sec = reader.sections[".rela.dyn"];
relocation_section_accessor reloc( reader, sec ); relocation_section_accessor reloc( reader, sec );
BOOST_CHECK_EQUAL( reloc.get_entries_num(), 2 ); EXPECT_EQ( reloc.get_entries_num(), 2 );
checkRelocation( &reloc, 1, 0x10010c0c, 0x10010c0c, "_ZSt4cout", 19, 0, 0 ); checkRelocation( &reloc, 1, 0x10010c0c, 0x10010c0c, "_ZSt4cout", 19, 0, 0 );
sec = reader.sections[".rela.plt"]; sec = reader.sections[".rela.plt"];
relocation_section_accessor reloc1( reader, sec ); relocation_section_accessor reloc1( reader, sec );
BOOST_CHECK_EQUAL( reloc1.get_entries_num(), 9 ); EXPECT_EQ( reloc1.get_entries_num(), 9 );
checkRelocation( &reloc1, 0, 0x10010be4, 0x100008e0, "__cxa_atexit", 21, 0, checkRelocation( &reloc1, 0, 0x10010be4, 0x100008e0, "__cxa_atexit", 21, 0,
0 ); 0 );
@ -685,13 +683,13 @@ BOOST_AUTO_TEST_CASE( test_ppc )
sec = reader.sections[".note.ABI-tag"]; sec = reader.sections[".note.ABI-tag"];
note_section_accessor notes( reader, sec ); note_section_accessor notes( reader, sec );
BOOST_CHECK_EQUAL( notes.get_notes_num(), 1u ); EXPECT_EQ( notes.get_notes_num(), 1u );
checkNote( notes, 0, 1, std::string( "GNU" ), 16 ); checkNote( notes, 0, 1, std::string( "GNU" ), 16 );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( test_dummy_out_i386_32 ) TEST( ELFIOTest, test_dummy_out_i386_32 )
{ {
elfio writer; elfio writer;
@ -714,14 +712,14 @@ BOOST_AUTO_TEST_CASE( test_dummy_out_i386_32 )
note_section_accessor note_writer( writer, note_sec ); note_section_accessor note_writer( writer, note_sec );
char descr[6] = { 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 }; char descr[6] = { 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
note_writer.add_note( 0x77, "Hello", &descr, 6 ); note_writer.add_note( 0x77, "Hello", &descr, 6 );
BOOST_CHECK_EQUAL( note_sec->get_index(), 2 ); EXPECT_EQ( note_sec->get_index(), 2 );
// Create ELF file // Create ELF file
writer.save( "elf_examples/elf_dummy_header_i386_32.elf" ); writer.save( "elf_examples/elf_dummy_header_i386_32.elf" );
elfio reader; elfio reader;
BOOST_REQUIRE_EQUAL( ASSERT_EQ( reader.load( "elf_examples/elf_dummy_header_i386_32.elf" ),
reader.load( "elf_examples/elf_dummy_header_i386_32.elf" ), true ); true );
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Check ELF header // Check ELF header
@ -739,12 +737,12 @@ BOOST_AUTO_TEST_CASE( test_dummy_out_i386_32 )
sec = reader.sections[".note"]; sec = reader.sections[".note"];
BOOST_CHECK_EQUAL( sec->get_index(), 2 ); EXPECT_EQ( sec->get_index(), 2 );
checkSection( sec, 2, ".note", SHT_NOTE, SHF_ALLOC, 0, 28, 0, 0, 4, 0 ); checkSection( sec, 2, ".note", SHT_NOTE, SHF_ALLOC, 0, 28, 0, 0, 4, 0 );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( test_dummy_out_ppc_32 ) TEST( ELFIOTest, test_dummy_out_ppc_32 )
{ {
elfio writer; elfio writer;
@ -767,14 +765,14 @@ BOOST_AUTO_TEST_CASE( test_dummy_out_ppc_32 )
note_section_accessor note_writer( writer, note_sec ); note_section_accessor note_writer( writer, note_sec );
char descr[6] = { 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 }; char descr[6] = { 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
note_writer.add_note( 0x77, "Hello", &descr, 6 ); note_writer.add_note( 0x77, "Hello", &descr, 6 );
BOOST_CHECK_EQUAL( note_sec->get_index(), 2 ); EXPECT_EQ( note_sec->get_index(), 2 );
// Create ELF file // Create ELF file
writer.save( "elf_examples/elf_dummy_header_ppc_32.elf" ); writer.save( "elf_examples/elf_dummy_header_ppc_32.elf" );
elfio reader; elfio reader;
BOOST_REQUIRE_EQUAL( ASSERT_EQ( reader.load( "elf_examples/elf_dummy_header_ppc_32.elf" ),
reader.load( "elf_examples/elf_dummy_header_ppc_32.elf" ), true ); true );
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Check ELF header // Check ELF header
@ -788,7 +786,7 @@ BOOST_AUTO_TEST_CASE( test_dummy_out_ppc_32 )
sec = reader.sections[".note"]; sec = reader.sections[".note"];
BOOST_CHECK_EQUAL( sec->get_index(), 2 ); EXPECT_EQ( sec->get_index(), 2 );
checkSection( sec, 2, ".note", SHT_NOTE, SHF_ALLOC, 0, 28, 0, 0, 4, 0 ); checkSection( sec, 2, ".note", SHT_NOTE, SHF_ALLOC, 0, 28, 0, 0, 4, 0 );
sec = reader.sections[".shstrtab"]; sec = reader.sections[".shstrtab"];
@ -797,7 +795,7 @@ BOOST_AUTO_TEST_CASE( test_dummy_out_ppc_32 )
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( test_dummy_out_i386_64 ) TEST( ELFIOTest, test_dummy_out_i386_64 )
{ {
elfio writer; elfio writer;
@ -820,14 +818,14 @@ BOOST_AUTO_TEST_CASE( test_dummy_out_i386_64 )
note_section_accessor note_writer( writer, note_sec ); note_section_accessor note_writer( writer, note_sec );
char descr[6] = { 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 }; char descr[6] = { 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
note_writer.add_note( 0x77, "Hello", &descr, 6 ); note_writer.add_note( 0x77, "Hello", &descr, 6 );
BOOST_CHECK_EQUAL( note_sec->get_index(), 2 ); EXPECT_EQ( note_sec->get_index(), 2 );
// Create ELF file // Create ELF file
writer.save( "elf_examples/elf_dummy_header_i386_64.elf" ); writer.save( "elf_examples/elf_dummy_header_i386_64.elf" );
elfio reader; elfio reader;
BOOST_REQUIRE_EQUAL( ASSERT_EQ( reader.load( "elf_examples/elf_dummy_header_i386_64.elf" ),
reader.load( "elf_examples/elf_dummy_header_i386_64.elf" ), true ); true );
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Check ELF header // Check ELF header
@ -841,7 +839,7 @@ BOOST_AUTO_TEST_CASE( test_dummy_out_i386_64 )
sec = reader.sections[".note"]; sec = reader.sections[".note"];
BOOST_CHECK_EQUAL( sec->get_index(), 2 ); EXPECT_EQ( sec->get_index(), 2 );
checkSection( sec, 2, ".note", SHT_NOTE, SHF_ALLOC, 0, 28, 0, 0, 4, 0 ); checkSection( sec, 2, ".note", SHT_NOTE, SHF_ALLOC, 0, 28, 0, 0, 4, 0 );
sec = reader.sections[".shstrtab"]; sec = reader.sections[".shstrtab"];
@ -850,7 +848,7 @@ BOOST_AUTO_TEST_CASE( test_dummy_out_i386_64 )
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( test_dummy_out_ppc_64 ) TEST( ELFIOTest, test_dummy_out_ppc_64 )
{ {
elfio writer; elfio writer;
@ -873,14 +871,14 @@ BOOST_AUTO_TEST_CASE( test_dummy_out_ppc_64 )
note_section_accessor note_writer( writer, note_sec ); note_section_accessor note_writer( writer, note_sec );
char descr[6] = { 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 }; char descr[6] = { 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
note_writer.add_note( 0x77, "Hello", &descr, 6 ); note_writer.add_note( 0x77, "Hello", &descr, 6 );
BOOST_CHECK_EQUAL( note_sec->get_index(), 2 ); EXPECT_EQ( note_sec->get_index(), 2 );
// Create ELF file // Create ELF file
writer.save( "elf_examples/elf_dummy_header_ppc_64.elf" ); writer.save( "elf_examples/elf_dummy_header_ppc_64.elf" );
elfio reader; elfio reader;
BOOST_REQUIRE_EQUAL( ASSERT_EQ( reader.load( "elf_examples/elf_dummy_header_ppc_64.elf" ),
reader.load( "elf_examples/elf_dummy_header_ppc_64.elf" ), true ); true );
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Check ELF header // Check ELF header
@ -898,87 +896,87 @@ BOOST_AUTO_TEST_CASE( test_dummy_out_ppc_64 )
sec = reader.sections[".note"]; sec = reader.sections[".note"];
BOOST_CHECK_EQUAL( sec->get_index(), 2 ); EXPECT_EQ( sec->get_index(), 2 );
checkSection( sec, 2, ".note", SHT_NOTE, SHF_ALLOC, 0, 28, 0, 0, 4, 0 ); checkSection( sec, 2, ".note", SHT_NOTE, SHF_ALLOC, 0, 28, 0, 0, 4, 0 );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( test_dynamic_64_1 ) TEST( ELFIOTest, test_dynamic_64_1 )
{ {
elfio reader; elfio reader;
BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/main" ), true ); ASSERT_EQ( reader.load( "elf_examples/main" ), true );
section* dynsec = reader.sections[".dynamic"]; section* dynsec = reader.sections[".dynamic"];
BOOST_REQUIRE( dynsec != NULL ); ASSERT_TRUE( dynsec != NULL );
dynamic_section_accessor da( reader, dynsec ); dynamic_section_accessor da( reader, dynsec );
BOOST_CHECK_EQUAL( da.get_entries_num(), 21 ); EXPECT_EQ( da.get_entries_num(), 21 );
Elf_Xword tag; Elf_Xword tag;
Elf_Xword value; Elf_Xword value;
std::string str; std::string str;
da.get_entry( 0, tag, value, str ); da.get_entry( 0, tag, value, str );
BOOST_CHECK_EQUAL( tag, DT_NEEDED ); EXPECT_EQ( tag, DT_NEEDED );
BOOST_CHECK_EQUAL( str, "libfunc.so" ); EXPECT_EQ( str, "libfunc.so" );
da.get_entry( 1, tag, value, str ); da.get_entry( 1, tag, value, str );
BOOST_CHECK_EQUAL( tag, DT_NEEDED ); EXPECT_EQ( tag, DT_NEEDED );
BOOST_CHECK_EQUAL( str, "libc.so.6" ); EXPECT_EQ( str, "libc.so.6" );
da.get_entry( 2, tag, value, str ); da.get_entry( 2, tag, value, str );
BOOST_CHECK_EQUAL( tag, DT_INIT ); EXPECT_EQ( tag, DT_INIT );
BOOST_CHECK_EQUAL( value, 0x400530 ); EXPECT_EQ( value, 0x400530 );
da.get_entry( 19, tag, value, str ); da.get_entry( 19, tag, value, str );
BOOST_CHECK_EQUAL( tag, 0x6ffffff0 ); EXPECT_EQ( tag, 0x6ffffff0 );
BOOST_CHECK_EQUAL( value, 0x40047e ); EXPECT_EQ( value, 0x40047e );
da.get_entry( 20, tag, value, str ); da.get_entry( 20, tag, value, str );
BOOST_CHECK_EQUAL( tag, DT_NULL ); EXPECT_EQ( tag, DT_NULL );
BOOST_CHECK_EQUAL( value, 0 ); EXPECT_EQ( value, 0 );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( test_dynamic_64_2 ) TEST( ELFIOTest, test_dynamic_64_2 )
{ {
elfio reader; elfio reader;
BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/libfunc.so" ), true ); ASSERT_EQ( reader.load( "elf_examples/libfunc.so" ), true );
section* dynsec = reader.sections[".dynamic"]; section* dynsec = reader.sections[".dynamic"];
BOOST_REQUIRE( dynsec != NULL ); ASSERT_TRUE( dynsec != NULL );
dynamic_section_accessor da( reader, dynsec ); dynamic_section_accessor da( reader, dynsec );
BOOST_CHECK_EQUAL( da.get_entries_num(), 20 ); EXPECT_EQ( da.get_entries_num(), 20 );
Elf_Xword tag; Elf_Xword tag;
Elf_Xword value; Elf_Xword value;
std::string str; std::string str;
da.get_entry( 0, tag, value, str ); da.get_entry( 0, tag, value, str );
BOOST_CHECK_EQUAL( tag, DT_NEEDED ); EXPECT_EQ( tag, DT_NEEDED );
BOOST_CHECK_EQUAL( str, "libc.so.6" ); EXPECT_EQ( str, "libc.so.6" );
da.get_entry( 1, tag, value, str ); da.get_entry( 1, tag, value, str );
BOOST_CHECK_EQUAL( tag, DT_INIT ); EXPECT_EQ( tag, DT_INIT );
BOOST_CHECK_EQUAL( value, 0x480 ); EXPECT_EQ( value, 0x480 );
da.get_entry( 18, tag, value, str ); da.get_entry( 18, tag, value, str );
BOOST_CHECK_EQUAL( tag, 0x6ffffff9 ); EXPECT_EQ( tag, 0x6ffffff9 );
BOOST_CHECK_EQUAL( value, 1 ); EXPECT_EQ( value, 1 );
da.get_entry( 19, tag, value, str ); da.get_entry( 19, tag, value, str );
BOOST_CHECK_EQUAL( tag, DT_NULL ); EXPECT_EQ( tag, DT_NULL );
BOOST_CHECK_EQUAL( value, 0 ); EXPECT_EQ( value, 0 );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( test_dynamic_64_3 ) TEST( ELFIOTest, test_dynamic_64_3 )
{ {
elfio reader; elfio reader;
BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/main" ), true ); ASSERT_EQ( reader.load( "elf_examples/main" ), true );
section* dynsec = reader.sections[".dynamic"]; section* dynsec = reader.sections[".dynamic"];
BOOST_REQUIRE( dynsec != NULL ); ASSERT_TRUE( dynsec != NULL );
dynamic_section_accessor da( reader, dynsec ); dynamic_section_accessor da( reader, dynsec );
BOOST_CHECK_EQUAL( da.get_entries_num(), 21 ); EXPECT_EQ( da.get_entries_num(), 21 );
section* strsec1 = reader.sections.add( ".dynstr" ); section* strsec1 = reader.sections.add( ".dynstr" );
strsec1->set_type( SHT_STRTAB ); strsec1->set_type( SHT_STRTAB );
@ -1009,13 +1007,13 @@ BOOST_AUTO_TEST_CASE( test_dynamic_64_3 )
da.get_entry( i, tag, value, str ); da.get_entry( i, tag, value, str );
da1.get_entry( i, tag1, value1, str1 ); da1.get_entry( i, tag1, value1, str1 );
BOOST_CHECK_EQUAL( tag, tag1 ); EXPECT_EQ( tag, tag1 );
if ( tag == DT_NEEDED || tag == DT_SONAME || tag == DT_RPATH || if ( tag == DT_NEEDED || tag == DT_SONAME || tag == DT_RPATH ||
tag == DT_RUNPATH ) { tag == DT_RUNPATH ) {
BOOST_CHECK_EQUAL( str, str1 ); EXPECT_EQ( str, str1 );
} }
else { else {
BOOST_CHECK_EQUAL( value, value1 ); EXPECT_EQ( value, value1 );
} }
} }
} }

View File

@ -25,10 +25,7 @@ THE SOFTWARE.
#define ELFIO_NO_INTTYPES #define ELFIO_NO_INTTYPES
#endif #endif
#include <boost/test/unit_test.hpp> #include <gtest/gtest.h>
#include <boost/test/tools/output_test_stream.hpp>
using boost::test_tools::output_test_stream;
#include <elfio/elfio.hpp> #include <elfio/elfio.hpp>
using namespace ELFIO; using namespace ELFIO;
@ -212,47 +209,47 @@ bool write_exe_i386( const std::string& filename,
return true; return true;
} }
/*
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void checkObjestsAreEqual( std::string file_name1, std::string file_name2 ) void checkObjestsAreEqual( std::string file_name1, std::string file_name2 )
{ {
elfio file1; elfio file1;
elfio file2; elfio file2;
BOOST_REQUIRE_EQUAL( file1.load( file_name1 ), true ); ASSERT_EQ( file1.load( file_name1 ), true );
BOOST_CHECK_EQUAL( file1.save( file_name2 ), true ); EXPECT_EQ( file1.save( file_name2 ), true );
BOOST_REQUIRE_EQUAL( file1.load( file_name1 ), true ); ASSERT_EQ( file1.load( file_name1 ), true );
BOOST_REQUIRE_EQUAL( file2.load( file_name2 ), true ); ASSERT_EQ( file2.load( file_name2 ), true );
for ( int i = 0; i < file1.sections.size(); ++i ) { for ( int i = 0; i < file1.sections.size(); ++i ) {
BOOST_CHECK_EQUAL( file1.sections[i]->get_address(), EXPECT_EQ( file1.sections[i]->get_address(),
file2.sections[i]->get_address() ); file2.sections[i]->get_address() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_addr_align(), EXPECT_EQ( file1.sections[i]->get_addr_align(),
file2.sections[i]->get_addr_align() ); file2.sections[i]->get_addr_align() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_entry_size(), EXPECT_EQ( file1.sections[i]->get_entry_size(),
file2.sections[i]->get_entry_size() ); file2.sections[i]->get_entry_size() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_flags(), EXPECT_EQ( file1.sections[i]->get_flags(),
file2.sections[i]->get_flags() ); file2.sections[i]->get_flags() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_index(), EXPECT_EQ( file1.sections[i]->get_index(),
file2.sections[i]->get_index() ); file2.sections[i]->get_index() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_info(), EXPECT_EQ( file1.sections[i]->get_info(),
file2.sections[i]->get_info() ); file2.sections[i]->get_info() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_link(), EXPECT_EQ( file1.sections[i]->get_link(),
file2.sections[i]->get_link() ); file2.sections[i]->get_link() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_name(), EXPECT_EQ( file1.sections[i]->get_name(),
file2.sections[i]->get_name() ); file2.sections[i]->get_name() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_name_string_offset(), EXPECT_EQ( file1.sections[i]->get_name_string_offset(),
file2.sections[i]->get_name_string_offset() ); file2.sections[i]->get_name_string_offset() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_size(), EXPECT_EQ( file1.sections[i]->get_size(),
file2.sections[i]->get_size() ); file2.sections[i]->get_size() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_type(), EXPECT_EQ( file1.sections[i]->get_type(),
file2.sections[i]->get_type() ); file2.sections[i]->get_type() );
if ( file1.sections[i]->get_type() == SHT_NULL || if ( file1.sections[i]->get_type() == SHT_NULL ||
file1.sections[i]->get_type() == SHT_NOBITS ) { file1.sections[i]->get_type() == SHT_NOBITS ) {
continue; continue;
} }
BOOST_REQUIRE_NE( file1.sections[i]->get_data(), (const char*)0 ); ASSERT_NE( file1.sections[i]->get_data(), (const char*)0 );
BOOST_REQUIRE_NE( file2.sections[i]->get_data(), (const char*)0 ); ASSERT_NE( file2.sections[i]->get_data(), (const char*)0 );
std::string pdata1( file1.sections[i]->get_data(), std::string pdata1( file1.sections[i]->get_data(),
file1.sections[i]->get_data() + file1.sections[i]->get_data() +
file1.sections[i]->get_size() ); file1.sections[i]->get_size() );
@ -260,12 +257,12 @@ void checkObjestsAreEqual( std::string file_name1, std::string file_name2 )
file2.sections[i]->get_data() + file2.sections[i]->get_data() +
file2.sections[i]->get_size() ); file2.sections[i]->get_size() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_size(), EXPECT_EQ( file1.sections[i]->get_size(),
file2.sections[i]->get_size() ); file2.sections[i]->get_size() );
if ( ( file2.sections[i]->get_type() != SHT_NULL ) && if ( ( file2.sections[i]->get_type() != SHT_NULL ) &&
( file2.sections[i]->get_type() != SHT_NOBITS ) ) { ( file2.sections[i]->get_type() != SHT_NOBITS ) ) {
BOOST_CHECK_EQUAL_COLLECTIONS( pdata1.begin(), pdata1.end(), EXPECT_EQ_COLLECTIONS( pdata1.begin(), pdata1.end(), pdata2.begin(),
pdata2.begin(), pdata2.end() ); pdata2.end() );
} }
} }
} }
@ -280,27 +277,27 @@ void checkExeAreEqual( std::string file_name1,
elfio file1; elfio file1;
elfio file2; elfio file2;
BOOST_REQUIRE_EQUAL( file1.load( file_name1 ), true ); ASSERT_EQ( file1.load( file_name1 ), true );
BOOST_REQUIRE_EQUAL( file2.load( file_name2 ), true ); ASSERT_EQ( file2.load( file_name2 ), true );
for ( int i = 0; i < file1.segments.size(); ++i ) { for ( int i = 0; i < file1.segments.size(); ++i ) {
if ( !( skipTests & SEG_ALIGN ) ) if ( !( skipTests & SEG_ALIGN ) )
BOOST_CHECK_EQUAL( file1.segments[i]->get_align(), EXPECT_EQ( file1.segments[i]->get_align(),
file2.segments[i]->get_align() ); file2.segments[i]->get_align() );
BOOST_CHECK_EQUAL( file1.segments[i]->get_file_size(), EXPECT_EQ( file1.segments[i]->get_file_size(),
file2.segments[i]->get_file_size() ); file2.segments[i]->get_file_size() );
BOOST_CHECK_EQUAL( file1.segments[i]->get_memory_size(), EXPECT_EQ( file1.segments[i]->get_memory_size(),
file2.segments[i]->get_memory_size() ); file2.segments[i]->get_memory_size() );
BOOST_CHECK_EQUAL( file1.segments[i]->get_type(), EXPECT_EQ( file1.segments[i]->get_type(),
file2.segments[i]->get_type() ); file2.segments[i]->get_type() );
// skip data comparisons of the program header and of empty segments // skip data comparisons of the program header and of empty segments
if ( file1.segments[i]->get_type() == PT_PHDR || if ( file1.segments[i]->get_type() == PT_PHDR ||
!file1.segments[i]->get_file_size() ) !file1.segments[i]->get_file_size() )
continue; continue;
BOOST_REQUIRE_NE( file1.segments[i]->get_data(), (const char*)0 ); ASSERT_NE( file1.segments[i]->get_data(), (const char*)0 );
BOOST_REQUIRE_NE( file2.segments[i]->get_data(), (const char*)0 ); ASSERT_NE( file2.segments[i]->get_data(), (const char*)0 );
std::string pdata1( file1.segments[i]->get_data(), std::string pdata1( file1.segments[i]->get_data(),
file1.segments[i]->get_data() + file1.segments[i]->get_data() +
@ -319,15 +316,15 @@ void checkExeAreEqual( std::string file_name1,
pdata2 = pdata2.substr( (unsigned int)afterPHDR ); pdata2 = pdata2.substr( (unsigned int)afterPHDR );
} }
BOOST_CHECK_EQUAL_COLLECTIONS( pdata1.begin(), pdata1.end(), EXPECT_EQ_COLLECTIONS( pdata1.begin(), pdata1.end(), pdata2.begin(),
pdata2.begin(), pdata2.end() ); pdata2.end() );
} }
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( write_obj_i386_32 ) TEST( ELFIOTest, write_obj_i386_32 )
{ {
BOOST_CHECK_EQUAL( true, write_obj_i386( false ) ); EXPECT_EQ( true, write_obj_i386( false ) );
output_test_stream output( "elf_examples/write_obj_i386_32_match.o", true, output_test_stream output( "elf_examples/write_obj_i386_32_match.o", true,
false ); false );
std::ifstream input( "elf_examples/write_obj_i386_32.o", std::ios::binary ); std::ifstream input( "elf_examples/write_obj_i386_32.o", std::ios::binary );
@ -336,9 +333,9 @@ BOOST_AUTO_TEST_CASE( write_obj_i386_32 )
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( write_obj_i386_64 ) TEST( ELFIOTest, write_obj_i386_64 )
{ {
BOOST_CHECK_EQUAL( true, write_obj_i386( true ) ); EXPECT_EQ( true, write_obj_i386( true ) );
output_test_stream output( "elf_examples/write_obj_i386_64_match.o", true, output_test_stream output( "elf_examples/write_obj_i386_64_match.o", true,
false ); false );
std::ifstream input( "elf_examples/write_obj_i386_64.o", std::ios::binary ); std::ifstream input( "elf_examples/write_obj_i386_64.o", std::ios::binary );
@ -347,11 +344,11 @@ BOOST_AUTO_TEST_CASE( write_obj_i386_64 )
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( write_exe_i386_32 ) TEST( ELFIOTest, write_exe_i386_32 )
{ {
const std::string generated_file( "elf_examples/write_exe_i386_32" ); const std::string generated_file( "elf_examples/write_exe_i386_32" );
const std::string reference_file( "elf_examples/write_exe_i386_32_match" ); const std::string reference_file( "elf_examples/write_exe_i386_32_match" );
BOOST_CHECK_EQUAL( true, write_exe_i386( generated_file, false ) ); EXPECT_EQ( true, write_exe_i386( generated_file, false ) );
output_test_stream output( reference_file, true, false ); output_test_stream output( reference_file, true, false );
std::ifstream input( generated_file, std::ios::binary ); std::ifstream input( generated_file, std::ios::binary );
output << input.rdbuf(); output << input.rdbuf();
@ -360,7 +357,7 @@ BOOST_AUTO_TEST_CASE( write_exe_i386_32 )
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( elf_object_copy_32 ) TEST( ELFIOTest, elf_object_copy_32 )
{ {
checkObjestsAreEqual( "elf_examples/hello_32.o", checkObjestsAreEqual( "elf_examples/hello_32.o",
"elf_examples/hello_32_copy.o" ); "elf_examples/hello_32_copy.o" );
@ -375,7 +372,7 @@ BOOST_AUTO_TEST_CASE( elf_object_copy_32 )
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( section_header_address_update ) TEST( ELFIOTest, section_header_address_update )
{ {
elfio reader; elfio reader;
@ -383,19 +380,19 @@ BOOST_AUTO_TEST_CASE( section_header_address_update )
write_exe_i386( file_w_addr, false, true, 0x08048100 ); write_exe_i386( file_w_addr, false, true, 0x08048100 );
reader.load( file_w_addr ); reader.load( file_w_addr );
section* sec = reader.sections[".text"]; section* sec = reader.sections[".text"];
BOOST_REQUIRE_NE( sec, (section*)0 ); ASSERT_NE( sec, (section*)0 );
BOOST_CHECK_EQUAL( sec->get_address(), 0x08048100 ); EXPECT_EQ( sec->get_address(), 0x08048100 );
const std::string file_wo_addr( "elf_examples/write_exe_i386_32_wo_addr" ); const std::string file_wo_addr( "elf_examples/write_exe_i386_32_wo_addr" );
write_exe_i386( file_wo_addr, false, false, 0 ); write_exe_i386( file_wo_addr, false, false, 0 );
reader.load( file_wo_addr ); reader.load( file_wo_addr );
sec = reader.sections[".text"]; sec = reader.sections[".text"];
BOOST_REQUIRE_NE( sec, (section*)0 ); ASSERT_NE( sec, (section*)0 );
BOOST_CHECK_EQUAL( sec->get_address(), 0x08048000 ); EXPECT_EQ( sec->get_address(), 0x08048000 );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( elfio_copy ) TEST( ELFIOTest, elfio_copy )
{ {
elfio e; elfio e;
@ -408,11 +405,11 @@ BOOST_AUTO_TEST_CASE( elfio_copy )
//section* new_sec = //section* new_sec =
e.sections.add( "new" ); e.sections.add( "new" );
e.save( filename ); e.save( filename );
BOOST_CHECK_EQUAL( num + 1, e.sections.size() ); EXPECT_EQ( num + 1, e.sections.size() );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( elf_exe_copy_64 ) TEST( ELFIOTest, elf_exe_copy_64 )
{ {
checkExeAreEqual( "elf_examples/64bitLOAD.elf", checkExeAreEqual( "elf_examples/64bitLOAD.elf",
"elf_examples/64bitLOAD_copy.elf" ); "elf_examples/64bitLOAD_copy.elf" );
@ -429,7 +426,7 @@ BOOST_AUTO_TEST_CASE( elf_exe_copy_64 )
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( elf_exe_copy_32 ) TEST( ELFIOTest, elf_exe_copy_32 )
{ {
checkExeAreEqual( "elf_examples/asm", "elf_examples/asm_copy" ); checkExeAreEqual( "elf_examples/asm", "elf_examples/asm_copy" );
checkExeAreEqual( "elf_examples/arm_v7m_test_debug.elf", checkExeAreEqual( "elf_examples/arm_v7m_test_debug.elf",
@ -446,20 +443,20 @@ BOOST_AUTO_TEST_CASE( elf_exe_copy_32 )
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( elf_exe_loadsave_ppc32big3 ) TEST( ELFIOTest, elf_exe_loadsave_ppc32big3 )
{ {
std::string in = "elf_examples/ppc-32bit-specimen3.elf"; std::string in = "elf_examples/ppc-32bit-specimen3.elf";
std::string out = "elf_examples/ppc-32bit-testcopy3.elf"; std::string out = "elf_examples/ppc-32bit-testcopy3.elf";
elfio elf; elfio elf;
BOOST_REQUIRE_EQUAL( elf.load( in ), true ); ASSERT_EQ( elf.load( in ), true );
BOOST_REQUIRE_EQUAL( elf.save( out ), true ); ASSERT_EQ( elf.save( out ), true );
checkObjestsAreEqual( in, out ); checkObjestsAreEqual( in, out );
checkExeAreEqual( in, out, SEG_ALIGN ); checkExeAreEqual( in, out, SEG_ALIGN );
} }
*/
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( get_symbol_32 ) TEST( ELFIOTest, get_symbol_32 )
{ {
elfio elf; elfio elf;
std::string name; std::string name;
@ -470,19 +467,19 @@ BOOST_AUTO_TEST_CASE( get_symbol_32 )
unsigned char other; unsigned char other;
std::string in = "elf_examples/hello_32"; std::string in = "elf_examples/hello_32";
BOOST_REQUIRE_EQUAL( elf.load( in ), true ); ASSERT_EQ( elf.load( in ), true );
section* psymsec = elf.sections[".symtab"]; section* psymsec = elf.sections[".symtab"];
const symbol_section_accessor symbols( elf, psymsec ); const symbol_section_accessor symbols( elf, psymsec );
BOOST_CHECK_EQUAL( true, symbols.get_symbol( 0x08048478, name, size, bind, EXPECT_EQ( true, symbols.get_symbol( 0x08048478, name, size, bind, type,
type, section_index, other ) ); section_index, other ) );
BOOST_CHECK_EQUAL( "_IO_stdin_used", name ); EXPECT_EQ( "_IO_stdin_used", name );
BOOST_CHECK_EQUAL( 14, section_index ); EXPECT_EQ( 14, section_index );
BOOST_CHECK_EQUAL( 4, size ); EXPECT_EQ( 4, size );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( get_symbol_64 ) TEST( ELFIOTest, get_symbol_64 )
{ {
elfio elf; elfio elf;
std::string name; std::string name;
@ -493,19 +490,19 @@ BOOST_AUTO_TEST_CASE( get_symbol_64 )
unsigned char other; unsigned char other;
std::string in = "elf_examples/hello_64"; std::string in = "elf_examples/hello_64";
BOOST_REQUIRE_EQUAL( elf.load( in ), true ); ASSERT_EQ( elf.load( in ), true );
section* psymsec = elf.sections[".symtab"]; section* psymsec = elf.sections[".symtab"];
const symbol_section_accessor symbols( elf, psymsec ); const symbol_section_accessor symbols( elf, psymsec );
BOOST_CHECK_EQUAL( true, symbols.get_symbol( 0x00400498, name, size, bind, EXPECT_EQ( true, symbols.get_symbol( 0x00400498, name, size, bind, type,
type, section_index, other ) ); section_index, other ) );
BOOST_CHECK_EQUAL( "main", name ); EXPECT_EQ( "main", name );
BOOST_CHECK_EQUAL( 12, section_index ); EXPECT_EQ( 12, section_index );
BOOST_CHECK_EQUAL( 21, size ); EXPECT_EQ( 21, size );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( null_section_inside_segment ) TEST( ELFIOTest, null_section_inside_segment )
{ {
// This test case checks the load/save of SHT_NULL sections in a segment // This test case checks the load/save of SHT_NULL sections in a segment
// See https://github.com/serge1/ELFIO/issues/19 // See https://github.com/serge1/ELFIO/issues/19
@ -570,16 +567,16 @@ BOOST_AUTO_TEST_CASE( null_section_inside_segment )
// Create ELF file // Create ELF file
std::string f1 = "elf_examples/null_section_inside_segment1"; std::string f1 = "elf_examples/null_section_inside_segment1";
std::string f2 = "elf_examples/null_section_inside_segment2"; std::string f2 = "elf_examples/null_section_inside_segment2";
BOOST_CHECK_EQUAL( writer.save( f1 ), true ); EXPECT_EQ( writer.save( f1 ), true );
// Load and check the ELF file created above // Load and check the ELF file created above
elfio elf; elfio elf;
BOOST_CHECK_EQUAL( elf.load( f1 ), true ); EXPECT_EQ( elf.load( f1 ), true );
BOOST_CHECK_EQUAL( elf.save( f2 ), true ); EXPECT_EQ( elf.save( f2 ), true );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( invalid_file ) TEST( ELFIOTest, invalid_file )
{ {
elfio elf; elfio elf;
std::string name; std::string name;
@ -591,27 +588,25 @@ BOOST_AUTO_TEST_CASE( invalid_file )
unsigned char other; unsigned char other;
std::string in = "elf_examples/crash.elf"; std::string in = "elf_examples/crash.elf";
BOOST_REQUIRE_EQUAL( elf.load( in ), true ); ASSERT_EQ( elf.load( in ), true );
section* psymsec = elf.sections[".symtab"]; section* psymsec = elf.sections[".symtab"];
BOOST_REQUIRE_NE( psymsec, (void*)0 ); ASSERT_NE( psymsec, (void*)0 );
const symbol_section_accessor symbols( elf, psymsec ); const symbol_section_accessor symbols( elf, psymsec );
BOOST_CHECK_EQUAL( true, symbols.get_symbol( "main", value, size, bind, EXPECT_EQ( true, symbols.get_symbol( "main", value, size, bind, type,
type, section_index, other ) ); section_index, other ) );
BOOST_CHECK_EQUAL( 0x402560, value ); EXPECT_EQ( 0x402560, value );
BOOST_CHECK_EQUAL( true, EXPECT_EQ( true, symbols.get_symbol( "frame_dummy", value, size, bind, type,
symbols.get_symbol( "frame_dummy", value, size, bind, section_index, other ) );
type, section_index, other ) ); EXPECT_EQ( 0x402550, value );
BOOST_CHECK_EQUAL( 0x402550, value );
BOOST_CHECK_EQUAL( false, EXPECT_EQ( false, symbols.get_symbol( 0x00400498, name, size, bind, type,
symbols.get_symbol( 0x00400498, name, size, bind, type, section_index, other ) );
section_index, other ) );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( rearrange_local_symbols ) TEST( ELFIOTest, rearrange_local_symbols )
{ {
std::string name = ""; std::string name = "";
ELFIO::Elf64_Addr value = 0; ELFIO::Elf64_Addr value = 0;
@ -684,46 +679,46 @@ BOOST_AUTO_TEST_CASE( rearrange_local_symbols )
symbols.arrange_local_symbols( [&]( Elf_Xword first, Elf_Xword ) -> void { symbols.arrange_local_symbols( [&]( Elf_Xword first, Elf_Xword ) -> void {
static int counter = 0; static int counter = 0;
BOOST_CHECK_EQUAL( first, ++counter ); EXPECT_EQ( first, ++counter );
} ); } );
BOOST_REQUIRE_EQUAL( writer.save( file_name ), true ); ASSERT_EQ( writer.save( file_name ), true );
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
elfio reader; elfio reader;
BOOST_REQUIRE_EQUAL( reader.load( file_name ), true ); ASSERT_EQ( reader.load( file_name ), true );
auto psymsec = reader.sections[".symtab"]; auto psymsec = reader.sections[".symtab"];
BOOST_REQUIRE_NE( psymsec, nullptr ); ASSERT_NE( psymsec, nullptr );
const_symbol_section_accessor rsymbols( reader, psymsec ); const_symbol_section_accessor rsymbols( reader, psymsec );
auto bound = psymsec->get_info(); auto bound = psymsec->get_info();
auto num = rsymbols.get_symbols_num(); auto num = rsymbols.get_symbols_num();
BOOST_CHECK_LE( (Elf_Xword)bound, num ); EXPECT_LE( (Elf_Xword)bound, num );
// Check that all symbols are LOCAL until the bound value // Check that all symbols are LOCAL until the bound value
for ( Elf_Word i = 0; i < bound; i++ ) { for ( Elf_Word i = 0; i < bound; i++ ) {
rsymbols.get_symbol( i, name, value, size, bind, type, section_index, rsymbols.get_symbol( i, name, value, size, bind, type, section_index,
other ); other );
BOOST_CHECK_EQUAL( bind, (unsigned char)STB_LOCAL ); EXPECT_EQ( bind, (unsigned char)STB_LOCAL );
} }
BOOST_CHECK_EQUAL( name, "Str7" ); EXPECT_EQ( name, "Str7" );
// Check that all symbols are not LOCAL after the bound value // Check that all symbols are not LOCAL after the bound value
for ( Elf_Word i = bound; i < num; i++ ) { for ( Elf_Word i = bound; i < num; i++ ) {
rsymbols.get_symbol( i, name, value, size, bind, type, section_index, rsymbols.get_symbol( i, name, value, size, bind, type, section_index,
other ); other );
BOOST_CHECK_NE( bind, (unsigned char)STB_LOCAL ); EXPECT_NE( bind, (unsigned char)STB_LOCAL );
} }
BOOST_CHECK_EQUAL( name, "Str8" ); EXPECT_EQ( name, "Str8" );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( rearrange_local_symbols_with_reallocation ) TEST( ELFIOTest, rearrange_local_symbols_with_reallocation )
{ {
std::string name = ""; std::string name = "";
ELFIO::Elf64_Addr value = 0; ELFIO::Elf64_Addr value = 0;
@ -843,18 +838,18 @@ BOOST_AUTO_TEST_CASE( rearrange_local_symbols_with_reallocation )
rela.swap_symbols( first, second ); rela.swap_symbols( first, second );
} ); } );
BOOST_REQUIRE_EQUAL( writer.save( file_name ), true ); ASSERT_EQ( writer.save( file_name ), true );
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
elfio reader; elfio reader;
BOOST_REQUIRE_EQUAL( reader.load( file_name ), true ); ASSERT_EQ( reader.load( file_name ), true );
auto prelsec = reader.sections[".rel.text"]; auto prelsec = reader.sections[".rel.text"];
auto psyms = reader.sections[".symtab"]; auto psyms = reader.sections[".symtab"];
BOOST_REQUIRE_NE( prelsec, nullptr ); ASSERT_NE( prelsec, nullptr );
BOOST_REQUIRE_NE( psyms, nullptr ); ASSERT_NE( psyms, nullptr );
const_relocation_section_accessor rel( reader, prelsec ); const_relocation_section_accessor rel( reader, prelsec );
const_symbol_section_accessor syms( reader, psyms ); const_symbol_section_accessor syms( reader, psyms );
@ -873,11 +868,12 @@ BOOST_AUTO_TEST_CASE( rearrange_local_symbols_with_reallocation )
after.emplace_back( name ); after.emplace_back( name );
} }
BOOST_CHECK_EQUAL_COLLECTIONS( before.begin(), before.end(), after.begin(), EXPECT_EQ( before, after );
after.end() ); // EXPECT_EQ_COLLECTIONS( before.begin(), before.end(), after.begin(),
// after.end() );
} }
BOOST_AUTO_TEST_CASE( detect_mismatched_section_segment_tables ) TEST( ELFIOTest, detect_mismatched_section_segment_tables )
{ {
/* This file is a hacked copy of hello_32 /* This file is a hacked copy of hello_32
* The error introduced is: * The error introduced is:
@ -886,6 +882,6 @@ BOOST_AUTO_TEST_CASE( detect_mismatched_section_segment_tables )
*/ */
std::string in = "elf_examples/mismatched_segments.elf"; std::string in = "elf_examples/mismatched_segments.elf";
elfio elf; elfio elf;
BOOST_REQUIRE_EQUAL( elf.load( in ), true ); ASSERT_EQ( elf.load( in ), true );
BOOST_REQUIRE( elf.validate().length() > 0 ); ASSERT_TRUE( elf.validate().length() > 0 );
} }

View File

@ -25,25 +25,22 @@ THE SOFTWARE.
#define ELFIO_NO_INTTYPES #define ELFIO_NO_INTTYPES
#endif #endif
#include <boost/test/unit_test.hpp> #include <gtest/gtest.h>
#include <boost/test/tools/output_test_stream.hpp>
using boost::test_tools::output_test_stream;
#include <elfio/elfio.hpp> #include <elfio/elfio.hpp>
using namespace ELFIO; using namespace ELFIO;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( modinfo_read ) TEST( ELFIOTest, modinfo_read )
{ {
elfio reader; elfio reader;
BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/zavl.ko" ), true ); ASSERT_EQ( reader.load( "elf_examples/zavl.ko" ), true );
section* modinfo_sec = reader.sections[".modinfo"]; section* modinfo_sec = reader.sections[".modinfo"];
BOOST_REQUIRE_NE( modinfo_sec, nullptr ); ASSERT_NE( modinfo_sec, nullptr );
const_modinfo_section_accessor modinfo( modinfo_sec ); const_modinfo_section_accessor modinfo( modinfo_sec );
BOOST_REQUIRE_EQUAL( modinfo.get_attribute_num(), (Elf_Word)9 ); ASSERT_EQ( modinfo.get_attribute_num(), (Elf_Word)9 );
struct struct
{ {
@ -65,8 +62,8 @@ BOOST_AUTO_TEST_CASE( modinfo_read )
std::string value; std::string value;
modinfo.get_attribute( i, field, value ); modinfo.get_attribute( i, field, value );
BOOST_CHECK_EQUAL( field, attributes[i].field ); EXPECT_EQ( field, attributes[i].field );
BOOST_CHECK_EQUAL( value, attributes[i].value ); EXPECT_EQ( value, attributes[i].value );
} }
for ( uint32_t i = 0; i < sizeof( attributes ) / sizeof( attributes[0] ); for ( uint32_t i = 0; i < sizeof( attributes ) / sizeof( attributes[0] );
@ -75,37 +72,37 @@ BOOST_AUTO_TEST_CASE( modinfo_read )
std::string value; std::string value;
modinfo.get_attribute( field, value ); modinfo.get_attribute( field, value );
BOOST_CHECK_EQUAL( value, attributes[i].value ); EXPECT_EQ( value, attributes[i].value );
} }
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( modinfo_write ) TEST( ELFIOTest, modinfo_write )
{ {
elfio writer; elfio writer;
BOOST_REQUIRE_EQUAL( writer.load( "elf_examples/zavl.ko" ), true ); ASSERT_EQ( writer.load( "elf_examples/zavl.ko" ), true );
section* modinfo_sec = writer.sections[".modinfo"]; section* modinfo_sec = writer.sections[".modinfo"];
BOOST_REQUIRE_NE( modinfo_sec, nullptr ); ASSERT_NE( modinfo_sec, nullptr );
modinfo_section_accessor modinfo( modinfo_sec ); modinfo_section_accessor modinfo( modinfo_sec );
BOOST_REQUIRE_EQUAL( modinfo.get_attribute_num(), (Elf_Word)9 ); ASSERT_EQ( modinfo.get_attribute_num(), (Elf_Word)9 );
modinfo.add_attribute( "test1", "value1" ); modinfo.add_attribute( "test1", "value1" );
modinfo.add_attribute( "test2", "value2" ); modinfo.add_attribute( "test2", "value2" );
BOOST_REQUIRE_EQUAL( modinfo.get_attribute_num(), (Elf_Word)11 ); ASSERT_EQ( modinfo.get_attribute_num(), (Elf_Word)11 );
BOOST_REQUIRE_EQUAL( writer.save( "elf_examples/zavl_gen.ko" ), true ); ASSERT_EQ( writer.save( "elf_examples/zavl_gen.ko" ), true );
elfio reader; elfio reader;
BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/zavl_gen.ko" ), true ); ASSERT_EQ( reader.load( "elf_examples/zavl_gen.ko" ), true );
modinfo_sec = reader.sections[".modinfo"]; modinfo_sec = reader.sections[".modinfo"];
BOOST_REQUIRE_NE( modinfo_sec, nullptr ); ASSERT_NE( modinfo_sec, nullptr );
const_modinfo_section_accessor modinfo1( modinfo_sec ); const_modinfo_section_accessor modinfo1( modinfo_sec );
BOOST_REQUIRE_EQUAL( modinfo1.get_attribute_num(), (Elf_Word)11 ); ASSERT_EQ( modinfo1.get_attribute_num(), (Elf_Word)11 );
struct struct
{ {
@ -129,8 +126,8 @@ BOOST_AUTO_TEST_CASE( modinfo_write )
std::string value; std::string value;
modinfo.get_attribute( i, field, value ); modinfo.get_attribute( i, field, value );
BOOST_CHECK_EQUAL( field, attributes[i].field ); EXPECT_EQ( field, attributes[i].field );
BOOST_CHECK_EQUAL( value, attributes[i].value ); EXPECT_EQ( value, attributes[i].value );
} }
for ( uint32_t i = 0; i < sizeof( attributes ) / sizeof( attributes[0] ); for ( uint32_t i = 0; i < sizeof( attributes ) / sizeof( attributes[0] );
@ -139,118 +136,117 @@ BOOST_AUTO_TEST_CASE( modinfo_write )
std::string value; std::string value;
modinfo.get_attribute( field, value ); modinfo.get_attribute( field, value );
BOOST_CHECK_EQUAL( value, attributes[i].value ); EXPECT_EQ( value, attributes[i].value );
} }
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( array_read_32 ) TEST( ELFIOTest, array_read_32 )
{ {
elfio reader; elfio reader;
BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/hello_32" ), true ); ASSERT_EQ( reader.load( "elf_examples/hello_32" ), true );
section* array_sec = reader.sections[".ctors"]; section* array_sec = reader.sections[".ctors"];
BOOST_REQUIRE_NE( array_sec, nullptr ); ASSERT_NE( array_sec, nullptr );
const_array_section_accessor<> array( reader, array_sec ); const_array_section_accessor<> array( reader, array_sec );
BOOST_REQUIRE_EQUAL( array.get_entries_num(), (Elf_Xword)2 ); ASSERT_EQ( array.get_entries_num(), (Elf_Xword)2 );
Elf64_Addr addr; Elf64_Addr addr;
BOOST_CHECK_EQUAL( array.get_entry( 0, addr ), true ); EXPECT_EQ( array.get_entry( 0, addr ), true );
BOOST_CHECK_EQUAL( addr, 0xFFFFFFFF ); EXPECT_EQ( addr, 0xFFFFFFFF );
BOOST_CHECK_EQUAL( array.get_entry( 1, addr ), true ); EXPECT_EQ( array.get_entry( 1, addr ), true );
BOOST_CHECK_EQUAL( addr, 0x00000000 ); EXPECT_EQ( addr, 0x00000000 );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( array_read_64 ) TEST( ELFIOTest, array_read_64 )
{ {
elfio reader; elfio reader;
BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/hello_64" ), true ); ASSERT_EQ( reader.load( "elf_examples/hello_64" ), true );
section* array_sec = reader.sections[".ctors"]; section* array_sec = reader.sections[".ctors"];
BOOST_REQUIRE_NE( array_sec, nullptr ); ASSERT_NE( array_sec, nullptr );
const_array_section_accessor<Elf64_Addr> array( reader, array_sec ); const_array_section_accessor<Elf64_Addr> array( reader, array_sec );
BOOST_REQUIRE_EQUAL( array.get_entries_num(), (Elf_Xword)2 ); ASSERT_EQ( array.get_entries_num(), (Elf_Xword)2 );
Elf64_Addr addr; Elf64_Addr addr;
BOOST_CHECK_EQUAL( array.get_entry( 0, addr ), true ); EXPECT_EQ( array.get_entry( 0, addr ), true );
BOOST_CHECK_EQUAL( addr, 0xFFFFFFFFFFFFFFFF ); EXPECT_EQ( addr, 0xFFFFFFFFFFFFFFFF );
BOOST_CHECK_EQUAL( array.get_entry( 1, addr ), true ); EXPECT_EQ( array.get_entry( 1, addr ), true );
BOOST_CHECK_EQUAL( addr, 0x0000000000000000 ); EXPECT_EQ( addr, 0x0000000000000000 );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( init_array_read_64 ) TEST( ELFIOTest, init_array_read_64 )
{ {
elfio reader; elfio reader;
Elf64_Addr addr; Elf64_Addr addr;
BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/ctors" ), true ); ASSERT_EQ( reader.load( "elf_examples/ctors" ), true );
section* array_sec = reader.sections[".init_array"]; section* array_sec = reader.sections[".init_array"];
BOOST_REQUIRE_NE( array_sec, nullptr ); ASSERT_NE( array_sec, nullptr );
const_array_section_accessor<Elf64_Addr> array( reader, array_sec ); const_array_section_accessor<Elf64_Addr> array( reader, array_sec );
BOOST_REQUIRE_EQUAL( array.get_entries_num(), (Elf_Xword)2 ); ASSERT_EQ( array.get_entries_num(), (Elf_Xword)2 );
BOOST_CHECK_EQUAL( array.get_entry( 0, addr ), true ); EXPECT_EQ( array.get_entry( 0, addr ), true );
BOOST_CHECK_EQUAL( addr, 0x12C0 ); EXPECT_EQ( addr, 0x12C0 );
BOOST_CHECK_EQUAL( array.get_entry( 1, addr ), true ); EXPECT_EQ( array.get_entry( 1, addr ), true );
BOOST_CHECK_EQUAL( addr, 0x149F ); EXPECT_EQ( addr, 0x149F );
array_sec = reader.sections[".fini_array"]; array_sec = reader.sections[".fini_array"];
BOOST_REQUIRE_NE( array_sec, nullptr ); ASSERT_NE( array_sec, nullptr );
array_section_accessor<Elf64_Addr> arrayf( reader, array_sec ); array_section_accessor<Elf64_Addr> arrayf( reader, array_sec );
BOOST_REQUIRE_EQUAL( arrayf.get_entries_num(), (Elf_Xword)1 ); ASSERT_EQ( arrayf.get_entries_num(), (Elf_Xword)1 );
BOOST_CHECK_EQUAL( arrayf.get_entry( 0, addr ), true ); EXPECT_EQ( arrayf.get_entry( 0, addr ), true );
BOOST_CHECK_EQUAL( addr, 0x1280 ); EXPECT_EQ( addr, 0x1280 );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( init_array_write_64 ) TEST( ELFIOTest, init_array_write_64 )
{ {
elfio reader; elfio reader;
Elf64_Addr addr; Elf64_Addr addr;
BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/ctors" ), true ); ASSERT_EQ( reader.load( "elf_examples/ctors" ), true );
section* array_sec = reader.sections[".init_array"]; section* array_sec = reader.sections[".init_array"];
BOOST_REQUIRE_NE( array_sec, nullptr ); ASSERT_NE( array_sec, nullptr );
array_section_accessor<Elf64_Addr> array( reader, array_sec ); array_section_accessor<Elf64_Addr> array( reader, array_sec );
BOOST_REQUIRE_EQUAL( array.get_entries_num(), (Elf_Xword)2 ); ASSERT_EQ( array.get_entries_num(), (Elf_Xword)2 );
BOOST_CHECK_EQUAL( array.get_entry( 0, addr ), true ); EXPECT_EQ( array.get_entry( 0, addr ), true );
BOOST_CHECK_EQUAL( addr, 0x12C0 ); EXPECT_EQ( addr, 0x12C0 );
BOOST_CHECK_EQUAL( array.get_entry( 1, addr ), true ); EXPECT_EQ( array.get_entry( 1, addr ), true );
BOOST_CHECK_EQUAL( addr, 0x149F ); EXPECT_EQ( addr, 0x149F );
array.add_entry( 0x12345678 ); array.add_entry( 0x12345678 );
BOOST_REQUIRE_EQUAL( array.get_entries_num(), (Elf_Xword)3 ); ASSERT_EQ( array.get_entries_num(), (Elf_Xword)3 );
BOOST_CHECK_EQUAL( array.get_entry( 0, addr ), true ); EXPECT_EQ( array.get_entry( 0, addr ), true );
BOOST_CHECK_EQUAL( addr, 0x12C0 ); EXPECT_EQ( addr, 0x12C0 );
BOOST_CHECK_EQUAL( array.get_entry( 1, addr ), true ); EXPECT_EQ( array.get_entry( 1, addr ), true );
BOOST_CHECK_EQUAL( addr, 0x149F ); EXPECT_EQ( addr, 0x149F );
BOOST_CHECK_EQUAL( array.get_entry( 2, addr ), true ); EXPECT_EQ( array.get_entry( 2, addr ), true );
BOOST_CHECK_EQUAL( addr, 0x12345678 ); EXPECT_EQ( addr, 0x12345678 );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( test_hex ) TEST( ELFIOTest, test_hex )
{ {
BOOST_CHECK_EQUAL( to_hex_string( 1 ), "0x1" ); EXPECT_EQ( to_hex_string( 1 ), "0x1" );
BOOST_CHECK_EQUAL( to_hex_string( 10 ), "0xA" ); EXPECT_EQ( to_hex_string( 10 ), "0xA" );
BOOST_CHECK_EQUAL( to_hex_string( 0x12345678 ), "0x12345678" ); EXPECT_EQ( to_hex_string( 0x12345678 ), "0x12345678" );
BOOST_CHECK_EQUAL( to_hex_string( 0xFFFFFFFF ), "0xFFFFFFFF" ); EXPECT_EQ( to_hex_string( 0xFFFFFFFF ), "0xFFFFFFFF" );
BOOST_CHECK_EQUAL( to_hex_string( 0xFFFFFFFFFFFFFFFF ), EXPECT_EQ( to_hex_string( 0xFFFFFFFFFFFFFFFF ), "0xFFFFFFFFFFFFFFFF" );
"0xFFFFFFFFFFFFFFFF" );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( hash32_le ) TEST( ELFIOTest, hash32_le )
{ {
elfio reader; elfio reader;
// Load ELF data // Load ELF data
BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/ARMSCII-8.so" ), true ); ASSERT_EQ( reader.load( "elf_examples/ARMSCII-8.so" ), true );
std::string name; std::string name;
Elf64_Addr value; Elf64_Addr value;
@ -263,22 +259,22 @@ BOOST_AUTO_TEST_CASE( hash32_le )
symbol_section_accessor syms( reader, symsec ); symbol_section_accessor syms( reader, symsec );
for ( Elf_Xword i = 0; i < syms.get_symbols_num(); i++ ) { for ( Elf_Xword i = 0; i < syms.get_symbols_num(); i++ ) {
BOOST_REQUIRE_EQUAL( syms.get_symbol( i, name, value, size, bind, type, ASSERT_EQ( syms.get_symbol( i, name, value, size, bind, type,
section_index, other ), section_index, other ),
true ); true );
BOOST_CHECK_EQUAL( syms.get_symbol( name, value, size, bind, type, EXPECT_EQ( syms.get_symbol( name, value, size, bind, type,
section_index, other ), section_index, other ),
true ); true );
} }
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( hash32_be ) TEST( ELFIOTest, hash32_be )
{ {
elfio reader; elfio reader;
// Load ELF data // Load ELF data
BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/test_ppc" ), true ); ASSERT_EQ( reader.load( "elf_examples/test_ppc" ), true );
std::string name; std::string name;
Elf64_Addr value; Elf64_Addr value;
@ -291,22 +287,22 @@ BOOST_AUTO_TEST_CASE( hash32_be )
symbol_section_accessor syms( reader, symsec ); symbol_section_accessor syms( reader, symsec );
for ( Elf_Xword i = 0; i < syms.get_symbols_num(); i++ ) { for ( Elf_Xword i = 0; i < syms.get_symbols_num(); i++ ) {
BOOST_REQUIRE_EQUAL( syms.get_symbol( i, name, value, size, bind, type, ASSERT_EQ( syms.get_symbol( i, name, value, size, bind, type,
section_index, other ), section_index, other ),
true ); true );
BOOST_CHECK_EQUAL( syms.get_symbol( name, value, size, bind, type, EXPECT_EQ( syms.get_symbol( name, value, size, bind, type,
section_index, other ), section_index, other ),
true ); true );
} }
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( gnu_hash32_le ) TEST( ELFIOTest, gnu_hash32_le )
{ {
elfio reader; elfio reader;
// Load ELF data // Load ELF data
BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/hello_32" ), true ); ASSERT_EQ( reader.load( "elf_examples/hello_32" ), true );
std::string name; std::string name;
Elf64_Addr value; Elf64_Addr value;
@ -319,22 +315,22 @@ BOOST_AUTO_TEST_CASE( gnu_hash32_le )
symbol_section_accessor syms( reader, symsec ); symbol_section_accessor syms( reader, symsec );
for ( Elf_Xword i = 0; i < syms.get_symbols_num(); i++ ) { for ( Elf_Xword i = 0; i < syms.get_symbols_num(); i++ ) {
BOOST_REQUIRE_EQUAL( syms.get_symbol( i, name, value, size, bind, type, ASSERT_EQ( syms.get_symbol( i, name, value, size, bind, type,
section_index, other ), section_index, other ),
true ); true );
BOOST_CHECK_EQUAL( syms.get_symbol( name, value, size, bind, type, EXPECT_EQ( syms.get_symbol( name, value, size, bind, type,
section_index, other ), section_index, other ),
true ); true );
} }
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( gnu_hash64_le ) TEST( ELFIOTest, gnu_hash64_le )
{ {
elfio reader; elfio reader;
// Load ELF data // Load ELF data
BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/main" ), true ); ASSERT_EQ( reader.load( "elf_examples/main" ), true );
std::string name; std::string name;
Elf64_Addr value; Elf64_Addr value;
@ -347,22 +343,22 @@ BOOST_AUTO_TEST_CASE( gnu_hash64_le )
symbol_section_accessor syms( reader, symsec ); symbol_section_accessor syms( reader, symsec );
for ( Elf_Xword i = 0; i < syms.get_symbols_num(); i++ ) { for ( Elf_Xword i = 0; i < syms.get_symbols_num(); i++ ) {
BOOST_REQUIRE_EQUAL( syms.get_symbol( i, name, value, size, bind, type, ASSERT_EQ( syms.get_symbol( i, name, value, size, bind, type,
section_index, other ), section_index, other ),
true ); true );
BOOST_CHECK_EQUAL( syms.get_symbol( name, value, size, bind, type, EXPECT_EQ( syms.get_symbol( name, value, size, bind, type,
section_index, other ), section_index, other ),
true ); true );
} }
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( gnu_version_64_le ) TEST( ELFIOTest, gnu_version_64_le )
{ {
elfio reader; elfio reader;
// Load ELF data // Load ELF data
BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/hello_64" ), true ); ASSERT_EQ( reader.load( "elf_examples/hello_64" ), true );
std::string name; std::string name;
Elf64_Addr value; Elf64_Addr value;
@ -383,27 +379,26 @@ BOOST_AUTO_TEST_CASE( gnu_version_64_le )
section* dynstr = reader.sections[".dynstr"]; section* dynstr = reader.sections[".dynstr"];
BOOST_CHECK_EQUAL( gnu_version->get_link(), dynsym->get_index() ); EXPECT_EQ( gnu_version->get_link(), dynsym->get_index() );
BOOST_CHECK_EQUAL( gnu_version_r->get_link(), dynstr->get_index() ); EXPECT_EQ( gnu_version_r->get_link(), dynstr->get_index() );
BOOST_CHECK_EQUAL( dynsym_acc.get_symbols_num(), EXPECT_EQ( dynsym_acc.get_symbols_num(),
gnu_version_arr.get_entries_num() ); gnu_version_arr.get_entries_num() );
for ( Elf64_Word i = 0; i < dynsym_acc.get_symbols_num(); i++ ) { for ( Elf64_Word i = 0; i < dynsym_acc.get_symbols_num(); i++ ) {
BOOST_REQUIRE_EQUAL( dynsym_acc.get_symbol( i, name, value, size, bind, ASSERT_EQ( dynsym_acc.get_symbol( i, name, value, size, bind, type,
type, section_index, section_index, other ),
other ), true );
true );
Elf64_Half verindex = 0; Elf64_Half verindex = 0;
gnu_version_arr.get_entry( i, verindex ); gnu_version_arr.get_entry( i, verindex );
if ( i < 2 ) if ( i < 2 )
BOOST_CHECK_EQUAL( 0, verindex ); EXPECT_EQ( 0, verindex );
else else
BOOST_CHECK_EQUAL( 2, verindex ); EXPECT_EQ( 2, verindex );
} }
BOOST_CHECK_EQUAL( gnu_version_r_arr.get_entries_num(), 1 ); EXPECT_EQ( gnu_version_r_arr.get_entries_num(), 1 );
Elf_Half version; Elf_Half version;
std::string file_name; std::string file_name;
@ -413,21 +408,21 @@ BOOST_AUTO_TEST_CASE( gnu_version_64_le )
std::string dep_name; std::string dep_name;
gnu_version_r_arr.get_entry( 0, version, file_name, hash, flags, vna_other, gnu_version_r_arr.get_entry( 0, version, file_name, hash, flags, vna_other,
dep_name ); dep_name );
BOOST_CHECK_EQUAL( version, 1 ); EXPECT_EQ( version, 1 );
BOOST_CHECK_EQUAL( file_name, "libc.so.6" ); EXPECT_EQ( file_name, "libc.so.6" );
BOOST_CHECK_EQUAL( hash, 0x09691a75 ); EXPECT_EQ( hash, 0x09691a75 );
BOOST_CHECK_EQUAL( flags, 0 ); EXPECT_EQ( flags, 0 );
BOOST_CHECK_EQUAL( vna_other, 2 ); EXPECT_EQ( vna_other, 2 );
BOOST_CHECK_EQUAL( dep_name, "GLIBC_2.2.5" ); EXPECT_EQ( dep_name, "GLIBC_2.2.5" );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// BOOST_AUTO_TEST_CASE( gnu_version_64_le_modify ) // TEST( ELFIOTest, gnu_version_64_le_modify )
// { // {
// elfio reader; // elfio reader;
// // Load ELF data // // Load ELF data
// BOOST_REQUIRE_EQUAL( reader.load( "elf_examples/hello_64" ), true ); // ASSERT_EQ( reader.load( "elf_examples/hello_64" ), true );
// std::string name; // std::string name;
// Elf64_Addr value; // Elf64_Addr value;
@ -450,23 +445,23 @@ BOOST_AUTO_TEST_CASE( gnu_version_64_le )
// } // }
// gnu_version_arr.add_entry( i + 10 ); // gnu_version_arr.add_entry( i + 10 );
// gnu_version_arr.add_entry( i + 11 ); // gnu_version_arr.add_entry( i + 11 );
// BOOST_CHECK_EQUAL( orig_entries_num + 2, // EXPECT_EQ( orig_entries_num + 2,
// gnu_version_arr.get_entries_num() ); // gnu_version_arr.get_entries_num() );
// for ( i = 0; i < gnu_version_arr.get_entries_num(); i++ ) { // for ( i = 0; i < gnu_version_arr.get_entries_num(); i++ ) {
// Elf_Half value; // Elf_Half value;
// gnu_version_arr.get_entry( i, value ); // gnu_version_arr.get_entry( i, value );
// BOOST_CHECK_EQUAL( i + 10, value ); // EXPECT_EQ( i + 10, value );
// } // }
// } // }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( move_constructor_and_assignment ) TEST( ELFIOTest, move_constructor_and_assignment )
{ {
elfio r1; elfio r1;
// Load ELF data // Load ELF data
BOOST_REQUIRE_EQUAL( r1.load( "elf_examples/hello_64" ), true ); ASSERT_EQ( r1.load( "elf_examples/hello_64" ), true );
Elf64_Addr entry = r1.get_entry(); Elf64_Addr entry = r1.get_entry();
std::string sec_name = r1.sections[".text"]->get_name(); std::string sec_name = r1.sections[".text"]->get_name();
Elf_Xword seg_size = r1.segments[1]->get_memory_size(); Elf_Xword seg_size = r1.segments[1]->get_memory_size();
@ -474,18 +469,18 @@ BOOST_AUTO_TEST_CASE( move_constructor_and_assignment )
// Move to a vector element // Move to a vector element
std::vector<elfio> v; std::vector<elfio> v;
v.emplace_back( std::move( r1 ) ); v.emplace_back( std::move( r1 ) );
BOOST_CHECK_EQUAL( v[0].get_entry(), entry ); EXPECT_EQ( v[0].get_entry(), entry );
BOOST_CHECK_EQUAL( v[0].sections[".text"]->get_name(), sec_name ); EXPECT_EQ( v[0].sections[".text"]->get_name(), sec_name );
BOOST_CHECK_EQUAL( v[0].segments[1]->get_memory_size(), seg_size ); EXPECT_EQ( v[0].segments[1]->get_memory_size(), seg_size );
elfio r2; elfio r2;
r2 = std::move( v[0] ); r2 = std::move( v[0] );
BOOST_CHECK_EQUAL( r2.get_entry(), entry ); EXPECT_EQ( r2.get_entry(), entry );
BOOST_CHECK_EQUAL( r2.sections[".text"]->get_name(), sec_name ); EXPECT_EQ( r2.sections[".text"]->get_name(), sec_name );
BOOST_CHECK_EQUAL( r2.segments[1]->get_memory_size(), seg_size ); EXPECT_EQ( r2.segments[1]->get_memory_size(), seg_size );
} }
BOOST_AUTO_TEST_CASE( address_translation_test ) TEST( ELFIOTest, address_translation_test )
{ {
std::vector<address_translation> ranges; std::vector<address_translation> ranges;
@ -496,18 +491,18 @@ BOOST_AUTO_TEST_CASE( address_translation_test )
address_translator tr; address_translator tr;
tr.set_address_translation( ranges ); tr.set_address_translation( ranges );
BOOST_CHECK_EQUAL( tr[0], 500 ); EXPECT_EQ( tr[0], 500 );
BOOST_CHECK_EQUAL( tr[510], 1010 ); EXPECT_EQ( tr[510], 1010 );
BOOST_CHECK_EQUAL( tr[1710], 1710 ); EXPECT_EQ( tr[1710], 1710 );
BOOST_CHECK_EQUAL( tr[2710], 3710 ); EXPECT_EQ( tr[2710], 3710 );
BOOST_CHECK_EQUAL( tr[3710], 3710 ); EXPECT_EQ( tr[3710], 3710 );
ranges.clear(); ranges.clear();
tr.set_address_translation( ranges ); tr.set_address_translation( ranges );
BOOST_CHECK_EQUAL( tr[0], 0 ); EXPECT_EQ( tr[0], 0 );
BOOST_CHECK_EQUAL( tr[510], 510 ); EXPECT_EQ( tr[510], 510 );
BOOST_CHECK_EQUAL( tr[1710], 1710 ); EXPECT_EQ( tr[1710], 1710 );
BOOST_CHECK_EQUAL( tr[2710], 2710 ); EXPECT_EQ( tr[2710], 2710 );
BOOST_CHECK_EQUAL( tr[3710], 3710 ); EXPECT_EQ( tr[3710], 3710 );
} }