]> git.siccegge.de Git - frida/frida.git/commitdiff
Create helper to generate disassembler tests
authorChristoph Egger <Christoph.Egger@fau.de>
Wed, 1 Apr 2015 15:41:26 +0000 (17:41 +0200)
committerChristoph Egger <Christoph.Egger@fau.de>
Wed, 1 Apr 2015 15:41:26 +0000 (17:41 +0200)
src/disassembler/llvm/tests/DisassemblerTest.cxx.m4 [new file with mode: 0644]
src/disassembler/llvm/tests/Makefile [new file with mode: 0644]
src/disassembler/llvm/tests/amd64LinuxDisassemblerTest.cxx
src/disassembler/llvm/tests/amd64MachODisassemblerTest.cxx
src/disassembler/llvm/tests/armelLinuxDisassemblerTest.cxx
src/disassembler/llvm/tests/mipselLinuxDisassemblerTest.cxx

diff --git a/src/disassembler/llvm/tests/DisassemblerTest.cxx.m4 b/src/disassembler/llvm/tests/DisassemblerTest.cxx.m4
new file mode 100644 (file)
index 0000000..8477671
--- /dev/null
@@ -0,0 +1,73 @@
+#include <gtest/gtest.h>
+#include <string>
+
+#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 (file)
index 0000000..3d68694
--- /dev/null
@@ -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 \
+          < $^ > $@
index 932f79a96216599c81db5820f3ee351ca12922d5..a57c728cf0cd9309fdf6f0ba6c3c4ad5de167fd8 100644 (file)
@@ -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();
index db7eaec3dd5b5514add94045b0e0d4518ac9e255..901ad284440b26d48c8f046650a34debf5e58f8b 100644 (file)
@@ -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));
 }
index 4e7997240f705aa8f1d68a96f8c6be1df51ef1db..92df91559ffad020b1196ec9fef43415e8c11cab 100644 (file)
@@ -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();
index 70511b4e6573553872cb638b34c4d69d42b40325..a502d0f2361a6b65a4980a890a4ba65a693f703b 100644 (file)
@@ -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();