]> rtime.felk.cvut.cz Git - coffee/buildroot.git/blob - support/testing/run-tests
f8cee09ed145921ab4732eac321d0db7d2c14d1e
[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     os.putenv("BR2_DL_DIR", BRTest.downloaddir)
62
63     if args.output is None:
64         print "Missing output directory, please use -o/--output"
65         print ""
66         parser.print_help()
67         return 1
68
69     if not os.path.exists(args.output):
70         os.mkdir(args.output)
71
72     BRTest.outputdir = os.path.abspath(args.output)
73
74     if args.all is False and len(args.testname) == 0:
75         print "No test selected"
76         print ""
77         parser.print_help()
78         return 1
79
80     BRTest.keepbuilds = args.keep
81
82     if args.testcases != 1:
83         if args.testcases < 1:
84             print "Invalid number of testcases to run simultaneously"
85             print ""
86             parser.print_help()
87             return 1
88         # same default BR2_JLEVEL as package/Makefile.in
89         br2_jlevel = 1 + multiprocessing.cpu_count()
90         each_testcase = br2_jlevel / args.testcases
91         if each_testcase < 1:
92             each_testcase = 1
93         BRTest.jlevel = each_testcase
94
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         BRTest.jlevel = args.jlevel
103
104     if args.timeout_multiplier < 1:
105         print "Invalid multiplier for timeout values"
106         print ""
107         parser.print_help()
108         return 1
109     BRTest.timeout_multiplier = args.timeout_multiplier
110
111     nose2_args = ["-v",
112                   "-N", str(args.testcases),
113                   "-s", test_dir,
114                   "-c", os.path.join(test_dir, "conf/unittest.cfg")]
115
116     if len(args.testname) != 0:
117         nose2_args += args.testname
118
119     nose2.discover(argv=nose2_args)
120
121
122 if __name__ == "__main__":
123     sys.exit(main())