[Cryptech-Commits] [sw/libhal] 01/02: Enable low-level debugging support in libhal.py.

git at cryptech.is git at cryptech.is
Thu Feb 2 19:07:32 UTC 2017


This is an automated email from the git hooks/post-receive script.

sra at hactrn.net pushed a commit to branch pymux
in repository sw/libhal.

commit 9ec81408c25207149d8b3bfcfc80faf1c8ff0811
Author: Rob Austein <sra at hactrn.net>
AuthorDate: Tue Jan 31 20:12:37 2017 -0500

    Enable low-level debugging support in libhal.py.
---
 libhal.py     | 4 ++--
 unit-tests.py | 8 ++------
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/libhal.py b/libhal.py
index 93746e1..7e8cc6f 100644
--- a/libhal.py
+++ b/libhal.py
@@ -417,7 +417,7 @@ class HSM(object):
 
     def _send(self, msg):       # Expects an xdrlib.Packer
         msg = slip_encode(msg.get_buffer())
-        #logger.debug("send: %s", ":".join("{:02x}".format(ord(c)) for c in msg))
+        logger.debug("send: %s", ":".join("{:02x}".format(ord(c)) for c in msg))
         self.socket.sendall(msg)
 
     def _recv(self, code):      # Returns an xdrlib.Unpacker
@@ -428,7 +428,7 @@ class HSM(object):
                 if msg[-1] == "":
                     raise HAL_ERROR_RPC_TRANSPORT()
                 msg.append(self.sockfile.read(1))
-            #logger.debug("recv: %s", ":".join("{:02x}".format(ord(c)) for c in msg))
+            logger.debug("recv: %s", ":".join("{:02x}".format(ord(c)) for c in msg))
             msg = slip_decode("".join(msg))
             if not msg:
                 continue
diff --git a/unit-tests.py b/unit-tests.py
index a8779c5..895bdb5 100644
--- a/unit-tests.py
+++ b/unit-tests.py
@@ -66,23 +66,19 @@ except ImportError:
     ecdsa_loaded = False
 
 
-def log(msg):
-    if not args.quiet:
-        sys.stderr.write(msg)
-        sys.stderr.write("\n")
-
-
 def main():
     from sys import argv
     global args
     args = parse_arguments(argv[1:])
     argv = argv[:1] + args.only_test
+    logging.basicConfig(level = logging.DEBUG if args.debug else logging.INFO)
     unittest.main(verbosity = 1 if args.quiet else 2, argv = argv, catchbreak = True, testRunner = TextTestRunner)
 
 def parse_arguments(argv = ()):
     from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
     parser = ArgumentParser(description = __doc__, formatter_class = ArgumentDefaultsHelpFormatter)
     parser.add_argument("--quiet",      action = "store_true",          help = "suppress chatter")
+    parser.add_argument("--debug",      action = "store_true",          help = "debug-level logging")
     parser.add_argument("--wheel-pin",  default = "fnord",              help = "PIN for wheel user")
     parser.add_argument("--so-pin",     default = "fnord",              help = "PIN for security officer")
     parser.add_argument("--user-pin",   default = "fnord",              help = "PIN for normal user")



More information about the Commits mailing list