]> git.siccegge.de Git - frida/frida.git/commitdiff
Add (failing) mipsel test
authorChristoph Egger <Christoph.Egger@fau.de>
Thu, 26 Mar 2015 16:59:46 +0000 (17:59 +0100)
committerChristoph Egger <Christoph.Egger@fau.de>
Thu, 26 Mar 2015 16:59:46 +0000 (17:59 +0100)
CMakeLists.txt
src/disassembler/llvm/tests/mipselLinuxDisassemblerTest.cxx [new file with mode: 0644]
testdata/disassembler/binaries/crypt.clang.O2.mipsel.elf [new file with mode: 0755]

index fabb0d9d07d43ab79dc478220455f1e988bfa026..c3ff63f9a50ecb0f7bbe636936e5275165195128 100644 (file)
@@ -130,6 +130,7 @@ set(fridatest_SOURCES
   src/core/tests/FunctionTest.cxx
   src/core/tests/CommentTest.cxx
   src/disassembler/llvm/tests/amd64LinuxDisassemblerTest.cxx
+  src/disassembler/llvm/tests/mipselLinuxDisassemblerTest.cxx
   src/disassembler/llvm/tests/amd64MachODisassemblerTest.cxx
   ${frida_SOURCES}
   )
diff --git a/src/disassembler/llvm/tests/mipselLinuxDisassemblerTest.cxx b/src/disassembler/llvm/tests/mipselLinuxDisassemblerTest.cxx
new file mode 100644 (file)
index 0000000..70511b4
--- /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(27, block->getInstructions().size());
+       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());
+}
+
+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(24, block->getInstructions().size());
+       EXPECT_EQ(0x0, block->getNextBlock(0));
+       EXPECT_EQ(0x0, block->getNextBlock(1));
+}
+
+TEST(llvmDisassemblerTest, mipselLinuxOpenBinaryBasicStructure) {
+       SCOPED_TRACE("opening cryptsample.clang.mipsel.elf");
+       InformationManager manager;
+
+       llvm::InitializeAllTargetInfos();
+       llvm::InitializeAllTargetMCs();
+       llvm::InitializeAllAsmParsers();
+       llvm::InitializeAllDisassemblers();
+
+       manager.reset(std::string(TEST_DATA_DIRECTORY)
+                     + "/disassembler/binaries/crypt.clang.O2.mipsel.elf");
+
+       ASSERT_NE(nullptr, manager.getDisassembler());
+       EXPECT_EQ(0x4005F0, manager.getDisassembler()->entryAddress());
+       testCheckFunction(manager.getFunction(0x400810));
+       testMainFunction(manager.getFunction(0x400870));
+}
+
+TEST(llvmDisassemblerTest, mipselLinuxLoadBinaryBasicStructure) {
+       SCOPED_TRACE("loading cryptsample.clang.mipsel.elf");
+       InformationManager manager;
+
+       llvm::InitializeAllTargetInfos();
+       llvm::InitializeAllTargetMCs();
+       llvm::InitializeAllAsmParsers();
+       llvm::InitializeAllDisassemblers();
+
+       manager.load(std::string(TEST_DATA_DIRECTORY)
+                     + "/disassembler/binaries/crypt.clang.O2.mipsel.elf.frida");
+
+       ASSERT_NE(nullptr, manager.getDisassembler());
+       EXPECT_EQ(0x4005F0, manager.getDisassembler()->entryAddress());
+       testCheckFunction(manager.getFunction(0x400810));
+       testMainFunction(manager.getFunction(0x400870));
+}
diff --git a/testdata/disassembler/binaries/crypt.clang.O2.mipsel.elf b/testdata/disassembler/binaries/crypt.clang.O2.mipsel.elf
new file mode 100755 (executable)
index 0000000..492011a
Binary files /dev/null and b/testdata/disassembler/binaries/crypt.clang.O2.mipsel.elf differ