1 #include <gtest/gtest.h>
4 #include "core/InformationManager.hxx"
5 #include "core/Function.hxx"
6 #include "core/BasicBlock.hxx"
7 #include "disassembler/llvm/LLVMDisassembler.hxx"
8 define(GEN_NAME, $1$2)dnl
10 extern char * TEST_DATA_DIRECTORY;
12 static void testMainFunction(Function* main) {
13 ASSERT_NE(nullptr, main);
14 EXPECT_STREQ("MAIN_NAME", main->getName().c_str());
16 auto blocks = main->blocks();
17 auto block = blocks.begin()->second;
18 EXPECT_EQ(MAIN_BLOCKS, blocks.size());
19 EXPECT_EQ(MAIN_SIZE, block->getInstructions().size());
20 EXPECT_EQ(MAIN_CHILD_0, block->getNextBlock(0));
21 EXPECT_EQ(MAIN_CHILD_1, block->getNextBlock(1));
23 EXPECT_TRUE(blocks.find(MAIN_CHILD_0) != blocks.end());
24 EXPECT_TRUE(blocks.find(MAIN_CHILD_1) != blocks.end());
27 static void testCheckFunction(Function* check) {
28 ASSERT_NE(nullptr, check);
29 EXPECT_STREQ("TEST_NAME", check->getName().c_str());
31 auto blocks = check->blocks();
32 auto block = blocks.begin()->second;
33 EXPECT_EQ(1, blocks.size());
34 EXPECT_EQ(TEST_SIZE, block->getInstructions().size());
35 EXPECT_EQ(0x0, block->getNextBlock(0));
36 EXPECT_EQ(0x0, block->getNextBlock(1));
39 TEST(llvmDisassemblerTest, GEN_NAME(NAME, OpenBinaryBasicStructure)) {
40 SCOPED_TRACE("opening cryptsample NAME");
41 InformationManager manager;
43 llvm::InitializeAllTargetInfos();
44 llvm::InitializeAllTargetMCs();
45 llvm::InitializeAllAsmParsers();
46 llvm::InitializeAllDisassemblers();
48 manager.reset(std::string(TEST_DATA_DIRECTORY)
51 ASSERT_NE(nullptr, manager.getDisassembler());
52 EXPECT_EQ(ENTRY, manager.getDisassembler()->entryAddress());
53 testCheckFunction(manager.getFunction(TEST_ENTRY));
54 testMainFunction(manager.getFunction(MAIN_ENTRY));
57 TEST(llvmDisassemblerTest, GEN_NAME(NAME, LoadBinaryBasicStructure)) {
58 SCOPED_TRACE("loading cryptsample NAME");
59 InformationManager manager;
61 llvm::InitializeAllTargetInfos();
62 llvm::InitializeAllTargetMCs();
63 llvm::InitializeAllAsmParsers();
64 llvm::InitializeAllDisassemblers();
66 manager.load(std::string(TEST_DATA_DIRECTORY)
69 ASSERT_NE(nullptr, manager.getDisassembler());
70 EXPECT_EQ(ENTRY, manager.getDisassembler()->entryAddress());
71 testCheckFunction(manager.getFunction(TEST_ENTRY));
72 testMainFunction(manager.getFunction(MAIN_ENTRY));