run-tests 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/usr/bin/env python3
  2. import argparse
  3. import multiprocessing
  4. import os
  5. import sys
  6. import nose2
  7. from infra.basetest import BRConfigTest
  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. parser.add_argument('--timeout-multiplier', type=int, default=1,
  30. help='increase timeouts (useful for slow machines)')
  31. args = parser.parse_args()
  32. script_path = os.path.realpath(__file__)
  33. test_dir = os.path.dirname(script_path)
  34. if args.stdout:
  35. BRConfigTest.logtofile = False
  36. if args.list:
  37. print("List of tests")
  38. nose2.discover(argv=[script_path,
  39. "-s", test_dir,
  40. "-v",
  41. "--collect-only"],
  42. plugins=["nose2.plugins.collect"])
  43. return 0
  44. if args.download is None:
  45. args.download = os.getenv("BR2_DL_DIR")
  46. if args.download is None:
  47. print("Missing download directory, please use -d/--download")
  48. print("")
  49. parser.print_help()
  50. return 1
  51. BRConfigTest.downloaddir = os.path.abspath(args.download)
  52. if args.output is None:
  53. print("Missing output directory, please use -o/--output")
  54. print("")
  55. parser.print_help()
  56. return 1
  57. if not os.path.exists(args.output):
  58. os.mkdir(args.output)
  59. BRConfigTest.outputdir = os.path.abspath(args.output)
  60. if args.all is False and not args.testname:
  61. print("No test selected")
  62. print("")
  63. parser.print_help()
  64. return 1
  65. BRConfigTest.keepbuilds = args.keep
  66. if args.testcases != 1:
  67. if args.testcases < 1:
  68. print("Invalid number of testcases to run simultaneously")
  69. print("")
  70. parser.print_help()
  71. return 1
  72. # same default BR2_JLEVEL as package/Makefile.in
  73. br2_jlevel = 1 + multiprocessing.cpu_count()
  74. each_testcase = br2_jlevel / args.testcases
  75. if each_testcase < 1:
  76. each_testcase = 1
  77. BRConfigTest.jlevel = each_testcase
  78. if args.jlevel:
  79. if args.jlevel < 0:
  80. print("Invalid BR2_JLEVEL to use for each testcase")
  81. print("")
  82. parser.print_help()
  83. return 1
  84. # the user can override the auto calculated value
  85. BRConfigTest.jlevel = args.jlevel
  86. if args.timeout_multiplier < 1:
  87. print("Invalid multiplier for timeout values")
  88. print("")
  89. parser.print_help()
  90. return 1
  91. BRConfigTest.timeout_multiplier = args.timeout_multiplier
  92. nose2_args = ["-v",
  93. "-N", str(args.testcases),
  94. "-s", test_dir,
  95. "-c", os.path.join(test_dir, "conf/unittest.cfg")]
  96. if args.testname:
  97. nose2_args += args.testname
  98. nose2.discover(argv=nose2_args)
  99. if __name__ == "__main__":
  100. sys.exit(main())