summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Potchik <brian@vector35.com>2020-09-13 23:11:32 -0400
committerBrian Potchik <brian@vector35.com>2020-09-13 23:11:32 -0400
commit1acc58d472470f96f12ac4dfc78dc221775d18d3 (patch)
tree4978099506a83fbbbd347a5d0d69b42a821c34e2
parent4b15ec8bebac3e04e954d4eb216df66cb101c02a (diff)
Disable logging during headless unit tests.
-rw-r--r--python/__init__.py5
-rw-r--r--python/examples/bin_info.py2
-rwxr-xr-xsuite/generator.py6
-rw-r--r--suite/testcommon.py5
4 files changed, 17 insertions, 1 deletions
diff --git a/python/__init__.py b/python/__init__.py
index db23a861..2d2da238 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -177,6 +177,11 @@ def _init_plugins():
_destruct_callbacks = _DestructionCallbackHandler()
+def disable_logging():
+ '''Disable logging in headless mode. By default, logging is enabled in headless mode.'''
+ _init_plugins()
+ close_logs()
+
def bundled_plugin_path():
"""
``bundled_plugin_path`` returns a string containing the current plugin path inside the `install path <https://docs.binary.ninja/getting-started.html#binary-path>`_
diff --git a/python/examples/bin_info.py b/python/examples/bin_info.py
index f74b9466..ca270493 100644
--- a/python/examples/bin_info.py
+++ b/python/examples/bin_info.py
@@ -26,6 +26,7 @@ import binaryninja.log as log
from binaryninja.binaryview import BinaryViewType
import binaryninja.interaction as interaction
from binaryninja.plugin import PluginCommand
+from binaryninja import disable_logging
# 2-3 compatibility
from binaryninja import range
@@ -76,6 +77,7 @@ def display_bininfo(bv):
if __name__ == "__main__":
+ disable_logging()
print(get_bininfo(None))
else:
PluginCommand.register("Binary Info", "Display basic info about the binary", display_bininfo)
diff --git a/suite/generator.py b/suite/generator.py
index a349789e..7f91a97f 100755
--- a/suite/generator.py
+++ b/suite/generator.py
@@ -125,12 +125,17 @@ class TestBinaryNinjaAPI(unittest.TestCase):
if __name__ == "__main__":
api_only = False
+ disable_logging = True
if len(sys.argv) > 1:
for i in range(1, len(sys.argv)):
if sys.argv[i] == '-v' or sys.argv[i] == '-V' or sys.argv[i] == '--verbose':
config.verbose = True
elif sys.argv[i] == '--api-only':
config.api_only = True
+ elif sys.argv[i] == '--log':
+ disable_logging = False
+ if disable_logging:
+ testcommon.disable_logging()
test_suite = unittest.defaultTestLoader.loadTestsFromModule(api_test)
test_suite = unittest.defaultTestLoader.loadTestsFromModule(rebasing_test)
@@ -322,6 +327,7 @@ def generate(test_store, outdir, exclude_binaries):
def main():
+ testcommon.disable_logging()
usage = "usage: %prog [-q] [-x] [-o <dir>] [-i <dir>]"
parser = OptionParser(usage=usage)
default_output = os.path.relpath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, "suite"))
diff --git a/suite/testcommon.py b/suite/testcommon.py
index 036dc8ac..4b49213e 100644
--- a/suite/testcommon.py
+++ b/suite/testcommon.py
@@ -60,6 +60,9 @@ def fixStrRepr(string):
return string.replace(b"\xe2\x80\xa6".decode("utf8"), "\\xe2\\x80\\xa6")
+def disable_logging():
+ binja.disable_logging()
+
def get_file_list(test_store_rel):
test_store = os.path.join(os.path.dirname(__file__), test_store_rel)
all_files = []
@@ -889,7 +892,7 @@ class VerifyBuilder(Builder):
try:
with binja.open_view(file_name) as bv:
# ConstantValue
- lhs = bv.parse_possiblevalueset("0", binja.RegisterValueType.ConstantValue)
+ lhs = bv.parse_possiblevalueset("0", binja.RegisterValueType.ConstantValue)
rhs = binja.PossibleValueSet.constant(0)
assert lhs == rhs
lhs = bv.parse_possiblevalueset("$here + 2", binja.RegisterValueType.ConstantValue, 0x2000)