]> git.siccegge.de Git - frida/frida.git/commitdiff
Add testcase for serializing / deserializing BasicBlocks
authorChristoph Egger <Christoph.Egger@fau.de>
Tue, 3 Mar 2015 16:59:23 +0000 (17:59 +0100)
committerChristoph Egger <Christoph.Egger@fau.de>
Tue, 3 Mar 2015 16:59:23 +0000 (17:59 +0100)
CMakeLists.txt
src/core/InformationManager.hxx
src/core/tests/BasicBlockTest.cxx [new file with mode: 0644]
testdata/core/BasicBlock/invalid.xml [new file with mode: 0644]
testdata/core/BasicBlock/valid.xml [new file with mode: 0644]

index e9ff46b72a838b4a8ad2c4d8f36f5bc36f874958..765746127367f82c0a4d451989edfbc86228f485 100644 (file)
@@ -33,6 +33,7 @@ execute_process(COMMAND ${LLVM_CONFIG} --system-libs OUTPUT_VARIABLE LLVM_SYSTEM
 string(REPLACE -O2 "" LLVM_CFLAGS ${LLVM_CFLAGS})
 string(REPLACE -fno-exceptions "" LLVM_CFLAGS ${LLVM_CFLAGS})
 string(REPLACE -fno-rtti "" LLVM_CFLAGS ${LLVM_CFLAGS})
+string(REPLACE -DNDEBUG "" LLVM_CFLAGS ${LLVM_CFLAGS})
 
 separate_arguments(LLVM_CFLAGS)
 add_definitions(${LLVM_CFLAGS})
@@ -43,7 +44,6 @@ separate_arguments(LLVM_LDFLAGS)
 separate_arguments(LLVM_LIBS)
 
 SET(frida_SOURCES
-  src/main.cxx
   src/core/InformationManager.cxx
   src/core/BasicBlock.cxx
   src/core/Function.cxx
@@ -72,7 +72,7 @@ SET(frida_HEADERS
   src/disassembler/Disassembler.hxx
   )
 
-ADD_EXECUTABLE(frida ${frida_SOURCES} ${frida_HEADERS_MOC})
+ADD_EXECUTABLE(frida src/main.cxx ${frida_SOURCES} ${frida_HEADERS_MOC})
 #ADD_LIBRARY(llvm SHARED )
 
 ADD_DEFINITIONS(${QT_DEFINITIONS})
@@ -88,11 +88,16 @@ TARGET_LINK_LIBRARIES(frida ${QT_LIBRARIES} ${LLVM_LDFLAGS} -lLLVM-3.5 ${LLVM_SY
 
 set(fridatest_SOURCES
   src/test.cxx
+  src/core/tests/BasicBlockTest.cxx
+  ${frida_SOURCES}
   )
 
 add_executable(fridatest ${fridatest_SOURCES})
+
+qt5_use_modules(fridatest Widgets)
+
 #ADD_SUBDIRECTORY(/usr/src/gtest gtest)
 ADD_SUBDIRECTORY(/usr/src/gmock gmock)
 enable_testing()
-target_link_libraries(fridatest gmock gtest gmock_main)
+target_link_libraries(fridatest gmock gtest gmock_main ${QT_LIBRARIES} ${LLVM_LDFLAGS} -lLLVM-3.5 ${LLVM_SYSTEM_LIBS} ${LOG4CXX_LDFLAGS} ${GUILE_LDFLAGS} ${QUAZIP_LIBRARIES})
 add_test( fridatest fridatest )
index 5681842ba92d18165167033d81a14c22ad59b863..f6eeb30f4cede67fbe4b28989993ea0815305133 100644 (file)
@@ -6,7 +6,8 @@
 #include <string>
 #include <map>
 
-class Disassembler;
+#include "disassembler/Disassembler.hxx"
+
 class Function;
 class BasicBlock;
 class Comment;
diff --git a/src/core/tests/BasicBlockTest.cxx b/src/core/tests/BasicBlockTest.cxx
new file mode 100644 (file)
index 0000000..0980af5
--- /dev/null
@@ -0,0 +1,62 @@
+#include <gtest/gtest.h>
+#include <algorithm>
+
+#include "gui/qt.hxx"
+#include "core/InformationManager.hxx"
+#include "core/BasicBlock.hxx"
+
+TEST(BasicBlockTest, deserializeValidInstance) {
+       QFile file("testdata/core/BasicBlock/valid.xml");
+       InformationManager manager;
+       file.open(QFile::ReadOnly | QFile::Text);
+       QXmlStreamReader reader(&file);
+
+       reader.readNextStartElement();
+       BasicBlock* block = BasicBlock::deserialize(reader, &manager);
+
+       ASSERT_NE((void*)NULL, (void*)block);
+       EXPECT_EQ(0x403e50, block->getStartAddress());
+       EXPECT_EQ(0x403e66, block->getEndAddress());
+       EXPECT_EQ(0x403e50, block->getNextBlock(0));
+       EXPECT_EQ(0x403e66, block->getNextBlock(1));
+}
+
+TEST(BasicBlockTest, deserializeInvalidInstance) {
+       QFile file("testdata/core/BasicBlock/invalid.xml");
+       InformationManager manager;
+       file.open(QFile::ReadOnly | QFile::Text);
+       QXmlStreamReader reader(&file);
+
+       reader.readNextStartElement();
+       BasicBlock* block = BasicBlock::deserialize(reader, &manager);
+
+       ASSERT_EQ((void*)NULL, (void*)block);
+}
+
+TEST(BasicBlockTest, deserializeThenSerializeIsIdentity) {
+       QFile infile("testdata/core/BasicBlock/valid.xml");
+       QTemporaryFile outfile;
+
+       InformationManager manager;
+       infile.open(QFile::ReadOnly | QFile::Text);
+       outfile.open();
+       QXmlStreamReader reader(&infile);
+       QXmlStreamWriter writer(&outfile);
+
+       reader.readNextStartElement();
+       BasicBlock* block = BasicBlock::deserialize(reader, &manager);
+       block->serialize(writer);
+
+       infile.seek(0);
+       outfile.seek(0);
+
+       std::string outtext = outfile.readAll().data();
+       outtext.erase(remove_if(outtext.begin(), outtext.end(), isspace),
+                     outtext.end());
+
+       std::string intext = infile.readAll().data();
+       intext.erase(remove_if(intext.begin(), intext.end(), isspace),
+                     intext.end());
+
+       ASSERT_STREQ(outtext.c_str(), intext.c_str());
+}
diff --git a/testdata/core/BasicBlock/invalid.xml b/testdata/core/BasicBlock/invalid.xml
new file mode 100644 (file)
index 0000000..61f9af2
--- /dev/null
@@ -0,0 +1,8 @@
+<block id="BLOCK_403e50_403e66">
+       <start>403e50</start>
+       <end>403e66</end>
+       <next>403e50</next>
+       <next>403e66</next>
+       <next>666</next>
+</block>
+
diff --git a/testdata/core/BasicBlock/valid.xml b/testdata/core/BasicBlock/valid.xml
new file mode 100644 (file)
index 0000000..c0502c7
--- /dev/null
@@ -0,0 +1,7 @@
+<block id="BLOCK_403e50_403e66">
+       <start>403e50</start>
+       <end>403e66</end>
+       <next>403e50</next>
+       <next>403e66</next>
+</block>
+