test_autoscan.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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]['ifname'], { "ssid": "autoscan" })
  14. try:
  15. if "OK" not in dev[0].request("AUTOSCAN periodic:1"):
  16. raise Exception("Failed to set autoscan")
  17. 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. finally:
  35. dev[0].request("AUTOSCAN ")
  36. def test_autoscan_exponential(dev, apdev):
  37. """autoscan_exponential"""
  38. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "autoscan" })
  39. try:
  40. if "OK" not in dev[0].request("AUTOSCAN exponential:2:10"):
  41. raise Exception("Failed to set autoscan")
  42. dev[0].connect("not-used", key_mgmt="NONE", scan_freq="2412",
  43. wait_connect=False)
  44. times = {}
  45. for i in range(0, 3):
  46. logger.info("Waiting for scan to start")
  47. start = os.times()[4]
  48. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
  49. if ev is None:
  50. raise Exception("did not start a scan")
  51. stop = os.times()[4]
  52. times[i] = stop - start
  53. logger.info("Waiting for scan to complete")
  54. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 10)
  55. if ev is None:
  56. raise Exception("did not complete a scan")
  57. if times[0] > 1 or times[1] < 1 or times[1] > 3 or times[2] < 3 or times[2] > 5:
  58. raise Exception("Unexpected scan timing: " + str(times))
  59. finally:
  60. dev[0].request("AUTOSCAN ")