tests: Log sigma_dut stdout/stderr separately for each command
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>
This commit is contained in:
parent
4bf78a79d0
commit
fb0f13fbf8
1 changed files with 34 additions and 0 deletions
|
@ -6,6 +6,8 @@
|
||||||
# See README for more details.
|
# See README for more details.
|
||||||
|
|
||||||
import binascii
|
import binascii
|
||||||
|
import errno
|
||||||
|
import fcntl
|
||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
@ -35,6 +37,24 @@ def to_hex(s):
|
||||||
def from_hex(s):
|
def from_hex(s):
|
||||||
return binascii.unhexlify(s).decode()
|
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):
|
def sigma_dut_cmd(cmd, port=9000, timeout=2):
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
|
||||||
socket.IPPROTO_TCP)
|
socket.IPPROTO_TCP)
|
||||||
|
@ -64,6 +84,9 @@ def sigma_dut_cmd(cmd, port=9000, timeout=2):
|
||||||
sock.close()
|
sock.close()
|
||||||
res = res.rstrip()
|
res = res.rstrip()
|
||||||
logger.debug("sigma_dut: '%s' --> '%s'" % (cmd, res))
|
logger.debug("sigma_dut: '%s' --> '%s'" % (cmd, res))
|
||||||
|
global sigma_prog
|
||||||
|
if sigma_prog:
|
||||||
|
sigma_log_output(sigma_prog)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def sigma_dut_cmd_check(cmd, port=9000, timeout=2):
|
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']
|
cmd += ['-2']
|
||||||
sigma = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
sigma = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
||||||
stderr=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):
|
for i in range(20):
|
||||||
try:
|
try:
|
||||||
res = sigma_dut_cmd("HELLO")
|
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}
|
return {'cmd': sigma, 'ifname': ifname}
|
||||||
|
|
||||||
def stop_sigma_dut(sigma):
|
def stop_sigma_dut(sigma):
|
||||||
|
global sigma_prog
|
||||||
|
sigma_prog = None
|
||||||
cmd = sigma['cmd']
|
cmd = sigma['cmd']
|
||||||
|
sigma_log_output(cmd)
|
||||||
|
logger.debug("Terminating sigma_dut process")
|
||||||
cmd.terminate()
|
cmd.terminate()
|
||||||
cmd.wait()
|
cmd.wait()
|
||||||
out, err = cmd.communicate()
|
out, err = cmd.communicate()
|
||||||
|
|
Loading…
Reference in a new issue