| # Copyright 2019 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| """Tests for elog summary parser""" |
| |
| from __future__ import absolute_import |
| |
| from chromite.lib.parser import elog |
| from chromite.lib import cros_test_lib |
| |
| SAMPLE_LOG = """ |
| >>> Messages generated by process 185551 on 2019-05-23 15:34:56 MDT for package sys-libs/libcxx-8.0_pre349610-r1: |
| |
| LOG: postinst |
| This package (libcxx) is mainly intended as a replacement for the C++ |
| standard library when using clang. |
| To use it, instead of libstdc++, use: |
| clang++ -stdlib=libc++ |
| to compile your C++ programs. |
| |
| >>> Messages generated by process 185951 on 2019-05-23 15:37:12 MDT for package app-vim/gentoo-syntax-20181023: |
| |
| WARN: prepare |
| deliberate warning |
| other warning |
| LOG: prepare |
| some info |
| WARN: prepare |
| last warning |
| LOG: prepare |
| last info |
| WARN: preinst |
| warning 1 |
| LOG: preinst |
| log 1 |
| WARN: preinst |
| warning 2 |
| WARN: postinst |
| later phase warning |
| |
| """ |
| |
| SAMPLE_FAILING_LOG = """ |
| >>> Messages generated by process 210458 on 2019-05-28 14:58:36 MDT for package sys-libs/libcxx-8.0_pre349610-r1: |
| |
| LOG: postinst |
| This package (libcxx) is mainly intended as a replacement for the C++ |
| standard library when using clang. |
| To use it, instead of libstdc++, use: |
| clang++ -stdlib=libc++ |
| to compile your C++ programs. |
| |
| >>> Messages generated by process 210858 on 2019-05-28 15:01:13 MDT for package app-vim/gentoo-syntax-20181023: |
| |
| WARN: prepare |
| deliberate warning |
| other warning |
| LOG: prepare |
| some info |
| WARN: prepare |
| last warning |
| LOG: prepare |
| last info |
| ERROR: compile |
| ERROR: app-vim/gentoo-syntax-20181023::portage-stable failed (compile phase): |
| deliberate error |
| |
| Call stack: |
| ebuild.sh, line 124: Called src_compile |
| environment, line 745: Called die |
| The specific snippet of code: |
| die "deliberate error" |
| |
| If you need support, post the output of `emerge --info '=app-vim/gentoo-syntax-20181023::portage-stable'`, |
| the complete build log and the output of `emerge -pqv '=app-vim/gentoo-syntax-20181023::portage-stable'`. |
| The complete build log is located at '/build/grunt/tmp/portage/logs/app-vim:gentoo-syntax-20181023:20190528-210112.log'. |
| For convenience, a symlink to the build log is located at '/build/grunt/tmp/portage/app-vim/gentoo-syntax-20181023/temp/build.log'. |
| The ebuild environment file is located at '/build/grunt/tmp/portage/app-vim/gentoo-syntax-20181023/temp/environment'. |
| Working directory: '/build/grunt/tmp/portage/app-vim/gentoo-syntax-20181023/work/gentoo-syntax-20181023' |
| S: '/build/grunt/tmp/portage/app-vim/gentoo-syntax-20181023/work/gentoo-syntax-20181023' |
| |
| """ |
| |
| |
| class ElogTest(cros_test_lib.TestCase): |
| """Unit tests for summary.log parser""" |
| |
| def testSingleSectionHeaderRegex(self): |
| match = elog.SECTION_HEADER.search(SAMPLE_LOG) |
| self.assertEqual('sys-libs/libcxx-8.0_pre349610-r1', match.group('package')) |
| |
| def testMultipleSectionHeaderRegex(self): |
| match = elog.SECTION_HEADER.search(SAMPLE_LOG) |
| match2 = elog.SECTION_HEADER.search(SAMPLE_LOG[match.end():]) |
| self.assertEqual('app-vim/gentoo-syntax-20181023', match2.group('package')) |
| |
| def testLogEntryRegex(self): |
| match = elog.LOG_ENTRY.search(SAMPLE_LOG) |
| self.assertEqual('LOG', match.group('level')) |
| self.assertEqual('postinst', match.group('phase')) |
| |
| def testMultipleLogEntryRegex(self): |
| match = elog.LOG_ENTRY.search(SAMPLE_LOG) |
| match2 = elog.LOG_ENTRY.search(SAMPLE_LOG[match.end():]) |
| self.assertEqual('WARN', match2.group('level')) |
| self.assertEqual('prepare', match2.group('phase')) |
| |
| def testNoPackageFailuresInSampleLog(self): |
| pkglog = elog.SummaryLog.parse_from_string(SAMPLE_LOG) |
| self.assertFalse(pkglog.has_failed_packages()) |
| |
| def testPackageFailureExistsInFailingLog(self): |
| pkglog = elog.SummaryLog.parse_from_string(SAMPLE_FAILING_LOG) |
| self.assertTrue(pkglog.has_failed_packages()) |
| |
| def testWhichPackageFailsInFailingLog(self): |
| pkglog = elog.SummaryLog.parse_from_string(SAMPLE_FAILING_LOG) |
| self.assertEqual(['app-vim/gentoo-syntax'], pkglog.failed_packages()) |
| |
| def testPackageWarningsDetectedInSampleLogs(self): |
| pkglog1 = elog.SummaryLog.parse_from_string(SAMPLE_LOG) |
| self.assertTrue(pkglog1.has_warned_packages()) |
| pkglog2 = elog.SummaryLog.parse_from_string(SAMPLE_FAILING_LOG) |
| self.assertTrue(pkglog2.has_warned_packages()) |