]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Log sigma_dut stdout/stderr separately for each command
authorJouni Malinen <jouni@codeaurora.org>
Thu, 9 Jan 2020 21:31:29 +0000 (23:31 +0200)
committerJouni Malinen <j@w1.fi>
Thu, 9 Jan 2020 21:31:29 +0000 (23:31 +0200)
This makes logs easier to understand and this may also help in running
over buffer space and getting stuck with sigma_dut termination.

Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
tests/hwsim/test_sigma_dut.py

index d3ffb5f5b5fe476d8e88456c70b9815d77a8e14a..ff7db302a3b1e594098e5d403c5ae2b344535d36 100644 (file)
@@ -6,6 +6,8 @@
 # See README for more details.
 
 import binascii
+import errno
+import fcntl
 import hashlib
 import logging
 logger = logging.getLogger()
@@ -35,6 +37,24 @@ def to_hex(s):
 def from_hex(s):
     return binascii.unhexlify(s).decode()
 
+def sigma_log_output(cmd):
+    try:
+        out = cmd.stdout.read()
+        if out:
+            logger.debug("sigma_dut stdout: " + str(out.decode()))
+    except IOError as e:
+        if e.errno != errno.EAGAIN:
+            raise
+    try:
+        out = cmd.stderr.read()
+        if out:
+            logger.debug("sigma_dut stderr: " + str(out.decode()))
+    except IOError as e:
+        if e.errno != errno.EAGAIN:
+            raise
+
+sigma_prog = None
+
 def sigma_dut_cmd(cmd, port=9000, timeout=2):
     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
                          socket.IPPROTO_TCP)
@@ -64,6 +84,9 @@ def sigma_dut_cmd(cmd, port=9000, timeout=2):
     sock.close()
     res = res.rstrip()
     logger.debug("sigma_dut: '%s' --> '%s'" % (cmd, res))
+    global sigma_prog
+    if sigma_prog:
+        sigma_log_output(sigma_prog)
     return res
 
 def sigma_dut_cmd_check(cmd, port=9000, timeout=2):
@@ -94,6 +117,13 @@ def start_sigma_dut(ifname, debug=False, hostapd_logdir=None, cert_path=None,
         cmd += ['-2']
     sigma = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE)
+    for stream in [sigma.stdout, sigma.stderr]:
+        fd = stream.fileno()
+        fl = fcntl.fcntl(fd, fcntl.F_GETFL)
+        fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
+
+    global sigma_prog
+    sigma_prog = sigma
     for i in range(20):
         try:
             res = sigma_dut_cmd("HELLO")
@@ -103,7 +133,11 @@ def start_sigma_dut(ifname, debug=False, hostapd_logdir=None, cert_path=None,
     return {'cmd': sigma, 'ifname': ifname}
 
 def stop_sigma_dut(sigma):
+    global sigma_prog
+    sigma_prog = None
     cmd = sigma['cmd']
+    sigma_log_output(cmd)
+    logger.debug("Terminating sigma_dut process")
     cmd.terminate()
     cmd.wait()
     out, err = cmd.communicate()