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
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
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:
|
|
|
|
d.reset()
|
2013-03-31 17:59:50 -04:00
|
|
|
for ap in apdev:
|
|
|
|
hapd.remove(ap['ifname'])
|
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-03-27 08:40:10 -04:00
|
|
|
idx = 1
|
|
|
|
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)
|
|
|
|
idx = idx + 1
|
|
|
|
else:
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
2013-04-26 06:48:48 -04:00
|
|
|
if len(sys.argv) > idx + 1 and sys.argv[idx] == '-e':
|
|
|
|
error_file = sys.argv[idx + 1]
|
|
|
|
idx = idx + 2
|
|
|
|
|
2013-03-31 09:29:16 -04:00
|
|
|
if len(sys.argv) > idx + 1 and sys.argv[idx] == '-f':
|
|
|
|
test_file = sys.argv[idx + 1]
|
|
|
|
idx = idx + 2
|
|
|
|
|
2013-03-27 08:40:10 -04:00
|
|
|
if len(sys.argv) > idx:
|
|
|
|
test_filter = sys.argv[idx]
|
|
|
|
else:
|
|
|
|
test_filter = None
|
|
|
|
|
|
|
|
dev0 = WpaSupplicant('wlan0')
|
|
|
|
dev1 = WpaSupplicant('wlan1')
|
2013-03-31 09:19:12 -04:00
|
|
|
dev2 = WpaSupplicant('wlan2')
|
|
|
|
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():
|
|
|
|
print d.ifname + ": No response from wpa_supplicant"
|
|
|
|
return
|
|
|
|
print "DEV: " + d.ifname + ": " + d.p2p_dev_addr()
|
2013-03-31 09:16:37 -04:00
|
|
|
for ap in apdev:
|
|
|
|
print "APDEV: " + ap['ifname']
|
2013-03-27 08:40:10 -04:00
|
|
|
|
|
|
|
tests = []
|
|
|
|
for t in os.listdir("."):
|
2013-03-31 09:22:28 -04:00
|
|
|
m = re.match(r'(test_.*)\.py$', t)
|
2013-03-27 08:40:10 -04:00
|
|
|
if m:
|
2013-03-31 09:29:16 -04:00
|
|
|
if test_file and test_file not in t:
|
|
|
|
continue
|
2013-03-27 08:40:10 -04:00
|
|
|
print "Import test cases from " + t
|
|
|
|
mod = __import__(m.group(1))
|
2013-03-29 15:03:55 -04:00
|
|
|
for s in dir(mod):
|
|
|
|
if s.startswith("test_"):
|
|
|
|
func = mod.__dict__.get(s)
|
|
|
|
tests.append(func)
|
2013-03-27 08:40:10 -04:00
|
|
|
|
|
|
|
passed = []
|
|
|
|
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-03-27 08:40:10 -04:00
|
|
|
print "START " + t.__name__
|
|
|
|
if t.__doc__:
|
|
|
|
print "Test: " + t.__doc__
|
|
|
|
for d in dev:
|
|
|
|
d.request("NOTE TEST-START " + t.__name__)
|
|
|
|
try:
|
2013-03-31 09:16:37 -04:00
|
|
|
if t.func_code.co_argcount > 1:
|
|
|
|
t(dev, apdev)
|
|
|
|
else:
|
|
|
|
t(dev)
|
2013-03-27 08:40:10 -04:00
|
|
|
passed.append(t.__name__)
|
|
|
|
print "PASS " + t.__name__
|
|
|
|
except Exception, e:
|
|
|
|
print e
|
|
|
|
failed.append(t.__name__)
|
|
|
|
print "FAIL " + t.__name__
|
|
|
|
for d in dev:
|
|
|
|
d.request("NOTE TEST-STOP " + t.__name__)
|
|
|
|
|
|
|
|
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-03-31 11:10:17 -04:00
|
|
|
print
|
2013-03-27 08:40:10 -04:00
|
|
|
if len(failed):
|
2013-03-31 11:10:17 -04:00
|
|
|
print "passed " + str(len(passed)) + " test case(s)"
|
|
|
|
print "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-03-31 11:10:17 -04:00
|
|
|
print "passed all " + str(len(passed)) + " test case(s)"
|
2013-03-27 08:40:10 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|