run-p2p-tests.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/python
  2. #
  3. # P2P 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 sys
  10. import time
  11. import logging
  12. from wpasupplicant import WpaSupplicant
  13. import test_p2p_grpform
  14. def main():
  15. idx = 1
  16. if len(sys.argv) > 1 and sys.argv[1] == '-d':
  17. logging.basicConfig(level=logging.DEBUG)
  18. idx = idx + 1
  19. elif len(sys.argv) > 1 and sys.argv[1] == '-q':
  20. logging.basicConfig(level=logging.WARNING)
  21. idx = idx + 1
  22. else:
  23. logging.basicConfig(level=logging.INFO)
  24. if len(sys.argv) > idx:
  25. test_filter = sys.argv[idx]
  26. else:
  27. test_filter = None
  28. dev0 = WpaSupplicant('wlan0')
  29. dev1 = WpaSupplicant('wlan1')
  30. dev2 = WpaSupplicant('wlan2')
  31. dev = [ dev0, dev1, dev2 ]
  32. for d in dev:
  33. if not d.ping():
  34. print d.ifname + ": No response from wpa_supplicant"
  35. return
  36. d.reset()
  37. print "DEV: " + d.ifname + ": " + d.p2p_dev_addr()
  38. tests = []
  39. test_p2p_grpform.add_tests(tests)
  40. passed = []
  41. failed = []
  42. for t in tests:
  43. if test_filter:
  44. if test_filter not in t.__name__:
  45. continue
  46. print "START " + t.__name__
  47. for d in dev:
  48. d.request("NOTE TEST-START " + t.__name__)
  49. try:
  50. t(dev)
  51. passed.append(t.__name__)
  52. print "PASS " + t.__name__
  53. except Exception, e:
  54. print e
  55. failed.append(t.__name__)
  56. print "FAIL " + t.__name__
  57. for d in dev:
  58. d.request("NOTE TEST-STOP " + t.__name__)
  59. print "passed tests: " + str(passed)
  60. print "failed tests: " + str(failed)
  61. if len(failed):
  62. sys.exit(1)
  63. if __name__ == "__main__":
  64. main()