From: Christoph Egger Date: Wed, 1 Apr 2015 15:41:26 +0000 (+0200) Subject: Create helper to generate disassembler tests X-Git-Tag: v0.1~4 X-Git-Url: https://git.siccegge.de//index.cgi?a=commitdiff_plain;h=7268ab21d8676b43dc115dfb2a242d2ed73c8166;p=frida%2Ffrida.git Create helper to generate disassembler tests --- diff --git a/src/disassembler/llvm/tests/DisassemblerTest.cxx.m4 b/src/disassembler/llvm/tests/DisassemblerTest.cxx.m4 new file mode 100644 index 0000000..8477671 --- /dev/null +++ b/src/disassembler/llvm/tests/DisassemblerTest.cxx.m4 @@ -0,0 +1,73 @@ +#include +#include + +#include "core/InformationManager.hxx" +#include "core/Function.hxx" +#include "core/BasicBlock.hxx" +#include "disassembler/llvm/LLVMDisassembler.hxx" +define(GEN_NAME, $1$2)dnl + +extern char * TEST_DATA_DIRECTORY; + +static void testMainFunction(Function* main) { + ASSERT_NE(nullptr, main); + EXPECT_STREQ("MAIN_NAME", main->getName().c_str()); + + auto blocks = main->blocks(); + auto block = blocks.begin()->second; + EXPECT_EQ(MAIN_BLOCKS, blocks.size()); + EXPECT_EQ(MAIN_SIZE, block->getInstructions().size()); + EXPECT_EQ(MAIN_CHILD_0, block->getNextBlock(0)); + EXPECT_EQ(MAIN_CHILD_1, block->getNextBlock(1)); + + EXPECT_TRUE(blocks.find(MAIN_CHILD_0) != blocks.end()); + EXPECT_TRUE(blocks.find(MAIN_CHILD_1) != blocks.end()); +} + +static void testCheckFunction(Function* check) { + ASSERT_NE(nullptr, check); + EXPECT_STREQ("TEST_NAME", check->getName().c_str()); + + auto blocks = check->blocks(); + auto block = blocks.begin()->second; + EXPECT_EQ(1, blocks.size()); + EXPECT_EQ(TEST_SIZE, block->getInstructions().size()); + EXPECT_EQ(0x0, block->getNextBlock(0)); + EXPECT_EQ(0x0, block->getNextBlock(1)); +} + +TEST(llvmDisassemblerTest, GEN_NAME(NAME, OpenBinaryBasicStructure)) { + SCOPED_TRACE("opening cryptsample NAME"); + InformationManager manager; + + llvm::InitializeAllTargetInfos(); + llvm::InitializeAllTargetMCs(); + llvm::InitializeAllAsmParsers(); + llvm::InitializeAllDisassemblers(); + + manager.reset(std::string(TEST_DATA_DIRECTORY) + + "FILENAME"); + + ASSERT_NE(nullptr, manager.getDisassembler()); + EXPECT_EQ(ENTRY, manager.getDisassembler()->entryAddress()); + testCheckFunction(manager.getFunction(TEST_ENTRY)); + testMainFunction(manager.getFunction(MAIN_ENTRY)); +} + +TEST(llvmDisassemblerTest, GEN_NAME(NAME, LoadBinaryBasicStructure)) { + SCOPED_TRACE("loading cryptsample NAME"); + InformationManager manager; + + llvm::InitializeAllTargetInfos(); + llvm::InitializeAllTargetMCs(); + llvm::InitializeAllAsmParsers(); + llvm::InitializeAllDisassemblers(); + + manager.load(std::string(TEST_DATA_DIRECTORY) + + "FILENAME.frida"); + + ASSERT_NE(nullptr, manager.getDisassembler()); + EXPECT_EQ(ENTRY, manager.getDisassembler()->entryAddress()); + testCheckFunction(manager.getFunction(TEST_ENTRY)); + testMainFunction(manager.getFunction(MAIN_ENTRY)); +} diff --git a/src/disassembler/llvm/tests/Makefile b/src/disassembler/llvm/tests/Makefile new file mode 100644 index 0000000..3d68694 --- /dev/null +++ b/src/disassembler/llvm/tests/Makefile @@ -0,0 +1,63 @@ +#!/usr/bin/make -f + +all: amd64LinuxDisassemblerTest.cxx armelLinuxDisassemblerTest.cxx mipselLinuxDisassemblerTest.cxx amd64MachODisassemblerTest.cxx + +amd64LinuxDisassemblerTest.cxx: DisassemblerTest.cxx.m4 + m4 -DNAME=amd64Linux \ + -DFILENAME=/disassembler/binaries/crypt.clang.O2.amd64.elf \ + -DENTRY=0x4005F0 \ + -DMAIN_ENTRY=0x400770 \ + -DMAIN_NAME=main \ + -DMAIN_SIZE=17 \ + -DMAIN_BLOCKS=4 \ + -DMAIN_CHILD_0=0x4007ea \ + -DMAIN_CHILD_1=0x4007ce \ + -DTEST_ENTRY=0x4006f0 \ + -DTEST_NAME=check \ + -DTEST_SIZE=29 \ + < $^ > $@ + +armelLinuxDisassemblerTest.cxx: DisassemblerTest.cxx.m4 + m4 -DNAME=armelLinux \ + -DFILENAME=/disassembler/binaries/crypt.clang.O2.armel.elf \ + -DENTRY=0x104a8 \ + -DMAIN_ENTRY=0x1062c \ + -DMAIN_NAME=main \ + -DMAIN_SIZE=22 \ + -DMAIN_BLOCKS=4 \ + -DMAIN_CHILD_0=0x1068c \ + -DMAIN_CHILD_1=0x10684 \ + -DTEST_ENTRY=0x105d8 \ + -DTEST_NAME=check \ + -DTEST_SIZE=18 \ + < $^ > $@ + +mipselLinuxDisassemblerTest.cxx: DisassemblerTest.cxx.m4 + m4 -DNAME=DISABLED_mipselLinux \ + -DFILENAME=/disassembler/binaries/crypt.clang.O2.mipsel.elf \ + -DENTRY=0x4005F0 \ + -DMAIN_ENTRY=0x400870 \ + -DMAIN_NAME=main \ + -DMAIN_SIZE=27 \ + -DMAIN_BLOCKS=4 \ + -DMAIN_CHILD_0=0x4008f4 \ + -DMAIN_CHILD_1=0x4008dc \ + -DTEST_ENTRY=0x400810 \ + -DTEST_NAME=check \ + -DTEST_SIZE=24 \ + < $^ > $@ + +amd64MachODisassemblerTest.cxx: DisassemblerTest.cxx.m4 + m4 -DNAME=amd64MachO \ + -DFILENAME=/disassembler/binaries/crypt.clang.O2.amd64.macho \ + -DENTRY=0x0 \ + -DMAIN_ENTRY=0x100000e30 \ + -DMAIN_NAME=_main \ + -DMAIN_SIZE=20 \ + -DMAIN_BLOCKS=6 \ + -DMAIN_CHILD_0=0x100000EB2 \ + -DMAIN_CHILD_1=0x100000E99 \ + -DTEST_ENTRY=0x100000db0 \ + -DTEST_NAME=_check \ + -DTEST_SIZE=29 \ + < $^ > $@ diff --git a/src/disassembler/llvm/tests/amd64LinuxDisassemblerTest.cxx b/src/disassembler/llvm/tests/amd64LinuxDisassemblerTest.cxx index 932f79a..a57c728 100644 --- a/src/disassembler/llvm/tests/amd64LinuxDisassemblerTest.cxx +++ b/src/disassembler/llvm/tests/amd64LinuxDisassemblerTest.cxx @@ -36,7 +36,7 @@ static void testCheckFunction(Function* check) { } TEST(llvmDisassemblerTest, amd64LinuxOpenBinaryBasicStructure) { - SCOPED_TRACE("opening cryptsample.clang.amd64.elf"); + SCOPED_TRACE("opening cryptsample amd64Linux"); InformationManager manager; llvm::InitializeAllTargetInfos(); @@ -54,7 +54,7 @@ TEST(llvmDisassemblerTest, amd64LinuxOpenBinaryBasicStructure) { } TEST(llvmDisassemblerTest, amd64LinuxLoadBinaryBasicStructure) { - SCOPED_TRACE("loading cryptsample.clang.amd64.elf"); + SCOPED_TRACE("loading cryptsample amd64Linux"); InformationManager manager; llvm::InitializeAllTargetInfos(); diff --git a/src/disassembler/llvm/tests/amd64MachODisassemblerTest.cxx b/src/disassembler/llvm/tests/amd64MachODisassemblerTest.cxx index db7eaec..901ad28 100644 --- a/src/disassembler/llvm/tests/amd64MachODisassemblerTest.cxx +++ b/src/disassembler/llvm/tests/amd64MachODisassemblerTest.cxx @@ -9,7 +9,6 @@ extern char * TEST_DATA_DIRECTORY; static void testMainFunction(Function* main) { - SCOPED_TRACE("main"); ASSERT_NE(nullptr, main); EXPECT_STREQ("_main", main->getName().c_str()); @@ -25,7 +24,6 @@ static void testMainFunction(Function* main) { } static void testCheckFunction(Function* check) { - SCOPED_TRACE("check"); ASSERT_NE(nullptr, check); EXPECT_STREQ("_check", check->getName().c_str()); @@ -38,7 +36,7 @@ static void testCheckFunction(Function* check) { } TEST(llvmDisassemblerTest, amd64MachOOpenBinaryBasicStructure) { - SCOPED_TRACE("opening cryptsample.clang.amd64.macho"); + SCOPED_TRACE("opening cryptsample amd64MachO"); InformationManager manager; llvm::InitializeAllTargetInfos(); @@ -50,12 +48,13 @@ TEST(llvmDisassemblerTest, amd64MachOOpenBinaryBasicStructure) { + "/disassembler/binaries/crypt.clang.O2.amd64.macho"); ASSERT_NE(nullptr, manager.getDisassembler()); + EXPECT_EQ(0x0, manager.getDisassembler()->entryAddress()); testCheckFunction(manager.getFunction(0x100000db0)); testMainFunction(manager.getFunction(0x100000e30)); } TEST(llvmDisassemblerTest, amd64MachOLoadBinaryBasicStructure) { - SCOPED_TRACE("loading cryptsample.clang.amd64.macho"); + SCOPED_TRACE("loading cryptsample amd64MachO"); InformationManager manager; llvm::InitializeAllTargetInfos(); @@ -67,6 +66,7 @@ TEST(llvmDisassemblerTest, amd64MachOLoadBinaryBasicStructure) { + "/disassembler/binaries/crypt.clang.O2.amd64.macho.frida"); ASSERT_NE(nullptr, manager.getDisassembler()); + EXPECT_EQ(0x0, manager.getDisassembler()->entryAddress()); testCheckFunction(manager.getFunction(0x100000db0)); testMainFunction(manager.getFunction(0x100000e30)); } diff --git a/src/disassembler/llvm/tests/armelLinuxDisassemblerTest.cxx b/src/disassembler/llvm/tests/armelLinuxDisassemblerTest.cxx index 4e79972..92df915 100644 --- a/src/disassembler/llvm/tests/armelLinuxDisassemblerTest.cxx +++ b/src/disassembler/llvm/tests/armelLinuxDisassemblerTest.cxx @@ -36,7 +36,7 @@ static void testCheckFunction(Function* check) { } TEST(llvmDisassemblerTest, armelLinuxOpenBinaryBasicStructure) { - SCOPED_TRACE("opening cryptsample.clang.armel.elf"); + SCOPED_TRACE("opening cryptsample armelLinux"); InformationManager manager; llvm::InitializeAllTargetInfos(); @@ -54,7 +54,7 @@ TEST(llvmDisassemblerTest, armelLinuxOpenBinaryBasicStructure) { } TEST(llvmDisassemblerTest, armelLinuxLoadBinaryBasicStructure) { - SCOPED_TRACE("loading cryptsample.clang.armel.elf"); + SCOPED_TRACE("loading cryptsample armelLinux"); InformationManager manager; llvm::InitializeAllTargetInfos(); diff --git a/src/disassembler/llvm/tests/mipselLinuxDisassemblerTest.cxx b/src/disassembler/llvm/tests/mipselLinuxDisassemblerTest.cxx index 70511b4..a502d0f 100644 --- a/src/disassembler/llvm/tests/mipselLinuxDisassemblerTest.cxx +++ b/src/disassembler/llvm/tests/mipselLinuxDisassemblerTest.cxx @@ -19,8 +19,8 @@ static void testMainFunction(Function* main) { EXPECT_EQ(0x4008f4, block->getNextBlock(0)); EXPECT_EQ(0x4008dc, block->getNextBlock(1)); - EXPECT_TRUE(blocks.find(0x4007ea) != blocks.end()); - EXPECT_TRUE(blocks.find(0x4007ce) != blocks.end()); + EXPECT_TRUE(blocks.find(0x4008f4) != blocks.end()); + EXPECT_TRUE(blocks.find(0x4008dc) != blocks.end()); } static void testCheckFunction(Function* check) { @@ -35,8 +35,8 @@ static void testCheckFunction(Function* check) { EXPECT_EQ(0x0, block->getNextBlock(1)); } -TEST(llvmDisassemblerTest, mipselLinuxOpenBinaryBasicStructure) { - SCOPED_TRACE("opening cryptsample.clang.mipsel.elf"); +TEST(llvmDisassemblerTest, DISABLED_mipselLinuxOpenBinaryBasicStructure) { + SCOPED_TRACE("opening cryptsample DISABLED_mipselLinux"); InformationManager manager; llvm::InitializeAllTargetInfos(); @@ -53,8 +53,8 @@ TEST(llvmDisassemblerTest, mipselLinuxOpenBinaryBasicStructure) { testMainFunction(manager.getFunction(0x400870)); } -TEST(llvmDisassemblerTest, mipselLinuxLoadBinaryBasicStructure) { - SCOPED_TRACE("loading cryptsample.clang.mipsel.elf"); +TEST(llvmDisassemblerTest, DISABLED_mipselLinuxLoadBinaryBasicStructure) { + SCOPED_TRACE("loading cryptsample DISABLED_mipselLinux"); InformationManager manager; llvm::InitializeAllTargetInfos();