Lines Matching +full:self +full:-

2 # SPDX-License-Identifier: GPL-2.0
43 def test_is_subset_of(self): argument
45 self.assertTrue(kconfig0.is_subset_of(kconfig0))
49 self.assertTrue(kconfig1.is_subset_of(kconfig1))
50 self.assertTrue(kconfig0.is_subset_of(kconfig1))
51 self.assertFalse(kconfig1.is_subset_of(kconfig0))
53 def test_read_from_file(self): argument
65 self.assertEqual(kconfig, expected_kconfig)
67 def test_write_to_file(self): argument
80 self.assertEqual(actual_kconfig, expected_kconfig)
83 def setUp(self): argument
84 self.print_mock = mock.patch('kunit_printer.Printer.print').start()
85 self.addCleanup(mock.patch.stopall)
87 def noPrintCallContains(self, substr: str): argument
88 for call in self.print_mock.mock_calls:
89 self.assertNotIn(substr, call.args[0])
91 def assertContains(self, needle: str, haystack: kunit_parser.LineStream): argument
99 def test_output_isolated_correctly(self): argument
103 self.assertContains('TAP version 14', result)
104 self.assertContains('# Subtest: example', result)
105 self.assertContains('1..2', result)
106 self.assertContains('ok 1 - example_simple_test', result)
107 self.assertContains('ok 2 - example_mock_test', result)
108 self.assertContains('ok 1 - example', result)
110 def test_output_with_prefix_isolated_correctly(self): argument
114 self.assertContains('TAP version 14', result)
115 self.assertContains('# Subtest: kunit-resource-test', result)
116 self.assertContains('1..5', result)
117 self.assertContains('ok 1 - kunit_resource_test_init_resources', result)
118 self.assertContains('ok 2 - kunit_resource_test_alloc_resource', result)
119 self.assertContains('ok 3 - kunit_resource_test_destroy_resource', result)
120 self.assertContains('foo bar #', result)
121 self.assertContains('ok 4 - kunit_resource_test_cleanup_resources', result)
122 self.assertContains('ok 5 - kunit_resource_test_proper_free_ordering', result)
123 self.assertContains('ok 1 - kunit-resource-test', result)
124 self.assertContains('foo bar # non-kunit output', result)
125 self.assertContains('# Subtest: kunit-try-catch-test', result)
126 self.assertContains('1..2', result)
127 self.assertContains('ok 1 - kunit_test_try_catch_successful_try_no_catch',
129 self.assertContains('ok 2 - kunit_test_try_catch_unsuccessful_try_does_catch',
131 self.assertContains('ok 2 - kunit-try-catch-test', result)
132 self.assertContains('# Subtest: string-stream-test', result)
133 self.assertContains('1..3', result)
134 self.assertContains('ok 1 - string_stream_test_empty_on_creation', result)
135 self.assertContains('ok 2 - string_stream_test_not_empty_after_add', result)
136 self.assertContains('ok 3 - string_stream_test_get_string', result)
137 self.assertContains('ok 3 - string-stream-test', result)
139 def test_parse_successful_test_log(self): argument
140 all_passed_log = test_data_path('test_is_test_passed-all_passed.log')
143 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
144 self.assertEqual(result.counts.errors, 0)
146 def test_parse_successful_nested_tests_log(self): argument
147 all_passed_log = test_data_path('test_is_test_passed-all_passed_nested.log')
150 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
151 self.assertEqual(result.counts.errors, 0)
153 def test_kselftest_nested(self): argument
154 kselftest_log = test_data_path('test_is_test_passed-kselftest.log')
157 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
158 self.assertEqual(result.counts.errors, 0)
160 def test_parse_failed_test_log(self): argument
161 failed_log = test_data_path('test_is_test_passed-failure.log')
164 self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status)
165 self.assertEqual(result.counts.errors, 0)
167 def test_no_header(self): argument
168 empty_log = test_data_path('test_is_test_passed-no_tests_run_no_header.log')
172 self.assertEqual(0, len(result.subtests))
173 self.assertEqual(kunit_parser.TestStatus.FAILURE_TO_PARSE_TESTS, result.status)
174 self.assertEqual(result.counts.errors, 1)
176 def test_missing_test_plan(self): argument
177 missing_plan_log = test_data_path('test_is_test_passed-'
184 self.assertEqual(result.counts, kunit_parser.TestCounts(passed=10, errors=0))
185 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
187 def test_no_tests(self): argument
188 header_log = test_data_path('test_is_test_passed-no_tests_run_with_header.log')
192 self.assertEqual(0, len(result.subtests))
193 self.assertEqual(kunit_parser.TestStatus.NO_TESTS, result.status)
194 self.assertEqual(result.counts.errors, 1)
196 def test_no_tests_no_plan(self): argument
197 no_plan_log = test_data_path('test_is_test_passed-no_tests_no_plan.log')
201 self.assertEqual(0, len(result.subtests[0].subtests[0].subtests))
202 self.assertEqual(
205 self.assertEqual(result.counts, kunit_parser.TestCounts(passed=1, errors=1))
208 def test_no_kunit_output(self): argument
216 self.assertEqual(0, len(result.subtests))
217 self.assertEqual(result.counts.errors, 1)
219 def test_skipped_test(self): argument
225 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
226 self.assertEqual(result.counts, kunit_parser.TestCounts(passed=4, skipped=1))
228 def test_skipped_all_tests(self): argument
233 self.assertEqual(kunit_parser.TestStatus.SKIPPED, result.status)
234 self.assertEqual(result.counts, kunit_parser.TestCounts(skipped=5))
236 def test_ignores_hyphen(self): argument
242 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
243 self.assertEqual(
246 self.assertEqual(
250 def test_ignores_prefix_printk_time(self): argument
254 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
255 self.assertEqual('kunit-resource-test', result.subtests[0].name)
256 self.assertEqual(result.counts.errors, 0)
258 def test_ignores_multiple_prefixes(self): argument
262 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
263 self.assertEqual('kunit-resource-test', result.subtests[0].name)
264 self.assertEqual(result.counts.errors, 0)
266 def test_prefix_mixed_kernel_output(self): argument
270 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
271 self.assertEqual('kunit-resource-test', result.subtests[0].name)
272 self.assertEqual(result.counts.errors, 0)
274 def test_prefix_poundsign(self): argument
278 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
279 self.assertEqual('kunit-resource-test', result.subtests[0].name)
280 self.assertEqual(result.counts.errors, 0)
282 def test_kernel_panic_end(self): argument
286 self.assertEqual(kunit_parser.TestStatus.TEST_CRASHED, result.status)
287 self.assertEqual('kunit-resource-test', result.subtests[0].name)
288 self.assertGreaterEqual(result.counts.errors, 1)
290 def test_pound_no_prefix(self): argument
294 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
295 self.assertEqual('kunit-resource-test', result.subtests[0].name)
296 self.assertEqual(result.counts.errors, 0)
298 def test_summarize_failures(self): argument
304 not ok 1 - test1
305 not ok 2 - test2
306 not ok 1 - all_failed_suite
309 ok 1 - test1
310 not ok 2 - test2
311 not ok 1 - some_failed_suite
314 self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status)
316 self.assertEqual(kunit_parser._summarize_failed_tests(result),
319 def test_ktap_format(self): argument
323 self.assertEqual(result.counts, kunit_parser.TestCounts(passed=3))
324 self.assertEqual('suite', result.subtests[0].name)
325 self.assertEqual('case_1', result.subtests[0].subtests[0].name)
326 self.assertEqual('case_2', result.subtests[0].subtests[1].name)
328 def test_parse_subtest_header(self): argument
332 self.print_mock.assert_any_call(StrContains('suite (1 subtest)'))
334 def test_parse_attributes(self): argument
340 self.assertEqual(result.counts, kunit_parser.TestCounts(passed=1, errors=0))
341 self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.status)
344 self.print_mock.assert_any_call(StrContains('suite (1 subtest)'))
347 self.assertContains('# module: example', result.subtests[0].log)
348 self.assertContains('# test.speed: slow', result.subtests[0].subtests[0].log)
350 def test_show_test_output_on_failure(self): argument
359 self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status)
361 self.print_mock.assert_any_call(StrContains('Test output.'))
362 self.print_mock.assert_any_call(StrContains(' Indented more.'))
363 self.noPrintCallContains('not ok 1 test1')
365 def line_stream_from_strs(strs: Iterable[str]) -> kunit_parser.LineStream:
370 def test_basic(self): argument
373 self.assertTrue(stream, msg='Should be more input')
374 self.assertEqual(stream.line_number(), 1)
375 self.assertEqual(stream.peek(), 'hello')
376 self.assertEqual(stream.pop(), 'hello')
378 self.assertTrue(stream, msg='Should be more input')
379 self.assertEqual(stream.line_number(), 2)
380 self.assertEqual(stream.peek(), 'world')
381 self.assertEqual(stream.pop(), 'world')
383 self.assertFalse(stream, msg='Should be no more input')
384 with self.assertRaisesRegex(ValueError, 'LineStream: going past EOF'):
387 def test_is_lazy(self): argument
396 self.assertEqual(called_times, 0)
398 self.assertEqual(stream.pop(), '1')
399 self.assertEqual(called_times, 1)
401 self.assertEqual(stream.pop(), '2')
402 self.assertEqual(called_times, 2)
406 def setUp(self): argument
408 self.addCleanup(mock.patch.stopall)
410 def test_invalid_kunitconfig(self): argument
411 with self.assertRaisesRegex(kunit_kernel.ConfigError, 'nonexistent.* does not exist'):
414 def test_valid_kunitconfig(self): argument
418 def test_dir_kunitconfig(self): argument
424 def test_multiple_kunitconfig(self): argument
438 self.assertTrue(want_kconfig.is_subset_of(tree._kconfig), msg=tree._kconfig)
441 def test_multiple_kunitconfig_invalid(self): argument
449 with self.assertRaisesRegex(kunit_kernel.ConfigError, '(?s)Multiple values.*CONFIG_KUNIT'):
453 def test_kconfig_add(self): argument
458 self.assertTrue(want_kconfig.is_subset_of(tree._kconfig), msg=tree._kconfig)
460 def test_invalid_arch(self): argument
461 with self.assertRaisesRegex(kunit_kernel.ConfigError, 'not a valid arch, options are.*x86_64'):
464 def test_run_kernel_hits_exception(self): argument
472 with self.assertRaises(ValueError):
474 self.assertEqual(line, 'hi\n')
478 self.assertEqual(outfile.read(), 'hi\nbye\n', msg='Missing some output')
480 def test_build_reconfig_no_config(self): argument
493 self.assertTrue(tree.build_reconfig(build_dir, make_options=[]))
496 def test_build_reconfig_existing_config(self): argument
513 self.assertTrue(tree.build_reconfig(build_dir, make_options=[]))
514 self.assertEqual(mock_build_config.call_count, 0)
516 def test_build_reconfig_remove_option(self): argument
534 self.assertTrue(tree.build_reconfig(build_dir, make_options=[]))
541 def setUp(self): argument
542 self.print_mock = mock.patch('kunit_printer.Printer.print').start()
543 self.addCleanup(mock.patch.stopall)
545 def _json_for(self, log_file): argument
553 def test_failed_test_json(self): argument
554 result = self._json_for('test_is_test_passed-failure.log')
555 self.assertEqual(
559 def test_crashed_test_json(self): argument
560 result = self._json_for('test_kernel_panic_interrupt.log')
561 self.assertEqual(
565 def test_skipped_test_json(self): argument
566 result = self._json_for('test_skip_tests.log')
567 self.assertEqual(
571 def test_no_tests_json(self): argument
572 result = self._json_for('test_is_test_passed-no_tests_run_with_header.log')
573 self.assertEqual(0, len(result['sub_groups']))
575 def test_nested_json(self): argument
576 result = self._json_for('test_is_test_passed-all_passed_nested.log')
577 self.assertEqual(
582 def __eq__(self, other): argument
583 return self in other
586 def setUp(self): argument
587 path = test_data_path('test_is_test_passed-all_passed.log')
591 self.print_mock = mock.patch('kunit_printer.Printer.print').start()
592 self.addCleanup(mock.patch.stopall)
594 self.mock_linux_init = mock.patch.object(kunit_kernel, 'LinuxSourceTree').start()
595 self.linux_source_mock = self.mock_linux_init.return_value
596 self.linux_source_mock.build_reconfig.return_value = True
597 self.linux_source_mock.build_kernel.return_value = True
598 self.linux_source_mock.run_kernel.return_value = all_passed_log
600 def test_config_passes_args_pass(self): argument
601 kunit.main(['config', '--build_dir=.kunit'])
602 self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 1)
603 self.assertEqual(self.linux_source_mock.run_kernel.call_count, 0)
605 def test_build_passes_args_pass(self): argument
607 self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 1)
608self.linux_source_mock.build_kernel.assert_called_once_with(kunit.get_default_jobs(), '.kunit', No…
609 self.assertEqual(self.linux_source_mock.run_kernel.call_count, 0)
611 def test_exec_passes_args_pass(self): argument
613 self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 0)
614 self.assertEqual(self.linux_source_mock.run_kernel.call_count, 1)
615 self.linux_source_mock.run_kernel.assert_called_once_with(
617 self.print_mock.assert_any_call(StrContains('Testing complete.'))
619 def test_run_passes_args_pass(self): argument
621 self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 1)
622 self.assertEqual(self.linux_source_mock.run_kernel.call_count, 1)
623 self.linux_source_mock.run_kernel.assert_called_once_with(
625 self.print_mock.assert_any_call(StrContains('Testing complete.'))
627 def test_exec_passes_args_fail(self): argument
628 self.linux_source_mock.run_kernel = mock.Mock(return_value=[])
629 with self.assertRaises(SystemExit) as e:
631 self.assertEqual(e.exception.code, 1)
633 def test_run_passes_args_fail(self): argument
634 self.linux_source_mock.run_kernel = mock.Mock(return_value=[])
635 with self.assertRaises(SystemExit) as e:
637 self.assertEqual(e.exception.code, 1)
638 self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 1)
639 self.assertEqual(self.linux_source_mock.run_kernel.call_count, 1)
640 self.print_mock.assert_any_call(StrContains('Could not find any KTAP output.'))
642 def test_exec_no_tests(self): argument
643 self.linux_source_mock.run_kernel = mock.Mock(return_value=['TAP version 14', '1..0'])
644 with self.assertRaises(SystemExit) as e:
646 self.assertEqual(e.exception.code, 1)
647 self.linux_source_mock.run_kernel.assert_called_once_with(
649 self.print_mock.assert_any_call(StrContains(' 0 tests run!'))
651 def test_exec_raw_output(self): argument
652 self.linux_source_mock.run_kernel = mock.Mock(return_value=[])
653 kunit.main(['exec', '--raw_output'])
654 self.assertEqual(self.linux_source_mock.run_kernel.call_count, 1)
655 for call in self.print_mock.call_args_list:
656 self.assertNotEqual(call, mock.call(StrContains('Testing complete.')))
657 self.assertNotEqual(call, mock.call(StrContains(' 0 tests run!')))
659 def test_run_raw_output(self): argument
660 self.linux_source_mock.run_kernel = mock.Mock(return_value=[])
661 kunit.main(['run', '--raw_output'])
662 self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 1)
663 self.assertEqual(self.linux_source_mock.run_kernel.call_count, 1)
664 for call in self.print_mock.call_args_list:
665 self.assertNotEqual(call, mock.call(StrContains('Testing complete.')))
666 self.assertNotEqual(call, mock.call(StrContains(' 0 tests run!')))
668 def test_run_raw_output_kunit(self): argument
669 self.linux_source_mock.run_kernel = mock.Mock(return_value=[])
670 kunit.main(['run', '--raw_output=kunit'])
671 self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 1)
672 self.assertEqual(self.linux_source_mock.run_kernel.call_count, 1)
673 for call in self.print_mock.call_args_list:
674 self.assertNotEqual(call, mock.call(StrContains('Testing complete.')))
675 self.assertNotEqual(call, mock.call(StrContains(' 0 tests run')))
677 def test_run_raw_output_invalid(self): argument
678 self.linux_source_mock.run_kernel = mock.Mock(return_value=[])
679 with self.assertRaises(SystemExit) as e:
680 kunit.main(['run', '--raw_output=invalid'])
681 self.assertNotEqual(e.exception.code, 0)
683 def test_run_raw_output_does_not_take_positional_args(self): argument
684 # --raw_output is a string flag, but we don't want it to consume
686 self.linux_source_mock.run_kernel = mock.Mock(return_value=[])
687 kunit.main(['run', '--raw_output', 'filter_glob'])
688 self.linux_source_mock.run_kernel.assert_called_once_with(
691 def test_exec_timeout(self): argument
693 kunit.main(['exec', '--timeout', str(timeout)])
694 self.linux_source_mock.run_kernel.assert_called_once_with(
696 self.print_mock.assert_any_call(StrContains('Testing complete.'))
698 def test_run_timeout(self): argument
700 kunit.main(['run', '--timeout', str(timeout)])
701 self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 1)
702 self.linux_source_mock.run_kernel.assert_called_once_with(
704 self.print_mock.assert_any_call(StrContains('Testing complete.'))
706 def test_run_builddir(self): argument
708 kunit.main(['run', '--build_dir=.kunit'])
709 self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 1)
710 self.linux_source_mock.run_kernel.assert_called_once_with(
712 self.print_mock.assert_any_call(StrContains('Testing complete.'))
714 def test_config_builddir(self): argument
716 kunit.main(['config', '--build_dir', build_dir])
717 self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 1)
719 def test_build_builddir(self): argument
722 kunit.main(['build', '--build_dir', build_dir])
723 self.linux_source_mock.build_kernel.assert_called_once_with(jobs, build_dir, None)
725 def test_exec_builddir(self): argument
727 kunit.main(['exec', '--build_dir', build_dir])
728 self.linux_source_mock.run_kernel.assert_called_once_with(
730 self.print_mock.assert_any_call(StrContains('Testing complete.'))
732 def test_run_kunitconfig(self): argument
733 kunit.main(['run', '--kunitconfig=mykunitconfig'])
735 self.mock_linux_init.assert_called_once_with('.kunit',
743 def test_config_kunitconfig(self): argument
744 kunit.main(['config', '--kunitconfig=mykunitconfig'])
746 self.mock_linux_init.assert_called_once_with('.kunit',
754 def test_config_alltests(self): argument
755 kunit.main(['config', '--kunitconfig=mykunitconfig', '--alltests'])
757 self.mock_linux_init.assert_called_once_with('.kunit',
767 def test_run_multiple_kunitconfig(self, mock_linux_init): argument
768 mock_linux_init.return_value = self.linux_source_mock
769 kunit.main(['run', '--kunitconfig=mykunitconfig', '--kunitconfig=other'])
779 def test_run_kconfig_add(self): argument
780 kunit.main(['run', '--kconfig_add=CONFIG_KASAN=y', '--kconfig_add=CONFIG_KCSAN=y'])
782 self.mock_linux_init.assert_called_once_with('.kunit',
790 def test_run_qemu_args(self): argument
791 kunit.main(['run', '--arch=x86_64', '--qemu_args', '-m 2048'])
793 self.mock_linux_init.assert_called_once_with('.kunit',
799 extra_qemu_args=['-m', '2048'])
801 def test_run_kernel_args(self): argument
802 kunit.main(['run', '--kernel_args=a=1', '--kernel_args=b=2'])
803 self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 1)
804 self.linux_source_mock.run_kernel.assert_called_once_with(
806 self.print_mock.assert_any_call(StrContains('Testing complete.'))
808 def test_list_tests(self): argument
810 self.linux_source_mock.run_kernel.return_value = ['TAP version 14', 'init: random output'] + want
812 got = kunit._list_tests(self.linux_source_mock,
814 self.assertEqual(got, want)
816 self.linux_source_mock.run_kernel.assert_called_once_with(
820 def test_run_isolated_by_suite(self, mock_tests): argument
822 kunit.main(['exec', '--run_isolated=suite', 'suite*.test*'])
827 self.linux_source_mock.run_kernel.assert_has_calls([
833 def test_run_isolated_by_test(self, mock_tests): argument
835 kunit.main(['exec', '--run_isolated=test', 'suite*'])
840 self.linux_source_mock.run_kernel.assert_has_calls([