def test_output_with_prefix_isolated_correctly(self): log_path = get_absolute_path('test_data/test_pound_sign.log') with open(log_path) as file: result = kunit_parser.isolate_kunit_output(file.readlines()) self.assertContains('TAP version 14', result) self.assertContains(' # Subtest: kunit-resource-test', result) self.assertContains(' 1..5', result) self.assertContains(' ok 1 - kunit_resource_test_init_resources', result) self.assertContains(' ok 2 - kunit_resource_test_alloc_resource', result) self.assertContains(' ok 3 - kunit_resource_test_destroy_resource', result) self.assertContains(' foo bar #', result) self.assertContains(' ok 4 - kunit_resource_test_cleanup_resources', result) self.assertContains(' ok 5 - kunit_resource_test_proper_free_ordering', result) self.assertContains('ok 1 - kunit-resource-test', result) self.assertContains(' foo bar # non-kunit output', result) self.assertContains(' # Subtest: kunit-try-catch-test', result) self.assertContains(' 1..2', result) self.assertContains( ' ok 1 - kunit_test_try_catch_successful_try_no_catch', result) self.assertContains( ' ok 2 - kunit_test_try_catch_unsuccessful_try_does_catch', result) self.assertContains('ok 2 - kunit-try-catch-test', result) self.assertContains(' # Subtest: string-stream-test', result) self.assertContains(' 1..3', result) self.assertContains(' ok 1 - string_stream_test_empty_on_creation', result) self.assertContains(' ok 2 - string_stream_test_not_empty_after_add', result) self.assertContains(' ok 3 - string_stream_test_get_string', result) self.assertContains('ok 3 - string-stream-test', result)
def test_no_tests(self): empty_log = test_data_path('test_is_test_passed-no_tests_run.log') with open(empty_log) as file: result = kunit_parser.parse_run_tests( kunit_parser.isolate_kunit_output(file.readlines())) self.assertEqual(0, len(result.suites)) self.assertEqual(kunit_parser.TestStatus.NO_TESTS, result.status)
def test_no_kunit_output(self): crash_log = get_absolute_path('test_data/test_insufficient_memory.log') file = open(crash_log) print_mock = mock.patch('builtins.print').start() result = kunit_parser.parse_run_tests( kunit_parser.isolate_kunit_output(file.readlines())) print_mock.assert_any_call(StrContains('no tests run!')) print_mock.stop() file.close()
def test_no_tests(self): empty_log = get_absolute_path( 'test_data/test_is_test_passed-no_tests_run.log') file = open(empty_log) result = kunit_parser.parse_run_tests( kunit_parser.isolate_kunit_output(file.readlines())) self.assertEqual(0, len(result.suites)) self.assertEqual(kunit_parser.TestStatus.NO_TESTS, result.status) file.close()
def test_output_isolated_correctly(self): log_path = get_absolute_path( 'test_data/test_output_isolated_correctly.log') file = open(log_path) result = kunit_parser.isolate_kunit_output(file.readlines()) self.assertContains('kunit example: initializing\n', result) self.assertContains('kunit example: example_mock_test passed\n', result) self.assertContains('kunit example: all tests passed\n', result) file.close()
def test_broken_test(self): broken_log = get_absolute_path( 'test_data/test_is_test_passed-broken_test.log') file = open(broken_log) result = kunit_parser.parse_run_tests( kunit_parser.isolate_kunit_output(file.readlines())) self.assertEqual( kunit_parser.TestStatus.KERNEL_CRASHED, result.status) file.close()
def test_output_isolated_correctly(self): log_path = test_data_path('test_output_isolated_correctly.log') with open(log_path) as file: result = kunit_parser.isolate_kunit_output(file.readlines()) self.assertContains('TAP version 14', result) self.assertContains(' # Subtest: example', result) self.assertContains(' 1..2', result) self.assertContains(' ok 1 - example_simple_test', result) self.assertContains(' ok 2 - example_mock_test', result) self.assertContains('ok 1 - example', result)
def test_output_isolated_correctly(self): log_path = get_absolute_path( 'test_data/test_output_isolated_correctly.log') file = open(log_path) result = kunit_parser.isolate_kunit_output(file.readlines()) self.assertContains('TAP version 14\n', result) self.assertContains(' # Subtest: example', result) self.assertContains(' 1..2', result) self.assertContains(' ok 1 - example_simple_test', result) self.assertContains(' ok 2 - example_mock_test', result) self.assertContains('ok 1 - example', result) file.close()
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 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)