test_hostapd_oom.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. # hostapd and out-of-memory error paths
  2. # Copyright (c) 2015, Jouni Malinen
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. from remotehost import remote_compatible
  7. import logging
  8. logger = logging.getLogger()
  9. import time
  10. import hostapd
  11. from utils import HwsimSkip
  12. def hostapd_oom_loop(apdev, params, start_func="main"):
  13. hapd = hostapd.add_ap(apdev[0], { "ssid": "ctrl" })
  14. count = 0
  15. for i in range(1, 1000):
  16. if "OK" not in hapd.request("TEST_ALLOC_FAIL %d:%s" % (i, start_func)):
  17. raise HwsimSkip("TEST_ALLOC_FAIL not supported")
  18. try:
  19. hostapd.add_ap(apdev[1], params, timeout=2.5)
  20. logger.info("Iteration %d - success" % i)
  21. hostapd.remove_bss(apdev[1])
  22. state = hapd.request('GET_ALLOC_FAIL')
  23. logger.info("GET_ALLOC_FAIL: " + state)
  24. hapd.request("TEST_ALLOC_FAIL 0:")
  25. if i < 3:
  26. raise Exception("AP setup succeeded during out-of-memory")
  27. if state.startswith('0:'):
  28. count = 0
  29. else:
  30. count += 1
  31. if count == 5:
  32. break
  33. except Exception, e:
  34. logger.info("Iteration %d - %s" % (i, str(e)))
  35. @remote_compatible
  36. def test_hostapd_oom_open(dev, apdev):
  37. """hostapd failing to setup open mode due to OOM"""
  38. params = { "ssid": "open" }
  39. hostapd_oom_loop(apdev, params)
  40. def test_hostapd_oom_wpa2_psk(dev, apdev):
  41. """hostapd failing to setup WPA2-PSK mode due to OOM"""
  42. params = hostapd.wpa2_params(ssid="test", passphrase="12345678")
  43. params['wpa_psk_file'] = 'hostapd.wpa_psk'
  44. hostapd_oom_loop(apdev, params)
  45. tests = [ "hostapd_config_read_wpa_psk", "hostapd_derive_psk" ]
  46. for t in tests:
  47. hapd = hostapd.add_ap(apdev[0], { "ssid": "ctrl" })
  48. hapd.request("TEST_ALLOC_FAIL 1:%s" % t)
  49. try:
  50. hostapd.add_ap(apdev[1], params, timeout=2.5)
  51. raise Exception("Unexpected add_ap() success during OOM")
  52. except Exception, e:
  53. if "Failed to enable hostapd" in str(e):
  54. pass
  55. else:
  56. raise
  57. state = hapd.request('GET_ALLOC_FAIL')
  58. if state != "0:%s" % t:
  59. raise Exception("OOM not triggered")
  60. @remote_compatible
  61. def test_hostapd_oom_wpa2_eap(dev, apdev):
  62. """hostapd failing to setup WPA2-EAP mode due to OOM"""
  63. params = hostapd.wpa2_eap_params(ssid="test")
  64. params['acct_server_addr'] = "127.0.0.1"
  65. params['acct_server_port'] = "1813"
  66. params['acct_server_shared_secret'] = "radius"
  67. hostapd_oom_loop(apdev, params)
  68. @remote_compatible
  69. def test_hostapd_oom_wpa2_eap_radius(dev, apdev):
  70. """hostapd failing to setup WPA2-EAP mode due to OOM in RADIUS"""
  71. params = hostapd.wpa2_eap_params(ssid="test")
  72. params['acct_server_addr'] = "127.0.0.1"
  73. params['acct_server_port'] = "1813"
  74. params['acct_server_shared_secret'] = "radius"
  75. hostapd_oom_loop(apdev, params, start_func="accounting_init")
  76. def test_hostapd_oom_wpa2_psk_connect(dev, apdev):
  77. """hostapd failing during WPA2-PSK mode connection due to OOM"""
  78. params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678")
  79. hapd = hostapd.add_ap(apdev[0], params)
  80. dev[0].request("SCAN_INTERVAL 1")
  81. count = 0
  82. for i in range(1, 1000):
  83. logger.info("Iteration %d" % i)
  84. if "OK" not in hapd.request("TEST_ALLOC_FAIL %d:main" % i):
  85. raise HwsimSkip("TEST_ALLOC_FAIL not supported")
  86. id = dev[0].connect("test-wpa2-psk", psk="12345678",
  87. scan_freq="2412", wait_connect=False)
  88. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  89. "CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=5)
  90. if ev is None:
  91. logger.info("Timeout while waiting for connection in iteration %d" % i)
  92. dev[0].request("REMOVE_NETWORK all")
  93. time.sleep(0.1)
  94. else:
  95. if "CTRL-EVENT-SSID-TEMP-DISABLED" in ev:
  96. logger.info("Re-select to avoid long wait for temp disavle")
  97. dev[0].select_network(id)
  98. dev[0].wait_connected()
  99. dev[0].request("REMOVE_NETWORK all")
  100. dev[0].wait_disconnected()
  101. for i in range(3):
  102. dev[i].dump_monitor()
  103. hapd.dump_monitor()
  104. state = hapd.request('GET_ALLOC_FAIL')
  105. logger.info("GET_ALLOC_FAIL: " + state)
  106. hapd.request("TEST_ALLOC_FAIL 0:")
  107. if state.startswith('0:'):
  108. count = 0
  109. else:
  110. count += 1
  111. if count == 5:
  112. break
  113. dev[0].request("SCAN_INTERVAL 5")
  114. def test_hostapd_oom_wpa2_eap_connect(dev, apdev, params):
  115. """hostapd failing during WPA2-EAP mode connection due to OOM"""
  116. if not params['long']:
  117. raise HwsimSkip("Skip test case with long duration due to --long not specified")
  118. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  119. params['acct_server_addr'] = "127.0.0.1"
  120. params['acct_server_port'] = "1813"
  121. params['acct_server_shared_secret'] = "radius"
  122. hapd = hostapd.add_ap(apdev[0], params)
  123. dev[0].request("SCAN_INTERVAL 1")
  124. count = 0
  125. for i in range(1, 1000):
  126. logger.info("Iteration %d" % i)
  127. if "OK" not in hapd.request("TEST_ALLOC_FAIL %d:main" % i):
  128. raise HwsimSkip("TEST_ALLOC_FAIL not supported")
  129. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  130. eap="GPSK", identity="gpsk user",
  131. password="abcdefghijklmnop0123456789abcdef",
  132. scan_freq="2412", wait_connect=False)
  133. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED",
  134. "CTRL-EVENT-SSID-TEMP-DISABLED"], timeout=5)
  135. if ev is None:
  136. logger.info("Timeout while waiting for connection in iteration %d" % i)
  137. dev[0].request("REMOVE_NETWORK all")
  138. time.sleep(0.1)
  139. else:
  140. if "CTRL-EVENT-SSID-TEMP-DISABLED" in ev:
  141. logger.info("Re-select to avoid long wait for temp disavle")
  142. dev[0].select_network(id)
  143. dev[0].wait_connected()
  144. dev[0].request("REMOVE_NETWORK all")
  145. dev[0].wait_disconnected()
  146. for i in range(3):
  147. dev[i].dump_monitor()
  148. hapd.dump_monitor()
  149. state = hapd.request('GET_ALLOC_FAIL')
  150. logger.info("GET_ALLOC_FAIL: " + state)
  151. hapd.request("TEST_ALLOC_FAIL 0:")
  152. if state.startswith('0:'):
  153. count = 0
  154. else:
  155. count += 1
  156. if count == 5:
  157. break
  158. dev[0].request("SCAN_INTERVAL 5")