tests: Handle hostapd dying more gracefully
Catch exceptions from operations that try to remove hostapd interface and rename the log file. If these operations fail due to socket connection issues, hostapd has likely died or gotten stuck somewhere. Report the test case as a failure and stop test run cleanly. Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>
This commit is contained in:
parent
217cf4991d
commit
66f0bdb465
1 changed files with 36 additions and 10 deletions
|
@ -24,17 +24,25 @@ from hostapd import HostapdGlobal
|
||||||
from check_kernel import check_kernel
|
from check_kernel import check_kernel
|
||||||
|
|
||||||
def reset_devs(dev, apdev):
|
def reset_devs(dev, apdev):
|
||||||
hapd = HostapdGlobal()
|
ok = True
|
||||||
for d in dev:
|
for d in dev:
|
||||||
try:
|
try:
|
||||||
d.reset()
|
d.reset()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.info("Failed to reset device " + d.ifname)
|
logger.info("Failed to reset device " + d.ifname)
|
||||||
print str(e)
|
print str(e)
|
||||||
|
ok = False
|
||||||
|
try:
|
||||||
|
hapd = HostapdGlobal()
|
||||||
hapd.remove('wlan3-3')
|
hapd.remove('wlan3-3')
|
||||||
hapd.remove('wlan3-2')
|
hapd.remove('wlan3-2')
|
||||||
for ap in apdev:
|
for ap in apdev:
|
||||||
hapd.remove(ap['ifname'])
|
hapd.remove(ap['ifname'])
|
||||||
|
except Exception, e:
|
||||||
|
logger.info("Failed to remove hostapd interface")
|
||||||
|
print str(e)
|
||||||
|
ok = False
|
||||||
|
return ok
|
||||||
|
|
||||||
def report(conn, prefill, build, commit, run, test, result, duration):
|
def report(conn, prefill, build, commit, run, test, result, duration):
|
||||||
if conn:
|
if conn:
|
||||||
|
@ -89,6 +97,7 @@ def rename_log(logdir, basename, testname, dev):
|
||||||
testname + '.' + basename + '-' + str(num))
|
testname + '.' + basename + '-' + str(num))
|
||||||
num = num + 1
|
num = num + 1
|
||||||
os.rename(srcname, dstname)
|
os.rename(srcname, dstname)
|
||||||
|
if dev:
|
||||||
dev.relog()
|
dev.relog()
|
||||||
subprocess.call(['sudo', 'chown', '-f', getpass.getuser(), srcname])
|
subprocess.call(['sudo', 'chown', '-f', getpass.getuser(), srcname])
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
|
@ -226,7 +235,11 @@ def main():
|
||||||
|
|
||||||
# make sure nothing is left over from previous runs
|
# make sure nothing is left over from previous runs
|
||||||
# (if there were any other manual runs or we crashed)
|
# (if there were any other manual runs or we crashed)
|
||||||
reset_devs(dev, apdev)
|
if not reset_devs(dev, apdev):
|
||||||
|
if conn:
|
||||||
|
conn.close()
|
||||||
|
conn = None
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if args.dmesg:
|
if args.dmesg:
|
||||||
subprocess.call(['sudo', 'dmesg', '-c'], stdout=open('/dev/null', 'w'))
|
subprocess.call(['sudo', 'dmesg', '-c'], stdout=open('/dev/null', 'w'))
|
||||||
|
@ -262,6 +275,7 @@ def main():
|
||||||
log_handler.setFormatter(log_formatter)
|
log_handler.setFormatter(log_formatter)
|
||||||
logger.addHandler(log_handler)
|
logger.addHandler(log_handler)
|
||||||
|
|
||||||
|
reset_ok = True
|
||||||
with DataCollector(args.logdir, name, args.tracing, args.dmesg):
|
with DataCollector(args.logdir, name, args.tracing, args.dmesg):
|
||||||
logger.info("START " + name)
|
logger.info("START " + name)
|
||||||
if args.loglevel == logging.WARNING:
|
if args.loglevel == logging.WARNING:
|
||||||
|
@ -299,15 +313,23 @@ def main():
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.info("Failed to issue TEST-STOP after {} for {}".format(name, d.ifname))
|
logger.info("Failed to issue TEST-STOP after {} for {}".format(name, d.ifname))
|
||||||
logger.info(e)
|
logger.info(e)
|
||||||
|
result = "FAIL"
|
||||||
if args.no_reset:
|
if args.no_reset:
|
||||||
print "Leaving devices in current state"
|
print "Leaving devices in current state"
|
||||||
else:
|
else:
|
||||||
reset_devs(dev, apdev)
|
reset_ok = reset_devs(dev, apdev)
|
||||||
|
|
||||||
for i in range(0, 3):
|
for i in range(0, 3):
|
||||||
rename_log(args.logdir, 'log' + str(i), name, dev[i])
|
rename_log(args.logdir, 'log' + str(i), name, dev[i])
|
||||||
|
|
||||||
|
try:
|
||||||
hapd = HostapdGlobal()
|
hapd = HostapdGlobal()
|
||||||
|
except Exception, e:
|
||||||
|
print "Failed to connect to hostapd interface"
|
||||||
|
print str(e)
|
||||||
|
reset_ok = False
|
||||||
|
result = "FAIL"
|
||||||
|
hapd = None
|
||||||
rename_log(args.logdir, 'hostapd', name, hapd)
|
rename_log(args.logdir, 'hostapd', name, hapd)
|
||||||
|
|
||||||
end = datetime.now()
|
end = datetime.now()
|
||||||
|
@ -331,6 +353,10 @@ def main():
|
||||||
print result
|
print result
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
if not reset_ok:
|
||||||
|
print "Terminating early due to device reset failure"
|
||||||
|
break
|
||||||
|
|
||||||
if log_handler:
|
if log_handler:
|
||||||
log_handler.stream.close()
|
log_handler.stream.close()
|
||||||
logger.removeHandler(log_handler)
|
logger.removeHandler(log_handler)
|
||||||
|
|
Loading…
Reference in a new issue