Example #1
0
 def test_output_with_prefix_isolated_correctly(self):
     log_path = test_data_path('test_pound_sign.log')
     with open(log_path) as file:
         result = kunit_parser.extract_tap_lines(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)
Example #2
0
 def test_no_tests(self):
     empty_log = test_data_path(
         'test_is_test_passed-no_tests_run_with_header.log')
     with open(empty_log) as file:
         result = kunit_parser.parse_run_tests(
             kunit_parser.extract_tap_lines(file.readlines()))
     self.assertEqual(0, len(result.suites))
     self.assertEqual(kunit_parser.TestStatus.NO_TESTS, result.status)
Example #3
0
 def test_missing_test_plan(self):
     missing_plan_log = test_data_path('test_is_test_passed-'
                                       'missing_plan.log')
     with open(missing_plan_log) as file:
         result = kunit_parser.parse_run_tests(
             kunit_parser.extract_tap_lines(file.readlines()))
     self.assertEqual(2, result.test.counts.errors)
     self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
Example #4
0
 def test_no_kunit_output(self):
     crash_log = test_data_path('test_insufficient_memory.log')
     print_mock = mock.patch('builtins.print').start()
     with open(crash_log) as file:
         result = kunit_parser.parse_run_tests(
             kunit_parser.extract_tap_lines(file.readlines()))
     print_mock.assert_any_call(StrContains('invalid KTAP input!'))
     print_mock.stop()
     self.assertEqual(0, len(result.subtests))
Example #5
0
	def test_no_kunit_output(self):
		crash_log = test_data_path('test_insufficient_memory.log')
		print_mock = mock.patch('builtins.print').start()
		with open(crash_log) as file:
			result = kunit_parser.parse_run_tests(
				kunit_parser.extract_tap_lines(file.readlines()))
		print_mock.assert_any_call(StrContains('no tests run!'))
		print_mock.stop()
		file.close()
Example #6
0
 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.extract_tap_lines(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)
Example #7
0
 def test_no_tests_no_plan(self):
     no_plan_log = test_data_path(
         'test_is_test_passed-no_tests_no_plan.log')
     with open(no_plan_log) as file:
         result = kunit_parser.parse_run_tests(
             kunit_parser.extract_tap_lines(file.readlines()))
     self.assertEqual(0, len(result.subtests[0].subtests[0].subtests))
     self.assertEqual(kunit_parser.TestStatus.NO_TESTS,
                      result.subtests[0].subtests[0].status)
     self.assertEqual(1, result.counts.errors)
Example #8
0
 def test_missing_test_plan(self):
     missing_plan_log = test_data_path('test_is_test_passed-'
                                       'missing_plan.log')
     with open(missing_plan_log) as file:
         result = kunit_parser.parse_run_tests(
             kunit_parser.extract_tap_lines(file.readlines()))
     # A missing test plan is not an error.
     self.assertEqual(0, result.counts.errors)
     # All tests should be accounted for.
     self.assertEqual(10, result.counts.total())
     self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
Example #9
0
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)]
Example #10
0
def parse_tests(request: KunitParseRequest,
                input_data: Iterable[str]) -> KunitResult:
    parse_start = time.time()

    test_result = kunit_parser.TestResult(kunit_parser.TestStatus.SUCCESS,
                                          kunit_parser.Test(),
                                          'Tests not Parsed.')

    if request.raw_output:
        # Treat unparsed results as one passing test.
        test_result.test.status = kunit_parser.TestStatus.SUCCESS
        test_result.test.counts.passed = 1

        output: Iterable[str] = input_data
        if request.raw_output == 'all':
            pass
        elif request.raw_output == 'kunit':
            output = kunit_parser.extract_tap_lines(output)
        else:
            print(f'Unknown --raw_output option "{request.raw_output}"',
                  file=sys.stderr)
        for line in output:
            print(line.rstrip())

    else:
        test_result = kunit_parser.parse_run_tests(input_data)
    parse_end = time.time()

    if request.json:
        json_obj = kunit_json.get_json_result(test_result=test_result,
                                              def_config='kunit_defconfig',
                                              build_dir=request.build_dir,
                                              json_path=request.json)
        if request.json == 'stdout':
            print(json_obj)

    if test_result.status != kunit_parser.TestStatus.SUCCESS:
        return KunitResult(KunitStatus.TEST_FAILURE, test_result,
                           parse_end - parse_start)

    return KunitResult(KunitStatus.SUCCESS, test_result,
                       parse_end - parse_start)
Example #11
0
def parse_tests(
        request: KunitParseRequest, metadata: kunit_json.Metadata,
        input_data: Iterable[str]) -> Tuple[KunitResult, kunit_parser.Test]:
    parse_start = time.time()

    test_result = kunit_parser.Test()

    if request.raw_output:
        # Treat unparsed results as one passing test.
        test_result.status = kunit_parser.TestStatus.SUCCESS
        test_result.counts.passed = 1

        output: Iterable[str] = input_data
        if request.raw_output == 'all':
            pass
        elif request.raw_output == 'kunit':
            output = kunit_parser.extract_tap_lines(output)
        for line in output:
            print(line.rstrip())

    else:
        test_result = kunit_parser.parse_run_tests(input_data)
    parse_end = time.time()

    if request.json:
        json_str = kunit_json.get_json_result(test=test_result,
                                              metadata=metadata)
        if request.json == 'stdout':
            print(json_str)
        else:
            with open(request.json, 'w') as f:
                f.write(json_str)
            kunit_parser.print_with_timestamp("Test results stored in %s" %
                                              os.path.abspath(request.json))

    if test_result.status != kunit_parser.TestStatus.SUCCESS:
        return KunitResult(KunitStatus.TEST_FAILURE,
                           parse_end - parse_start), test_result

    return KunitResult(KunitStatus.SUCCESS,
                       parse_end - parse_start), test_result