2013-03-02 11:22:28 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
# P2P tests
|
|
|
|
# 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
|
2013-03-09 22:18:20 +01:00
|
|
|
import re
|
2013-03-02 11:22:28 +01:00
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from wpasupplicant import WpaSupplicant
|
|
|
|
|
|
|
|
def main():
|
2013-03-09 15:01:11 +01:00
|
|
|
idx = 1
|
2013-03-02 11:22:28 +01:00
|
|
|
if len(sys.argv) > 1 and sys.argv[1] == '-d':
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
2013-03-09 15:01:11 +01:00
|
|
|
idx = idx + 1
|
2013-03-02 11:22:28 +01:00
|
|
|
elif len(sys.argv) > 1 and sys.argv[1] == '-q':
|
|
|
|
logging.basicConfig(level=logging.WARNING)
|
2013-03-09 15:01:11 +01:00
|
|
|
idx = idx + 1
|
2013-03-02 11:22:28 +01:00
|
|
|
else:
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
2013-03-09 15:01:11 +01:00
|
|
|
if len(sys.argv) > idx:
|
|
|
|
test_filter = sys.argv[idx]
|
|
|
|
else:
|
|
|
|
test_filter = None
|
|
|
|
|
2013-03-02 11:22:28 +01:00
|
|
|
dev0 = WpaSupplicant('wlan0')
|
|
|
|
dev1 = WpaSupplicant('wlan1')
|
|
|
|
dev2 = WpaSupplicant('wlan2')
|
|
|
|
dev = [ dev0, dev1, dev2 ]
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
tests = []
|
2013-03-09 22:18:20 +01:00
|
|
|
for t in os.listdir("."):
|
|
|
|
m = re.match(r'(test_p2p_.*)\.py$', t)
|
|
|
|
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-02 11:22:28 +01:00
|
|
|
|
|
|
|
passed = []
|
|
|
|
failed = []
|
|
|
|
|
|
|
|
for t in tests:
|
2013-03-09 15:01:11 +01:00
|
|
|
if test_filter:
|
2013-03-29 20:03:55 +01:00
|
|
|
if test_filter != t.__name__:
|
2013-03-09 15:01:11 +01:00
|
|
|
continue
|
2013-03-09 18:00:57 +01:00
|
|
|
for d in dev:
|
|
|
|
d.reset()
|
2013-03-02 11:22:28 +01:00
|
|
|
print "START " + t.__name__
|
2013-03-17 10:19:24 +01:00
|
|
|
if t.__doc__:
|
|
|
|
print "Test: " + t.__doc__
|
2013-03-02 11:22:28 +01:00
|
|
|
for d in dev:
|
|
|
|
d.request("NOTE TEST-START " + t.__name__)
|
|
|
|
try:
|
|
|
|
t(dev)
|
|
|
|
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__)
|
|
|
|
|
2013-03-09 15:32:09 +01:00
|
|
|
if not test_filter:
|
|
|
|
for d in dev:
|
|
|
|
d.reset()
|
|
|
|
|
2013-03-02 11:22:28 +01:00
|
|
|
print "passed tests: " + str(passed)
|
|
|
|
print "failed tests: " + str(failed)
|
|
|
|
if len(failed):
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|