lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231118104040.386381-5-zhangxiaoxu@huaweicloud.com>
Date:   Sat, 18 Nov 2023 18:40:30 +0800
From:   Zhang Xiaoxu <zhangxiaoxu@...weicloud.com>
To:     zhangxiaoxu5@...wei.com, weiyongjun1@...wei.com,
        linux-kernel@...r.kernel.org, broonie@...nel.org,
        rostedt@...dmis.org, mingo@...hat.com, frowand.list@...il.com,
        linux-spi@...r.kernel.org
Subject: [PATCH -next 04/14] kddv/core: Check kmsg before return from test case

From: Zhang Xiaoxu <zhangxiaoxu5@...wei.com>

Check kernel message before return from test case, if bug
or error in kernel message, fail the test case.

Signed-off-by: Wei Yongjun <weiyongjun1@...wei.com>
Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@...wei.com>
---
 tools/testing/kddv/kddv/core/ddunit.py  | 12 ++++++++
 tools/testing/kddv/kddv/core/dmesg.py   | 41 +++++++++++++++++++++++++
 tools/testing/kddv/kddv/core/environ.py | 28 +++++++++++++++++
 3 files changed, 81 insertions(+)
 create mode 100755 tools/testing/kddv/kddv/core/dmesg.py
 create mode 100755 tools/testing/kddv/kddv/core/environ.py

diff --git a/tools/testing/kddv/kddv/core/ddunit.py b/tools/testing/kddv/kddv/core/ddunit.py
index fd4ab9fe048c..197300f8a6d4 100755
--- a/tools/testing/kddv/kddv/core/ddunit.py
+++ b/tools/testing/kddv/kddv/core/ddunit.py
@@ -10,6 +10,7 @@ import logging
 import unittest
 
 from .model import DriverModel
+from .environ import environ
 
 logger = logging.getLogger(__name__)
 
@@ -25,12 +26,18 @@ class DriverTest(unittest.TestCase, DriverModel):
         except:
             self.skipTest(f"Module {self.module_name} not found")
         self.mockup.load()
+        environ.setup()
 
     def tearDown(self):
+        environ.teardown()
         self.mockup.unload()
         self.driver.teardown()
         super().tearDown()
 
+    def _callTestMethod(self, method):
+        method()
+        self.assertFault()
+
     def assertRegEqual(self, reg, data, msg=None):
         value = self.read_reg(reg)
         self.assertEqual(value, data, msg)
@@ -42,3 +49,8 @@ class DriverTest(unittest.TestCase, DriverModel):
     def assertRegsEqual(self, reg, data, msg=None):
         value = self.read_regs(reg, len(data))
         self.assertListEqual(value, data, msg)
+
+    def assertFault(self):
+        msg = environ.check_failure()
+        if msg:
+            raise self.failureException(msg)
diff --git a/tools/testing/kddv/kddv/core/dmesg.py b/tools/testing/kddv/kddv/core/dmesg.py
new file mode 100755
index 000000000000..e528b6164f46
--- /dev/null
+++ b/tools/testing/kddv/kddv/core/dmesg.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+#
+# Kernel device driver verification
+#
+# Copyright (C) 2022-2023 Huawei Technologies Co., Ltd
+# Author: Wei Yongjun <weiyongjun1@...wei.com>
+
+import re
+import logging
+import subprocess
+
+KERNEL_PANIC = [
+    "BUG:",
+    "WARNING:",
+    "INFO:",
+    "[kK]ernel BUG",
+    "PANIC: double fault",
+    "divide error:",
+    "UBSAN:",
+    "Unable to handle kernel",
+    "general protection fault",
+]
+
+logger = logging.getLogger(__name__)
+
+class KernelMessage(object):
+
+    def setup(self):
+        subprocess.run(["/usr/bin/dmesg", "-C"])
+
+    def teardown(self):
+        subprocess.run(["/usr/bin/dmesg", "-C"])
+
+    def check_failure(self):
+        logger.debug('check kernel message')
+        kmsg = subprocess.check_output(["/usr/bin/dmesg", "-c"])
+        regex_pattern = re.compile("|".join(KERNEL_PANIC))
+        if regex_pattern.search(kmsg.decode()):
+            return kmsg.decode()
+        return None
diff --git a/tools/testing/kddv/kddv/core/environ.py b/tools/testing/kddv/kddv/core/environ.py
new file mode 100755
index 000000000000..d57e33a6ac6e
--- /dev/null
+++ b/tools/testing/kddv/kddv/core/environ.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+#
+# Kernel device driver verification
+#
+# Copyright (C) 2022-2023 Huawei Technologies Co., Ltd
+# Author: Wei Yongjun <weiyongjun1@...wei.com>
+
+import logging
+
+from .dmesg import KernelMessage
+
+logger = logging.getLogger(__name__)
+
+class Environ(object):
+    def __init__(self):
+        self.kmsg = KernelMessage()
+
+    def setup(self):
+        self.kmsg.setup()
+
+    def teardown(self):
+        self.kmsg.teardown()
+
+    def check_failure(self):
+        return self.kmsg.check_failure()
+
+environ = Environ()
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ