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