run-tests 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/env python2
  2. import argparse
  3. import sys
  4. import os
  5. import nose2
  6. from infra.basetest import BRTest
  7. def main():
  8. parser = argparse.ArgumentParser(description='Run Buildroot tests')
  9. parser.add_argument('testname', nargs='*',
  10. help='list of test cases to execute')
  11. parser.add_argument('-l', '--list', action='store_true',
  12. help='list of available test cases')
  13. parser.add_argument('-a', '--all', action='store_true',
  14. help='execute all test cases')
  15. parser.add_argument('-s', '--stdout', action='store_true',
  16. help='log everything to stdout')
  17. parser.add_argument('-o', '--output',
  18. help='output directory')
  19. parser.add_argument('-d', '--download',
  20. help='download directory')
  21. parser.add_argument('-k', '--keep',
  22. help='keep build directories',
  23. action='store_true')
  24. args = parser.parse_args()
  25. script_path = os.path.realpath(__file__)
  26. test_dir = os.path.dirname(script_path)
  27. if args.stdout:
  28. BRTest.logtofile = False
  29. if args.list:
  30. print "List of tests"
  31. nose2.discover(argv=[script_path,
  32. "-s", test_dir,
  33. "-v",
  34. "--collect-only"],
  35. plugins=["nose2.plugins.collect"])
  36. return 0
  37. if args.download is None:
  38. args.download = os.getenv("BR2_DL_DIR")
  39. if args.download is None:
  40. print "Missing download directory, please use -d/--download"
  41. print ""
  42. parser.print_help()
  43. return 1
  44. BRTest.downloaddir = os.path.abspath(args.download)
  45. if args.output is None:
  46. print "Missing output directory, please use -o/--output"
  47. print ""
  48. parser.print_help()
  49. return 1
  50. if not os.path.exists(args.output):
  51. os.mkdir(args.output)
  52. BRTest.outputdir = os.path.abspath(args.output)
  53. if args.all is False and len(args.testname) == 0:
  54. print "No test selected"
  55. print ""
  56. parser.print_help()
  57. return 1
  58. BRTest.keepbuilds = args.keep
  59. nose2_args = ["-v",
  60. "-s", "support/testing",
  61. "-c", "support/testing/conf/unittest.cfg"]
  62. if len(args.testname) != 0:
  63. nose2_args += args.testname
  64. nose2.discover(argv=nose2_args)
  65. if __name__ == "__main__":
  66. sys.exit(main())