kunit.py (6cb51a1874d0617579a6bf095b87a510f7dc07ba) kunit.py (6a499c9c42d039ce9341a0c655a76c8dd56f0578)
1#!/usr/bin/env python3
2# SPDX-License-Identifier: GPL-2.0
3#
4# A thin wrapper on top of the KUnit Kernel
5#
6# Copyright (C) 2019, Google LLC.
7# Author: Felix Guo <felixguoxiuping@gmail.com>
8# Author: Brendan Higgins <brendanhiggins@google.com>
9
10import argparse
11import sys
12import os
13import time
14
15assert sys.version_info >= (3, 7), "Python version is too old"
16
17from collections import namedtuple
18from enum import Enum, auto
1#!/usr/bin/env python3
2# SPDX-License-Identifier: GPL-2.0
3#
4# A thin wrapper on top of the KUnit Kernel
5#
6# Copyright (C) 2019, Google LLC.
7# Author: Felix Guo <felixguoxiuping@gmail.com>
8# Author: Brendan Higgins <brendanhiggins@google.com>
9
10import argparse
11import sys
12import os
13import time
14
15assert sys.version_info >= (3, 7), "Python version is too old"
16
17from collections import namedtuple
18from enum import Enum, auto
19from typing import Iterable
19
20import kunit_config
21import kunit_json
22import kunit_kernel
23import kunit_parser
24
25KunitResult = namedtuple('KunitResult', ['status','result','elapsed_time'])
26

--- 82 unchanged lines hidden (view full) ---

109def parse_tests(request: KunitParseRequest) -> KunitResult:
110 parse_start = time.time()
111
112 test_result = kunit_parser.TestResult(kunit_parser.TestStatus.SUCCESS,
113 [],
114 'Tests not Parsed.')
115
116 if request.raw_output:
20
21import kunit_config
22import kunit_json
23import kunit_kernel
24import kunit_parser
25
26KunitResult = namedtuple('KunitResult', ['status','result','elapsed_time'])
27

--- 82 unchanged lines hidden (view full) ---

110def parse_tests(request: KunitParseRequest) -> KunitResult:
111 parse_start = time.time()
112
113 test_result = kunit_parser.TestResult(kunit_parser.TestStatus.SUCCESS,
114 [],
115 'Tests not Parsed.')
116
117 if request.raw_output:
117 kunit_parser.raw_output(request.input_data)
118 output: Iterable[str] = request.input_data
119 if request.raw_output == 'all':
120 pass
121 elif request.raw_output == 'kunit':
122 output = kunit_parser.extract_tap_lines(output)
123 else:
124 print(f'Unknown --raw_output option "{request.raw_output}"', file=sys.stderr)
125 for line in output:
126 print(line.rstrip())
127
118 else:
119 test_result = kunit_parser.parse_run_tests(request.input_data)
120 parse_end = time.time()
121
122 if request.json:
123 json_obj = kunit_json.get_json_result(
124 test_result=test_result,
125 def_config='kunit_defconfig',

--- 4 unchanged lines hidden (view full) ---

130
131 if test_result.status != kunit_parser.TestStatus.SUCCESS:
132 return KunitResult(KunitStatus.TEST_FAILURE, test_result,
133 parse_end - parse_start)
134
135 return KunitResult(KunitStatus.SUCCESS, test_result,
136 parse_end - parse_start)
137
128 else:
129 test_result = kunit_parser.parse_run_tests(request.input_data)
130 parse_end = time.time()
131
132 if request.json:
133 json_obj = kunit_json.get_json_result(
134 test_result=test_result,
135 def_config='kunit_defconfig',

--- 4 unchanged lines hidden (view full) ---

140
141 if test_result.status != kunit_parser.TestStatus.SUCCESS:
142 return KunitResult(KunitStatus.TEST_FAILURE, test_result,
143 parse_end - parse_start)
144
145 return KunitResult(KunitStatus.SUCCESS, test_result,
146 parse_end - parse_start)
147
138
139def run_tests(linux: kunit_kernel.LinuxSourceTree,
140 request: KunitRequest) -> KunitResult:
141 run_start = time.time()
142
143 config_request = KunitConfigRequest(request.build_dir,
144 request.make_options)
145 config_result = config_tests(linux, config_request)
146 if config_result.status != KunitStatus.SUCCESS:

--- 29 unchanged lines hidden (view full) ---

176 build_result.elapsed_time,
177 exec_result.elapsed_time))
178 return parse_result
179
180def add_common_opts(parser) -> None:
181 parser.add_argument('--build_dir',
182 help='As in the make command, it specifies the build '
183 'directory.',
148def run_tests(linux: kunit_kernel.LinuxSourceTree,
149 request: KunitRequest) -> KunitResult:
150 run_start = time.time()
151
152 config_request = KunitConfigRequest(request.build_dir,
153 request.make_options)
154 config_result = config_tests(linux, config_request)
155 if config_result.status != KunitStatus.SUCCESS:

--- 29 unchanged lines hidden (view full) ---

185 build_result.elapsed_time,
186 exec_result.elapsed_time))
187 return parse_result
188
189def add_common_opts(parser) -> None:
190 parser.add_argument('--build_dir',
191 help='As in the make command, it specifies the build '
192 'directory.',
184 type=str, default='.kunit', metavar='build_dir')
193 type=str, default='.kunit', metavar='build_dir')
185 parser.add_argument('--make_options',
186 help='X=Y make option, can be repeated.',
187 action='append')
188 parser.add_argument('--alltests',
189 help='Run all KUnit tests through allyesconfig',
190 action='store_true')
191 parser.add_argument('--kunitconfig',
192 help='Path to Kconfig fragment that enables KUnit tests.'

--- 48 unchanged lines hidden (view full) ---

241 nargs='?',
242 default='',
243 metavar='filter_glob')
244 parser.add_argument('--kernel_args',
245 help='Kernel command-line parameters. Maybe be repeated',
246 action='append')
247
248def add_parse_opts(parser) -> None:
194 parser.add_argument('--make_options',
195 help='X=Y make option, can be repeated.',
196 action='append')
197 parser.add_argument('--alltests',
198 help='Run all KUnit tests through allyesconfig',
199 action='store_true')
200 parser.add_argument('--kunitconfig',
201 help='Path to Kconfig fragment that enables KUnit tests.'

--- 48 unchanged lines hidden (view full) ---

250 nargs='?',
251 default='',
252 metavar='filter_glob')
253 parser.add_argument('--kernel_args',
254 help='Kernel command-line parameters. Maybe be repeated',
255 action='append')
256
257def add_parse_opts(parser) -> None:
249 parser.add_argument('--raw_output', help='don\'t format output from kernel',
250 action='store_true')
258 parser.add_argument('--raw_output', help='If set don\'t format output from kernel. '
259 'If set to --raw_output=kunit, filters to just KUnit output.',
260 type=str, nargs='?', const='all', default=None)
251 parser.add_argument('--json',
252 nargs='?',
253 help='Stores test results in a JSON, and either '
254 'prints to stdout or saves to file if a '
255 'filename is specified',
256 type=str, const='stdout', default=None)
257
258def main(argv, linux=None):

--- 145 unchanged lines hidden ---
261 parser.add_argument('--json',
262 nargs='?',
263 help='Stores test results in a JSON, and either '
264 'prints to stdout or saves to file if a '
265 'filename is specified',
266 type=str, const='stdout', default=None)
267
268def main(argv, linux=None):

--- 145 unchanged lines hidden ---