]>
Commit | Line | Data |
---|---|---|
26b84667 JM |
1 | # Radio work tests |
2 | # Copyright (c) 2014, Jouni Malinen <j@w1.fi> | |
3 | # | |
4 | # This software may be distributed under the terms of the BSD license. | |
5 | # See README for more details. | |
6 | ||
7 | import time | |
8 | import logging | |
9 | logger = logging.getLogger() | |
10 | import subprocess | |
11 | ||
12 | import hostapd | |
8ec83adf | 13 | from wpasupplicant import WpaSupplicant |
26b84667 JM |
14 | |
15 | def test_ext_radio_work(dev, apdev): | |
16 | """External radio work item""" | |
17 | id = dev[0].request("RADIO_WORK add test-work-a") | |
18 | if "FAIL" in id: | |
19 | raise Exception("Failed to add radio work") | |
20 | id2 = dev[0].request("RADIO_WORK add test-work-b freq=2417") | |
21 | if "FAIL" in id2: | |
22 | raise Exception("Failed to add radio work") | |
23 | id3 = dev[0].request("RADIO_WORK add test-work-c") | |
24 | if "FAIL" in id3: | |
25 | raise Exception("Failed to add radio work") | |
26 | ||
27 | ev = dev[0].wait_event(["EXT-RADIO-WORK-START"]) | |
28 | if ev is None: | |
29 | raise Exception("Timeout while waiting radio work to start") | |
30 | if "EXT-RADIO-WORK-START " + id not in ev: | |
31 | raise Exception("Unexpected radio work start id") | |
32 | ||
33 | items = dev[0].request("RADIO_WORK show") | |
34 | if "ext:test-work-a@wlan0:0:1:" not in items: | |
35 | logger.info("Pending radio work items:\n" + items) | |
36 | raise Exception("Radio work item(a) missing from the list") | |
37 | if "ext:test-work-b@wlan0:2417:0:" not in items: | |
38 | logger.info("Pending radio work items:\n" + items) | |
39 | raise Exception("Radio work item(b) missing from the list") | |
40 | if "ext:test-work-c@wlan0:0:0:" not in items: | |
41 | logger.info("Pending radio work items:\n" + items) | |
42 | raise Exception("Radio work item(c) missing from the list") | |
43 | ||
44 | dev[0].request("RADIO_WORK done " + id2) | |
45 | dev[0].request("RADIO_WORK done " + id) | |
46 | ||
47 | ev = dev[0].wait_event(["EXT-RADIO-WORK-START"]) | |
48 | if ev is None: | |
49 | raise Exception("Timeout while waiting radio work to start") | |
50 | if "EXT-RADIO-WORK-START " + id3 not in ev: | |
51 | raise Exception("Unexpected radio work start id") | |
52 | dev[0].request("RADIO_WORK done " + id3) | |
53 | items = dev[0].request("RADIO_WORK show") | |
54 | if "ext:" in items: | |
55 | logger.info("Pending radio work items:\n" + items) | |
56 | raise Exception("Unexpected remaining radio work item") | |
9d89c639 JM |
57 | |
58 | id = dev[0].request("RADIO_WORK add test-work timeout=1") | |
59 | ev = dev[0].wait_event(["EXT-RADIO-WORK-START"]) | |
60 | if ev is None: | |
61 | raise Exception("Timeout while waiting radio work to start") | |
62 | ev = dev[0].wait_event(["EXT-RADIO-WORK-TIMEOUT"], timeout=2) | |
63 | if ev is None: | |
64 | raise Exception("Timeout while waiting radio work to time out") | |
65 | if id not in ev: | |
66 | raise Exception("Radio work id mismatch") | |
8ec83adf | 67 | |
530b519f JM |
68 | for i in range(5): |
69 | dev[0].request(("RADIO_WORK add test-work-%d-" % i) + 100*'a') | |
70 | ev = dev[0].wait_event(["EXT-RADIO-WORK-START"]) | |
71 | if ev is None: | |
72 | raise Exception("Timeout while waiting radio work to start") | |
73 | if "FAIL" not in dev[0].request("RADIO_WORK done 12345678"): | |
74 | raise Exception("Invalid RADIO_WORK done accepted"); | |
75 | if "FAIL" not in dev[0].request("RADIO_WORK foo"): | |
76 | raise Exception("Invalid RADIO_WORK accepted"); | |
77 | dev[0].request("FLUSH") | |
78 | items = dev[0].request("RADIO_WORK show") | |
79 | if items != "": | |
80 | raise Exception("Unexpected radio work remaining after FLUSH: " + items) | |
81 | ||
8ec83adf JM |
82 | def test_radio_work_cancel(dev, apdev): |
83 | """Radio work items cancelled on interface removal""" | |
84 | params = hostapd.wpa2_params(ssid="radio", passphrase="12345678") | |
85 | hostapd.add_ap(apdev[0]['ifname'], params) | |
86 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
87 | wpas.interface_add("wlan5") | |
88 | wpas.scan(freq="2412") | |
89 | ||
90 | id = wpas.request("RADIO_WORK add test-work-a") | |
91 | if "FAIL" in id: | |
92 | raise Exception("Failed to add radio work") | |
93 | ev = wpas.wait_event(["EXT-RADIO-WORK-START"]) | |
94 | if ev is None: | |
95 | raise Exception("Timeout while waiting radio work to start") | |
96 | if "EXT-RADIO-WORK-START " + id not in ev: | |
97 | raise Exception("Unexpected radio work start id") | |
98 | ||
99 | wpas.connect("radio", psk="12345678", scan_freq="2412", | |
100 | wait_connect=False) | |
101 | time.sleep(1) | |
102 | wpas.interface_remove("wlan5") | |
103 | # add to allow log file renaming | |
104 | wpas.interface_add("wlan5") |