linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhang Xiaoxu <zhangxiaoxu@huaweicloud.com>
To: zhangxiaoxu5@huawei.com, weiyongjun1@huawei.com,
	linux-kernel@vger.kernel.org, broonie@kernel.org,
	rostedt@goodmis.org, mingo@redhat.com, frowand.list@gmail.com,
	linux-spi@vger.kernel.org
Subject: [PATCH -next 08/14] kddv/cmd: Add command to run testcases
Date: Sat, 18 Nov 2023 18:40:34 +0800	[thread overview]
Message-ID: <20231118104040.386381-9-zhangxiaoxu@huaweicloud.com> (raw)
In-Reply-To: <20231118104040.386381-1-zhangxiaoxu@huaweicloud.com>

From: Zhang Xiaoxu <zhangxiaoxu5@huawei.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@huawei.com>
Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.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@huawei.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


  parent reply	other threads:[~2023-11-18 10:41 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-18 10:40 [PATCH -next 00/14] Implement a ligth weight device driver test framework Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 01/14] kddv/core: " Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 02/14] kddv/core: Allow test case config bpf program Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 03/14] kddv/core: Add io fault support to " Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 04/14] kddv/core: Check kmsg before return from test case Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 05/14] kddv/core: Support kernel memory leak detector Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 06/14] kddv/core: Add page and slab fault inject support Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 07/14] kddv/cmd: Add command to create/remove mockup device Zhang Xiaoxu
2023-11-18 10:40 ` Zhang Xiaoxu [this message]
2023-11-18 10:40 ` [PATCH -next 09/14] kddv/core: Add test support for SPI driver Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 10/14] kddv/tests: Add support for testing hwmon driver Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 11/14] kddv/tests/hwmon: Add test cases for max31722 driver Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 12/14] kddv/tests: Add support for testing mtd driver Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 13/14] kddv/tests/mtd: Add test cases for mchp23k256 driver Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 14/14] kddv: Add document for kddv Zhang Xiaoxu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231118104040.386381-9-zhangxiaoxu@huaweicloud.com \
    --to=zhangxiaoxu@huaweicloud.com \
    --cc=broonie@kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=weiyongjun1@huawei.com \
    --cc=zhangxiaoxu5@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).