test_autoscan.py 3.2 KB

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