[PATCH 1/1][autotest-client-tests] UBUNTU: SAUCE: ubuntu_boot: add tests to check error in log and kernel_tainted flags

Po-Hsu Lin po-hsu.lin at canonical.com
Wed Jul 8 12:11:30 UTC 2020


Add two sub-tests into the boot test to help us catching issues like
lp:1840046 ("BUG: non-zero pgtables_bytes on freeing mm: -16384") in the
early stage:
  1. log_check test - use regex to search for error patterns in syslog
  2. kernel_tainted test - check for kernel tainted flags

Call the original test as a boot_smoke_test, so now there will be 3
tests under this ubuntu_boot test.

This ubuntu_boot test will be executed when the kernel was copied to
our ppa.

Signed-off-by: Po-Hsu Lin <po-hsu.lin at canonical.com>
---
 ubuntu_boot/control.ubuntu |  8 +++---
 ubuntu_boot/ubuntu_boot.py | 54 ++++++++++++++++++++++++++++++++++++--
 2 files changed, 57 insertions(+), 5 deletions(-)

diff --git a/ubuntu_boot/control.ubuntu b/ubuntu_boot/control.ubuntu
index f9986199..bc687b8a 100644
--- a/ubuntu_boot/control.ubuntu
+++ b/ubuntu_boot/control.ubuntu
@@ -1,11 +1,13 @@
 AUTHOR = 'brad.figg at canonical.com (Brad Figg)'
 TIME = 'MEDIUM'
-NAME = 'Perform a simple "boot" test'
+NAME = 'Perform a simple "boot" test and check error / taint flags'
 TEST_TYPE = 'client'
 TEST_CLASS = 'Kernel'
-TEST_CATEGORY = 'Stress'
+TEST_CATEGORY = 'Smoke'
 
 DOC = '''
 '''
 
-job.run_test_detail('ubuntu_boot', test_time=600)
+job.run_test_detail('ubuntu_boot', test_name='kernel_tainted', tag='kernel_tainted')
+job.run_test_detail('ubuntu_boot', test_name='log_check', tag='log_check')
+job.run_test_detail('ubuntu_boot', test_name='boot_smoke_test', tag='boot_smoke_test')
diff --git a/ubuntu_boot/ubuntu_boot.py b/ubuntu_boot/ubuntu_boot.py
index dba7a1ae..c799c560 100644
--- a/ubuntu_boot/ubuntu_boot.py
+++ b/ubuntu_boot/ubuntu_boot.py
@@ -1,12 +1,62 @@
 import os
+import re
 from autotest.client import test, utils
+from autotest.client.shared import error
 
 
 class ubuntu_boot(test.test):
     version = 1
+    def log_check(self):
+        '''Test for checking error patterns in log files'''
+        # dmesg will be cleared out in autotest with dmesg -c before the test starts
+        # Let's check for /var/log/syslog instead
+        logfile = '/var/log/syslog'
+        patterns = [
+            'kernel: \[ *\d+\.\d+\] BUG:',
+            'kernel: \[ *\d+\.\d+\] Oops:',
+            'kernel: \[ *\d+\.\d+\] kernel BUG at',
+            'kernel: \[ *\d+\.\d+\] WARNING:'
+        ]
+        test_passed = True
+        print('Checking error message in {}:'.format(logfile))
+        if os.path.exists(logfile):
+            with open(logfile) as f:
+                content = f.read()
+                for pat in patterns:
+                    print('Scanning for pattern "{}"'.format(pat))
+                    if re.search(pat, content):
+                        print('Pattern found, Log NOT clean.')
+                        test_passed = False
+        else:
+            print('Log file was not found.')
+            test_passed = False
+        return test_passed
+
+    def kernel_tainted(self):
+        '''Test for checking kernel tatined flags'''
+        test_passed = True
+        print('Checking kernel tainted flags in /proc/sys/kernel/tainted')
+        with open('/proc/sys/kernel/tainted') as f:
+            content = f.read()
+            if content != '0\n':
+                test_passed = False
+        return test_passed
+
+    def run_once(self, test_name, exit_on_error=True):
+        if test_name == 'log_check':
+            if not self.log_check():
+                raise error.TestFail()
+            else:
+                print("GOOD: Log clean.")
+            return
+        elif test_name == 'kernel_tainted':
+            if not self.kernel_tainted():
+                raise error.TestFail()
+            else:
+                print('GOOD: Kernel not tainted.')
+            return
 
-    def run_once(self, test_time=10, exit_on_error=True, set_time=True):
         cmd = "uname -a"
         utils.system(cmd)
-        cmd = "lsb_release"
+        cmd = "lsb_release -a"
         utils.system(cmd)
-- 
2.17.1




More information about the kernel-team mailing list