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