test_radio_work.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # Radio work 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 subprocess
  10. import hostapd
  11. from wpasupplicant import WpaSupplicant
  12. def test_ext_radio_work(dev, apdev):
  13. """External radio work item"""
  14. id = dev[0].request("RADIO_WORK add test-work-a")
  15. if "FAIL" in id:
  16. raise Exception("Failed to add radio work")
  17. id2 = dev[0].request("RADIO_WORK add test-work-b freq=2417")
  18. if "FAIL" in id2:
  19. raise Exception("Failed to add radio work")
  20. id3 = dev[0].request("RADIO_WORK add test-work-c")
  21. if "FAIL" in id3:
  22. raise Exception("Failed to add radio work")
  23. ev = dev[0].wait_event(["EXT-RADIO-WORK-START"])
  24. if ev is None:
  25. raise Exception("Timeout while waiting radio work to start")
  26. if "EXT-RADIO-WORK-START " + id not in ev:
  27. raise Exception("Unexpected radio work start id")
  28. items = dev[0].request("RADIO_WORK show")
  29. if "ext:test-work-a@wlan0:0:1:" not in items:
  30. logger.info("Pending radio work items:\n" + items)
  31. raise Exception("Radio work item(a) missing from the list")
  32. if "ext:test-work-b@wlan0:2417:0:" not in items:
  33. logger.info("Pending radio work items:\n" + items)
  34. raise Exception("Radio work item(b) missing from the list")
  35. if "ext:test-work-c@wlan0:0:0:" not in items:
  36. logger.info("Pending radio work items:\n" + items)
  37. raise Exception("Radio work item(c) missing from the list")
  38. dev[0].request("RADIO_WORK done " + id2)
  39. dev[0].request("RADIO_WORK done " + id)
  40. ev = dev[0].wait_event(["EXT-RADIO-WORK-START"])
  41. if ev is None:
  42. raise Exception("Timeout while waiting radio work to start")
  43. if "EXT-RADIO-WORK-START " + id3 not in ev:
  44. raise Exception("Unexpected radio work start id")
  45. dev[0].request("RADIO_WORK done " + id3)
  46. items = dev[0].request("RADIO_WORK show")
  47. if "ext:" in items:
  48. logger.info("Pending radio work items:\n" + items)
  49. raise Exception("Unexpected remaining radio work item")
  50. id = dev[0].request("RADIO_WORK add test-work timeout=1")
  51. ev = dev[0].wait_event(["EXT-RADIO-WORK-START"])
  52. if ev is None:
  53. raise Exception("Timeout while waiting radio work to start")
  54. ev = dev[0].wait_event(["EXT-RADIO-WORK-TIMEOUT"], timeout=2)
  55. if ev is None:
  56. raise Exception("Timeout while waiting radio work to time out")
  57. if id not in ev:
  58. raise Exception("Radio work id mismatch")
  59. def test_radio_work_cancel(dev, apdev):
  60. """Radio work items cancelled on interface removal"""
  61. params = hostapd.wpa2_params(ssid="radio", passphrase="12345678")
  62. hostapd.add_ap(apdev[0]['ifname'], params)
  63. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  64. wpas.interface_add("wlan5")
  65. wpas.scan(freq="2412")
  66. id = wpas.request("RADIO_WORK add test-work-a")
  67. if "FAIL" in id:
  68. raise Exception("Failed to add radio work")
  69. ev = wpas.wait_event(["EXT-RADIO-WORK-START"])
  70. if ev is None:
  71. raise Exception("Timeout while waiting radio work to start")
  72. if "EXT-RADIO-WORK-START " + id not in ev:
  73. raise Exception("Unexpected radio work start id")
  74. wpas.connect("radio", psk="12345678", scan_freq="2412",
  75. wait_connect=False)
  76. time.sleep(1)
  77. wpas.interface_remove("wlan5")
  78. # add to allow log file renaming
  79. wpas.interface_add("wlan5")