run-ap-tests.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/usr/bin/python
  2. #
  3. # AP tests
  4. # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
  5. #
  6. # This software may be distributed under the terms of the BSD license.
  7. # See README for more details.
  8. import os
  9. import re
  10. import sys
  11. import time
  12. import logging
  13. from wpasupplicant import WpaSupplicant
  14. from hostapd import HostapdGlobal
  15. def reset_devs(dev, apdev):
  16. for d in dev:
  17. d.reset()
  18. hapd = HostapdGlobal()
  19. for ap in apdev:
  20. hapd.remove(ap['ifname'])
  21. def main():
  22. idx = 1
  23. if len(sys.argv) > 1 and sys.argv[1] == '-d':
  24. logging.basicConfig(level=logging.DEBUG)
  25. idx = idx + 1
  26. elif len(sys.argv) > 1 and sys.argv[1] == '-q':
  27. logging.basicConfig(level=logging.WARNING)
  28. idx = idx + 1
  29. else:
  30. logging.basicConfig(level=logging.INFO)
  31. if len(sys.argv) > idx:
  32. test_filter = sys.argv[idx]
  33. else:
  34. test_filter = None
  35. dev0 = WpaSupplicant('wlan0')
  36. dev1 = WpaSupplicant('wlan1')
  37. dev = [ dev0, dev1 ]
  38. apdev = [ ]
  39. apdev.append({"ifname": 'wlan2', "bssid": "02:00:00:00:02:00"})
  40. apdev.append({"ifname": 'wlan3', "bssid": "02:00:00:00:03:00"})
  41. for d in dev:
  42. if not d.ping():
  43. print d.ifname + ": No response from wpa_supplicant"
  44. return
  45. d.reset()
  46. print "DEV: " + d.ifname + ": " + d.p2p_dev_addr()
  47. for ap in apdev:
  48. print "APDEV: " + ap['ifname']
  49. tests = []
  50. for t in os.listdir("."):
  51. m = re.match(r'(test_ap_.*)\.py$', t)
  52. if m:
  53. print "Import test cases from " + t
  54. mod = __import__(m.group(1))
  55. for s in dir(mod):
  56. if s.startswith("test_"):
  57. func = mod.__dict__.get(s)
  58. tests.append(func)
  59. passed = []
  60. failed = []
  61. for t in tests:
  62. if test_filter:
  63. if test_filter != t.__name__:
  64. continue
  65. reset_devs(dev, apdev)
  66. print "START " + t.__name__
  67. if t.__doc__:
  68. print "Test: " + t.__doc__
  69. for d in dev:
  70. d.request("NOTE TEST-START " + t.__name__)
  71. try:
  72. if t.func_code.co_argcount > 1:
  73. t(dev, apdev)
  74. else:
  75. t(dev)
  76. passed.append(t.__name__)
  77. print "PASS " + t.__name__
  78. except Exception, e:
  79. print e
  80. failed.append(t.__name__)
  81. print "FAIL " + t.__name__
  82. for d in dev:
  83. d.request("NOTE TEST-STOP " + t.__name__)
  84. if not test_filter:
  85. reset_devs(dev, apdev)
  86. print "passed tests: " + str(passed)
  87. print "failed tests: " + str(failed)
  88. if len(failed):
  89. sys.exit(1)
  90. if __name__ == "__main__":
  91. main()