summaryrefslogtreecommitdiff
path: root/tests/analysis/disass
diff options
context:
space:
mode:
Diffstat (limited to 'tests/analysis/disass')
-rw-r--r--tests/analysis/disass/Makefile10
-rw-r--r--tests/analysis/disass/__init__.py0
-rw-r--r--tests/analysis/disass/block.py74
-rw-r--r--tests/analysis/disass/hello.c12
4 files changed, 96 insertions, 0 deletions
diff --git a/tests/analysis/disass/Makefile b/tests/analysis/disass/Makefile
new file mode 100644
index 0000000..6f12036
--- /dev/null
+++ b/tests/analysis/disass/Makefile
@@ -0,0 +1,10 @@
+
+EXECUTABLES=hello
+
+all: $(EXECUTABLES)
+
+hello: hello.c
+ $(ARM_CROSS)gcc $< -o $@
+
+clean:
+ rm -f $(EXECUTABLES)
diff --git a/tests/analysis/disass/__init__.py b/tests/analysis/disass/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/analysis/disass/__init__.py
diff --git a/tests/analysis/disass/block.py b/tests/analysis/disass/block.py
new file mode 100644
index 0000000..8de44e1
--- /dev/null
+++ b/tests/analysis/disass/block.py
@@ -0,0 +1,74 @@
+#!/usr/bin/python3
+# -*- coding: utf-8 -*-
+
+
+# S'assure du bon fonctionnement des blocs basiques
+
+
+from chrysacase import ChrysalideTestCase
+from pychrysalide.analysis.contents import FileContent
+from pychrysalide.analysis import LoadedBinary
+from pychrysalide.format.elf import ElfFormat
+import os
+import sys
+
+
+class TestBasicBlocks(ChrysalideTestCase):
+ """TestCase for basic blocks."""
+
+ @classmethod
+ def setUpClass(cls):
+
+ super(TestBasicBlocks, cls).setUpClass()
+
+ cls.log('Compile binary "hello" if needed...')
+
+ fullname = sys.modules[cls.__module__].__file__
+ dirpath = os.path.dirname(fullname)
+
+ os.system('make -C %s hello 2>&1 > /dev/null' % dirpath)
+
+
+ @classmethod
+ def tearDownClass(cls):
+
+ super(TestBasicBlocks, cls).tearDownClass()
+
+ cls.log('Delete built binaries...')
+
+ fullname = sys.modules[cls.__module__].__file__
+ dirpath = os.path.dirname(fullname)
+
+ os.system('make -C %s clean 2>&1 > /dev/null' % dirpath)
+
+
+ def testBlockList(self):
+ """Check basic tests for basic block list."""
+
+ fullname = sys.modules[self.__class__.__module__].__file__
+ filename = os.path.basename(fullname)
+
+ baselen = len(fullname) - len(filename)
+
+ cnt = FileContent(fullname[:baselen] + 'hello')
+ self.assertIsNotNone(cnt)
+
+ fmt = ElfFormat(cnt)
+ self.assertIsNotNone(fmt)
+
+ binary = LoadedBinary(fmt)
+ self.assertIsNotNone(binary)
+
+ binary.analyze_and_wait()
+
+ sym = fmt.find_symbol_by_label('main')
+ self.assertIsNotNone(sym)
+
+ found = sym.basic_blocks.find_by_starting_addr(sym.range.addr)
+ self.assertIsNotNone(found)
+
+ self.assertEqual(found, sym.basic_blocks.items[0])
+
+ self.assertEqual(found.index, 0)
+
+ self.assertEqual(found.rank, 0)
diff --git a/tests/analysis/disass/hello.c b/tests/analysis/disass/hello.c
new file mode 100644
index 0000000..c226e8a
--- /dev/null
+++ b/tests/analysis/disass/hello.c
@@ -0,0 +1,12 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+
+
+int main(void)
+{
+ printf("Hello World!\n");
+
+ return EXIT_SUCCESS;
+
+}