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] [day] [month] [year] [list]
Message-Id: <20231118104040.386381-9-zhangxiaoxu@huaweicloud.com>
Date:   Sat, 18 Nov 2023 18:40:34 +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 08/14] kddv/cmd: Add command to run testcases

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

Add command kddv.cmds.test, which can help to run the testcase
use the python unittest framework.
  $ python3 -m kddv.cmd.test
  or
  $ python3 -m kddv.cmd.test kddv.tests.hwmon.test_max31722

Also enable fault inject test or enable kmemleak check. Usage:

Enable fault inject test:
  $ python3 -m kddv.cmds.test --fault-inject=all
  or
  $ python3 -m kddv.cmds.test --fault-inject=all \
  kddv.tests.hwmon.test_max31722.TestMax31722.test_device_probe

Enable kmemleak check:
  $ python3 -m kddv.cmds.test --kmemleak

Both fault inject and kmemleak will increase the time times.

Signed-off-by: Wei Yongjun <weiyongjun1@...wei.com>
Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@...wei.com>
---
 tools/testing/kddv/kddv/cmds/test.py | 75 ++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100755 tools/testing/kddv/kddv/cmds/test.py

diff --git a/tools/testing/kddv/kddv/cmds/test.py b/tools/testing/kddv/kddv/cmds/test.py
new file mode 100755
index 000000000000..9be346983286
--- /dev/null
+++ b/tools/testing/kddv/kddv/cmds/test.py
@@ -0,0 +1,75 @@
+#!/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 os
+import sys
+import fnmatch
+import argparse
+import unittest
+
+from kddv.core.ddunit import DriverTest
+from kddv.core.environ import environ
+from . import utils
+
+ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+
+def _list_suite(suite, tfilter=None):
+    for t in suite:
+        if isinstance(t, unittest.TestSuite):
+            _list_suite(t, tfilter)
+        elif isinstance(t, DriverTest):
+            id = t.id()
+            if tfilter and not any(fnmatch.fnmatch(id, f) for f in tfilter):
+                continue
+            print(f"kddv.tests.{id}")
+        else:
+            return None
+
+def list_suite(args):
+    args.filter = [f"*{f}*" for f in args.filter]
+    loader = unittest.defaultTestLoader
+    suites = loader.discover(os.path.join(ROOT_DIR, 'tests'))
+    _list_suite(suites, args.filter)
+    return 0
+
+def main() -> None:
+    parser = argparse.ArgumentParser()
+
+    parser.add_argument(
+        "--log-level", type=str, default=None,
+        choices=utils.LOG_LEVELS, help="Log Level"
+    )
+    parser.add_argument(
+        "--list", action='store_true', default=False,
+        help="List test cases",
+    )
+    parser.add_argument(
+        "--kmemleak", action='store_true', default=False,
+        help="Enable kmemeleak check",
+    )
+    parser.add_argument(
+        "--fault-inject", type=str, default=None,
+        choices=["slab", "page", "all"],
+        help="Enable fault inject features",
+    )
+    parser.add_argument("--filter", nargs="+", default=[],)
+
+    args, argv = parser.parse_known_args(sys.argv)
+    if args.log_level:
+        utils.setup_logger(args.log_level)
+    if args.list:
+        return list_suite(args)
+    if args.kmemleak:
+        environ.enable_kmemleak()
+    if args.fault_inject:
+        environ.enable_fault_inject(args.fault_inject)
+
+    unittest.main(verbosity=2, module=None, argv=argv)
+
+if __name__ == "__main__":
+    main()
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ