test_autoscan.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # autoscan 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. import time
  7. import logging
  8. logger = logging.getLogger()
  9. import os
  10. import hostapd
  11. def test_autoscan_periodic(dev, apdev):
  12. """autoscan_periodic"""
  13. hostapd.add_ap(apdev[0], { "ssid": "autoscan" })
  14. try:
  15. if "OK" not in dev[0].request("AUTOSCAN periodic:1"):
  16. raise Exception("Failed to set autoscan")
  17. id = dev[0].connect("not-used", key_mgmt="NONE", scan_freq="2412",
  18. wait_connect=False)
  19. times = {}
  20. for i in range(0, 3):
  21. logger.info("Waiting for scan to start")
  22. start = os.times()[4]
  23. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
  24. if ev is None:
  25. raise Exception("did not start a scan")
  26. stop = os.times()[4]
  27. times[i] = stop - start
  28. logger.info("Waiting for scan to complete")
  29. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 10)
  30. if ev is None:
  31. raise Exception("did not complete a scan")
  32. if times[0] > 1 or times[1] < 0.5 or times[1] > 1.5 or times[2] < 0.5 or times[2] > 1.5:
  33. raise Exception("Unexpected scan timing: " + str(times))
  34. # scan some more channels to allow some more time for reseting AUTOSCAN
  35. # while a scan is in progress
  36. dev[0].set_network(id, "scan_freq", "2412 2437 2462 5180 5200 5220 5240")
  37. dev[0].dump_monitor()
  38. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
  39. if ev is None:
  40. raise Exception("did not start a scan")
  41. if "OK" not in dev[0].request("AUTOSCAN periodic:2"):
  42. raise Exception("Failed to (re)set autoscan")
  43. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 10)
  44. if ev is None:
  45. raise Exception("did not complete a scan")
  46. finally:
  47. dev[0].request("AUTOSCAN ")
  48. def test_autoscan_exponential(dev, apdev):
  49. """autoscan_exponential"""
  50. hostapd.add_ap(apdev[0], { "ssid": "autoscan" })
  51. try:
  52. if "OK" not in dev[0].request("AUTOSCAN exponential:2:10"):
  53. raise Exception("Failed to set autoscan")
  54. dev[0].connect("not-used", key_mgmt="NONE", scan_freq="2412",
  55. wait_connect=False)
  56. times = {}
  57. for i in range(0, 3):
  58. logger.info("Waiting for scan to start")
  59. start = os.times()[4]
  60. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
  61. if ev is None:
  62. raise Exception("did not start a scan")
  63. stop = os.times()[4]
  64. times[i] = stop - start
  65. logger.info("Waiting for scan to complete")
  66. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 10)
  67. if ev is None:
  68. raise Exception("did not complete a scan")
  69. if times[0] > 1 or times[1] < 1 or times[1] > 3 or times[2] < 3 or times[2] > 5:
  70. raise Exception("Unexpected scan timing: " + str(times))
  71. finally:
  72. dev[0].request("AUTOSCAN ")