2 # Copyright (c) 2016, Tieto Corporation
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
8 from wpasupplicant import WpaSupplicant
17 logger = logging.getLogger()
19 def run_hwsim_test(devices, setup_params, refs, duts, monitors, hwsim_test):
28 ref_host = rutils.get_host(devices, ref)
29 ref_hosts.append(ref_host)
31 dut_host = rutils.get_host(devices, dut)
32 dut_hosts.append(dut_host)
35 local_log_dir = setup_params['local_log_dir']
37 # setup hw before test
38 rutils.setup_hw(ref_hosts, setup_params)
39 rutils.setup_hw(dut_hosts, setup_params)
41 # run monitors if requested/possible
42 for ref_host in ref_hosts:
43 monitor.add(ref_host, monitors)
44 monitor.run(ref_host, setup_params)
45 for dut_host in dut_hosts:
46 monitor.add(dut_host, monitors)
47 monitor.run(dut_host, setup_params)
49 monitor_hosts = monitor.create(devices, setup_params, refs, duts,
52 if len(monitor_hosts) > 0:
53 mon = monitor_hosts[0]
54 wlantest.Wlantest.reset_remote_wlantest()
55 wlantest.Wlantest.register_remote_wlantest(mon, setup_params,
58 # run hostapd/wpa_supplicant
59 for ref_host in ref_hosts:
60 rutils.run_wpasupplicant(ref_host, setup_params)
61 wpas = WpaSupplicant(hostname=ref_host.host, global_iface="udp",
62 global_port=ref_host.port)
63 wpas.interface_add(ref_host.ifname)
65 for dut_host in dut_hosts:
66 rutils.run_hostapd(dut_host, setup_params)
67 dut_host.dev['bssid'] = rutils.get_mac_addr(dut_host)
68 apdev.append(dut_host.dev)
70 # run hwsim test/currently only 2 params tests
71 if hwsim_test.func_code.co_argcount == 1:
73 elif hwsim_test.func_code.co_argcount == 2:
74 hwsim_test(dev, apdev)
76 raise Exception("more than 2 arguments required")
78 # hostapd/wpa_supplicant cleanup
80 wpas.interface_remove(wpas.host.ifname)
85 for ref_host in ref_hosts:
86 monitor.remove(ref_host)
87 for dut_host in dut_hosts:
88 monitor.remove(dut_host)
90 for ref_host in ref_hosts:
91 ref_host.execute(["killall", "wpa_supplicant"])
92 ref_host.get_logs(local_log_dir)
93 for dut_host in dut_hosts:
94 dut_host.execute(["killall", "hostapd"])
95 dut_host.get_logs(local_log_dir)
97 wlantest.Wlantest.reset_remote_wlantest()
98 mon.get_logs(local_log_dir)
102 logger.info(traceback.format_exc())
105 wpas.interface_remove(wpas.host.ifname)
110 for ref_host in ref_hosts:
111 monitor.remove(ref_host)
112 for dut_host in dut_hosts:
113 monitor.remove(dut_host)
115 for ref_host in ref_hosts:
116 ref_host.execute(["killall", "wpa_supplicant"])
117 ref_host.get_logs(local_log_dir)
118 for dut_host in dut_hosts:
119 dut_host.execute(["killall", "hostapd"])
120 dut_host.get_logs(local_log_dir)
122 wlantest.Wlantest.reset_remote_wlantest()
123 mon.get_logs(local_log_dir)