]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/run-tests.py
tests: Use a single set of scripts for running both P2P and AP tests
[thirdparty/hostap.git] / tests / hwsim / run-tests.py
1 #!/usr/bin/python
2 #
3 # AP tests
4 # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
5 #
6 # This software may be distributed under the terms of the BSD license.
7 # See README for more details.
8
9 import os
10 import re
11 import sys
12 import time
13
14 import logging
15
16 from wpasupplicant import WpaSupplicant
17 from hostapd import HostapdGlobal
18
19 def reset_devs(dev, apdev):
20 for d in dev:
21 d.reset()
22 hapd = HostapdGlobal()
23 for ap in apdev:
24 hapd.remove(ap['ifname'])
25
26 def main():
27 idx = 1
28 if len(sys.argv) > 1 and sys.argv[1] == '-d':
29 logging.basicConfig(level=logging.DEBUG)
30 idx = idx + 1
31 elif len(sys.argv) > 1 and sys.argv[1] == '-q':
32 logging.basicConfig(level=logging.WARNING)
33 idx = idx + 1
34 else:
35 logging.basicConfig(level=logging.INFO)
36
37 if len(sys.argv) > idx:
38 test_filter = sys.argv[idx]
39 else:
40 test_filter = None
41
42 dev0 = WpaSupplicant('wlan0')
43 dev1 = WpaSupplicant('wlan1')
44 dev2 = WpaSupplicant('wlan2')
45 dev = [ dev0, dev1, dev2 ]
46 apdev = [ ]
47 apdev.append({"ifname": 'wlan3', "bssid": "02:00:00:00:03:00"})
48 apdev.append({"ifname": 'wlan4', "bssid": "02:00:00:00:04:00"})
49
50 for d in dev:
51 if not d.ping():
52 print d.ifname + ": No response from wpa_supplicant"
53 return
54 d.reset()
55 print "DEV: " + d.ifname + ": " + d.p2p_dev_addr()
56 for ap in apdev:
57 print "APDEV: " + ap['ifname']
58
59 tests = []
60 for t in os.listdir("."):
61 m = re.match(r'(test_.*)\.py$', t)
62 if m:
63 print "Import test cases from " + t
64 mod = __import__(m.group(1))
65 for s in dir(mod):
66 if s.startswith("test_"):
67 func = mod.__dict__.get(s)
68 tests.append(func)
69
70 passed = []
71 failed = []
72
73 for t in tests:
74 if test_filter:
75 if test_filter != t.__name__:
76 continue
77 reset_devs(dev, apdev)
78 print "START " + t.__name__
79 if t.__doc__:
80 print "Test: " + t.__doc__
81 for d in dev:
82 d.request("NOTE TEST-START " + t.__name__)
83 try:
84 if t.func_code.co_argcount > 1:
85 t(dev, apdev)
86 else:
87 t(dev)
88 passed.append(t.__name__)
89 print "PASS " + t.__name__
90 except Exception, e:
91 print e
92 failed.append(t.__name__)
93 print "FAIL " + t.__name__
94 for d in dev:
95 d.request("NOTE TEST-STOP " + t.__name__)
96
97 if not test_filter:
98 reset_devs(dev, apdev)
99
100 print "passed tests: " + str(passed)
101 print "failed tests: " + str(failed)
102 if len(failed):
103 sys.exit(1)
104
105 if __name__ == "__main__":
106 main()