test_radio_work.py 4.0 KB

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