<div dir="ltr"><div dir="ltr"><br></div><div>Acked-by: Sean Feole <<a href="mailto:sean.feole@canonical.com">sean.feole@canonical.com</a>></div><div><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 8, 2020 at 8:12 AM Po-Hsu Lin <<a href="mailto:po-hsu.lin@canonical.com">po-hsu.lin@canonical.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Add two sub-tests into the boot test to help us catching issues like<br>
lp:1840046 ("BUG: non-zero pgtables_bytes on freeing mm: -16384") in the<br>
early stage:<br>
  1. log_check test - use regex to search for error patterns in syslog<br>
  2. kernel_tainted test - check for kernel tainted flags<br>
<br>
Call the original test as a boot_smoke_test, so now there will be 3<br>
tests under this ubuntu_boot test.<br>
<br>
This ubuntu_boot test will be executed when the kernel was copied to<br>
our ppa.<br>
<br>
Signed-off-by: Po-Hsu Lin <<a href="mailto:po-hsu.lin@canonical.com" target="_blank">po-hsu.lin@canonical.com</a>><br>
---<br>
 ubuntu_boot/control.ubuntu |  8 +++---<br>
 ubuntu_boot/ubuntu_boot.py | 54 ++++++++++++++++++++++++++++++++++++--<br>
 2 files changed, 57 insertions(+), 5 deletions(-)<br>
<br>
diff --git a/ubuntu_boot/control.ubuntu b/ubuntu_boot/control.ubuntu<br>
index f9986199..bc687b8a 100644<br>
--- a/ubuntu_boot/control.ubuntu<br>
+++ b/ubuntu_boot/control.ubuntu<br>
@@ -1,11 +1,13 @@<br>
 AUTHOR = '<a href="mailto:brad.figg@canonical.com" target="_blank">brad.figg@canonical.com</a> (Brad Figg)'<br>
 TIME = 'MEDIUM'<br>
-NAME = 'Perform a simple "boot" test'<br>
+NAME = 'Perform a simple "boot" test and check error / taint flags'<br>
 TEST_TYPE = 'client'<br>
 TEST_CLASS = 'Kernel'<br>
-TEST_CATEGORY = 'Stress'<br>
+TEST_CATEGORY = 'Smoke'<br>
<br>
 DOC = '''<br>
 '''<br>
<br>
-job.run_test_detail('ubuntu_boot', test_time=600)<br>
+job.run_test_detail('ubuntu_boot', test_name='kernel_tainted', tag='kernel_tainted')<br>
+job.run_test_detail('ubuntu_boot', test_name='log_check', tag='log_check')<br>
+job.run_test_detail('ubuntu_boot', test_name='boot_smoke_test', tag='boot_smoke_test')<br>
diff --git a/ubuntu_boot/ubuntu_boot.py b/ubuntu_boot/ubuntu_boot.py<br>
index dba7a1ae..c799c560 100644<br>
--- a/ubuntu_boot/ubuntu_boot.py<br>
+++ b/ubuntu_boot/ubuntu_boot.py<br>
@@ -1,12 +1,62 @@<br>
 import os<br>
+import re<br>
 from autotest.client import test, utils<br>
+from autotest.client.shared import error<br>
<br>
<br>
 class ubuntu_boot(test.test):<br>
     version = 1<br>
+    def log_check(self):<br>
+        '''Test for checking error patterns in log files'''<br>
+        # dmesg will be cleared out in autotest with dmesg -c before the test starts<br>
+        # Let's check for /var/log/syslog instead<br>
+        logfile = '/var/log/syslog'<br>
+        patterns = [<br>
+            'kernel: \[ *\d+\.\d+\] BUG:',<br>
+            'kernel: \[ *\d+\.\d+\] Oops:',<br>
+            'kernel: \[ *\d+\.\d+\] kernel BUG at',<br>
+            'kernel: \[ *\d+\.\d+\] WARNING:'<br>
+        ]<br>
+        test_passed = True<br>
+        print('Checking error message in {}:'.format(logfile))<br>
+        if os.path.exists(logfile):<br>
+            with open(logfile) as f:<br>
+                content = f.read()<br>
+                for pat in patterns:<br>
+                    print('Scanning for pattern "{}"'.format(pat))<br>
+                    if re.search(pat, content):<br>
+                        print('Pattern found, Log NOT clean.')<br>
+                        test_passed = False<br>
+        else:<br>
+            print('Log file was not found.')<br>
+            test_passed = False<br>
+        return test_passed<br>
+<br>
+    def kernel_tainted(self):<br>
+        '''Test for checking kernel tatined flags'''<br>
+        test_passed = True<br>
+        print('Checking kernel tainted flags in /proc/sys/kernel/tainted')<br>
+        with open('/proc/sys/kernel/tainted') as f:<br>
+            content = f.read()<br>
+            if content != '0\n':<br>
+                test_passed = False<br>
+        return test_passed<br>
+<br>
+    def run_once(self, test_name, exit_on_error=True):<br>
+        if test_name == 'log_check':<br>
+            if not self.log_check():<br>
+                raise error.TestFail()<br>
+            else:<br>
+                print("GOOD: Log clean.")<br>
+            return<br>
+        elif test_name == 'kernel_tainted':<br>
+            if not self.kernel_tainted():<br>
+                raise error.TestFail()<br>
+            else:<br>
+                print('GOOD: Kernel not tainted.')<br>
+            return<br>
<br>
-    def run_once(self, test_time=10, exit_on_error=True, set_time=True):<br>
         cmd = "uname -a"<br>
         utils.system(cmd)<br>
-        cmd = "lsb_release"<br>
+        cmd = "lsb_release -a"<br>
         utils.system(cmd)<br>
-- <br>
2.17.1<br>
<br>
<br>
-- <br>
kernel-team mailing list<br>
<a href="mailto:kernel-team@lists.ubuntu.com" target="_blank">kernel-team@lists.ubuntu.com</a><br>
<a href="https://lists.ubuntu.com/mailman/listinfo/kernel-team" rel="noreferrer" target="_blank">https://lists.ubuntu.com/mailman/listinfo/kernel-team</a><br>
</blockquote></div></div>