summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Potchik <brian@vector35.com>2020-05-31 15:10:51 -0400
committerBrian Potchik <brian@vector35.com>2020-05-31 15:10:51 -0400
commit260458c7c753d66e384ba9b534ab70a474ae7b65 (patch)
treefd4ce5e7b84504828be15e2ccd6899f3bf56bb54
parentc5ae680e93164baf7499ac6822ab0621a5af24d6 (diff)
Remove rebasing unittests from API submodule.
-rw-r--r--suite/api_test.py111
m---------suite/binaries0
-rwxr-xr-xsuite/generator.py4
3 files changed, 3 insertions, 112 deletions
diff --git a/suite/api_test.py b/suite/api_test.py
index 90ba6c7d..894e17d3 100644
--- a/suite/api_test.py
+++ b/suite/api_test.py
@@ -1,11 +1,6 @@
import unittest
import platform
import os
-import sys
-import pickle
-import zipfile
-import difflib
-from collections import Counter
from binaryninja.binaryview import BinaryView, BinaryViewType
from binaryninja.settings import Settings, SettingsScope
@@ -13,12 +8,6 @@ from binaryninja.metadata import Metadata
from binaryninja.demangle import demangle_gnu3, get_qualified_name
from binaryninja.architecture import Architecture
-api_suite_path = os.path.join(os.path.dirname(os.path.realpath(__file__)))
-sys.path.append(api_suite_path)
-import testcommon
-
-global verbose
-verbose = False
class SettingsAPI(unittest.TestCase):
@classmethod
@@ -185,106 +174,6 @@ class SettingsAPI(unittest.TestCase):
assert len(mapped_view) == 4, "test_load_settings failed"
-class RebaseAPI(unittest.TestCase):
- @classmethod
- def setUpClass(cls):
- pass
-
- @classmethod
- def tearDownClass(cls):
- pass
-
- # Returns a tuple of:
- # bool : Two lists are equal
- # string : The string diff
- # Args:
- # list
- # list : (compare list one vs list two)
- # string : anything additional wanted to be printed before the string diff
- # bool : the ordering of the items in the two lists must be the same
- def report(self, oracle, test, firstText='', strictOrdering = False):
- stringDiff = ""
-
- equality = False
- if not strictOrdering:
- equality = (Counter(oracle) == Counter(test))
- else:
- equality = (oracle == test)
-
- if equality:
- return (True, '')
- elif not strictOrdering:
- try:
- for elem in oracle:
- test.remove(elem)
- oracle.remove(elem) # If it's not in the test, it won't get here!
- except ValueError:
- pass
-
- differ = difflib.Differ(charjunk=difflib.IS_CHARACTER_JUNK)
- skipped_lines = 0
- for delta in differ.compare(oracle, test):
- if delta[0] == ' ':
- skipped_lines += 1
- continue
- if skipped_lines > 0:
- stringDiff += "<---" + str(skipped_lines) + ' same lines--->\n'
- skipped_lines = 0
- delta = delta.replace('\n', '')
- stringDiff += delta + '\n'
-
- stringDiffList = stringDiff.split('\n')
-
- if len(stringDiffList) > 10:
- if not verbose:
- stringDiff = '\n'.join(line if len(line) <= 100 else line[:100] + "...and " + str(len(line) - 100) + " more characters" for line in stringDiffList[:10])
- stringDiff += '\n\n### And ' + str(len(stringDiffList)) + " more lines, use '-v' to show ###"
- elif not verbose:
- stringDiff = '\n'.join(line if len(line) <= 100 else line[:100] + "...and " + str(len(line) - 100) + " more characters" for line in stringDiffList)
- stringDiff = '\n\n' + firstText + stringDiff
- return (equality, stringDiff)
-
- def run_rebase_test(self, testfile):
- testname = None
- with zipfile.ZipFile(os.path.join(api_suite_path, testfile), "r") as zf:
- testname = zf.namelist()[0]
- zf.extractall(path=api_suite_path)
-
- pickle_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), testname + "_rebasing.pkl")
- self.assertTrue(pickle_path, "Test pickle doesn't exist")
- try:
- # Python 2 does not have the encodings option
- binary_oracle = pickle.load(open(pickle_path, "rb"), encoding='charmap')
- except TypeError:
- binary_oracle = pickle.load(open(pickle_path, "rb"))
-
- test_builder = testcommon.BinaryViewTestBuilder(testname, imageBase=0xf00000)
- self.assertTrue(test_builder.bv.start == 0xf00000)
- for method in test_builder.methods():
- test = getattr(test_builder, method)()
- oracle = binary_oracle[method]
- if test == oracle:
- continue
-
- result = getattr(test_builder, method).__doc__
- result += ":\n"
- report = self.report(oracle, test, result)
- self.assertTrue(report[0], report[1]) # Test does not agree with oracle
- os.unlink(os.path.join(api_suite_path, testname))
-
- def test_rebasing__elf(self):
- self.run_rebase_test('binaries/test_corpus/helloworld.zip')
-
- def test_rebasing__macho(self):
- self.run_rebase_test('binaries/test_corpus/duff.zip')
-
- def test_rebasing__pe(self):
- self.run_rebase_test('binaries/test_corpus/partial_register_dataflow.zip')
-
- def test_rebasing__raw(self):
- self.run_rebase_test('binaries/test_corpus/raw.zip')
-
-
class MetaddataAPI(unittest.TestCase):
def test_metadata_basic_types(self):
# Core is tested thoroughly through the C++ unit tests here we focus on the python api side
diff --git a/suite/binaries b/suite/binaries
-Subproject bf241255e99bcbec0d34536d7bb6f29593757b9
+Subproject 682daed19a9b7e25320b5261f43f39e809e063d
diff --git a/suite/generator.py b/suite/generator.py
index 2fe7e8e0..78925e97 100755
--- a/suite/generator.py
+++ b/suite/generator.py
@@ -21,6 +21,7 @@ api_suite_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), {4})
sys.path.append(api_suite_path)
import testcommon
import api_test
+import rebasing_test
global verbose
verbose = False
@@ -126,6 +127,7 @@ if __name__ == "__main__":
api_only = True
test_suite = unittest.defaultTestLoader.loadTestsFromModule(api_test)
+ test_suite = unittest.defaultTestLoader.loadTestsFromModule(rebasing_test)
if not api_only:
test_suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(TestBinaryNinjaAPI))
runner = unittest.TextTestRunner(verbosity=2)
@@ -294,7 +296,7 @@ def generate(test_store, outdir, exclude_binaries):
name = oraclefile_rel[len(test_store):].replace(os.path.sep, "_").replace(".", "_")[1:]
if name in ["helloworld", "duff", "partial_register_dataflow", "raw"]:
test_data = testcommon.BinaryViewTestBuilder(oraclefile_rel, imageBase=0xf00000)
- binary_oracle = OracleTestFile(oraclefile + "_rebasing")
+ binary_oracle = OracleTestFile(os.path.join(outdir, oraclefile_rel) + "_rebasing")
for method in test_data.methods():
binary_oracle.add_entry(test_data, method)
binary_oracle.close()