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