test_radio_work.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. for i in range(5):
  60. dev[0].request(("RADIO_WORK add test-work-%d-" % i) + 100*'a')
  61. ev = dev[0].wait_event(["EXT-RADIO-WORK-START"])
  62. if ev is None:
  63. raise Exception("Timeout while waiting radio work to start")
  64. if "FAIL" not in dev[0].request("RADIO_WORK done 12345678"):
  65. raise Exception("Invalid RADIO_WORK done accepted");
  66. if "FAIL" not in dev[0].request("RADIO_WORK foo"):
  67. raise Exception("Invalid RADIO_WORK accepted");
  68. dev[0].request("FLUSH")
  69. items = dev[0].request("RADIO_WORK show")
  70. if items != "":
  71. raise Exception("Unexpected radio work remaining after FLUSH: " + items)
  72. def test_radio_work_cancel(dev, apdev):
  73. """Radio work items cancelled on interface removal"""
  74. params = hostapd.wpa2_params(ssid="radio", passphrase="12345678")
  75. hostapd.add_ap(apdev[0], params)
  76. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  77. wpas.interface_add("wlan5")
  78. wpas.scan(freq="2412")
  79. id = wpas.request("RADIO_WORK add test-work-a")
  80. if "FAIL" in id:
  81. raise Exception("Failed to add radio work")
  82. ev = wpas.wait_event(["EXT-RADIO-WORK-START"])
  83. if ev is None:
  84. raise Exception("Timeout while waiting radio work to start")
  85. if "EXT-RADIO-WORK-START " + id not in ev:
  86. raise Exception("Unexpected radio work start id")
  87. wpas.connect("radio", psk="12345678", scan_freq="2412",
  88. wait_connect=False)
  89. time.sleep(1)
  90. wpas.interface_remove("wlan5")
  91. # add to allow log file renaming
  92. wpas.interface_add("wlan5")