]> git.siccegge.de Git - frida/frida.git/commitdiff
Add armel testcase
authorChristoph Egger <Christoph.Egger@fau.de>
Wed, 1 Apr 2015 14:53:50 +0000 (16:53 +0200)
committerChristoph Egger <Christoph.Egger@fau.de>
Wed, 1 Apr 2015 14:53:50 +0000 (16:53 +0200)
This one doesn't do thumb so it's easy

CMakeLists.txt
src/disassembler/llvm/tests/armelLinuxDisassemblerTest.cxx [new file with mode: 0644]
testdata/disassembler/binaries/crypt.clang.O2.armel.elf [new file with mode: 0755]
testdata/disassembler/binaries/crypt.clang.O2.armel.elf.frida [new file with mode: 0644]

index c3ff63f9a50ecb0f7bbe636936e5275165195128..c0abdf52e0029821f24e1dabcf26f29a55e9650f 100644 (file)
@@ -131,6 +131,7 @@ set(fridatest_SOURCES
   src/core/tests/CommentTest.cxx
   src/disassembler/llvm/tests/amd64LinuxDisassemblerTest.cxx
   src/disassembler/llvm/tests/mipselLinuxDisassemblerTest.cxx
+  src/disassembler/llvm/tests/armelLinuxDisassemblerTest.cxx
   src/disassembler/llvm/tests/amd64MachODisassemblerTest.cxx
   ${frida_SOURCES}
   )
diff --git a/src/disassembler/llvm/tests/armelLinuxDisassemblerTest.cxx b/src/disassembler/llvm/tests/armelLinuxDisassemblerTest.cxx
new file mode 100644 (file)
index 0000000..4e79972
--- /dev/null
@@ -0,0 +1,72 @@
+#include <gtest/gtest.h>
+#include <string>
+
+#include "core/InformationManager.hxx"
+#include "core/Function.hxx"
+#include "core/BasicBlock.hxx"
+#include "disassembler/llvm/LLVMDisassembler.hxx"
+
+extern char * TEST_DATA_DIRECTORY;
+
+static void testMainFunction(Function* main) {
+       ASSERT_NE(nullptr, main);
+       EXPECT_STREQ("main", main->getName().c_str());
+
+       auto blocks = main->blocks();
+       auto block = blocks.begin()->second;
+       EXPECT_EQ(4, blocks.size());
+       EXPECT_EQ(22, block->getInstructions().size());
+       EXPECT_EQ(0x1068c, block->getNextBlock(0));
+       EXPECT_EQ(0x10684, block->getNextBlock(1));
+
+       EXPECT_TRUE(blocks.find(0x1068c) != blocks.end());
+       EXPECT_TRUE(blocks.find(0x10684) != blocks.end());
+}
+
+static void testCheckFunction(Function* check) {
+       ASSERT_NE(nullptr, check);
+       EXPECT_STREQ("check", check->getName().c_str());
+
+       auto blocks = check->blocks();
+       auto block = blocks.begin()->second;
+       EXPECT_EQ(1, blocks.size());
+       EXPECT_EQ(18, block->getInstructions().size());
+       EXPECT_EQ(0x0, block->getNextBlock(0));
+       EXPECT_EQ(0x0, block->getNextBlock(1));
+}
+
+TEST(llvmDisassemblerTest, armelLinuxOpenBinaryBasicStructure) {
+       SCOPED_TRACE("opening cryptsample.clang.armel.elf");
+       InformationManager manager;
+
+       llvm::InitializeAllTargetInfos();
+       llvm::InitializeAllTargetMCs();
+       llvm::InitializeAllAsmParsers();
+       llvm::InitializeAllDisassemblers();
+
+       manager.reset(std::string(TEST_DATA_DIRECTORY)
+                     + "/disassembler/binaries/crypt.clang.O2.armel.elf");
+
+       ASSERT_NE(nullptr, manager.getDisassembler());
+       EXPECT_EQ(0x104a8, manager.getDisassembler()->entryAddress());
+       testCheckFunction(manager.getFunction(0x105d8));
+       testMainFunction(manager.getFunction(0x1062c));
+}
+
+TEST(llvmDisassemblerTest, armelLinuxLoadBinaryBasicStructure) {
+       SCOPED_TRACE("loading cryptsample.clang.armel.elf");
+       InformationManager manager;
+
+       llvm::InitializeAllTargetInfos();
+       llvm::InitializeAllTargetMCs();
+       llvm::InitializeAllAsmParsers();
+       llvm::InitializeAllDisassemblers();
+
+       manager.load(std::string(TEST_DATA_DIRECTORY)
+                     + "/disassembler/binaries/crypt.clang.O2.armel.elf.frida");
+
+       ASSERT_NE(nullptr, manager.getDisassembler());
+       EXPECT_EQ(0x104a8, manager.getDisassembler()->entryAddress());
+       testCheckFunction(manager.getFunction(0x105d8));
+       testMainFunction(manager.getFunction(0x1062c));
+}
diff --git a/testdata/disassembler/binaries/crypt.clang.O2.armel.elf b/testdata/disassembler/binaries/crypt.clang.O2.armel.elf
new file mode 100755 (executable)
index 0000000..4ca765e
Binary files /dev/null and b/testdata/disassembler/binaries/crypt.clang.O2.armel.elf differ
diff --git a/testdata/disassembler/binaries/crypt.clang.O2.armel.elf.frida b/testdata/disassembler/binaries/crypt.clang.O2.armel.elf.frida
new file mode 100644 (file)
index 0000000..f60308f
Binary files /dev/null and b/testdata/disassembler/binaries/crypt.clang.O2.armel.elf.frida differ