Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1090036rdb; Sat, 18 Nov 2023 02:43:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IG+ABFoEpgyp3O5cjsj1My5HMKVaCzto6Gw1G7UrUtqJc+5+ukYopwQukr5TIdlxQCItFcp X-Received: by 2002:a05:6808:17aa:b0:3b6:dc6f:271f with SMTP id bg42-20020a05680817aa00b003b6dc6f271fmr3180789oib.18.1700304199202; Sat, 18 Nov 2023 02:43:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700304199; cv=none; d=google.com; s=arc-20160816; b=a3aUFMSNE1l2yNGbKTi30hdhP/qYUlMhqeEuoqOJkXgzVHqziJC9W7JTDZGl73ajZd UlIDKEdHX9dt375luw7tCu98CKT43vFFVezivaVIF8IkVqUa3I2f7ws3MJJwknC3sSwC 9YsgwT7xp4pKgFeNH5Vh9W9NLlPYBql5yRBL6zvv7UrWhXNBP23YE+4/NPJJf+fXH10B 31ixtnGo9yDrHH1STL7O7C8xsbDWiCJewRiGSP9TotHKhge6R8qg07nLa8xBEJZOmDOo X7q5nRMG5QaDu+UzQUbvjQhUkdhxzA43ZpzfZG6iIZK3JwQ6LXO9mXZQc4izx7MaoO+8 upOg== 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=r+yxxGphpR3zgZXP6ogpnII5hTdLB8byqQCxVaaEBvA=; fh=cKgRupAwAqvDHHS6VAzGoPs3pyLdUCOVkk/Q20cDUOo=; b=Wh4rrd9+sgdhgebxcbJr8OxYxdbCHHxb8QNYQhGLX4f6BUQvKJqjCfsl2lBAIp6/Qu EJOmA59UqL1YcIOm/Y02ebV0Bc0Gi0u2ZmkGu85Bc1svU7lzfZbDZMUgr5uKkHJft8G7 6/5HjCcmFG3015Ic0czqrhK0iZAciQvjIYQznBa24oyde4YaRxOPDZXEYk9ZzxX2prFQ 8j58se+3BBJw6krx3WegYjR0Pdl+J5D0asb4yy0g7j0cUWT9/dJhZiguL0I4i7HaSXga 2e9swnotXwSLj6fEd0yLcfiqFNCHRPMBV0RfLePUmNFXTStF4hbhMe7L377e26zO7G87 j9lw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id w10-20020a63160a000000b005b403446f1dsi3941758pgl.129.2023.11.18.02.43.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 02:43:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 9FF4180ABDE2; Sat, 18 Nov 2023 02:43:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233183AbjKRKmM (ORCPT + 99 others); Sat, 18 Nov 2023 05:42:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232760AbjKRKlo (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 2E64410DC; Sat, 18 Nov 2023 02:41:41 -0800 (PST) Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4SXVgf2pxcz4f3lff; 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 82BEF1A016E; 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--.58135S17; 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 13/14] kddv/tests/mtd: Add test cases for mchp23k256 driver Date: Sat, 18 Nov 2023 18:40:39 +0800 Message-Id: <20231118104040.386381-14-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--.58135S17 X-Coremail-Antispam: 1UD129KBjvJXoWxXFyxJF1rJr1fZw4DXFWDArb_yoWrWw4xpF WrCayYqr1UZFn293sa9F43Jr15uw4kXry5GrWvgw1a9w4aqw1DKr48KFyUta43W3ykXrWr uayjvrW8Grs5WaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 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=-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 agentk.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 (agentk.vger.email [0.0.0.0]); Sat, 18 Nov 2023 02:43:05 -0800 (PST) From: Zhang Xiaoxu This add test case for mchp23k256 mtd driver, test for create mchp23k256 device, default size of the device and read/write data from device. Signed-off-by: Wei Yongjun Signed-off-by: Zhang Xiaoxu --- .../kddv/kddv/data/bpf/mtd/mtd-mchp23k256.c | 72 +++++++++++++++++++ .../kddv/kddv/tests/mtd/test_mchp23k256.py | 41 +++++++++++ 2 files changed, 113 insertions(+) create mode 100644 tools/testing/kddv/kddv/data/bpf/mtd/mtd-mchp23k256.c create mode 100755 tools/testing/kddv/kddv/tests/mtd/test_mchp23k256.py diff --git a/tools/testing/kddv/kddv/data/bpf/mtd/mtd-mchp23k256.c b/tools/testing/kddv/kddv/data/bpf/mtd/mtd-mchp23k256.c new file mode 100644 index 000000000000..b1aa8a25edc0 --- /dev/null +++ b/tools/testing/kddv/kddv/data/bpf/mtd/mtd-mchp23k256.c @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2022-2023 Huawei Technologies Co., Ltd */ + +#include "vmlinux.h" +#include +#include +#include + +#include "spi-xfer-base.h" + +#define MCHP23K256_CMD_WRITE_STATUS 0x01 +#define MCHP23K256_CMD_WRITE 0x02 +#define MCHP23K256_CMD_READ 0x03 + +#define CHIP_REGS_SIZE 0x20000 + +#define MAX_CMD_SIZE 4 + +struct { + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, CHIP_REGS_SIZE); + __type(key, __u32); + __type(value, __u8); +} regs_mtd_mchp23k256 SEC(".maps"); + +static unsigned int chip_reg; + +static int spi_transfer_read(struct spi_msg_ctx *msg, unsigned int len) +{ + return spi_xfer_read_u8(msg, len, ®s_mtd_mchp23k256, chip_reg, 0); +} + +static int spi_transfer_write(struct spi_msg_ctx *msg, unsigned int len) +{ + u8 opcode = msg->data[0]; + int i; + + switch (opcode) { + case MCHP23K256_CMD_READ: + case MCHP23K256_CMD_WRITE: + if (len < 2) + return -EINVAL; + + chip_reg = 0; + for (i = 0; i < MAX_CMD_SIZE && i < len - 1; i++) + chip_reg = (chip_reg << 8) + msg->data[1 + i]; + + return 0; + case MCHP23K256_CMD_WRITE_STATUS: + // ignore write status + return 0; + default: + break; + } + + return spi_xfer_write_u8(msg, len, ®s_mtd_mchp23k256, chip_reg, 0); +} + +SEC("raw_tp.w/spi_transfer_writeable") +int BPF_PROG(mtd_mchp23k256, struct spi_msg_ctx *msg, u8 chip, unsigned int len) +{ + int ret = 0; + + if (msg->tx_nbits) + ret = spi_transfer_write(msg, len); + else if (msg->rx_nbits) + ret = spi_transfer_read(msg, len); + + return ret; +} + +char LICENSE[] SEC("license") = "GPL"; diff --git a/tools/testing/kddv/kddv/tests/mtd/test_mchp23k256.py b/tools/testing/kddv/kddv/tests/mtd/test_mchp23k256.py new file mode 100755 index 000000000000..eefad9d70483 --- /dev/null +++ b/tools/testing/kddv/kddv/tests/mtd/test_mchp23k256.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 + +from kddv.core import SPIDriverTest +from . import MTDDriver + +MCHP23K256_TEST_DATA = [0x78] * 16 + +class TestMCHP23K256(SPIDriverTest, MTDDriver): + name = "mchp23k256" + + @property + def bpf(self): + return f"mtd-{self.name}" + + def test_device_probe(self): + with self.assertRaisesFault(): + with self.device() as _: + pass + + def test_device_size(self): + with self.device() as dev: + size = self.mtd_read_attr(dev, 'size') + self.assertEqual(size, '32768') + + def test_read_data(self): + with self.device() as dev: + self.write_regs(0x00, MCHP23K256_TEST_DATA) + data = self.mtd_read_bytes(dev, 16) + self.assertEqual(data, bytes(MCHP23K256_TEST_DATA)) + + def test_write_data(self): + with self.device() as dev: + self.write_regs(0x00, [0] * 16) + self.mtd_write_bytes(dev, bytes(MCHP23K256_TEST_DATA)) + self.assertRegsEqual(0x00, MCHP23K256_TEST_DATA) -- 2.34.1