diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2017-08-07 21:50:38 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2017-08-07 21:50:38 (GMT) |
commit | a9328553fc558bca2e75f2c93b35acc5518d9568 (patch) | |
tree | ce15e5259df278d386683dac217ec2b4a86e7c94 /tests | |
parent | 5f55377ff6c014d513f13b76ec5faf56c31da478 (diff) |
Stored all errors detected when loading and disassembling a binary file.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/arch/errors.py | 35 | ||||
-rw-r--r-- | tests/format/errors.py | 58 |
2 files changed, 93 insertions, 0 deletions
diff --git a/tests/arch/errors.py b/tests/arch/errors.py new file mode 100644 index 0000000..9d5e273 --- /dev/null +++ b/tests/arch/errors.py @@ -0,0 +1,35 @@ +#!/usr/bin/python3-dbg +# -*- coding: utf-8 -*- + + +# Tests minimalistes pour valider la gestion des erreurs relevées. + + +from chrysacase import ChrysalideTestCase +from pychrysalide.arch import vmpa +from pychrysalide.arch import ArchProcessor + + +class TestArchErrors(ChrysalideTestCase): + """TestCase for arch.ArchProcessor errors.""" + + def testBasic(self): + """Perform some sanity tests on architecture error handling.""" + + errlen = 3 + + pattern = [] + + for i in range(errlen): + + addr = vmpa(vmpa.VMPA_NO_PHYSICAL, 0x100 + i * 0x10) + + pattern.append([ArchProcessor.APE_LABEL, addr, 'random desc #%d' % i]) + + proc = ArchProcessor() + + for i in range(errlen): + + proc.add_error(pattern[i][0], pattern[i][1], pattern[i][2]) + + self.assertEqual(len(proc.errors), errlen) diff --git a/tests/format/errors.py b/tests/format/errors.py new file mode 100644 index 0000000..36b7129 --- /dev/null +++ b/tests/format/errors.py @@ -0,0 +1,58 @@ +#!/usr/bin/python3-dbg +# -*- coding: utf-8 -*- + + +# Tests minimalistes pour valider la gestion des erreurs relevées. + + +from chrysacase import ChrysalideTestCase +from pychrysalide.analysis.contents import FileContent +from pychrysalide.arch import vmpa +from pychrysalide.format import BinFormat +from pychrysalide.format.elf import ElfFormat +import os +import sys + + +class TestFormatErrors(ChrysalideTestCase): + """TestCase for format.BinFormat errors.""" + + @classmethod + def setUpClass(cls): + + super(TestFormatErrors, cls).setUpClass() + + cls.log('Compile binary "strings" if needed...') + + fullname = sys.modules[cls.__module__].__file__ + dirpath = os.path.dirname(fullname) + + os.system('make -C %s%self strings 2>&1 > /dev/null' % (dirpath, os.sep)) + + + def testBasic(self): + """Perform some sanity tests on format error handling.""" + + errlen = 3 + + pattern = [] + + for i in range(errlen): + + addr = vmpa(vmpa.VMPA_NO_PHYSICAL, 0x100 + i * 0x10) + + pattern.append([BinFormat.BFE_STRUCTURE, addr, 'random desc #%d' % i]) + + fullname = sys.modules[self.__class__.__module__].__file__ + filename = os.path.basename(fullname) + + baselen = len(fullname) - len(filename) + + cnt = FileContent(fullname[:baselen] + 'elf' + os.sep + 'strings') + fmt = ElfFormat(cnt, None, None) + + for i in range(errlen): + + fmt.add_error(pattern[i][0], pattern[i][1], pattern[i][2]) + + self.assertEqual(len(fmt.errors), errlen) |