def run_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitRequest) -> KunitResult: if request.defconfig: create_default_kunitconfig() config_start = time.time() success = linux.build_reconfig(request.build_dir) config_end = time.time() if not success: return KunitResult(KunitStatus.CONFIG_FAILURE, 'could not configure kernel') kunit_parser.print_with_timestamp('Building KUnit Kernel ...') build_start = time.time() success = linux.build_um_kernel(request.jobs, request.build_dir) build_end = time.time() if not success: return KunitResult(KunitStatus.BUILD_FAILURE, 'could not build kernel') kunit_parser.print_with_timestamp('Starting KUnit Kernel ...') test_start = time.time() test_result = kunit_parser.TestResult(kunit_parser.TestStatus.SUCCESS, [], 'Tests not Parsed.') if request.raw_output: kunit_parser.raw_output( linux.run_kernel(timeout=request.timeout, build_dir=request.build_dir)) else: kunit_output = linux.run_kernel(timeout=request.timeout, build_dir=request.build_dir) test_result = kunit_parser.parse_run_tests(kunit_output) test_end = time.time() kunit_parser.print_with_timestamp( ('Elapsed time: %.3fs total, %.3fs configuring, %.3fs ' + 'building, %.3fs running\n') % (test_end - config_start, config_end - config_start, build_end - build_start, test_end - test_start)) if test_result.status != kunit_parser.TestStatus.SUCCESS: return KunitResult(KunitStatus.TEST_FAILURE, test_result) else: return KunitResult(KunitStatus.SUCCESS, test_result)
def run_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitRequest) -> KunitResult: config_start = time.time() linux.make_external_config(request.external_config) # TODO config_result = linux.build_reconfig() config_end = time.time() if config_result.status != kunit_kernel.ConfigStatus.SUCCESS: return KunitResult(KunitStatus.CONFIG_FAILURE, config_result) print(kunit_parser.timestamp('Building KUnit Kernel ...')) build_start = time.time() build_result = linux.build_um_kernel(request.jobs) build_end = time.time() if build_result.status != kunit_kernel.BuildStatus.SUCCESS: return KunitResult(KunitStatus.BUILD_FAILURE, build_result) print(kunit_parser.timestamp('Starting KUnit Kernel ...')) test_start = time.time() test_result = kunit_parser.TestResult(kunit_parser.TestStatus.SUCCESS, [], 'Tests not Parsed.') if request.raw_output: kunit_parser.raw_output(linux.run_kernel(timeout=request.timeout)) else: test_result = kunit_parser.parse_run_tests( kunit_parser.isolate_kunit_output( linux.run_kernel(timeout=request.timeout))) test_end = time.time() test_result.print_pretty_log() print( kunit_parser.timestamp( ('Elapsed time: %.3fs total, %.3fs configuring, %.3fs ' + 'building, %.3fs running.\n') % (test_end - config_start, config_end - config_start, build_end - build_start, test_end - test_start))) if test_result.status != kunit_parser.TestStatus.SUCCESS: return KunitResult(KunitStatus.TEST_FAILURE, test_result) else: return KunitResult(KunitStatus.SUCCESS, test_result)
def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest) -> KunitResult: kunit_parser.print_with_timestamp('Starting KUnit Kernel ...') test_start = time.time() result = linux.run_kernel( timeout=None if request.alltests else request.timeout, build_dir=request.build_dir) test_end = time.time() return KunitResult(KunitStatus.SUCCESS, result, test_end - test_start)
def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest) -> KunitResult: filter_globs = [request.filter_glob] if request.run_isolated: tests = _list_tests(linux, request) if request.run_isolated == 'test': filter_globs = tests if request.run_isolated == 'suite': filter_globs = _suites_from_test_list(tests) # Apply the test-part of the user's glob, if present. if '.' in request.filter_glob: test_glob = request.filter_glob.split('.', maxsplit=2)[1] filter_globs = [g + '.' + test_glob for g in filter_globs] metadata = kunit_json.Metadata(arch=linux.arch(), build_dir=request.build_dir, def_config='kunit_defconfig') test_counts = kunit_parser.TestCounts() exec_time = 0.0 for i, filter_glob in enumerate(filter_globs): kunit_parser.print_with_timestamp( 'Starting KUnit Kernel ({}/{})...'.format(i + 1, len(filter_globs))) test_start = time.time() run_result = linux.run_kernel( args=request.kernel_args, timeout=None if request.alltests else request.timeout, filter_glob=filter_glob, build_dir=request.build_dir) _, test_result = parse_tests(request, metadata, run_result) # run_kernel() doesn't block on the kernel exiting. # That only happens after we get the last line of output from `run_result`. # So exec_time here actually contains parsing + execution time, which is fine. test_end = time.time() exec_time += test_end - test_start test_counts.add_subtest_counts(test_result.counts) if len(filter_globs) == 1 and test_counts.crashed > 0: bd = request.build_dir print( 'The kernel seems to have crashed; you can decode the stack traces with:' ) print( '$ scripts/decode_stacktrace.sh {}/vmlinux {} < {} | tee {}/decoded.log | {} parse' .format(bd, bd, kunit_kernel.get_outfile_path(bd), bd, sys.argv[0])) kunit_status = _map_to_overall_status(test_counts.get_status()) return KunitResult(status=kunit_status, elapsed_time=exec_time)
def _list_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest) -> List[str]: args = ['kunit.action=list'] if request.kernel_args: args.extend(request.kernel_args) output = linux.run_kernel(args=args, timeout=None if request.alltests else request.timeout, filter_glob=request.filter_glob, build_dir=request.build_dir) lines = kunit_parser.extract_tap_lines(output) # Hack! Drop the dummy TAP version header that the executor prints out. lines.pop() # Filter out any extraneous non-test output that might have gotten mixed in. return [l for l in lines if re.match(r'^[^\s.]+\.[^\s.]+$', l)]
def run_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitRequest) -> KunitResult: kunit_parser.print_with_timestamp('Starting KUnit Kernel ...') test_start = time.time() test_result = kunit_parser.TestResult(kunit_parser.TestStatus.SUCCESS, [], 'Tests not Parsed.') if request.raw_output: kunit_parser.raw_output( linux.run_kernel(timeout=request.timeout, build_dir=request.build_dir)) else: kunit_output = linux.run_kernel(timeout=request.timeout, build_dir=request.build_dir) test_result = kunit_parser.parse_run_tests(kunit_output) test_end = time.time() kunit_parser.print_with_timestamp( ('Elapsed time: %.3fs running\n') % (test_end - test_start)) if test_result.status != kunit_parser.TestStatus.SUCCESS: return KunitResult(KunitStatus.TEST_FAILURE, test_result) else: return KunitResult(KunitStatus.SUCCESS, test_result)
def run_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitRequest) -> KunitResult: config_start = time.time() success = linux.build_reconfig(request.build_dir, request.make_options) config_end = time.time() if not success: return KunitResult(KunitStatus.CONFIG_FAILURE, 'could not configure kernel') kunit_parser.print_with_timestamp('Building KUnit Kernel ...') build_start = time.time() success = linux.build_um_kernel(request.alltests, request.jobs, request.build_dir, request.make_options) build_end = time.time() if not success: return KunitResult(KunitStatus.BUILD_FAILURE, 'could not build kernel') kunit_parser.print_with_timestamp('Starting KUnit Kernel ...') test_start = time.time() kunit_output = linux.run_kernel( timeout=None if request.alltests else request.timeout, build_dir=request.build_dir) if request.raw_output: raw_output = kunit_parser.raw_output(kunit_output) isolated = list(kunit_parser.isolate_kunit_output(raw_output)) test_result = kunit_parser.parse_test_result(isolated) else: test_result = kunit_parser.parse_run_tests(kunit_output) test_end = time.time() kunit_parser.print_with_timestamp( ('Elapsed time: %.3fs total, %.3fs configuring, %.3fs ' + 'building, %.3fs running\n') % (test_end - config_start, config_end - config_start, build_end - build_start, test_end - test_start)) if test_result.status != kunit_parser.TestStatus.SUCCESS: return KunitResult(KunitStatus.TEST_FAILURE, test_result) else: return KunitResult(KunitStatus.SUCCESS, test_result)
def exec_tests(linux: kunit_kernel.LinuxSourceTree, request: KunitExecRequest, parse_request: KunitParseRequest) -> KunitResult: filter_globs = [request.filter_glob] if request.run_isolated: tests = _list_tests(linux, request) if request.run_isolated == 'test': filter_globs = tests if request.run_isolated == 'suite': filter_globs = _suites_from_test_list(tests) # Apply the test-part of the user's glob, if present. if '.' in request.filter_glob: test_glob = request.filter_glob.split('.', maxsplit=2)[1] filter_globs = [g + '.' + test_glob for g in filter_globs] test_counts = kunit_parser.TestCounts() exec_time = 0.0 for i, filter_glob in enumerate(filter_globs): kunit_parser.print_with_timestamp( 'Starting KUnit Kernel ({}/{})...'.format(i + 1, len(filter_globs))) test_start = time.time() run_result = linux.run_kernel( args=request.kernel_args, timeout=None if request.alltests else request.timeout, filter_glob=filter_glob, build_dir=request.build_dir) result = parse_tests(parse_request, run_result) # run_kernel() doesn't block on the kernel exiting. # That only happens after we get the last line of output from `run_result`. # So exec_time here actually contains parsing + execution time, which is fine. test_end = time.time() exec_time += test_end - test_start test_counts.add_subtest_counts(result.result.test.counts) kunit_status = _map_to_overall_status(test_counts.get_status()) return KunitResult(status=kunit_status, result=result.result, elapsed_time=exec_time)