kunit.py (885210d348f71e14b91bdf626d5d9039bf1afb03) | kunit.py (baa3331503271c84c252ab42475729c028b07acf) |
---|---|
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> --- 192 unchanged lines hidden (view full) --- 201 test_result.status = kunit_parser.TestStatus.SUCCESS 202 test_result.counts.passed = 1 203 204 output: Iterable[str] = input_data 205 if request.raw_output == 'all': 206 pass 207 elif request.raw_output == 'kunit': 208 output = kunit_parser.extract_tap_lines(output) | 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> --- 192 unchanged lines hidden (view full) --- 201 test_result.status = kunit_parser.TestStatus.SUCCESS 202 test_result.counts.passed = 1 203 204 output: Iterable[str] = input_data 205 if request.raw_output == 'all': 206 pass 207 elif request.raw_output == 'kunit': 208 output = kunit_parser.extract_tap_lines(output) |
209 else: 210 print(f'Unknown --raw_output option "{request.raw_output}"', file=sys.stderr) | |
211 for line in output: 212 print(line.rstrip()) 213 214 else: 215 test_result = kunit_parser.parse_run_tests(input_data) 216 parse_end = time.time() 217 218 if request.json: --- 60 unchanged lines hidden (view full) --- 279 280def get_default_jobs() -> int: 281 return len(os.sched_getaffinity(0)) 282 283def add_common_opts(parser) -> None: 284 parser.add_argument('--build_dir', 285 help='As in the make command, it specifies the build ' 286 'directory.', | 209 for line in output: 210 print(line.rstrip()) 211 212 else: 213 test_result = kunit_parser.parse_run_tests(input_data) 214 parse_end = time.time() 215 216 if request.json: --- 60 unchanged lines hidden (view full) --- 277 278def get_default_jobs() -> int: 279 return len(os.sched_getaffinity(0)) 280 281def add_common_opts(parser) -> None: 282 parser.add_argument('--build_dir', 283 help='As in the make command, it specifies the build ' 284 'directory.', |
287 type=str, default='.kunit', metavar='build_dir') | 285 type=str, default='.kunit', metavar='DIR') |
288 parser.add_argument('--make_options', 289 help='X=Y make option, can be repeated.', | 286 parser.add_argument('--make_options', 287 help='X=Y make option, can be repeated.', |
290 action='append') | 288 action='append', metavar='X=Y') |
291 parser.add_argument('--alltests', 292 help='Run all KUnit tests through allyesconfig', 293 action='store_true') 294 parser.add_argument('--kunitconfig', 295 help='Path to Kconfig fragment that enables KUnit tests.' 296 ' If given a directory, (e.g. lib/kunit), "/.kunitconfig" ' 297 'will get automatically appended.', | 289 parser.add_argument('--alltests', 290 help='Run all KUnit tests through allyesconfig', 291 action='store_true') 292 parser.add_argument('--kunitconfig', 293 help='Path to Kconfig fragment that enables KUnit tests.' 294 ' If given a directory, (e.g. lib/kunit), "/.kunitconfig" ' 295 'will get automatically appended.', |
298 metavar='kunitconfig') | 296 metavar='PATH') |
299 parser.add_argument('--kconfig_add', 300 help='Additional Kconfig options to append to the ' 301 '.kunitconfig, e.g. CONFIG_KASAN=y. Can be repeated.', | 297 parser.add_argument('--kconfig_add', 298 help='Additional Kconfig options to append to the ' 299 '.kunitconfig, e.g. CONFIG_KASAN=y. Can be repeated.', |
302 action='append') | 300 action='append', metavar='CONFIG_X=Y') |
303 304 parser.add_argument('--arch', 305 help=('Specifies the architecture to run tests under. ' 306 'The architecture specified here must match the ' 307 'string passed to the ARCH make param, ' 308 'e.g. i386, x86_64, arm, um, etc. Non-UML ' 309 'architectures run on QEMU.'), | 301 302 parser.add_argument('--arch', 303 help=('Specifies the architecture to run tests under. ' 304 'The architecture specified here must match the ' 305 'string passed to the ARCH make param, ' 306 'e.g. i386, x86_64, arm, um, etc. Non-UML ' 307 'architectures run on QEMU.'), |
310 type=str, default='um', metavar='arch') | 308 type=str, default='um', metavar='ARCH') |
311 312 parser.add_argument('--cross_compile', 313 help=('Sets make\'s CROSS_COMPILE variable; it should ' 314 'be set to a toolchain path prefix (the prefix ' 315 'of gcc and other tools in your toolchain, for ' 316 'example `sparc64-linux-gnu-` if you have the ' 317 'sparc toolchain installed on your system, or ' 318 '`$HOME/toolchains/microblaze/gcc-9.2.0-nolibc/microblaze-linux/bin/microblaze-linux-` ' 319 'if you have downloaded the microblaze toolchain ' 320 'from the 0-day website to a directory in your ' 321 'home directory called `toolchains`).'), | 309 310 parser.add_argument('--cross_compile', 311 help=('Sets make\'s CROSS_COMPILE variable; it should ' 312 'be set to a toolchain path prefix (the prefix ' 313 'of gcc and other tools in your toolchain, for ' 314 'example `sparc64-linux-gnu-` if you have the ' 315 'sparc toolchain installed on your system, or ' 316 '`$HOME/toolchains/microblaze/gcc-9.2.0-nolibc/microblaze-linux/bin/microblaze-linux-` ' 317 'if you have downloaded the microblaze toolchain ' 318 'from the 0-day website to a directory in your ' 319 'home directory called `toolchains`).'), |
322 metavar='cross_compile') | 320 metavar='PREFIX') |
323 324 parser.add_argument('--qemu_config', 325 help=('Takes a path to a path to a file containing ' 326 'a QemuArchParams object.'), | 321 322 parser.add_argument('--qemu_config', 323 help=('Takes a path to a path to a file containing ' 324 'a QemuArchParams object.'), |
327 type=str, metavar='qemu_config') | 325 type=str, metavar='FILE') |
328 329def add_build_opts(parser) -> None: 330 parser.add_argument('--jobs', 331 help='As in the make command, "Specifies the number of ' 332 'jobs (commands) to run simultaneously."', | 326 327def add_build_opts(parser) -> None: 328 parser.add_argument('--jobs', 329 help='As in the make command, "Specifies the number of ' 330 'jobs (commands) to run simultaneously."', |
333 type=int, default=get_default_jobs(), metavar='jobs') | 331 type=int, default=get_default_jobs(), metavar='N') |
334 335def add_exec_opts(parser) -> None: 336 parser.add_argument('--timeout', 337 help='maximum number of seconds to allow for all tests ' 338 'to run. This does not include time taken to build the ' 339 'tests.', 340 type=int, 341 default=300, | 332 333def add_exec_opts(parser) -> None: 334 parser.add_argument('--timeout', 335 help='maximum number of seconds to allow for all tests ' 336 'to run. This does not include time taken to build the ' 337 'tests.', 338 type=int, 339 default=300, |
342 metavar='timeout') | 340 metavar='SECONDS') |
343 parser.add_argument('filter_glob', 344 help='Filter which KUnit test suites/tests run at ' 345 'boot-time, e.g. list* or list*.*del_test', 346 type=str, 347 nargs='?', 348 default='', 349 metavar='filter_glob') 350 parser.add_argument('--kernel_args', 351 help='Kernel command-line parameters. Maybe be repeated', | 341 parser.add_argument('filter_glob', 342 help='Filter which KUnit test suites/tests run at ' 343 'boot-time, e.g. list* or list*.*del_test', 344 type=str, 345 nargs='?', 346 default='', 347 metavar='filter_glob') 348 parser.add_argument('--kernel_args', 349 help='Kernel command-line parameters. Maybe be repeated', |
352 action='append') | 350 action='append', metavar='') |
353 parser.add_argument('--run_isolated', help='If set, boot the kernel for each ' 354 'individual suite/test. This is can be useful for debugging ' 355 'a non-hermetic test, one that might pass/fail based on ' 356 'what ran before it.', 357 type=str, 358 choices=['suite', 'test']), 359 360def add_parse_opts(parser) -> None: 361 parser.add_argument('--raw_output', help='If set don\'t format output from kernel. ' 362 'If set to --raw_output=kunit, filters to just KUnit output.', | 351 parser.add_argument('--run_isolated', help='If set, boot the kernel for each ' 352 'individual suite/test. This is can be useful for debugging ' 353 'a non-hermetic test, one that might pass/fail based on ' 354 'what ran before it.', 355 type=str, 356 choices=['suite', 'test']), 357 358def add_parse_opts(parser) -> None: 359 parser.add_argument('--raw_output', help='If set don\'t format output from kernel. ' 360 'If set to --raw_output=kunit, filters to just KUnit output.', |
363 type=str, nargs='?', const='all', default=None) | 361 type=str, nargs='?', const='all', default=None, choices=['all', 'kunit']) |
364 parser.add_argument('--json', 365 nargs='?', 366 help='Stores test results in a JSON, and either ' 367 'prints to stdout or saves to file if a ' 368 'filename is specified', | 362 parser.add_argument('--json', 363 nargs='?', 364 help='Stores test results in a JSON, and either ' 365 'prints to stdout or saves to file if a ' 366 'filename is specified', |
369 type=str, const='stdout', default=None) | 367 type=str, const='stdout', default=None, metavar='FILE') |
370 371def main(argv, linux=None): 372 parser = argparse.ArgumentParser( 373 description='Helps writing and running KUnit tests.') 374 subparser = parser.add_subparsers(dest='subcommand') 375 376 # The 'run' command will config, build, exec, and parse in one go. 377 run_parser = subparser.add_parser('run', help='Runs KUnit tests.') --- 142 unchanged lines hidden --- | 368 369def main(argv, linux=None): 370 parser = argparse.ArgumentParser( 371 description='Helps writing and running KUnit tests.') 372 subparser = parser.add_subparsers(dest='subcommand') 373 374 # The 'run' command will config, build, exec, and parse in one go. 375 run_parser = subparser.add_parser('run', help='Runs KUnit tests.') --- 142 unchanged lines hidden --- |