Add attributes for QCA_NL80211_VENDOR_SUBCMD_LL_STATS_EXT
[mech_eap.git] / tests / remote / hwsim_wrapper.py
1 # Hwsim wrapper
2 # Copyright (c) 2016, Tieto Corporation
3 #
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
6
7 import remotehost
8 from wpasupplicant import WpaSupplicant
9 import hostapd
10 import config
11 import rutils
12 import monitor
13 import traceback
14 import wlantest
15
16 import logging
17 logger = logging.getLogger()
18
19 def run_hwsim_test(devices, setup_params, refs, duts, monitors, hwsim_test):
20     try:
21         ref_hosts = []
22         dut_hosts = []
23         dev = []
24         apdev = []
25
26         # get hosts
27         for ref in refs:
28             ref_host = rutils.get_host(devices, ref)
29             ref_hosts.append(ref_host)
30         for dut in duts:
31             dut_host = rutils.get_host(devices, dut)
32             dut_hosts.append(dut_host)
33
34         # setup log dir
35         local_log_dir = setup_params['local_log_dir']
36
37         # setup hw before test
38         rutils.setup_hw(ref_hosts, setup_params)
39         rutils.setup_hw(dut_hosts, setup_params)
40
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)
48
49         monitor_hosts = monitor.create(devices, setup_params, refs, duts,
50                                        monitors)
51         mon = None
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,
56                                                        monitor)
57
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)
64             dev.append(wpas)
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)
69
70         # run hwsim test/currently only 2 params tests
71         if hwsim_test.func_code.co_argcount == 1:
72             hwsim_test(dev)
73         elif hwsim_test.func_code.co_argcount == 2:
74             hwsim_test(dev, apdev)
75         else:
76             raise Exception("more than 2 arguments required")
77
78        # hostapd/wpa_supplicant cleanup
79         for wpas in dev:
80             wpas.interface_remove(wpas.host.ifname)
81             wpas.terminate()
82         dev = []
83
84         # remove monitors
85         for ref_host in ref_hosts:
86             monitor.remove(ref_host)
87         for dut_host in dut_hosts:
88             monitor.remove(dut_host)
89
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)
96         if mon is not None:
97             wlantest.Wlantest.reset_remote_wlantest()
98             mon.get_logs(local_log_dir)
99
100         return ""
101     except:
102         logger.info(traceback.format_exc())
103         for wpas in dev:
104             try:
105                 wpas.interface_remove(wpas.host.ifname)
106                 wpas.terminate()
107             except:
108                 pass
109
110         for ref_host in ref_hosts:
111             monitor.remove(ref_host)
112         for dut_host in dut_hosts:
113             monitor.remove(dut_host)
114
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)
121         if mon is not None:
122             wlantest.Wlantest.reset_remote_wlantest()
123             mon.get_logs(local_log_dir)
124         raise