run-tests.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. test_file = None
  23. idx = 1
  24. if len(sys.argv) > 1 and sys.argv[1] == '-d':
  25. logging.basicConfig(level=logging.DEBUG)
  26. idx = idx + 1
  27. elif len(sys.argv) > 1 and sys.argv[1] == '-q':
  28. logging.basicConfig(level=logging.WARNING)
  29. idx = idx + 1
  30. else:
  31. logging.basicConfig(level=logging.INFO)
  32. if len(sys.argv) > idx + 1 and sys.argv[idx] == '-f':
  33. test_file = sys.argv[idx + 1]
  34. idx = idx + 2
  35. if len(sys.argv) > idx:
  36. test_filter = sys.argv[idx]
  37. else:
  38. test_filter = None
  39. dev0 = WpaSupplicant('wlan0')
  40. dev1 = WpaSupplicant('wlan1')
  41. dev2 = WpaSupplicant('wlan2')
  42. dev = [ dev0, dev1, dev2 ]
  43. apdev = [ ]
  44. apdev.append({"ifname": 'wlan3', "bssid": "02:00:00:00:03:00"})
  45. apdev.append({"ifname": 'wlan4', "bssid": "02:00:00:00:04:00"})
  46. for d in dev:
  47. if not d.ping():
  48. print d.ifname + ": No response from wpa_supplicant"
  49. return
  50. d.reset()
  51. print "DEV: " + d.ifname + ": " + d.p2p_dev_addr()
  52. for ap in apdev:
  53. print "APDEV: " + ap['ifname']
  54. tests = []
  55. for t in os.listdir("."):
  56. m = re.match(r'(test_.*)\.py$', t)
  57. if m:
  58. if test_file and test_file not in t:
  59. continue
  60. print "Import test cases from " + t
  61. mod = __import__(m.group(1))
  62. for s in dir(mod):
  63. if s.startswith("test_"):
  64. func = mod.__dict__.get(s)
  65. tests.append(func)
  66. passed = []
  67. failed = []
  68. for t in tests:
  69. if test_filter:
  70. if test_filter != t.__name__:
  71. continue
  72. reset_devs(dev, apdev)
  73. print "START " + t.__name__
  74. if t.__doc__:
  75. print "Test: " + t.__doc__
  76. for d in dev:
  77. d.request("NOTE TEST-START " + t.__name__)
  78. try:
  79. if t.func_code.co_argcount > 1:
  80. t(dev, apdev)
  81. else:
  82. t(dev)
  83. passed.append(t.__name__)
  84. print "PASS " + t.__name__
  85. except Exception, e:
  86. print e
  87. failed.append(t.__name__)
  88. print "FAIL " + t.__name__
  89. for d in dev:
  90. d.request("NOTE TEST-STOP " + t.__name__)
  91. if not test_filter:
  92. reset_devs(dev, apdev)
  93. print "passed tests: " + str(passed)
  94. print "failed tests: " + str(failed)
  95. if len(failed):
  96. sys.exit(1)
  97. if __name__ == "__main__":
  98. main()