run-tests 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. import infra
  9. def main():
  10. parser = argparse.ArgumentParser(description='Run Buildroot tests')
  11. parser.add_argument('testname', nargs='*',
  12. help='list of test cases to execute')
  13. parser.add_argument('-l', '--list', action='store_true',
  14. help='list of available test cases')
  15. parser.add_argument('-a', '--all', action='store_true',
  16. help='execute all test cases')
  17. parser.add_argument('-s', '--stdout', action='store_true',
  18. help='log everything to stdout')
  19. parser.add_argument('-o', '--output',
  20. help='output directory')
  21. parser.add_argument('-d', '--download',
  22. help='download directory')
  23. parser.add_argument('-p', '--prepare-only', action='store_true',
  24. help='download emulator builtin binaries')
  25. parser.add_argument('-k', '--keep',
  26. help='keep build directories',
  27. action='store_true')
  28. parser.add_argument('-t', '--testcases', type=int, default=1,
  29. help='number of testcases to run simultaneously')
  30. parser.add_argument('-j', '--jlevel', type=int,
  31. help='BR2_JLEVEL to use for each testcase')
  32. parser.add_argument('--timeout-multiplier', type=int, default=1,
  33. help='increase timeouts (useful for slow machines)')
  34. parser.add_argument('-D', '--debug', action='store_true',
  35. help='enable debug log')
  36. args = parser.parse_args()
  37. script_path = os.path.realpath(__file__)
  38. test_dir = os.path.dirname(script_path)
  39. if args.stdout:
  40. BRConfigTest.logtofile = False
  41. if args.list:
  42. print("List of tests")
  43. nose2_args = [
  44. script_path,
  45. "-s", test_dir,
  46. "-v",
  47. "--collect-only"
  48. ]
  49. if args.debug:
  50. nose2_args += ["--log-level", "debug"]
  51. nose2.discover(argv=nose2_args,
  52. plugins=["nose2.plugins.collect"])
  53. return 0
  54. if args.download is None:
  55. args.download = os.getenv("BR2_DL_DIR")
  56. if args.download is None:
  57. print("Missing download directory, please use -d/--download")
  58. print("")
  59. parser.print_help()
  60. return 1
  61. BRConfigTest.downloaddir = os.path.abspath(args.download)
  62. if args.prepare_only:
  63. emulator_builtin_binaries = ["kernel-vexpress-5.10.202",
  64. "vexpress-v2p-ca9-5.10.202.dtb",
  65. "kernel-versatile-5.10.202",
  66. "versatile-pb-5.10.202.dtb"]
  67. print("Downloading emulator builtin binaries")
  68. for binary in emulator_builtin_binaries:
  69. infra.download(BRConfigTest.downloaddir, binary)
  70. return 0
  71. if args.output is None:
  72. print("Missing output directory, please use -o/--output")
  73. print("")
  74. parser.print_help()
  75. return 1
  76. if not os.path.exists(args.output):
  77. os.mkdir(args.output)
  78. BRConfigTest.outputdir = os.path.abspath(args.output)
  79. if args.all is False and not args.testname:
  80. print("No test selected")
  81. print("")
  82. parser.print_help()
  83. return 1
  84. BRConfigTest.keepbuilds = args.keep
  85. if args.testcases != 1:
  86. if args.testcases < 1:
  87. print("Invalid number of testcases to run simultaneously")
  88. print("")
  89. parser.print_help()
  90. return 1
  91. # same default BR2_JLEVEL as package/Makefile.in
  92. br2_jlevel = 1 + multiprocessing.cpu_count()
  93. each_testcase = int((br2_jlevel + args.testcases) / args.testcases)
  94. BRConfigTest.jlevel = each_testcase
  95. if args.jlevel:
  96. if args.jlevel < 0:
  97. print("Invalid BR2_JLEVEL to use for each testcase")
  98. print("")
  99. parser.print_help()
  100. return 1
  101. # the user can override the auto calculated value
  102. BRConfigTest.jlevel = args.jlevel
  103. if args.timeout_multiplier < 1:
  104. print("Invalid multiplier for timeout values")
  105. print("")
  106. parser.print_help()
  107. return 1
  108. BRConfigTest.timeout_multiplier = args.timeout_multiplier
  109. nose2_args = ["-v",
  110. "-N", str(args.testcases),
  111. "-s", test_dir,
  112. "-c", os.path.join(test_dir, "conf/unittest.cfg")]
  113. if args.debug:
  114. nose2_args += ["--log-level", "debug"]
  115. if args.testname:
  116. nose2_args += args.testname
  117. nose2.discover(argv=nose2_args)
  118. if __name__ == "__main__":
  119. sys.exit(main())