2
1

run-tests 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. args = parser.parse_args()
  35. script_path = os.path.realpath(__file__)
  36. test_dir = os.path.dirname(script_path)
  37. if args.stdout:
  38. BRConfigTest.logtofile = False
  39. if args.list:
  40. print("List of tests")
  41. nose2.discover(argv=[script_path,
  42. "-s", test_dir,
  43. "-v",
  44. "--collect-only"],
  45. plugins=["nose2.plugins.collect"])
  46. return 0
  47. if args.download is None:
  48. args.download = os.getenv("BR2_DL_DIR")
  49. if args.download is None:
  50. print("Missing download directory, please use -d/--download")
  51. print("")
  52. parser.print_help()
  53. return 1
  54. BRConfigTest.downloaddir = os.path.abspath(args.download)
  55. if args.prepare_only:
  56. emulator_builtin_binaries = ["kernel-vexpress-5.10.202",
  57. "vexpress-v2p-ca9-5.10.202.dtb",
  58. "kernel-versatile-5.10.202",
  59. "versatile-pb-5.10.202.dtb"]
  60. print("Downloading emulator builtin binaries")
  61. for binary in emulator_builtin_binaries:
  62. infra.download(BRConfigTest.downloaddir, binary)
  63. return 0
  64. if args.output is None:
  65. print("Missing output directory, please use -o/--output")
  66. print("")
  67. parser.print_help()
  68. return 1
  69. if not os.path.exists(args.output):
  70. os.mkdir(args.output)
  71. BRConfigTest.outputdir = os.path.abspath(args.output)
  72. if args.all is False and not args.testname:
  73. print("No test selected")
  74. print("")
  75. parser.print_help()
  76. return 1
  77. BRConfigTest.keepbuilds = args.keep
  78. if args.testcases != 1:
  79. if args.testcases < 1:
  80. print("Invalid number of testcases to run simultaneously")
  81. print("")
  82. parser.print_help()
  83. return 1
  84. # same default BR2_JLEVEL as package/Makefile.in
  85. br2_jlevel = 1 + multiprocessing.cpu_count()
  86. each_testcase = int((br2_jlevel + args.testcases) / args.testcases)
  87. BRConfigTest.jlevel = each_testcase
  88. if args.jlevel:
  89. if args.jlevel < 0:
  90. print("Invalid BR2_JLEVEL to use for each testcase")
  91. print("")
  92. parser.print_help()
  93. return 1
  94. # the user can override the auto calculated value
  95. BRConfigTest.jlevel = args.jlevel
  96. if args.timeout_multiplier < 1:
  97. print("Invalid multiplier for timeout values")
  98. print("")
  99. parser.print_help()
  100. return 1
  101. BRConfigTest.timeout_multiplier = args.timeout_multiplier
  102. nose2_args = ["-v",
  103. "-N", str(args.testcases),
  104. "-s", test_dir,
  105. "-c", os.path.join(test_dir, "conf/unittest.cfg")]
  106. if args.testname:
  107. nose2_args += args.testname
  108. nose2.discover(argv=nose2_args)
  109. if __name__ == "__main__":
  110. sys.exit(main())