Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1090240rdb; Sat, 18 Nov 2023 02:44:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IGPw3QFJ5pWO+fpX45xs/Vw/SL957VGKmbFaBaHrFZekQQ3TuFFRBvOzu5wt/qUEn8tNHJb X-Received: by 2002:a05:6a20:e128:b0:187:725c:6305 with SMTP id kr40-20020a056a20e12800b00187725c6305mr2170246pzb.12.1700304248034; Sat, 18 Nov 2023 02:44:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700304248; cv=none; d=google.com; s=arc-20160816; b=RrAc2mSIM1TenMHQYjDEFLbPWyZOOFxNawt+Oa4FscVCHirPGXCD9ICyLaAgJefajd rI3GoX/2IFO1QOfJRzmjJEGt87K5FE/SCb0eP1rQjDxpN6Nvy5XIjzEwyIO74zRK8v8u KjZPu4djz90fFGb13AaUyNtS67ev7jrFYIYY8L8WrC+tlb+ew3x+8yoYNAojZ7ajdyos tEbh1AGhXNvVNAaUr0JfPbdMpHcNZFKp8SD/i0XCKoxGi3BXpmti5GkbQc6HFTLVNtSl 5ACKOXCmmeYYxWRHlw4AhbSyoifOrUX86/XkDdw2m5Cdp2YO67XeB9jyrrr5nYAe0yIB NVQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from; bh=4XUQzlNfL9a6v7cSPExKn+2n70iIPQxp646rNMvwLwo=; fh=cKgRupAwAqvDHHS6VAzGoPs3pyLdUCOVkk/Q20cDUOo=; b=yD7l6EaNLINYyPxaxZhEMsyC80htRX6QvWJIkUGFyUFp50YkdyDO12bqDgwGl5GKOl 3Rrc/3yCxPuWfgQFKwUWvJ/FsOhGUL/BEyASbglsi/qO5J+oM6BhktY0MEcvm7TnaRl2 KIFwRUdcHJGHgx/s7sUqHwtAFhst7u1K/h1svppsFPsjWdP9GrKtIGioLEhQxl9QTHDl BGQ9u4WhfWdB5YuRMMFHiAORrcrrps9RCHnDmnH4bKV2ievDO3WRJKcS/2BuWXAIxpFV g0ng5E0XcTSMFYl203ZERevwLBtkUSnL81KPtGAaoI108z8p/uNDMvYCsrSPgyEdpJlw yA8g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id s202-20020a632cd3000000b005ab7b51ab5bsi3757903pgs.110.2023.11.18.02.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 02:44:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id E1D71810EC35; Sat, 18 Nov 2023 02:43:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229510AbjKRKl4 (ORCPT + 99 others); Sat, 18 Nov 2023 05:41:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232403AbjKRKlm (ORCPT ); Sat, 18 Nov 2023 05:41:42 -0500 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E937B10DC; Sat, 18 Nov 2023 02:41:38 -0800 (PST) Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4SXVgf5xsGz4f3kFf; Sat, 18 Nov 2023 18:41:34 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 55D731A01A1; Sat, 18 Nov 2023 18:41:36 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.107]) by APP1 (Coremail) with SMTP id cCh0CgDn6hDQlFhlQPAFBQ--.58135S11; Sat, 18 Nov 2023 18:41:36 +0800 (CST) From: Zhang Xiaoxu 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 07/14] kddv/cmd: Add command to create/remove mockup device Date: Sat, 18 Nov 2023 18:40:33 +0800 Message-Id: <20231118104040.386381-8-zhangxiaoxu@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231118104040.386381-1-zhangxiaoxu@huaweicloud.com> References: <20231118104040.386381-1-zhangxiaoxu@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: cCh0CgDn6hDQlFhlQPAFBQ--.58135S11 X-Coremail-Antispam: 1UD129KBjvJXoWxtF47Xr1xKr47Zw45tw18Krg_yoW7uF18pa 1rGa1Uur48ur15Krn5ZryjqrWrXr4kCFWFgr1xZr12grnxCr95GrWxta4Yq343W3WrJFWS vFykuw10kr1UJw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU90b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7 v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF 1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIx AIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4l IxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIda VFxhVjvjDU0xZFpf9x07UZo7tUUUUU= X-CM-SenderInfo: x2kd0wp0ld053x6k3tpzhluzxrxghudrp/ X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sat, 18 Nov 2023 02:43:58 -0800 (PST) From: Zhang Xiaoxu Add command kddv.cmds.mock to create/remove mockup device which support by the test framework. Usage: Create device: $ python3 -m kddv.cmds.mock --bus spi --devid mchp23k256 create spi device mchp23k256 success! Then the mockup device can be accessed by exists user space tools. $ ls /dev/mtd0 mtd0 mtd0ro $ hexdump /dev/mtd0 0000000 0000 0000 0000 0000 0000 0000 0000 0000 * 0008000 Remove the mockup device: $ python3 -m kddv.cmds.mock --bus spi --devid mchp23k256 -r [ 198.718172] Deleting MTD partitions on "spi0.0": remove spi device mchp23k256 success! Signed-off-by: Wei Yongjun Signed-off-by: Zhang Xiaoxu --- tools/testing/kddv/kddv/Makefile | 1 + tools/testing/kddv/kddv/cmds/__init__.py | 0 tools/testing/kddv/kddv/cmds/mock.py | 105 +++++++++++++++++++++++ tools/testing/kddv/kddv/cmds/utils.py | 28 ++++++ 4 files changed, 134 insertions(+) create mode 100755 tools/testing/kddv/kddv/cmds/__init__.py create mode 100755 tools/testing/kddv/kddv/cmds/mock.py create mode 100755 tools/testing/kddv/kddv/cmds/utils.py diff --git a/tools/testing/kddv/kddv/Makefile b/tools/testing/kddv/kddv/Makefile index a68112154669..a5c91fcb0e9a 100644 --- a/tools/testing/kddv/kddv/Makefile +++ b/tools/testing/kddv/kddv/Makefile @@ -12,6 +12,7 @@ install: $(INSTALL) -m 0755 -d $(INSTALL_PATH) $(INSTALL) __init__.py $(INSTALL_PATH) cp -rf core/ $(INSTALL_PATH) + cp -rf cmds/ $(INSTALL_PATH) cp -rf tests/ $(INSTALL_PATH) clean: diff --git a/tools/testing/kddv/kddv/cmds/__init__.py b/tools/testing/kddv/kddv/cmds/__init__.py new file mode 100755 index 000000000000..e69de29bb2d1 diff --git a/tools/testing/kddv/kddv/cmds/mock.py b/tools/testing/kddv/kddv/cmds/mock.py new file mode 100755 index 000000000000..2ec5e45219a0 --- /dev/null +++ b/tools/testing/kddv/kddv/cmds/mock.py @@ -0,0 +1,105 @@ +#!/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 + +import os +import sys +import logging +import argparse +import unittest +import subprocess + +from kddv.core.mockup import Mockup +from kddv.core.ddunit import DriverTest +from kddv.core.buses import * +from . import utils + +ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +logger = logging.getLogger() + +def search(suite, bus: str, devid: str): + mdrv = None + for t in suite: + if isinstance(t, unittest.TestSuite): + driver = search(t, bus, devid) + if driver: + if driver.device_id == devid: + return driver + mdrv = driver + elif isinstance(t, DriverTest): + if not hasattr(t, 'bus') or not hasattr(t, 'device_id'): + logger.debug(f"not a driver test case: {t}") + continue + if t.bus != bus: + continue + if t.device_id == devid: + return t + if t.driver_name == devid: + mdrv = t + else: + return mdrv + +def do_mockup_device(t): + mock = Mockup.create(t.bus, t) + try: + subprocess.check_output( + ["/sbin/modprobe", t.module_name], stderr=subprocess.STDOUT + ) + except: + logger.warning(f"Module {t.module_name} not found") + sys.exit(1) + + mock.load() + logger.warning(f"create {t.bus} device {t.device_id} success!") + +def do_remove_device(t): + mock = Mockup.create(t.bus, t) + try: + mock.unload() + logger.warning(f"remove {t.bus} device {t.device_id} success!") + except: + logger.warning(f"{t.bus} device {t.device_id} not found") + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument( + "--bus", "-b", type=str, required=True, + choices=["i2c", "spi", "pci", "platform"], help="Bus Types" + ) + parser.add_argument( + "--devid", "-d", type=str, required=True, help="Device ID" + ) + parser.add_argument( + "--log-level", "-l", type=str, default=None, + choices=utils.LOG_LEVELS, help="Log level" + ) + parser.add_argument( + "--remove", "-r", action='store_true', default=False, + help="Remove device", + ) + args = parser.parse_args() + + if args.log_level: + utils.setup_logger(args.log_level) + + loader = unittest.defaultTestLoader + suites = loader.discover(os.path.join(ROOT_DIR, 'tests')) + driver = search(suites, args.bus, args.devid) + if driver is None: + logger.error(f"{args.bus} device {args.devid} not support") + sys.exit(1) + + if not args.remove: + do_mockup_device(driver) + else: + do_remove_device(driver) + + sys.exit(0) + +if __name__ == "__main__": + main() diff --git a/tools/testing/kddv/kddv/cmds/utils.py b/tools/testing/kddv/kddv/cmds/utils.py new file mode 100755 index 000000000000..8130d7a57a36 --- /dev/null +++ b/tools/testing/kddv/kddv/cmds/utils.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 + +import sys +import logging + +logger = logging.getLogger() + +LOG_FORMAT = "%(asctime)-15s [%(levelname)-7s] %(message)s" +LOG_LEVELS = { + 'ERROR': logging.ERROR, + 'WARN': logging.WARN, + 'INFO': logging.INFO, + 'DEBUG': logging.DEBUG +} + +def setup_logger(level): + logger.setLevel(LOG_LEVELS.get(level)) + handler = logging.StreamHandler(sys.stdout) + handler.setFormatter(logging.Formatter( + fmt=LOG_FORMAT, datefmt="%Y-%m-%d %H:%M:%S" + )) + logger.addHandler(handler) -- 2.34.1