]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_hostapd_oom.py
1 # hostapd and out-of-memory error paths
2 # Copyright (c) 2015, Jouni Malinen
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
7 from remotehost
import remote_compatible
9 logger
= logging
.getLogger()
13 from utils
import HwsimSkip
15 def hostapd_oom_loop(apdev
, params
, start_func
="main"):
16 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "ctrl"})
19 for i
in range(1, 1000):
20 if "OK" not in hapd
.request("TEST_ALLOC_FAIL %d:%s" % (i
, start_func
)):
21 raise HwsimSkip("TEST_ALLOC_FAIL not supported")
23 hostapd
.add_ap(apdev
[1], params
, timeout
=2.5)
24 logger
.info("Iteration %d - success" % i
)
25 hostapd
.remove_bss(apdev
[1])
27 state
= hapd
.request('GET_ALLOC_FAIL')
28 logger
.info("GET_ALLOC_FAIL: " + state
)
29 hapd
.request("TEST_ALLOC_FAIL 0:")
31 raise Exception("AP setup succeeded during out-of-memory")
32 if state
.startswith('0:'):
38 except Exception as e
:
39 logger
.info("Iteration %d - %s" % (i
, str(e
)))
42 def test_hostapd_oom_open(dev
, apdev
):
43 """hostapd failing to setup open mode due to OOM"""
44 params
= {"ssid": "open"}
45 hostapd_oom_loop(apdev
, params
)
47 def test_hostapd_oom_wpa2_psk(dev
, apdev
):
48 """hostapd failing to setup WPA2-PSK mode due to OOM"""
49 params
= hostapd
.wpa2_params(ssid
="test", passphrase
="12345678")
50 params
['wpa_psk_file'] = 'hostapd.wpa_psk'
51 hostapd_oom_loop(apdev
, params
)
53 tests
= ["hostapd_config_read_wpa_psk", "hostapd_derive_psk"]
55 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "ctrl"})
56 hapd
.request("TEST_ALLOC_FAIL 1:%s" % t
)
58 hostapd
.add_ap(apdev
[1], params
, timeout
=2.5)
59 raise Exception("Unexpected add_ap() success during OOM")
60 except Exception as e
:
61 if "Failed to enable hostapd" in str(e
):
65 state
= hapd
.request('GET_ALLOC_FAIL')
66 if state
!= "0:%s" % t
:
67 raise Exception("OOM not triggered")
70 def test_hostapd_oom_wpa2_eap(dev
, apdev
):
71 """hostapd failing to setup WPA2-EAP mode due to OOM"""
72 params
= hostapd
.wpa2_eap_params(ssid
="test")
73 params
['acct_server_addr'] = "127.0.0.1"
74 params
['acct_server_port'] = "1813"
75 params
['acct_server_shared_secret'] = "radius"
76 hostapd_oom_loop(apdev
, params
)
79 def test_hostapd_oom_wpa2_eap_radius(dev
, apdev
):
80 """hostapd failing to setup WPA2-EAP mode due to OOM in RADIUS"""
81 params
= hostapd
.wpa2_eap_params(ssid
="test")
82 params
['acct_server_addr'] = "127.0.0.1"
83 params
['acct_server_port'] = "1813"
84 params
['acct_server_shared_secret'] = "radius"
85 hostapd_oom_loop(apdev
, params
, start_func
="accounting_init")
87 def test_hostapd_oom_wpa2_psk_connect(dev
, apdev
):
88 """hostapd failing during WPA2-PSK mode connection due to OOM"""
89 params
= hostapd
.wpa2_params(ssid
="test-wpa2-psk", passphrase
="12345678")
90 hapd
= hostapd
.add_ap(apdev
[0], params
)
92 dev
[0].request("SCAN_INTERVAL 1")
94 for i
in range(1, 1000):
95 logger
.info("Iteration %d" % i
)
96 if "OK" not in hapd
.request("TEST_ALLOC_FAIL %d:main" % i
):
97 raise HwsimSkip("TEST_ALLOC_FAIL not supported")
98 id = dev
[0].connect("test-wpa2-psk", psk
="12345678",
99 scan_freq
="2412", wait_connect
=False)
100 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED",
101 "CTRL-EVENT-SSID-TEMP-DISABLED"], timeout
=5)
103 logger
.info("Timeout while waiting for connection in iteration %d" % i
)
104 dev
[0].request("REMOVE_NETWORK all")
107 if "CTRL-EVENT-SSID-TEMP-DISABLED" in ev
:
108 logger
.info("Re-select to avoid long wait for temp disavle")
109 dev
[0].select_network(id)
110 dev
[0].wait_connected()
111 dev
[0].request("REMOVE_NETWORK all")
112 dev
[0].wait_disconnected()
114 dev
[i
].dump_monitor()
117 state
= hapd
.request('GET_ALLOC_FAIL')
118 logger
.info("GET_ALLOC_FAIL: " + state
)
119 hapd
.request("TEST_ALLOC_FAIL 0:")
120 if state
.startswith('0:'):
126 dev
[0].request("SCAN_INTERVAL 5")
128 def test_hostapd_oom_wpa2_eap_connect(dev
, apdev
, params
):
129 """hostapd failing during WPA2-EAP mode connection due to OOM"""
130 if not params
['long']:
131 raise HwsimSkip("Skip test case with long duration due to --long not specified")
132 params
= hostapd
.wpa2_eap_params(ssid
="test-wpa2-eap")
133 params
['acct_server_addr'] = "127.0.0.1"
134 params
['acct_server_port'] = "1813"
135 params
['acct_server_shared_secret'] = "radius"
136 hapd
= hostapd
.add_ap(apdev
[0], params
)
138 dev
[0].request("SCAN_INTERVAL 1")
140 for i
in range(1, 1000):
141 logger
.info("Iteration %d" % i
)
142 if "OK" not in hapd
.request("TEST_ALLOC_FAIL %d:main" % i
):
143 raise HwsimSkip("TEST_ALLOC_FAIL not supported")
144 id = dev
[0].connect("test-wpa2-eap", key_mgmt
="WPA-EAP",
145 eap
="GPSK", identity
="gpsk user",
146 password
="abcdefghijklmnop0123456789abcdef",
147 scan_freq
="2412", wait_connect
=False)
148 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED",
149 "CTRL-EVENT-SSID-TEMP-DISABLED"], timeout
=5)
151 logger
.info("Timeout while waiting for connection in iteration %d" % i
)
152 dev
[0].request("REMOVE_NETWORK all")
155 if "CTRL-EVENT-SSID-TEMP-DISABLED" in ev
:
156 logger
.info("Re-select to avoid long wait for temp disavle")
157 dev
[0].select_network(id)
158 dev
[0].wait_connected()
159 dev
[0].request("REMOVE_NETWORK all")
160 dev
[0].wait_disconnected()
162 dev
[i
].dump_monitor()
165 state
= hapd
.request('GET_ALLOC_FAIL')
166 logger
.info("GET_ALLOC_FAIL: " + state
)
167 hapd
.request("TEST_ALLOC_FAIL 0:")
168 if state
.startswith('0:'):
174 dev
[0].request("SCAN_INTERVAL 5")