4 # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
6 # This software may be distributed under the terms of the BSD license.
7 # See README for more details.
16 from wpasupplicant import WpaSupplicant
17 from hostapd import HostapdGlobal
19 def reset_devs(dev, apdev):
20 hapd = HostapdGlobal()
24 hapd.remove(ap['ifname'])
30 if len(sys.argv) > 1 and sys.argv[1] == '-d':
31 logging.basicConfig(level=logging.DEBUG)
33 elif len(sys.argv) > 1 and sys.argv[1] == '-q':
34 logging.basicConfig(level=logging.WARNING)
37 logging.basicConfig(level=logging.INFO)
39 if len(sys.argv) > idx + 1 and sys.argv[idx] == '-e':
40 error_file = sys.argv[idx + 1]
43 if len(sys.argv) > idx + 1 and sys.argv[idx] == '-f':
44 test_file = sys.argv[idx + 1]
47 if len(sys.argv) > idx:
48 test_filter = sys.argv[idx]
52 dev0 = WpaSupplicant('wlan0', '/tmp/wpas-wlan0')
53 dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
54 dev2 = WpaSupplicant('wlan2', '/tmp/wpas-wlan2')
55 dev = [ dev0, dev1, dev2 ]
57 apdev.append({"ifname": 'wlan3', "bssid": "02:00:00:00:03:00"})
58 apdev.append({"ifname": 'wlan4', "bssid": "02:00:00:00:04:00"})
62 print d.ifname + ": No response from wpa_supplicant"
64 print "DEV: " + d.ifname + ": " + d.p2p_dev_addr()
66 print "APDEV: " + ap['ifname']
69 for t in os.listdir("."):
70 m = re.match(r'(test_.*)\.py$', t)
72 if test_file and test_file not in t:
74 print "Import test cases from " + t
75 mod = __import__(m.group(1))
77 if s.startswith("test_"):
78 func = mod.__dict__.get(s)
86 if test_filter != t.__name__:
88 reset_devs(dev, apdev)
89 print "START " + t.__name__
91 print "Test: " + t.__doc__
93 d.request("NOTE TEST-START " + t.__name__)
95 if t.func_code.co_argcount > 1:
99 passed.append(t.__name__)
100 print "PASS " + t.__name__
103 failed.append(t.__name__)
104 print "FAIL " + t.__name__
106 d.request("NOTE TEST-STOP " + t.__name__)
109 reset_devs(dev, apdev)
113 print "passed " + str(len(passed)) + " test case(s)"
114 print "failed tests: " + str(failed)
116 f = open(error_file, 'w')
117 f.write(str(failed) + '\n')
120 print "passed all " + str(len(passed)) + " test case(s)"
122 if __name__ == "__main__":