Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1089795rdb; Sat, 18 Nov 2023 02:42:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IH9j/QPMV82eBeRqgXryOXDpikjJVEt8Ty7UJpInP+QoCyEz1mhuUEH/U/2OMa59zn8dsfM X-Received: by 2002:a17:903:183:b0:1cc:5c49:6af8 with SMTP id z3-20020a170903018300b001cc5c496af8mr2600161plg.25.1700304148528; Sat, 18 Nov 2023 02:42:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700304148; cv=none; d=google.com; s=arc-20160816; b=rU/NgOyPBZJr1WjReJHvKS+WsvBZQmh7kyQnRIWv3s8aQBjURrK9fa6kHmVBlu0ABu OpjxwdwhHsgyk7Nly+1J3eUgnBekTSAbHontpRC+w+BF7Rlz+EEOlniE3R0CsKqp8DUG AlcI4ufp40y0DXDJniXAZ6TIZgBVOSDHlF6W4CJmgQsk9l7YcajhMFHUZoR3HmyjsH1Y bcvH9NKj8H4PIIsnVv3nHsqQ9VCzybwqx+py5EAxawcVDo4wLxp6YZqZQBRaooeuSFyn yuOh9O0y2YzefM47emBXT9bPCfqRdTysn0uh+9EORqiLglaIKIfZP+oAT0JDvDtWAMyk Z2EQ== 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=IXL4j4YrupxjWIJ+rV/YSn8HjZNRWzRPlITuMUpxdvA=; fh=cKgRupAwAqvDHHS6VAzGoPs3pyLdUCOVkk/Q20cDUOo=; b=tnv0beQJfbn9UPN+E5YQ7YddhtPRi9zygTqawoU522PtOWTAQh5fe/8l4OpJrd6zLH ++y1H1jdu3HcX2f2La3xlq3UfelQzTm/G2My2Oi4CHXcSo/map0j69oswHbisu2ko01D Tr+IkLN+qZ5LOEKjDSEtNF3JOIbhOSNlc6sINYZJkk+u1rs/kfO3Ka8iZvPjD1xiojFX pvmTQ4MtapwmQUxJ2Wj5UY/RZdax20gfFVoo1dk7g6tD+Be4szHs6OBdpBRZ956SIt0R fsoyvzMFjZD7DP2VeSfEgTKY2v/L3etAb4KS1EsilLska3HirfQ+OGOioVlPoYU2qNbG YL4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id l12-20020a170903244c00b001c74f2d8980si4326635pls.160.2023.11.18.02.42.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 02:42:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 61AB680C5913; Sat, 18 Nov 2023 02:42:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233152AbjKRKmJ (ORCPT + 99 others); Sat, 18 Nov 2023 05:42:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232726AbjKRKlo (ORCPT ); Sat, 18 Nov 2023 05:41:44 -0500 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E8B210C1; Sat, 18 Nov 2023 02:41:40 -0800 (PST) Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4SXVgg3ydbz4f3k6f; Sat, 18 Nov 2023 18:41:35 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 29E341A016F; Sat, 18 Nov 2023 18:41:38 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.107]) by APP1 (Coremail) with SMTP id cCh0CgDn6hDQlFhlQPAFBQ--.58135S16; Sat, 18 Nov 2023 18:41:38 +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 12/14] kddv/tests: Add support for testing mtd driver Date: Sat, 18 Nov 2023 18:40:38 +0800 Message-Id: <20231118104040.386381-13-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--.58135S16 X-Coremail-Antispam: 1UD129KBjvJXoW7AF13WrWUGF45uryfZrWkJFb_yoW8Kw1rpa yfAa1Y9r17Zr13GwsakFy7X39Y9r4kCFW7GrZrAr4j9rnxK34SqFW7K34Yq3W5tFyxWFWS vrWv9FWxuF47A3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9Yb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7 v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF 1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIx AIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1x MIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCT nIWIevJa73UjIFyTuYvjxUFgAwUUUUU X-CM-SenderInfo: x2kd0wp0ld053x6k3tpzhluzxrxghudrp/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Sat, 18 Nov 2023 02:42:27 -0800 (PST) From: Zhang Xiaoxu This implement some helper function for mtd device, mtd driver test case can inherit 'MTDDriver' to simplify code. Signed-off-by: Wei Yongjun Signed-off-by: Zhang Xiaoxu --- tools/testing/kddv/kddv/tests/mtd/__init__.py | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tools/testing/kddv/kddv/tests/mtd/__init__.py diff --git a/tools/testing/kddv/kddv/tests/mtd/__init__.py b/tools/testing/kddv/kddv/tests/mtd/__init__.py new file mode 100644 index 000000000000..4defd92deb05 --- /dev/null +++ b/tools/testing/kddv/kddv/tests/mtd/__init__.py @@ -0,0 +1,63 @@ +#!/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 logging + +from pathlib import Path + +logger = logging.getLogger(__name__) + +class MTD(object): + def __init__(self, path): + mtd = next(path.glob("mtd/mtd*")).name + self.cdev = Path(f"/sys/class/mtd/{mtd}") + self.rdev = f"/dev/{mtd}" + + def read_bytes(self, len, offset = 0): + with open(self.rdev, "rb") as dev: + if offset: + dev.seek(offset) + return dev.read(len) + + def write_bytes(self, data, offset = 0): + with open(self.rdev, "wb") as dev: + if offset: + dev.seek(offset) + dev.write(data) + + def read_attr(self, attr): + path = self.cdev / attr + logger.debug(f"read from {path}") + if not os.path.exists(path): + return f"attr '{attr}' not exists" + return path.read_text().rstrip() + + def write_attr(self, attr, val): + path = self.cdev / attr + if not os.path.exists(path): + return f"attr '{attr}' not exists" + logger.debug(f"write '{val}' to {path}") + return path.write_bytes(val.encode()) + +class MTDDriver(object): + def mtd_read_attr(self, dev, attr): + mtddev = MTD(dev.path) + return mtddev.read_attr(attr) + + def mtd_write_attr(self, dev, attr, val): + mtddev = MTD(dev.path) + return mtddev.write_attr(attr) + + def mtd_read_bytes(self, dev, len): + mtddev = MTD(dev.path) + return mtddev.read_bytes(len) + + def mtd_write_bytes(self, dev, data): + mtddev = MTD(dev.path) + return mtddev.write_bytes(data) -- 2.34.1