2013-03-27 08:40:10 -04:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
2013-03-29 12:37:03 -04:00
|
|
|
# AP tests
|
2013-03-27 08:40:10 -04:00
|
|
|
# Copyright (c) 2013, Jouni Malinen <j@w1.fi>
|
|
|
|
#
|
|
|
|
# This software may be distributed under the terms of the BSD license.
|
|
|
|
# See README for more details.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import time
|
2013-10-26 18:05:45 -04:00
|
|
|
import sqlite3
|
2013-09-28 11:20:32 -04:00
|
|
|
from datetime import datetime
|
2013-03-27 08:40:10 -04:00
|
|
|
|
|
|
|
import logging
|
2013-08-24 12:48:04 -04:00
|
|
|
logger = logging.getLogger(__name__)
|
2013-03-27 08:40:10 -04:00
|
|
|
|
2013-10-27 12:28:28 -04:00
|
|
|
sys.path.append('../../wpaspy')
|
|
|
|
|
2013-03-27 08:40:10 -04:00
|
|
|
from wpasupplicant import WpaSupplicant
|
2013-03-29 12:37:03 -04:00
|
|
|
from hostapd import HostapdGlobal
|
|
|
|
|
2013-03-31 09:16:37 -04:00
|
|
|
def reset_devs(dev, apdev):
|
|
|
|
hapd = HostapdGlobal()
|
2013-03-31 13:32:33 -04:00
|
|
|
for d in dev:
|
2013-08-24 14:16:04 -04:00
|
|
|
try:
|
|
|
|
d.reset()
|
|
|
|
except Exception, e:
|
|
|
|
logger.info("Failed to reset device " + d.ifname)
|
2013-09-28 11:20:32 -04:00
|
|
|
print str(e)
|
2013-03-31 17:59:50 -04:00
|
|
|
for ap in apdev:
|
|
|
|
hapd.remove(ap['ifname'])
|
2013-03-27 08:40:10 -04:00
|
|
|
|
2013-10-26 18:05:45 -04:00
|
|
|
def report(conn, build, commit, run, test, result, diff):
|
|
|
|
if conn:
|
|
|
|
if not build:
|
|
|
|
build = ''
|
|
|
|
if not commit:
|
|
|
|
commit = ''
|
|
|
|
sql = "INSERT INTO results(test,result,run,time,duration,build,commitid) VALUES('" + test.replace('test_', '', 1) + "', '" + result + "', " + str(run) + ", " + str(time.time()) + ", " + str(diff.total_seconds()) + ", '" + build + "', '" + commit + "')"
|
|
|
|
try:
|
|
|
|
conn.execute(sql)
|
|
|
|
conn.commit()
|
|
|
|
except Exception, e:
|
|
|
|
print "sqlite: " + str(e)
|
|
|
|
print "sql: " + sql
|
|
|
|
|
2013-03-27 08:40:10 -04:00
|
|
|
def main():
|
2013-03-31 09:29:16 -04:00
|
|
|
test_file = None
|
2013-04-26 06:48:48 -04:00
|
|
|
error_file = None
|
2013-08-25 13:15:54 -04:00
|
|
|
log_file = None
|
2013-09-28 11:31:00 -04:00
|
|
|
results_file = None
|
2013-10-26 18:05:45 -04:00
|
|
|
conn = None
|
|
|
|
run = None
|
|
|
|
build = None
|
|
|
|
commit = None
|
2013-03-27 08:40:10 -04:00
|
|
|
idx = 1
|
2013-09-29 09:07:01 -04:00
|
|
|
print_res = False
|
2013-03-27 08:40:10 -04:00
|
|
|
if len(sys.argv) > 1 and sys.argv[1] == '-d':
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
idx = idx + 1
|
|
|
|
elif len(sys.argv) > 1 and sys.argv[1] == '-q':
|
|
|
|
logging.basicConfig(level=logging.WARNING)
|
2013-09-29 09:07:01 -04:00
|
|
|
print_res = True
|
2013-03-27 08:40:10 -04:00
|
|
|
idx = idx + 1
|
2013-08-25 13:15:54 -04:00
|
|
|
elif len(sys.argv) > 2 and sys.argv[1] == '-l':
|
|
|
|
log_file = sys.argv[2]
|
|
|
|
logging.basicConfig(filename=log_file,level=logging.DEBUG)
|
|
|
|
idx = idx + 2
|
2013-03-27 08:40:10 -04:00
|
|
|
else:
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
2013-09-28 11:35:17 -04:00
|
|
|
while len(sys.argv) > idx:
|
|
|
|
if len(sys.argv) > idx + 1 and sys.argv[idx] == '-e':
|
|
|
|
error_file = sys.argv[idx + 1]
|
|
|
|
idx = idx + 2
|
|
|
|
elif len(sys.argv) > idx + 1 and sys.argv[idx] == '-r':
|
|
|
|
results_file = sys.argv[idx + 1]
|
|
|
|
idx = idx + 2
|
|
|
|
elif len(sys.argv) > idx + 1 and sys.argv[idx] == '-f':
|
|
|
|
test_file = sys.argv[idx + 1]
|
|
|
|
idx = idx + 2
|
2013-10-26 18:05:45 -04:00
|
|
|
elif len(sys.argv) > idx + 1 and sys.argv[idx] == '-S':
|
|
|
|
conn = sqlite3.connect(sys.argv[idx + 1])
|
|
|
|
idx = idx + 2
|
|
|
|
elif len(sys.argv) > idx + 1 and sys.argv[idx] == '-b':
|
|
|
|
build = sys.argv[idx + 1]
|
|
|
|
idx = idx + 2
|
2013-09-28 11:35:17 -04:00
|
|
|
else:
|
|
|
|
break
|
2013-03-31 09:29:16 -04:00
|
|
|
|
2013-10-26 18:05:45 -04:00
|
|
|
if conn:
|
|
|
|
run = str(int(time.time()))
|
2013-10-27 06:16:36 -04:00
|
|
|
try:
|
|
|
|
with open("commit") as f:
|
|
|
|
val = f.readlines()
|
|
|
|
if len(val) > 0:
|
|
|
|
commit = val[0].rstrip()
|
|
|
|
except IOError:
|
|
|
|
pass
|
2013-10-26 18:05:45 -04:00
|
|
|
|
2013-09-29 09:11:48 -04:00
|
|
|
tests = []
|
|
|
|
for t in os.listdir("."):
|
|
|
|
m = re.match(r'(test_.*)\.py$', t)
|
|
|
|
if m:
|
|
|
|
if test_file and test_file not in t:
|
|
|
|
continue
|
|
|
|
logger.debug("Import test cases from " + t)
|
|
|
|
mod = __import__(m.group(1))
|
|
|
|
for s in dir(mod):
|
|
|
|
if s.startswith("test_"):
|
|
|
|
func = mod.__dict__.get(s)
|
|
|
|
tests.append(func)
|
|
|
|
|
2013-10-27 06:16:36 -04:00
|
|
|
if len(sys.argv) > idx and sys.argv[idx] == '-L':
|
2013-09-29 09:11:48 -04:00
|
|
|
for t in tests:
|
|
|
|
print t.__name__ + " - " + t.__doc__
|
2013-10-27 06:16:36 -04:00
|
|
|
if conn:
|
|
|
|
sql = 'INSERT OR REPLACE INTO tests(test,description) VALUES ("' + t.__name__.replace('test_', '', 1) + '", "' + t.__doc__ + '")';
|
|
|
|
try:
|
|
|
|
conn.execute(sql)
|
|
|
|
except Exception, e:
|
|
|
|
print "sqlite: " + str(e)
|
|
|
|
print "sql: " + sql
|
|
|
|
if conn:
|
|
|
|
conn.commit()
|
|
|
|
conn.close()
|
2013-09-29 09:11:48 -04:00
|
|
|
sys.exit(0)
|
|
|
|
|
2013-03-27 08:40:10 -04:00
|
|
|
if len(sys.argv) > idx:
|
|
|
|
test_filter = sys.argv[idx]
|
|
|
|
else:
|
|
|
|
test_filter = None
|
|
|
|
|
2013-06-30 17:13:11 -04:00
|
|
|
dev0 = WpaSupplicant('wlan0', '/tmp/wpas-wlan0')
|
|
|
|
dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
|
|
|
|
dev2 = WpaSupplicant('wlan2', '/tmp/wpas-wlan2')
|
2013-03-31 09:19:12 -04:00
|
|
|
dev = [ dev0, dev1, dev2 ]
|
2013-03-31 09:16:37 -04:00
|
|
|
apdev = [ ]
|
|
|
|
apdev.append({"ifname": 'wlan3', "bssid": "02:00:00:00:03:00"})
|
2013-03-31 09:19:12 -04:00
|
|
|
apdev.append({"ifname": 'wlan4', "bssid": "02:00:00:00:04:00"})
|
2013-03-27 08:40:10 -04:00
|
|
|
|
|
|
|
for d in dev:
|
|
|
|
if not d.ping():
|
2013-08-24 12:48:04 -04:00
|
|
|
logger.info(d.ifname + ": No response from wpa_supplicant")
|
2013-03-27 08:40:10 -04:00
|
|
|
return
|
2013-08-24 12:48:04 -04:00
|
|
|
logger.info("DEV: " + d.ifname + ": " + d.p2p_dev_addr())
|
2013-03-31 09:16:37 -04:00
|
|
|
for ap in apdev:
|
2013-08-24 12:48:04 -04:00
|
|
|
logger.info("APDEV: " + ap['ifname'])
|
2013-03-27 08:40:10 -04:00
|
|
|
|
|
|
|
passed = []
|
2013-09-29 09:21:42 -04:00
|
|
|
skipped = []
|
2013-03-27 08:40:10 -04:00
|
|
|
failed = []
|
|
|
|
|
|
|
|
for t in tests:
|
|
|
|
if test_filter:
|
|
|
|
if test_filter != t.__name__:
|
|
|
|
continue
|
2013-03-31 09:16:37 -04:00
|
|
|
reset_devs(dev, apdev)
|
2013-08-24 12:48:04 -04:00
|
|
|
logger.info("START " + t.__name__)
|
2013-08-25 13:15:54 -04:00
|
|
|
if log_file:
|
|
|
|
print "START " + t.__name__
|
2013-09-29 13:42:37 -04:00
|
|
|
sys.stdout.flush()
|
2013-03-27 08:40:10 -04:00
|
|
|
if t.__doc__:
|
2013-08-24 12:48:04 -04:00
|
|
|
logger.info("Test: " + t.__doc__)
|
2013-09-28 11:20:32 -04:00
|
|
|
start = datetime.now()
|
2013-03-27 08:40:10 -04:00
|
|
|
for d in dev:
|
2013-08-24 12:41:08 -04:00
|
|
|
try:
|
|
|
|
d.request("NOTE TEST-START " + t.__name__)
|
|
|
|
except Exception, e:
|
2013-08-24 12:48:04 -04:00
|
|
|
logger.info("Failed to issue TEST-START before " + t.__name__ + " for " + d.ifname)
|
|
|
|
logger.info(e)
|
2013-10-20 12:14:41 -04:00
|
|
|
print "FAIL " + t.__name__ + " - could not start test"
|
2013-10-26 18:05:45 -04:00
|
|
|
if conn:
|
|
|
|
conn.close()
|
|
|
|
conn = None
|
2013-10-20 12:14:41 -04:00
|
|
|
sys.exit(1)
|
2013-03-27 08:40:10 -04:00
|
|
|
try:
|
2013-03-31 09:16:37 -04:00
|
|
|
if t.func_code.co_argcount > 1:
|
2013-09-29 09:21:42 -04:00
|
|
|
res = t(dev, apdev)
|
2013-03-31 09:16:37 -04:00
|
|
|
else:
|
2013-09-29 09:21:42 -04:00
|
|
|
res = t(dev)
|
2013-09-28 11:20:32 -04:00
|
|
|
end = datetime.now()
|
|
|
|
diff = end - start
|
2013-09-29 09:21:42 -04:00
|
|
|
if res == "skip":
|
|
|
|
skipped.append(t.__name__)
|
2013-10-26 18:05:45 -04:00
|
|
|
result = "SKIP"
|
2013-09-29 09:21:42 -04:00
|
|
|
else:
|
|
|
|
passed.append(t.__name__)
|
2013-10-26 18:05:45 -04:00
|
|
|
result = "PASS"
|
|
|
|
report(conn, build, commit, run, t.__name__, result, diff)
|
|
|
|
result = result + " " + t.__name__ + " "
|
2013-09-29 09:21:42 -04:00
|
|
|
result = result + str(diff.total_seconds()) + " " + str(end)
|
2013-09-28 11:31:00 -04:00
|
|
|
logger.info(result)
|
2013-09-29 09:07:01 -04:00
|
|
|
if log_file or print_res:
|
2013-09-28 11:31:00 -04:00
|
|
|
print result
|
2013-09-29 13:42:37 -04:00
|
|
|
sys.stdout.flush()
|
2013-09-28 11:31:00 -04:00
|
|
|
if results_file:
|
|
|
|
f = open(results_file, 'a')
|
|
|
|
f.write(result + "\n")
|
|
|
|
f.close()
|
2013-03-27 08:40:10 -04:00
|
|
|
except Exception, e:
|
2013-09-28 11:20:32 -04:00
|
|
|
end = datetime.now()
|
|
|
|
diff = end - start
|
2013-08-24 12:48:04 -04:00
|
|
|
logger.info(e)
|
2013-03-27 08:40:10 -04:00
|
|
|
failed.append(t.__name__)
|
2013-10-26 18:05:45 -04:00
|
|
|
report(conn, build, commit, run, t.__name__, "FAIL", diff)
|
2013-09-28 11:31:00 -04:00
|
|
|
result = "FAIL " + t.__name__ + " " + str(diff.total_seconds()) + " " + str(end)
|
|
|
|
logger.info(result)
|
2013-08-25 13:15:54 -04:00
|
|
|
if log_file:
|
2013-09-28 11:31:00 -04:00
|
|
|
print result
|
2013-09-29 13:42:37 -04:00
|
|
|
sys.stdout.flush()
|
2013-09-28 11:31:00 -04:00
|
|
|
if results_file:
|
|
|
|
f = open(results_file, 'a')
|
|
|
|
f.write(result + "\n")
|
|
|
|
f.close()
|
2013-03-27 08:40:10 -04:00
|
|
|
for d in dev:
|
2013-08-24 12:41:08 -04:00
|
|
|
try:
|
|
|
|
d.request("NOTE TEST-STOP " + t.__name__)
|
|
|
|
except Exception, e:
|
2013-08-24 12:48:04 -04:00
|
|
|
logger.info("Failed to issue TEST-STOP after " + t.__name__ + " for " + d.ifname)
|
|
|
|
logger.info(e)
|
2013-03-27 08:40:10 -04:00
|
|
|
|
|
|
|
if not test_filter:
|
2013-03-31 09:16:37 -04:00
|
|
|
reset_devs(dev, apdev)
|
2013-03-27 08:40:10 -04:00
|
|
|
|
2013-10-26 18:05:45 -04:00
|
|
|
if conn:
|
|
|
|
conn.close()
|
|
|
|
|
2013-03-27 08:40:10 -04:00
|
|
|
if len(failed):
|
2013-08-24 12:48:04 -04:00
|
|
|
logger.info("passed " + str(len(passed)) + " test case(s)")
|
2013-09-29 09:21:42 -04:00
|
|
|
logger.info("skipped " + str(len(skipped)) + " test case(s)")
|
2013-08-24 12:48:04 -04:00
|
|
|
logger.info("failed tests: " + str(failed))
|
2013-04-26 06:48:48 -04:00
|
|
|
if error_file:
|
|
|
|
f = open(error_file, 'w')
|
|
|
|
f.write(str(failed) + '\n')
|
|
|
|
f.close()
|
2013-03-27 08:40:10 -04:00
|
|
|
sys.exit(1)
|
2013-08-24 12:48:04 -04:00
|
|
|
logger.info("passed all " + str(len(passed)) + " test case(s)")
|
2013-09-29 09:21:42 -04:00
|
|
|
if len(skipped):
|
|
|
|
logger.info("skipped " + str(len(skipped)) + " test case(s)")
|
2013-08-25 13:15:54 -04:00
|
|
|
if log_file:
|
|
|
|
print "passed all " + str(len(passed)) + " test case(s)"
|
2013-09-29 09:21:42 -04:00
|
|
|
if len(skipped):
|
|
|
|
print "skipped " + str(len(skipped)) + " test case(s)"
|
2013-03-27 08:40:10 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|