Finn Behrens | c25ce58 | 2020-11-23 15:15:33 +0100 | [diff] [blame^] | 1 | #!/usr/bin/env python3 |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0 |
| 3 | # |
| 4 | # A collection of tests for tools/testing/kunit/kunit.py |
| 5 | # |
| 6 | # Copyright (C) 2019, Google LLC. |
| 7 | # Author: Brendan Higgins <brendanhiggins@google.com> |
| 8 | |
| 9 | import unittest |
| 10 | from unittest import mock |
| 11 | |
| 12 | import tempfile, shutil # Handling test_tmpdir |
| 13 | |
Heidi Fahim | 21a6d17 | 2020-08-11 14:27:56 -0700 | [diff] [blame] | 14 | import json |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 15 | import os |
| 16 | |
| 17 | import kunit_config |
| 18 | import kunit_parser |
| 19 | import kunit_kernel |
Heidi Fahim | 21a6d17 | 2020-08-11 14:27:56 -0700 | [diff] [blame] | 20 | import kunit_json |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 21 | import kunit |
| 22 | |
| 23 | test_tmpdir = '' |
| 24 | |
| 25 | def setUpModule(): |
| 26 | global test_tmpdir |
| 27 | test_tmpdir = tempfile.mkdtemp() |
| 28 | |
| 29 | def tearDownModule(): |
| 30 | shutil.rmtree(test_tmpdir) |
| 31 | |
| 32 | def get_absolute_path(path): |
| 33 | return os.path.join(os.path.dirname(__file__), path) |
| 34 | |
| 35 | class KconfigTest(unittest.TestCase): |
| 36 | |
| 37 | def test_is_subset_of(self): |
| 38 | kconfig0 = kunit_config.Kconfig() |
| 39 | self.assertTrue(kconfig0.is_subset_of(kconfig0)) |
| 40 | |
| 41 | kconfig1 = kunit_config.Kconfig() |
David Gow | 97752c3 | 2020-03-23 19:43:33 -0700 | [diff] [blame] | 42 | kconfig1.add_entry(kunit_config.KconfigEntry('TEST', 'y')) |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 43 | self.assertTrue(kconfig1.is_subset_of(kconfig1)) |
| 44 | self.assertTrue(kconfig0.is_subset_of(kconfig1)) |
| 45 | self.assertFalse(kconfig1.is_subset_of(kconfig0)) |
| 46 | |
| 47 | def test_read_from_file(self): |
| 48 | kconfig = kunit_config.Kconfig() |
| 49 | kconfig_path = get_absolute_path( |
| 50 | 'test_data/test_read_from_file.kconfig') |
| 51 | |
| 52 | kconfig.read_from_file(kconfig_path) |
| 53 | |
| 54 | expected_kconfig = kunit_config.Kconfig() |
| 55 | expected_kconfig.add_entry( |
David Gow | 97752c3 | 2020-03-23 19:43:33 -0700 | [diff] [blame] | 56 | kunit_config.KconfigEntry('UML', 'y')) |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 57 | expected_kconfig.add_entry( |
David Gow | 97752c3 | 2020-03-23 19:43:33 -0700 | [diff] [blame] | 58 | kunit_config.KconfigEntry('MMU', 'y')) |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 59 | expected_kconfig.add_entry( |
David Gow | 97752c3 | 2020-03-23 19:43:33 -0700 | [diff] [blame] | 60 | kunit_config.KconfigEntry('TEST', 'y')) |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 61 | expected_kconfig.add_entry( |
David Gow | 97752c3 | 2020-03-23 19:43:33 -0700 | [diff] [blame] | 62 | kunit_config.KconfigEntry('EXAMPLE_TEST', 'y')) |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 63 | expected_kconfig.add_entry( |
David Gow | 97752c3 | 2020-03-23 19:43:33 -0700 | [diff] [blame] | 64 | kunit_config.KconfigEntry('MK8', 'n')) |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 65 | |
| 66 | self.assertEqual(kconfig.entries(), expected_kconfig.entries()) |
| 67 | |
| 68 | def test_write_to_file(self): |
| 69 | kconfig_path = os.path.join(test_tmpdir, '.config') |
| 70 | |
| 71 | expected_kconfig = kunit_config.Kconfig() |
| 72 | expected_kconfig.add_entry( |
David Gow | 97752c3 | 2020-03-23 19:43:33 -0700 | [diff] [blame] | 73 | kunit_config.KconfigEntry('UML', 'y')) |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 74 | expected_kconfig.add_entry( |
David Gow | 97752c3 | 2020-03-23 19:43:33 -0700 | [diff] [blame] | 75 | kunit_config.KconfigEntry('MMU', 'y')) |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 76 | expected_kconfig.add_entry( |
David Gow | 97752c3 | 2020-03-23 19:43:33 -0700 | [diff] [blame] | 77 | kunit_config.KconfigEntry('TEST', 'y')) |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 78 | expected_kconfig.add_entry( |
David Gow | 97752c3 | 2020-03-23 19:43:33 -0700 | [diff] [blame] | 79 | kunit_config.KconfigEntry('EXAMPLE_TEST', 'y')) |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 80 | expected_kconfig.add_entry( |
David Gow | 97752c3 | 2020-03-23 19:43:33 -0700 | [diff] [blame] | 81 | kunit_config.KconfigEntry('MK8', 'n')) |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 82 | |
| 83 | expected_kconfig.write_to_file(kconfig_path) |
| 84 | |
| 85 | actual_kconfig = kunit_config.Kconfig() |
| 86 | actual_kconfig.read_from_file(kconfig_path) |
| 87 | |
| 88 | self.assertEqual(actual_kconfig.entries(), |
| 89 | expected_kconfig.entries()) |
| 90 | |
| 91 | class KUnitParserTest(unittest.TestCase): |
| 92 | |
| 93 | def assertContains(self, needle, haystack): |
| 94 | for line in haystack: |
| 95 | if needle in line: |
| 96 | return |
| 97 | raise AssertionError('"' + |
| 98 | str(needle) + '" not found in "' + str(haystack) + '"!') |
| 99 | |
| 100 | def test_output_isolated_correctly(self): |
| 101 | log_path = get_absolute_path( |
| 102 | 'test_data/test_output_isolated_correctly.log') |
| 103 | file = open(log_path) |
| 104 | result = kunit_parser.isolate_kunit_output(file.readlines()) |
Daniel Latypov | 060352e | 2020-10-30 15:38:53 -0700 | [diff] [blame] | 105 | self.assertContains('TAP version 14', result) |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 106 | self.assertContains(' # Subtest: example', result) |
| 107 | self.assertContains(' 1..2', result) |
| 108 | self.assertContains(' ok 1 - example_simple_test', result) |
| 109 | self.assertContains(' ok 2 - example_mock_test', result) |
| 110 | self.assertContains('ok 1 - example', result) |
| 111 | file.close() |
| 112 | |
Heidi Fahim | afc63da | 2020-03-16 13:21:24 -0700 | [diff] [blame] | 113 | def test_output_with_prefix_isolated_correctly(self): |
| 114 | log_path = get_absolute_path( |
| 115 | 'test_data/test_pound_sign.log') |
| 116 | with open(log_path) as file: |
| 117 | result = kunit_parser.isolate_kunit_output(file.readlines()) |
Daniel Latypov | 060352e | 2020-10-30 15:38:53 -0700 | [diff] [blame] | 118 | self.assertContains('TAP version 14', result) |
Heidi Fahim | afc63da | 2020-03-16 13:21:24 -0700 | [diff] [blame] | 119 | self.assertContains(' # Subtest: kunit-resource-test', result) |
| 120 | self.assertContains(' 1..5', result) |
| 121 | self.assertContains(' ok 1 - kunit_resource_test_init_resources', result) |
| 122 | self.assertContains(' ok 2 - kunit_resource_test_alloc_resource', result) |
| 123 | self.assertContains(' ok 3 - kunit_resource_test_destroy_resource', result) |
| 124 | self.assertContains(' foo bar #', result) |
| 125 | self.assertContains(' ok 4 - kunit_resource_test_cleanup_resources', result) |
| 126 | self.assertContains(' ok 5 - kunit_resource_test_proper_free_ordering', result) |
| 127 | self.assertContains('ok 1 - kunit-resource-test', result) |
| 128 | self.assertContains(' foo bar # non-kunit output', result) |
| 129 | self.assertContains(' # Subtest: kunit-try-catch-test', result) |
| 130 | self.assertContains(' 1..2', result) |
| 131 | self.assertContains(' ok 1 - kunit_test_try_catch_successful_try_no_catch', |
| 132 | result) |
| 133 | self.assertContains(' ok 2 - kunit_test_try_catch_unsuccessful_try_does_catch', |
| 134 | result) |
| 135 | self.assertContains('ok 2 - kunit-try-catch-test', result) |
| 136 | self.assertContains(' # Subtest: string-stream-test', result) |
| 137 | self.assertContains(' 1..3', result) |
| 138 | self.assertContains(' ok 1 - string_stream_test_empty_on_creation', result) |
| 139 | self.assertContains(' ok 2 - string_stream_test_not_empty_after_add', result) |
| 140 | self.assertContains(' ok 3 - string_stream_test_get_string', result) |
| 141 | self.assertContains('ok 3 - string-stream-test', result) |
| 142 | |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 143 | def test_parse_successful_test_log(self): |
| 144 | all_passed_log = get_absolute_path( |
| 145 | 'test_data/test_is_test_passed-all_passed.log') |
| 146 | file = open(all_passed_log) |
| 147 | result = kunit_parser.parse_run_tests(file.readlines()) |
| 148 | self.assertEqual( |
| 149 | kunit_parser.TestStatus.SUCCESS, |
| 150 | result.status) |
| 151 | file.close() |
| 152 | |
| 153 | def test_parse_failed_test_log(self): |
| 154 | failed_log = get_absolute_path( |
| 155 | 'test_data/test_is_test_passed-failure.log') |
| 156 | file = open(failed_log) |
| 157 | result = kunit_parser.parse_run_tests(file.readlines()) |
| 158 | self.assertEqual( |
| 159 | kunit_parser.TestStatus.FAILURE, |
| 160 | result.status) |
| 161 | file.close() |
| 162 | |
| 163 | def test_no_tests(self): |
| 164 | empty_log = get_absolute_path( |
| 165 | 'test_data/test_is_test_passed-no_tests_run.log') |
| 166 | file = open(empty_log) |
| 167 | result = kunit_parser.parse_run_tests( |
| 168 | kunit_parser.isolate_kunit_output(file.readlines())) |
| 169 | self.assertEqual(0, len(result.suites)) |
| 170 | self.assertEqual( |
| 171 | kunit_parser.TestStatus.NO_TESTS, |
| 172 | result.status) |
| 173 | file.close() |
| 174 | |
Uriel Guajardo | e173b8b | 2020-06-11 21:05:45 +0000 | [diff] [blame] | 175 | def test_no_kunit_output(self): |
| 176 | crash_log = get_absolute_path( |
| 177 | 'test_data/test_insufficient_memory.log') |
| 178 | file = open(crash_log) |
| 179 | print_mock = mock.patch('builtins.print').start() |
| 180 | result = kunit_parser.parse_run_tests( |
| 181 | kunit_parser.isolate_kunit_output(file.readlines())) |
Brendan Higgins | 0d0d245 | 2020-10-21 13:39:14 -0700 | [diff] [blame] | 182 | print_mock.assert_any_call(StrContains('no tests run!')) |
Uriel Guajardo | e173b8b | 2020-06-11 21:05:45 +0000 | [diff] [blame] | 183 | print_mock.stop() |
| 184 | file.close() |
| 185 | |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 186 | def test_crashed_test(self): |
| 187 | crashed_log = get_absolute_path( |
| 188 | 'test_data/test_is_test_passed-crash.log') |
| 189 | file = open(crashed_log) |
| 190 | result = kunit_parser.parse_run_tests(file.readlines()) |
| 191 | self.assertEqual( |
| 192 | kunit_parser.TestStatus.TEST_CRASHED, |
| 193 | result.status) |
| 194 | file.close() |
| 195 | |
Heidi Fahim | afc63da | 2020-03-16 13:21:24 -0700 | [diff] [blame] | 196 | def test_ignores_prefix_printk_time(self): |
| 197 | prefix_log = get_absolute_path( |
| 198 | 'test_data/test_config_printk_time.log') |
| 199 | with open(prefix_log) as file: |
| 200 | result = kunit_parser.parse_run_tests(file.readlines()) |
Brendan Higgins | 0d0d245 | 2020-10-21 13:39:14 -0700 | [diff] [blame] | 201 | self.assertEqual( |
| 202 | kunit_parser.TestStatus.SUCCESS, |
| 203 | result.status) |
| 204 | self.assertEqual('kunit-resource-test', result.suites[0].name) |
Heidi Fahim | afc63da | 2020-03-16 13:21:24 -0700 | [diff] [blame] | 205 | |
| 206 | def test_ignores_multiple_prefixes(self): |
| 207 | prefix_log = get_absolute_path( |
| 208 | 'test_data/test_multiple_prefixes.log') |
| 209 | with open(prefix_log) as file: |
| 210 | result = kunit_parser.parse_run_tests(file.readlines()) |
Brendan Higgins | 0d0d245 | 2020-10-21 13:39:14 -0700 | [diff] [blame] | 211 | self.assertEqual( |
| 212 | kunit_parser.TestStatus.SUCCESS, |
| 213 | result.status) |
| 214 | self.assertEqual('kunit-resource-test', result.suites[0].name) |
Heidi Fahim | afc63da | 2020-03-16 13:21:24 -0700 | [diff] [blame] | 215 | |
| 216 | def test_prefix_mixed_kernel_output(self): |
| 217 | mixed_prefix_log = get_absolute_path( |
| 218 | 'test_data/test_interrupted_tap_output.log') |
| 219 | with open(mixed_prefix_log) as file: |
| 220 | result = kunit_parser.parse_run_tests(file.readlines()) |
Brendan Higgins | 0d0d245 | 2020-10-21 13:39:14 -0700 | [diff] [blame] | 221 | self.assertEqual( |
| 222 | kunit_parser.TestStatus.SUCCESS, |
| 223 | result.status) |
| 224 | self.assertEqual('kunit-resource-test', result.suites[0].name) |
Heidi Fahim | afc63da | 2020-03-16 13:21:24 -0700 | [diff] [blame] | 225 | |
| 226 | def test_prefix_poundsign(self): |
| 227 | pound_log = get_absolute_path('test_data/test_pound_sign.log') |
| 228 | with open(pound_log) as file: |
| 229 | result = kunit_parser.parse_run_tests(file.readlines()) |
Brendan Higgins | 0d0d245 | 2020-10-21 13:39:14 -0700 | [diff] [blame] | 230 | self.assertEqual( |
| 231 | kunit_parser.TestStatus.SUCCESS, |
| 232 | result.status) |
| 233 | self.assertEqual('kunit-resource-test', result.suites[0].name) |
Heidi Fahim | afc63da | 2020-03-16 13:21:24 -0700 | [diff] [blame] | 234 | |
| 235 | def test_kernel_panic_end(self): |
| 236 | panic_log = get_absolute_path('test_data/test_kernel_panic_interrupt.log') |
| 237 | with open(panic_log) as file: |
| 238 | result = kunit_parser.parse_run_tests(file.readlines()) |
Brendan Higgins | 0d0d245 | 2020-10-21 13:39:14 -0700 | [diff] [blame] | 239 | self.assertEqual( |
| 240 | kunit_parser.TestStatus.TEST_CRASHED, |
| 241 | result.status) |
| 242 | self.assertEqual('kunit-resource-test', result.suites[0].name) |
Heidi Fahim | afc63da | 2020-03-16 13:21:24 -0700 | [diff] [blame] | 243 | |
| 244 | def test_pound_no_prefix(self): |
| 245 | pound_log = get_absolute_path('test_data/test_pound_no_prefix.log') |
| 246 | with open(pound_log) as file: |
| 247 | result = kunit_parser.parse_run_tests(file.readlines()) |
Brendan Higgins | 0d0d245 | 2020-10-21 13:39:14 -0700 | [diff] [blame] | 248 | self.assertEqual( |
| 249 | kunit_parser.TestStatus.SUCCESS, |
| 250 | result.status) |
| 251 | self.assertEqual('kunit-resource-test', result.suites[0].name) |
Heidi Fahim | afc63da | 2020-03-16 13:21:24 -0700 | [diff] [blame] | 252 | |
Heidi Fahim | 21a6d17 | 2020-08-11 14:27:56 -0700 | [diff] [blame] | 253 | class KUnitJsonTest(unittest.TestCase): |
| 254 | |
| 255 | def _json_for(self, log_file): |
| 256 | with(open(get_absolute_path(log_file))) as file: |
| 257 | test_result = kunit_parser.parse_run_tests(file) |
| 258 | json_obj = kunit_json.get_json_result( |
| 259 | test_result=test_result, |
| 260 | def_config='kunit_defconfig', |
| 261 | build_dir=None, |
| 262 | json_path='stdout') |
| 263 | return json.loads(json_obj) |
| 264 | |
| 265 | def test_failed_test_json(self): |
| 266 | result = self._json_for( |
| 267 | 'test_data/test_is_test_passed-failure.log') |
| 268 | self.assertEqual( |
| 269 | {'name': 'example_simple_test', 'status': 'FAIL'}, |
| 270 | result["sub_groups"][1]["test_cases"][0]) |
| 271 | |
| 272 | def test_crashed_test_json(self): |
| 273 | result = self._json_for( |
| 274 | 'test_data/test_is_test_passed-crash.log') |
| 275 | self.assertEqual( |
| 276 | {'name': 'example_simple_test', 'status': 'ERROR'}, |
| 277 | result["sub_groups"][1]["test_cases"][0]) |
| 278 | |
| 279 | def test_no_tests_json(self): |
| 280 | result = self._json_for( |
| 281 | 'test_data/test_is_test_passed-no_tests_run.log') |
| 282 | self.assertEqual(0, len(result['sub_groups'])) |
| 283 | |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 284 | class StrContains(str): |
| 285 | def __eq__(self, other): |
| 286 | return self in other |
| 287 | |
| 288 | class KUnitMainTest(unittest.TestCase): |
| 289 | def setUp(self): |
| 290 | path = get_absolute_path('test_data/test_is_test_passed-all_passed.log') |
| 291 | file = open(path) |
| 292 | all_passed_log = file.readlines() |
| 293 | self.print_patch = mock.patch('builtins.print') |
| 294 | self.print_mock = self.print_patch.start() |
| 295 | self.linux_source_mock = mock.Mock() |
| 296 | self.linux_source_mock.build_reconfig = mock.Mock(return_value=True) |
| 297 | self.linux_source_mock.build_um_kernel = mock.Mock(return_value=True) |
| 298 | self.linux_source_mock.run_kernel = mock.Mock(return_value=all_passed_log) |
| 299 | |
| 300 | def tearDown(self): |
| 301 | self.print_patch.stop() |
| 302 | pass |
| 303 | |
David Gow | 45ba7a8 | 2020-04-30 21:27:01 -0700 | [diff] [blame] | 304 | def test_config_passes_args_pass(self): |
Brendan Higgins | d43c7fb | 2020-07-14 13:41:30 -0700 | [diff] [blame] | 305 | kunit.main(['config', '--build_dir=.kunit'], self.linux_source_mock) |
David Gow | 45ba7a8 | 2020-04-30 21:27:01 -0700 | [diff] [blame] | 306 | assert self.linux_source_mock.build_reconfig.call_count == 1 |
| 307 | assert self.linux_source_mock.run_kernel.call_count == 0 |
| 308 | |
| 309 | def test_build_passes_args_pass(self): |
| 310 | kunit.main(['build'], self.linux_source_mock) |
| 311 | assert self.linux_source_mock.build_reconfig.call_count == 0 |
Brendan Higgins | 6816fe6 | 2020-07-14 13:41:29 -0700 | [diff] [blame] | 312 | self.linux_source_mock.build_um_kernel.assert_called_once_with(False, 8, '.kunit', None) |
David Gow | 45ba7a8 | 2020-04-30 21:27:01 -0700 | [diff] [blame] | 313 | assert self.linux_source_mock.run_kernel.call_count == 0 |
| 314 | |
| 315 | def test_exec_passes_args_pass(self): |
| 316 | kunit.main(['exec'], self.linux_source_mock) |
| 317 | assert self.linux_source_mock.build_reconfig.call_count == 0 |
| 318 | assert self.linux_source_mock.run_kernel.call_count == 1 |
Brendan Higgins | 6816fe6 | 2020-07-14 13:41:29 -0700 | [diff] [blame] | 319 | self.linux_source_mock.run_kernel.assert_called_once_with(build_dir='.kunit', timeout=300) |
David Gow | 45ba7a8 | 2020-04-30 21:27:01 -0700 | [diff] [blame] | 320 | self.print_mock.assert_any_call(StrContains('Testing complete.')) |
| 321 | |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 322 | def test_run_passes_args_pass(self): |
| 323 | kunit.main(['run'], self.linux_source_mock) |
| 324 | assert self.linux_source_mock.build_reconfig.call_count == 1 |
| 325 | assert self.linux_source_mock.run_kernel.call_count == 1 |
Heidi Fahim | 021ed9f | 2020-03-16 13:21:25 -0700 | [diff] [blame] | 326 | self.linux_source_mock.run_kernel.assert_called_once_with( |
Brendan Higgins | 6816fe6 | 2020-07-14 13:41:29 -0700 | [diff] [blame] | 327 | build_dir='.kunit', timeout=300) |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 328 | self.print_mock.assert_any_call(StrContains('Testing complete.')) |
| 329 | |
David Gow | 45ba7a8 | 2020-04-30 21:27:01 -0700 | [diff] [blame] | 330 | def test_exec_passes_args_fail(self): |
| 331 | self.linux_source_mock.run_kernel = mock.Mock(return_value=[]) |
| 332 | with self.assertRaises(SystemExit) as e: |
| 333 | kunit.main(['exec'], self.linux_source_mock) |
| 334 | assert type(e.exception) == SystemExit |
| 335 | assert e.exception.code == 1 |
| 336 | |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 337 | def test_run_passes_args_fail(self): |
| 338 | self.linux_source_mock.run_kernel = mock.Mock(return_value=[]) |
| 339 | with self.assertRaises(SystemExit) as e: |
| 340 | kunit.main(['run'], self.linux_source_mock) |
| 341 | assert type(e.exception) == SystemExit |
| 342 | assert e.exception.code == 1 |
| 343 | assert self.linux_source_mock.build_reconfig.call_count == 1 |
| 344 | assert self.linux_source_mock.run_kernel.call_count == 1 |
| 345 | self.print_mock.assert_any_call(StrContains(' 0 tests run')) |
| 346 | |
David Gow | 45ba7a8 | 2020-04-30 21:27:01 -0700 | [diff] [blame] | 347 | def test_exec_raw_output(self): |
| 348 | self.linux_source_mock.run_kernel = mock.Mock(return_value=[]) |
| 349 | kunit.main(['exec', '--raw_output'], self.linux_source_mock) |
| 350 | assert self.linux_source_mock.run_kernel.call_count == 1 |
| 351 | for kall in self.print_mock.call_args_list: |
| 352 | assert kall != mock.call(StrContains('Testing complete.')) |
| 353 | assert kall != mock.call(StrContains(' 0 tests run')) |
| 354 | |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 355 | def test_run_raw_output(self): |
| 356 | self.linux_source_mock.run_kernel = mock.Mock(return_value=[]) |
David Gow | 45ba7a8 | 2020-04-30 21:27:01 -0700 | [diff] [blame] | 357 | kunit.main(['run', '--raw_output'], self.linux_source_mock) |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 358 | assert self.linux_source_mock.build_reconfig.call_count == 1 |
| 359 | assert self.linux_source_mock.run_kernel.call_count == 1 |
David Gow | 45ba7a8 | 2020-04-30 21:27:01 -0700 | [diff] [blame] | 360 | for kall in self.print_mock.call_args_list: |
| 361 | assert kall != mock.call(StrContains('Testing complete.')) |
| 362 | assert kall != mock.call(StrContains(' 0 tests run')) |
| 363 | |
| 364 | def test_exec_timeout(self): |
| 365 | timeout = 3453 |
| 366 | kunit.main(['exec', '--timeout', str(timeout)], self.linux_source_mock) |
Brendan Higgins | 6816fe6 | 2020-07-14 13:41:29 -0700 | [diff] [blame] | 367 | self.linux_source_mock.run_kernel.assert_called_once_with(build_dir='.kunit', timeout=timeout) |
David Gow | 45ba7a8 | 2020-04-30 21:27:01 -0700 | [diff] [blame] | 368 | self.print_mock.assert_any_call(StrContains('Testing complete.')) |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 369 | |
| 370 | def test_run_timeout(self): |
| 371 | timeout = 3453 |
| 372 | kunit.main(['run', '--timeout', str(timeout)], self.linux_source_mock) |
| 373 | assert self.linux_source_mock.build_reconfig.call_count == 1 |
Heidi Fahim | 021ed9f | 2020-03-16 13:21:25 -0700 | [diff] [blame] | 374 | self.linux_source_mock.run_kernel.assert_called_once_with( |
Brendan Higgins | 6816fe6 | 2020-07-14 13:41:29 -0700 | [diff] [blame] | 375 | build_dir='.kunit', timeout=timeout) |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 376 | self.print_mock.assert_any_call(StrContains('Testing complete.')) |
| 377 | |
SeongJae Park | b1b3520 | 2019-12-20 05:14:08 +0000 | [diff] [blame] | 378 | def test_run_builddir(self): |
| 379 | build_dir = '.kunit' |
Brendan Higgins | d43c7fb | 2020-07-14 13:41:30 -0700 | [diff] [blame] | 380 | kunit.main(['run', '--build_dir=.kunit'], self.linux_source_mock) |
SeongJae Park | b1b3520 | 2019-12-20 05:14:08 +0000 | [diff] [blame] | 381 | assert self.linux_source_mock.build_reconfig.call_count == 1 |
Heidi Fahim | 021ed9f | 2020-03-16 13:21:25 -0700 | [diff] [blame] | 382 | self.linux_source_mock.run_kernel.assert_called_once_with( |
| 383 | build_dir=build_dir, timeout=300) |
SeongJae Park | b1b3520 | 2019-12-20 05:14:08 +0000 | [diff] [blame] | 384 | self.print_mock.assert_any_call(StrContains('Testing complete.')) |
| 385 | |
David Gow | 45ba7a8 | 2020-04-30 21:27:01 -0700 | [diff] [blame] | 386 | def test_config_builddir(self): |
| 387 | build_dir = '.kunit' |
| 388 | kunit.main(['config', '--build_dir', build_dir], self.linux_source_mock) |
| 389 | assert self.linux_source_mock.build_reconfig.call_count == 1 |
| 390 | |
| 391 | def test_build_builddir(self): |
| 392 | build_dir = '.kunit' |
| 393 | kunit.main(['build', '--build_dir', build_dir], self.linux_source_mock) |
| 394 | self.linux_source_mock.build_um_kernel.assert_called_once_with(False, 8, build_dir, None) |
| 395 | |
| 396 | def test_exec_builddir(self): |
| 397 | build_dir = '.kunit' |
| 398 | kunit.main(['exec', '--build_dir', build_dir], self.linux_source_mock) |
| 399 | self.linux_source_mock.run_kernel.assert_called_once_with(build_dir=build_dir, timeout=300) |
| 400 | self.print_mock.assert_any_call(StrContains('Testing complete.')) |
| 401 | |
Felix Guo | 6ebf586 | 2019-09-23 02:02:43 -0700 | [diff] [blame] | 402 | if __name__ == '__main__': |
| 403 | unittest.main() |