From 0f213e2ab9068c939ac0f7c8a462fbd6f5604bdb Mon Sep 17 00:00:00 2001 From: Po-Hsu Lin Date: Thu, 1 Apr 2021 16:19:25 +0800 Subject: Add kernel log check test Add a test to check various error messages in dmesg. Signed-off-by: Po-Hsu Lin --- bin/kernel_log_check.py | 55 +++++++++++++++++++++++++++++++++++++++++ units/miscellanea/jobs.pxu | 9 +++++++ units/miscellanea/test-plan.pxu | 7 ++++++ 3 files changed, 71 insertions(+) create mode 100755 bin/kernel_log_check.py diff --git a/bin/kernel_log_check.py b/bin/kernel_log_check.py new file mode 100755 index 0000000..22e88b1 --- /dev/null +++ b/bin/kernel_log_check.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +""" +Test to check if the kernel dmesg is free with error messages. + +Copyright (C) 2021 Canonical Ltd. + +Authors: + Po-Hsu Lin + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License version 3, +as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +""" +import re +import os +import sys + +def main(): + '''Test for checking error patterns in log files''' + logfile = '/var/log/dmesg' + patterns = { + 'BUG': '\[ *\d+\.\d+\] kernel: BUG:.*', + 'Oops': '\[ *\d+\.\d+\] kernel: Oops:.*', + 'kernel BUG': '\[ *\d+\.\d+\] kernel: kernel BUG at.*', + 'WARNING': '\[ *\d+\.\d+\] kernel: WARNING:.*' + } + error = 0 + print('Checking error message in {}:'.format(logfile)) + if os.path.exists(logfile): + with open(logfile) as _file: + content = _file.read() + for pat in patterns: + print('Scanning for pattern "{}"'.format(pat)) + if re.search(patterns[pat], content): + print('Pattern found. Matching lines as follows:') + for item in re.finditer(patterns[pat], content): + print(item.group(0)) + error = 1 + else: + print('PASSED, log clean.') + else: + print('Log file was not found.') + error = 1 + return error + +if __name__ == '__main__': + sys.exit(main()) diff --git a/units/miscellanea/jobs.pxu b/units/miscellanea/jobs.pxu index 4772507..5e81f7b 100644 --- a/units/miscellanea/jobs.pxu +++ b/units/miscellanea/jobs.pxu @@ -197,6 +197,15 @@ _description: drivers, live patches, proprietary modules, etc. command: kernel_taint_test.py +plugin: shell +category_id: com.canonical.plainbox::miscellanea +estimated_duration: 0.5 +id: miscellanea/kernel_log_check +_summary: Scan dmesg for errors +_description: + Check for BUG / Oops / kernel BUG / WARNING pattern in dmesg. +command: kernel_log_check.py + plugin: shell category_id: com.canonical.plainbox::miscellanea id: miscellanea/bmc_info diff --git a/units/miscellanea/test-plan.pxu b/units/miscellanea/test-plan.pxu index 60741b6..6abd628 100644 --- a/units/miscellanea/test-plan.pxu +++ b/units/miscellanea/test-plan.pxu @@ -94,3 +94,10 @@ mandatory_include: miscellanea/dmitest_server miscellanea/maas_user_check include: + +id: kernel-log-check +unit: test plan +_name: Kernel dmesg log check +_description: Kernel dmesg log check +include: + miscellanea/kernel_log_check -- cgit v1.2.3