2013-03-27 13:40:10 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
2013-03-29 17:37:03 +01:00
|
|
|
# AP tests
|
2013-03-27 13:40:10 +01: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 17:37:03 +01:00
|
|
|
from hostapd import HostapdGlobal
|
|
|
|
|
2013-03-31 15:16:37 +02:00
|
|
|
def reset_devs(dev, apdev):
|
|
|
|
for d in dev:
|
|
|
|
d.reset()
|
|
|
|
hapd = HostapdGlobal()
|
|
|
|
for ap in apdev:
|
|
|
|
hapd.remove(ap['ifname'])
|
2013-03-27 13:40:10 +01:00
|
|
|
|
|
|
|
def main():
|
|
|
|
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)
|
|
|
|
|
|
|
|
if len(sys.argv) > idx:
|
|
|
|
test_filter = sys.argv[idx]
|
|
|
|
else:
|
|
|
|
test_filter = None
|
|
|
|
|
|
|
|
dev0 = WpaSupplicant('wlan0')
|
|
|
|
dev1 = WpaSupplicant('wlan1')
|
2013-03-31 15:19:12 +02:00
|
|
|
dev2 = WpaSupplicant('wlan2')
|
|
|
|
dev = [ dev0, dev1, dev2 ]
|
2013-03-31 15:16:37 +02:00
|
|
|
apdev = [ ]
|
|
|
|
apdev.append({"ifname": 'wlan3', "bssid": "02:00:00:00:03:00"})
|
2013-03-31 15:19:12 +02:00
|
|
|
apdev.append({"ifname": 'wlan4', "bssid": "02:00:00:00:04:00"})
|
2013-03-27 13:40:10 +01:00
|
|
|
|
|
|
|
for d in dev:
|
|
|
|
if not d.ping():
|
|
|
|
print d.ifname + ": No response from wpa_supplicant"
|
|
|
|
return
|
|
|
|
d.reset()
|
|
|
|
print "DEV: " + d.ifname + ": " + d.p2p_dev_addr()
|
2013-03-31 15:16:37 +02:00
|
|
|
for ap in apdev:
|
|
|
|
print "APDEV: " + ap['ifname']
|
2013-03-27 13:40:10 +01:00
|
|
|
|
|
|
|
tests = []
|
|
|
|
for t in os.listdir("."):
|
2013-03-29 16:19:47 +01:00
|
|
|
m = re.match(r'(test_ap_.*)\.py$', t)
|
2013-03-27 13:40:10 +01:00
|
|
|
if m:
|
|
|
|
print "Import test cases from " + t
|
|
|
|
mod = __import__(m.group(1))
|
2013-03-29 20:03:55 +01:00
|
|
|
for s in dir(mod):
|
|
|
|
if s.startswith("test_"):
|
|
|
|
func = mod.__dict__.get(s)
|
|
|
|
tests.append(func)
|
2013-03-27 13:40:10 +01:00
|
|
|
|
|
|
|
passed = []
|
|
|
|
failed = []
|
|
|
|
|
|
|
|
for t in tests:
|
|
|
|
if test_filter:
|
|
|
|
if test_filter != t.__name__:
|
|
|
|
continue
|
2013-03-31 15:16:37 +02:00
|
|
|
reset_devs(dev, apdev)
|
2013-03-27 13:40:10 +01: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 15:16:37 +02:00
|
|
|
if t.func_code.co_argcount > 1:
|
|
|
|
t(dev, apdev)
|
|
|
|
else:
|
|
|
|
t(dev)
|
2013-03-27 13:40:10 +01: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 15:16:37 +02:00
|
|
|
reset_devs(dev, apdev)
|
2013-03-27 13:40:10 +01:00
|
|
|
|
|
|
|
print "passed tests: " + str(passed)
|
|
|
|
print "failed tests: " + str(failed)
|
|
|
|
if len(failed):
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|