run-tests 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/usr/bin/env python2
  2. import argparse
  3. import sys
  4. import os
  5. import nose2
  6. import multiprocessing
  7. from infra.basetest import BRTest
  8. def main():
  9. parser = argparse.ArgumentParser(description='Run Buildroot tests')
  10. parser.add_argument('testname', nargs='*',
  11. help='list of test cases to execute')
  12. parser.add_argument('-l', '--list', action='store_true',
  13. help='list of available test cases')
  14. parser.add_argument('-a', '--all', action='store_true',
  15. help='execute all test cases')
  16. parser.add_argument('-s', '--stdout', action='store_true',
  17. help='log everything to stdout')
  18. parser.add_argument('-o', '--output',
  19. help='output directory')
  20. parser.add_argument('-d', '--download',
  21. help='download directory')
  22. parser.add_argument('-k', '--keep',
  23. help='keep build directories',
  24. action='store_true')
  25. parser.add_argument('-t', '--testcases', type=int, default=1,
  26. help='number of testcases to run simultaneously')
  27. parser.add_argument('-j', '--jlevel', type=int,
  28. help='BR2_JLEVEL to use for each testcase')
  29. args = parser.parse_args()
  30. script_path = os.path.realpath(__file__)
  31. test_dir = os.path.dirname(script_path)
  32. if args.stdout:
  33. BRTest.logtofile = False
  34. if args.list:
  35. print "List of tests"
  36. nose2.discover(argv=[script_path,
  37. "-s", test_dir,
  38. "-v",
  39. "--collect-only"],
  40. plugins=["nose2.plugins.collect"])
  41. return 0
  42. if args.download is None:
  43. args.download = os.getenv("BR2_DL_DIR")
  44. if args.download is None:
  45. print "Missing download directory, please use -d/--download"
  46. print ""
  47. parser.print_help()
  48. return 1
  49. BRTest.downloaddir = os.path.abspath(args.download)
  50. if args.output is None:
  51. print "Missing output directory, please use -o/--output"
  52. print ""
  53. parser.print_help()
  54. return 1
  55. if not os.path.exists(args.output):
  56. os.mkdir(args.output)
  57. BRTest.outputdir = os.path.abspath(args.output)
  58. if args.all is False and len(args.testname) == 0:
  59. print "No test selected"
  60. print ""
  61. parser.print_help()
  62. return 1
  63. BRTest.keepbuilds = args.keep
  64. if args.testcases != 1:
  65. if args.testcases < 1:
  66. print "Invalid number of testcases to run simultaneously"
  67. print ""
  68. parser.print_help()
  69. return 1
  70. # same default BR2_JLEVEL as package/Makefile.in
  71. br2_jlevel = 1 + multiprocessing.cpu_count()
  72. each_testcase = br2_jlevel / args.testcases
  73. if each_testcase < 1:
  74. each_testcase = 1
  75. BRTest.jlevel = each_testcase
  76. if args.jlevel:
  77. if args.jlevel < 0:
  78. print "Invalid BR2_JLEVEL to use for each testcase"
  79. print ""
  80. parser.print_help()
  81. return 1
  82. # the user can override the auto calculated value
  83. BRTest.jlevel = args.jlevel
  84. nose2_args = ["-v",
  85. "-N", str(args.testcases),
  86. "-s", "support/testing",
  87. "-c", "support/testing/conf/unittest.cfg"]
  88. if len(args.testname) != 0:
  89. nose2_args += args.testname
  90. nose2.discover(argv=nose2_args)
  91. if __name__ == "__main__":
  92. sys.exit(main())