diff --git a/squad/plugins/linux_log_parser.py b/squad/plugins/linux_log_parser.py index 3ac0bde2..0df34916 100644 --- a/squad/plugins/linux_log_parser.py +++ b/squad/plugins/linux_log_parser.py @@ -78,30 +78,49 @@ def __create_tests(self, testrun, suite, test_name, lines, test_regex=None): regex, then a new test will be generated using test_name + shasum. This helps comparing kernel logs accross different builds """ - metadata, _ = SuiteMetadata.objects.get_or_create(suite=suite.slug, name=test_name, kind='test') - testrun.tests.create( - suite=suite, - result=(len(lines) == 0), - log='\n'.join(lines), - metadata=metadata, - build=testrun.build, - environment=testrun.environment, - ) - - # Some lines of the matched regex might be the same, and we don't want to create - # multiple tests like test1-sha1, test1-sha1, etc, so we'll create a set of sha1sums - # then create only new tests for unique sha's + # Run the REGEX_EXTRACT_NAME regex over the log lines to sort them by + # extracted name. If no name is extracted or the log parser did not + # have any output for a particular regex, just use the default name + # (for example "check-kernel-oops"). + tests_to_create = defaultdict(set) shas = defaultdict(set) + + # If there are no lines, use the default name and create a passing + # test. For example "check-kernel-oops" + if not lines: + tests_to_create[test_name] = [] + + # If there are lines, then create the tests for these. for line in lines: - sha = self.__create_shasum(line) - name = self.__create_name(line, test_regex) - if name: - sha = f"{name}-{sha}" - shas[sha].add(line) - - for sha, lines in shas.items(): - name = f'{test_name}-{sha}' + extracted_name = self.__create_name(line, test_regex) + if extracted_name: + extended_test_name = f"{test_name}-{extracted_name}" + else: + extended_test_name = test_name + tests_to_create[extended_test_name].add(line) + + for name, lines in tests_to_create.items(): metadata, _ = SuiteMetadata.objects.get_or_create(suite=suite.slug, name=name, kind='test') + testrun.tests.create( + suite=suite, + result=(len(lines) == 0), + log='\n'.join(lines), + metadata=metadata, + build=testrun.build, + environment=testrun.environment, + ) + + # Some lines of the matched regex might be the same, and we don't want to create + # multiple tests like test1-sha1, test1-sha1, etc, so we'll create a set of sha1sums + # then create only new tests for unique sha's + + for line in lines: + sha = self.__create_shasum(line) + name_with_sha = f"{name}-{sha}" + shas[name_with_sha].add(line) + + for name_with_sha, lines in shas.items(): + metadata, _ = SuiteMetadata.objects.get_or_create(suite=suite.slug, name=name_with_sha, kind='test') testrun.tests.create( suite=suite, result=False, diff --git a/test/plugins/test_linux_log_parser.py b/test/plugins/test_linux_log_parser.py index 0b72ac41..c775a0bf 100644 --- a/test/plugins/test_linux_log_parser.py +++ b/test/plugins/test_linux_log_parser.py @@ -29,7 +29,7 @@ def test_detects_oops(self): testrun = self.new_testrun('oops.log') self.plugin.postprocess_testrun(testrun) - test = testrun.tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-oops') + test = testrun.tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-oops-oops-bug-preempt-smp') self.assertFalse(test.result) self.assertIsNotNone(test.log) self.assertNotIn('Linux version 4.4.89-01529-gb29bace', test.log) @@ -40,19 +40,19 @@ def test_detects_kernel_panic(self): testrun = self.new_testrun('kernelpanic.log') self.plugin.postprocess_testrun(testrun) - test = testrun.tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-panic') + test = testrun.tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-panic-kernel-panic-not-syncing-attempted-to-kill-the-idle-task') self.assertFalse(test.result) self.assertIsNotNone(test.log) self.assertNotIn('Booting Linux', test.log) self.assertIn('Kernel panic - not syncing', test.log) - self.assertIn('Attempted to kill init! exitcode=0x00000009', test.log) + self.assertNotIn('Attempted to kill init! exitcode=0x00000009', test.log) self.assertNotIn('Internal error: Oops', test.log) def test_detects_kernel_exception(self): testrun = self.new_testrun('kernelexceptiontrace.log') self.plugin.postprocess_testrun(testrun) - test = testrun.tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-exception') + test = testrun.tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-exception-warning-cpu-pid-at-kernelsmpc-smp_call_function_many_cond') self.assertFalse(test.result) self.assertIsNotNone(test.log) self.assertNotIn('Booting Linux', test.log) @@ -64,7 +64,7 @@ def test_detects_kernel_exception_without_square_braces(self): testrun = self.new_testrun('kernelexceptiontrace_without_squarebraces.log') self.plugin.postprocess_testrun(testrun) - test = testrun.tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-exception') + test = testrun.tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-exception-warning-cpu-pid-at-kernelsmpc-smp_call_function_many_cond') self.assertFalse(test.result) self.assertIsNotNone(test.log) self.assertNotIn('Booting Linux', test.log) @@ -76,7 +76,7 @@ def test_detects_kernel_kasan(self): testrun = self.new_testrun('kasan.log') self.plugin.postprocess_testrun(testrun) - test = testrun.tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-kasan') + test = testrun.tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-kasan-bug-kasan-slab-out-of-bounds-in-kmalloc_oob_right') self.assertFalse(test.result) self.assertIsNotNone(test.log) self.assertNotIn('Booting Linux', test.log) @@ -89,7 +89,7 @@ def test_detects_kernel_kfence(self): testrun = self.new_testrun('kfence.log') self.plugin.postprocess_testrun(testrun) - test = testrun.tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-kfence') + test = testrun.tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-kfence-bug-kfence-memory-corruption-in-kfree') self.assertFalse(test.result) self.assertIsNotNone(test.log) self.assertNotIn('Booting Linux', test.log) @@ -102,7 +102,7 @@ def test_detects_kernel_bug(self): testrun = self.new_testrun('oops.log') self.plugin.postprocess_testrun(testrun) - test = testrun.tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-bug') + test = testrun.tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-bug-bug-spinlock-lockup-suspected-on-cpu-gdbus') self.assertFalse(test.result) self.assertIsNotNone(test.log) self.assertNotIn('Booting Linux', test.log) @@ -112,7 +112,7 @@ def test_detects_kernel_bug(self): testrun = self.new_testrun('kernel_bug_and_invalid_opcode.log', job_id='1000') self.plugin.postprocess_testrun(testrun) - test = testrun.tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-bug') + test = testrun.tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-exception-kernel-bug-at-usrsrckernelarchxkvmmmummuc') self.assertFalse(test.result) self.assertIsNotNone(test.log) self.assertNotIn('Booting Linux', test.log) @@ -124,7 +124,7 @@ def test_detects_kernel_invalid_opcode(self): testrun = self.new_testrun('kernel_bug_and_invalid_opcode.log') self.plugin.postprocess_testrun(testrun) - test = testrun.tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-invalid-opcode') + test = testrun.tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-invalid-opcode-invalid-opcode-smp-pti') self.assertFalse(test.result) self.assertIsNotNone(test.log) self.assertNotIn('Booting Linux', test.log) @@ -137,11 +137,11 @@ def test_detects_multiple(self): self.plugin.postprocess_testrun(testrun) tests = testrun.tests - test_panic = tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-panic') - test_exception = tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-exception') - test_warning = tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-warning') - test_oops = tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-oops') - test_fault = tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-fault') + test_panic = tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-panic-kernel-panic-not-syncing-stack-protector-kernel-stack-is-corrupted-in-ffffffffcc') + test_exception = tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-exception-warning-cpu-pid-at-driversgpudrmradeonradeon_objectc-radeon_ttm_bo_destroy') + test_warning = tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-warning-warning-cpu-pid-at-driversregulatorcorec-_regulator_putpart') + test_oops = tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-oops-oops-preempt-smp') + test_fault = tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-fault-unhandled-fault-external-abort-on-non-linefetch-at') self.assertFalse(test_panic.result) self.assertNotIn('Boot CPU', test_panic.log) @@ -208,7 +208,7 @@ def test_rcu_warning(self): tests = testrun.tests test_panic = tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-panic') test_exception = tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-exception') - test_warning = tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-warning') + test_warning = tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-warning-warning-suspicious-rcu-usage') test_oops = tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-oops') test_fault = tests.get(suite__slug='log-parser-test', metadata__name='check-kernel-fault') @@ -240,7 +240,7 @@ def test_boot_log(self): testrun = self.new_testrun('oops.log') self.plugin.postprocess_testrun(testrun) - test = testrun.tests.get(suite__slug='log-parser-boot', metadata__name='check-kernel-oops') + test = testrun.tests.get(suite__slug='log-parser-boot', metadata__name='check-kernel-oops-oops-bug-preempt-smp') self.assertFalse(test.result) self.assertIsNotNone(test.log) self.assertNotIn('Linux version 4.4.89-01529-gb29bace', test.log) @@ -251,7 +251,7 @@ def test_sha_name(self): testrun = self.new_testrun('oops.log') self.plugin.postprocess_testrun(testrun) - test = testrun.tests.get(suite__slug='log-parser-boot', metadata__name='check-kernel-oops') + test = testrun.tests.get(suite__slug='log-parser-boot', metadata__name='check-kernel-oops-oops-bug-preempt-smp') self.assertFalse(test.result) self.assertIsNotNone(test.log) self.assertNotIn('Linux version 4.4.89-01529-gb29bace', test.log)