From patchwork Fri Jun 16 15:44:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Pagani X-Patchwork-Id: 109217 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1442793vqr; Fri, 16 Jun 2023 08:56:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6wNgnxE/AraMVSG5+14rkH4SjyksRHobXI59poaOchV79lOx5Z7kLDl3Vs/B6UoXUCKy9X X-Received: by 2002:a17:902:d2cb:b0:1b3:f3a2:a391 with SMTP id n11-20020a170902d2cb00b001b3f3a2a391mr2617077plc.48.1686931001210; Fri, 16 Jun 2023 08:56:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686931001; cv=none; d=google.com; s=arc-20160816; b=gBh0001fPyRqAQz7x7xLS9T9Sl+HgFTct52bEA4i9nJM4jlJZitErY6u3KOeXMS6pz bDZUFKR5TbN7rUUbPbu+bnCIuGaJEqbDWjyg/tpD59LMhXolxCqbeV/Dtt2BMnZDVUGS 3JmqO3jb9vo9v61CefV5w7+oqeqZPC7maNY6z4kU0CukzWW1wTwZ+w1ae0WkVcQGdYhD /3vxpXoX+p2WyscDnb6W/BolLb9dxCPLhZpuqvx/wV18k12tpnFGqlOixmzRrdmDjvqJ rUinW4sE6RuEplpAcX9Q30V33/kV8n/oS7B+Eih9DuBBHm10s30ZV6OLHoEYrkNnFnPW PVKA== 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:cc:to:from :dkim-signature; bh=VH0KKJcNZdhv+KXmN/7rOQUAjwGdBm7kB0o87VP7404=; b=ypO5oAIrQMePRUmbx82afRKinAqJMztpaYiAM0tkG19Lxt3dAaJ1CBtBBFWK3tLgca c5iptxaaw1VEhP3vtVBPosrq4XCWq2A72EgOyEEMopJ5VTpyc5q9sCLb/zxNI4gpQs2E rSB7U/l7gbnpuyzJo3wnHm2YvDqgoI5bfCwRnT/Shi6hkmEkL/58d8v/Jbx1XxMp+7EV TEyqejYOp+LBXyeHvagJq9kGO3Y/vjLkWPqO064Mk0gwh2kCpjDV/dzMNOoej7pZq9bu Z/GExlrCAKuqTXNvZ1LHRhvNw6Jr+1EIXX+0hYl/sKovMykPclCwuFJRvO45+pQJKLc7 Q/bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=P3zX3fEH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z18-20020a170903019200b001ab089f7329si12860163plg.73.2023.06.16.08.56.27; Fri, 16 Jun 2023 08:56:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=P3zX3fEH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346077AbjFPPp1 (ORCPT + 99 others); Fri, 16 Jun 2023 11:45:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230060AbjFPPpS (ORCPT ); Fri, 16 Jun 2023 11:45:18 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57B852D43 for ; Fri, 16 Jun 2023 08:44:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686930270; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VH0KKJcNZdhv+KXmN/7rOQUAjwGdBm7kB0o87VP7404=; b=P3zX3fEHGJ3X/ysFi3XkSD0JInrFQ0b+PHoMXbNcyjBGdTDxwhj9f5BnNYQb832qSC0d0E fIV3e4clMy2okSfuqgSlGcNIO9HyDOUsFD8nemAHBng/W70tImMztrLq5dTLbS9BhWT+6b Nqc7WqPBsaL5K/1CvPcLuxcF382IM14= Received: from mail-yw1-f199.google.com (mail-yw1-f199.google.com [209.85.128.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-343-LeEI9tWSNP622ir7Js4HvA-1; Fri, 16 Jun 2023 11:44:29 -0400 X-MC-Unique: LeEI9tWSNP622ir7Js4HvA-1 Received: by mail-yw1-f199.google.com with SMTP id 00721157ae682-5704970148dso11892247b3.3 for ; Fri, 16 Jun 2023 08:44:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686930269; x=1689522269; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VH0KKJcNZdhv+KXmN/7rOQUAjwGdBm7kB0o87VP7404=; b=LKb3fWXQCVpBev79x+NTWjdh4lq4G588RY2PHnIvc+/zkH4GoCPja51+tMwS0SciyW UFF/TMsZfgG7uOpdgq+gWZ+7KWxV6L+nXtonGNkQcAvfSAHiZUUQmGvDIn1oV2Xz5WKP +B1tpHkUmM7QJebWYycMg13VTBrp0NNKGK8l7aTdky5NCB5DZirDwXI2c7Bq2A3AFRAT J7htZC9ijoiOc4+tIAV8fW85TlMMeuOCfNzgswQVdmqT2ZPLkEoqZRSQWAVyYyLPKj3r kEqbhXyA4h5UKESiEUxt3EC6WSUUMN4DrCkcg0FjQKt865fuwXSjEoYJhmd1Lus/GkPZ O4jw== X-Gm-Message-State: AC+VfDzHprApSrJ7mq197H+lWa6H/lP4Y25S/xvQZ8DLr5IeD8MZ0Pnu aOKzf/tjYi6hHVN9e1ixOFF//giYyqItDnLBJYLwI8DHcI7M9zHn3ApEFKGLj6ovqsfWaRen/8t X9yWK6R6HPjlCztYaZXeXDR0= X-Received: by 2002:a0d:dd51:0:b0:55a:40d3:4d6f with SMTP id g78-20020a0ddd51000000b0055a40d34d6fmr2041398ywe.26.1686930268704; Fri, 16 Jun 2023 08:44:28 -0700 (PDT) X-Received: by 2002:a0d:dd51:0:b0:55a:40d3:4d6f with SMTP id g78-20020a0ddd51000000b0055a40d34d6fmr2041389ywe.26.1686930268386; Fri, 16 Jun 2023 08:44:28 -0700 (PDT) Received: from klayman.redhat.com (net-2-34-28-201.cust.vodafonedsl.it. [2.34.28.201]) by smtp.gmail.com with ESMTPSA id 27-20020a05620a079b00b007607ecd58ecsm4436931qka.59.2023.06.16.08.44.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 08:44:28 -0700 (PDT) From: Marco Pagani To: Moritz Fischer , Wu Hao , Xu Yilun , Tom Rix Cc: Marco Pagani , linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v7 1/4] fpga: add an initial KUnit suite for the FPGA Manager Date: Fri, 16 Jun 2023 17:44:02 +0200 Message-Id: <20230616154405.220502-2-marpagan@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230616154405.220502-1-marpagan@redhat.com> References: <20230616154405.220502-1-marpagan@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768875361415512443?= X-GMAIL-MSGID: =?utf-8?q?1768875361415512443?= The suite tests the basic behaviors of the FPGA Manager including programming using a single contiguous buffer and a scatter gather table. Signed-off-by: Marco Pagani --- drivers/fpga/tests/fpga-mgr-test.c | 302 +++++++++++++++++++++++++++++ 1 file changed, 302 insertions(+) create mode 100644 drivers/fpga/tests/fpga-mgr-test.c diff --git a/drivers/fpga/tests/fpga-mgr-test.c b/drivers/fpga/tests/fpga-mgr-test.c new file mode 100644 index 000000000000..70e897dad3b6 --- /dev/null +++ b/drivers/fpga/tests/fpga-mgr-test.c @@ -0,0 +1,302 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit test for the FPGA Manager + * + * Copyright (C) 2023 Red Hat, Inc. + * + * Author: Marco Pagani + */ + +#include +#include +#include +#include +#include +#include + +#define HEADER_FILL 'H' +#define IMAGE_FILL 'P' +#define IMAGE_BLOCK 1024 + +#define HEADER_SIZE IMAGE_BLOCK +#define IMAGE_SIZE (IMAGE_BLOCK * 4) + +struct mgr_stats { + bool header_match; + bool image_match; + u32 seq_num; + u32 op_parse_header_seq; + u32 op_write_init_seq; + u32 op_write_seq; + u32 op_write_sg_seq; + u32 op_write_complete_seq; + enum fpga_mgr_states op_parse_header_state; + enum fpga_mgr_states op_write_init_state; + enum fpga_mgr_states op_write_state; + enum fpga_mgr_states op_write_sg_state; + enum fpga_mgr_states op_write_complete_state; +}; + +struct mgr_ctx { + struct fpga_image_info *img_info; + struct fpga_manager *mgr; + struct platform_device *pdev; + struct mgr_stats stats; +}; + +/** + * init_test_buffer() - Allocate and initialize a test image in a buffer. + * @test: KUnit test context object. + * @count: image size in bytes. + * + * Return: pointer to the newly allocated image. + */ +static char *init_test_buffer(struct kunit *test, size_t count) +{ + char *buf; + size_t i; + + buf = kunit_kzalloc(test, count, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + + for (i = 0; i < count; i++) + buf[i] = i < HEADER_SIZE ? HEADER_FILL : IMAGE_FILL; + + return buf; +} + +static int op_parse_header(struct fpga_manager *mgr, struct fpga_image_info *info, + const char *buf, size_t count) +{ + struct mgr_stats *stats = mgr->priv; + size_t i; + + /* Set header_size and data_size for later */ + info->header_size = HEADER_SIZE; + info->data_size = info->count - HEADER_SIZE; + + stats->header_match = true; + + /* Check header */ + for (i = 0; i < info->header_size; i++) + if (buf[i] != HEADER_FILL) + stats->header_match = false; + + stats->op_parse_header_state = mgr->state; + stats->op_parse_header_seq = stats->seq_num++; + + return 0; +} + +static int op_write_init(struct fpga_manager *mgr, struct fpga_image_info *info, + const char *buf, size_t count) +{ + struct mgr_stats *stats = mgr->priv; + + stats->op_write_init_state = mgr->state; + stats->op_write_init_seq = stats->seq_num++; + + return 0; +} + +static int op_write(struct fpga_manager *mgr, const char *buf, size_t count) +{ + struct mgr_stats *stats = mgr->priv; + size_t i; + + /* Check image */ + stats->image_match = true; + for (i = 0; i < count; i++) + if (buf[i] != IMAGE_FILL) + stats->image_match = false; + + stats->op_write_state = mgr->state; + stats->op_write_seq = stats->seq_num++; + + return 0; +} + +static int op_write_sg(struct fpga_manager *mgr, struct sg_table *sgt) +{ + struct mgr_stats *stats = mgr->priv; + struct scatterlist *sg; + char *img; + unsigned int si, i, j = 0; + + stats->image_match = true; + + /* Check image (write_sg will still get whole image in sg_table) */ + for_each_sgtable_sg(sgt, sg, si) { + img = sg_virt(sg); + for (i = 0; i < sg->length; i++) { + if (i + j > HEADER_SIZE && img[i] != IMAGE_FILL) + stats->image_match = false; + } + j += i; + } + + stats->op_write_sg_state = mgr->state; + stats->op_write_sg_seq = stats->seq_num++; + + return 0; +} + +static int op_write_complete(struct fpga_manager *mgr, struct fpga_image_info *info) +{ + struct mgr_stats *stats = mgr->priv; + + stats->op_write_complete_state = mgr->state; + stats->op_write_complete_seq = stats->seq_num++; + + return 0; +} + +/* + * Fake Manager that implements all ops required to check the programming + * sequence using a single contiguous buffer and a scatter gather table. + */ +static const struct fpga_manager_ops fake_mgr_ops = { + .skip_header = true, + .parse_header = op_parse_header, + .write_init = op_write_init, + .write = op_write, + .write_sg = op_write_sg, + .write_complete = op_write_complete, +}; + +static void fpga_mgr_test_get(struct kunit *test) +{ + struct mgr_ctx *ctx = test->priv; + struct fpga_manager *mgr; + + mgr = fpga_mgr_get(&ctx->pdev->dev); + KUNIT_EXPECT_PTR_EQ(test, mgr, ctx->mgr); + + fpga_mgr_put(ctx->mgr); +} + +static void fpga_mgr_test_lock(struct kunit *test) +{ + struct mgr_ctx *ctx = test->priv; + int ret; + + ret = fpga_mgr_lock(ctx->mgr); + KUNIT_EXPECT_EQ(test, ret, 0); + + ret = fpga_mgr_lock(ctx->mgr); + KUNIT_EXPECT_EQ(test, ret, -EBUSY); + + fpga_mgr_unlock(ctx->mgr); +} + +/* Check the programming sequence using an image in a buffer */ +static void fpga_mgr_test_img_load_buf(struct kunit *test) +{ + struct mgr_ctx *ctx = test->priv; + char *img_buf; + int ret; + + img_buf = init_test_buffer(test, IMAGE_SIZE); + + ctx->img_info->count = IMAGE_SIZE; + ctx->img_info->buf = img_buf; + + ret = fpga_mgr_load(ctx->mgr, ctx->img_info); + KUNIT_EXPECT_EQ(test, ret, 0); + + KUNIT_EXPECT_TRUE(test, ctx->stats.header_match); + KUNIT_EXPECT_TRUE(test, ctx->stats.image_match); + + KUNIT_EXPECT_EQ(test, ctx->stats.op_parse_header_state, FPGA_MGR_STATE_PARSE_HEADER); + KUNIT_EXPECT_EQ(test, ctx->stats.op_write_init_state, FPGA_MGR_STATE_WRITE_INIT); + KUNIT_EXPECT_EQ(test, ctx->stats.op_write_state, FPGA_MGR_STATE_WRITE); + KUNIT_EXPECT_EQ(test, ctx->stats.op_write_complete_state, FPGA_MGR_STATE_WRITE_COMPLETE); + + KUNIT_EXPECT_EQ(test, ctx->stats.op_write_init_seq, ctx->stats.op_parse_header_seq + 1); + KUNIT_EXPECT_EQ(test, ctx->stats.op_write_seq, ctx->stats.op_parse_header_seq + 2); + KUNIT_EXPECT_EQ(test, ctx->stats.op_write_complete_seq, ctx->stats.op_parse_header_seq + 3); +} + +/* Check the programming sequence using an image in a scatter gather table */ +static void fpga_mgr_test_img_load_sgt(struct kunit *test) +{ + struct mgr_ctx *ctx = test->priv; + struct sg_table *sgt; + char *img_buf; + int ret; + + img_buf = init_test_buffer(test, IMAGE_SIZE); + + sgt = kunit_kzalloc(test, sizeof(*sgt), GFP_KERNEL); + ret = sg_alloc_table(sgt, 1, GFP_KERNEL); + KUNIT_ASSERT_EQ(test, ret, 0); + sg_init_one(sgt->sgl, img_buf, IMAGE_SIZE); + + ctx->img_info->sgt = sgt; + + ret = fpga_mgr_load(ctx->mgr, ctx->img_info); + KUNIT_EXPECT_EQ(test, ret, 0); + + KUNIT_EXPECT_TRUE(test, ctx->stats.header_match); + KUNIT_EXPECT_TRUE(test, ctx->stats.image_match); + + KUNIT_EXPECT_EQ(test, ctx->stats.op_parse_header_state, FPGA_MGR_STATE_PARSE_HEADER); + KUNIT_EXPECT_EQ(test, ctx->stats.op_write_init_state, FPGA_MGR_STATE_WRITE_INIT); + KUNIT_EXPECT_EQ(test, ctx->stats.op_write_sg_state, FPGA_MGR_STATE_WRITE); + KUNIT_EXPECT_EQ(test, ctx->stats.op_write_complete_state, FPGA_MGR_STATE_WRITE_COMPLETE); + + KUNIT_EXPECT_EQ(test, ctx->stats.op_write_init_seq, ctx->stats.op_parse_header_seq + 1); + KUNIT_EXPECT_EQ(test, ctx->stats.op_write_sg_seq, ctx->stats.op_parse_header_seq + 2); + KUNIT_EXPECT_EQ(test, ctx->stats.op_write_complete_seq, ctx->stats.op_parse_header_seq + 3); + + sg_free_table(ctx->img_info->sgt); +} + +static int fpga_mgr_test_init(struct kunit *test) +{ + struct mgr_ctx *ctx; + + ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); + + ctx->pdev = platform_device_register_simple("mgr_pdev", PLATFORM_DEVID_AUTO, NULL, 0); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->pdev); + + ctx->mgr = devm_fpga_mgr_register(&ctx->pdev->dev, "Fake FPGA Manager", &fake_mgr_ops, + &ctx->stats); + KUNIT_ASSERT_FALSE(test, IS_ERR_OR_NULL(ctx->mgr)); + + ctx->img_info = fpga_image_info_alloc(&ctx->pdev->dev); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->img_info); + + test->priv = ctx; + + return 0; +} + +static void fpga_mgr_test_exit(struct kunit *test) +{ + struct mgr_ctx *ctx = test->priv; + + fpga_image_info_free(ctx->img_info); + platform_device_unregister(ctx->pdev); +} + +static struct kunit_case fpga_mgr_test_cases[] = { + KUNIT_CASE(fpga_mgr_test_get), + KUNIT_CASE(fpga_mgr_test_lock), + KUNIT_CASE(fpga_mgr_test_img_load_buf), + KUNIT_CASE(fpga_mgr_test_img_load_sgt), + {} +}; + +static struct kunit_suite fpga_mgr_suite = { + .name = "fpga_mgr", + .init = fpga_mgr_test_init, + .exit = fpga_mgr_test_exit, + .test_cases = fpga_mgr_test_cases, +}; + +kunit_test_suite(fpga_mgr_suite); + +MODULE_LICENSE("GPL"); From patchwork Fri Jun 16 15:44:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Pagani X-Patchwork-Id: 109239 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1458295vqr; Fri, 16 Jun 2023 09:16:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5r7yrv2zI2oOVdXDGSu5uifvmylxdV+myyr6EjxxNZJTLyTn9nkRh6Udx9x1WNQzXv+hPV X-Received: by 2002:a17:90a:195d:b0:25b:f37d:a075 with SMTP id 29-20020a17090a195d00b0025bf37da075mr1968661pjh.14.1686932170162; Fri, 16 Jun 2023 09:16:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686932170; cv=none; d=google.com; s=arc-20160816; b=QNLg1nL+jwAzpUvk0oesBSnu/yk62JneZLL0VNH0xMiplPVVeV3mJeeCQuRDm26PUQ fAZxcHecFa9MNMm9zW/nueFBT8qkpabKzooT4gLd8Bb69n8DP8dcyKlWlyXaOJ8r+9YN E8Or72UXKZEeXsHyncHItK9vubuw7vOJ7mdvRc2Jd/obbfhigFogvTAj5JO59XP0ICAP 0TfSombhL+hdSD00GNbKoRa5krL7VyRqWuwvwHE5jETiFUW+nF66cD6e0vvQWC1TnxjT G8E/XX0Vv4TWgHTQLQsFzUAGqf8r45H76Qii6/u7OqcNngh8zva29AeZMD3qilcFov6t /64Q== 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:cc:to:from :dkim-signature; bh=0tmpX0UMp42WCZHiMzV6s9gBD7RFJYF8/+0DSuUNrP8=; b=GCHPlRLYk9Kfl6LeW+LWxYB8CwZsiaC4IpgpPxOXrrp3WMFcMkSGqSkZQoWLrqTN+/ TM8mEb89yipRPwhRTlXlukUw0JEwXHObJ4dEj8+Sf/cLOD9w8tO4BsxuwNd7qovF8fbP DzQKpKHbIQ2lZz3QgthA2dTvgtOYFXRk4XAmFHRkcPTdKkk0b6z8Qb1vv76lilmhRvlt nRlWkGMQp6D4b1amPpze3r9kUCC9WK30k6zY3msECNqNI7bKUKL7fmyy0nKCCh6pFroO 7NAVPEj2sk/TC8rtW4Drqd33xALPl6IcIEKcEx7T+/G9w3Lnm9X4+RHd9CevsK/kDop9 9mnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TIVxxL6u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv127-20020a632e85000000b005481915c0c7si613494pgb.32.2023.06.16.09.15.53; Fri, 16 Jun 2023 09:16:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TIVxxL6u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346086AbjFPPpg (ORCPT + 99 others); Fri, 16 Jun 2023 11:45:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346063AbjFPPp0 (ORCPT ); Fri, 16 Jun 2023 11:45:26 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D19CC2D71 for ; Fri, 16 Jun 2023 08:44:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686930279; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0tmpX0UMp42WCZHiMzV6s9gBD7RFJYF8/+0DSuUNrP8=; b=TIVxxL6uOCg9ZWTVStBcf27cqHqjQKsh38Qy11V15DHxzSY1u/rHr5s5X/CK6smIV7ZFFZ xWMJ9E6YAcZMZXgPjtDoa84HWlmvpqGrVmUYejy5DQevXmiFtO6+M793dG/T81549zlWl7 eJEcL/5s+GUzLOGfW9ly3s546pZQh1I= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-321-NZ1dbu66P0Cqf0lDL0VgkQ-1; Fri, 16 Jun 2023 11:44:37 -0400 X-MC-Unique: NZ1dbu66P0Cqf0lDL0VgkQ-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-76239d8a374so50103185a.2 for ; Fri, 16 Jun 2023 08:44:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686930277; x=1689522277; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0tmpX0UMp42WCZHiMzV6s9gBD7RFJYF8/+0DSuUNrP8=; b=C6tKkGFR6YvzlOhW2Qy/2ow5O51i7aGPBtXNEmu4Xr39Au6VtjwXV0Xzei43WcGD6O CoIPKfXV06a2uEvcrvKDDydEs5bSI8kGYFVLdz05qpLdFeyAnfDq7k2/Fdcbek5uc6JP cN0q84P9JgZS0YV+8Nu+j0bwHB1ObIx6S5QAjZtESkO7QSY64SuMotzLNhjksSMAFgYw wInuEdjg7nyII4f/WVaNUh/b1oegTfklsZQM2y7KrDm7+e3Jx6xW9YhQzbQGV19t6th0 wnMFBve4se3r4ahqE7GtlLi+5/V2ORqgAqn1WuhoQcVUavb/QpPCZnM6M3X7fLBTquIy 4ioQ== X-Gm-Message-State: AC+VfDx0LC5YBiEuzCd66dwoSunx6ZHcUoeVrXOggiZpN3fPtmma2O58 YkD/zxGzPAy/XLai7DQckiLwGKlFZglVrFJY/uEM35EI1qUVI2tX4dqL86W8261wfrkzZnLh51/ XHqdbHM8WbSjFFlaSivBCf8U3UjeR23Y= X-Received: by 2002:a05:620a:2493:b0:75e:d8db:5e4 with SMTP id i19-20020a05620a249300b0075ed8db05e4mr2588740qkn.49.1686930277073; Fri, 16 Jun 2023 08:44:37 -0700 (PDT) X-Received: by 2002:a05:620a:2493:b0:75e:d8db:5e4 with SMTP id i19-20020a05620a249300b0075ed8db05e4mr2588725qkn.49.1686930276831; Fri, 16 Jun 2023 08:44:36 -0700 (PDT) Received: from klayman.redhat.com (net-2-34-28-201.cust.vodafonedsl.it. [2.34.28.201]) by smtp.gmail.com with ESMTPSA id 27-20020a05620a079b00b007607ecd58ecsm4436931qka.59.2023.06.16.08.44.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 08:44:36 -0700 (PDT) From: Marco Pagani To: Moritz Fischer , Wu Hao , Xu Yilun , Tom Rix Cc: Marco Pagani , linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v7 2/4] fpga: add an initial KUnit suite for the FPGA Bridge Date: Fri, 16 Jun 2023 17:44:03 +0200 Message-Id: <20230616154405.220502-3-marpagan@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230616154405.220502-1-marpagan@redhat.com> References: <20230616154405.220502-1-marpagan@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768876587124506876?= X-GMAIL-MSGID: =?utf-8?q?1768876587124506876?= The suite tests the basic behaviors of the FPGA Bridge including the functions that operate on a list of Bridges. Signed-off-by: Marco Pagani Acked-by: Xu Yilun --- drivers/fpga/tests/fpga-bridge-test.c | 175 ++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 drivers/fpga/tests/fpga-bridge-test.c diff --git a/drivers/fpga/tests/fpga-bridge-test.c b/drivers/fpga/tests/fpga-bridge-test.c new file mode 100644 index 000000000000..fce67ac59a7c --- /dev/null +++ b/drivers/fpga/tests/fpga-bridge-test.c @@ -0,0 +1,175 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit test for the FPGA Bridge + * + * Copyright (C) 2023 Red Hat, Inc. + * + * Author: Marco Pagani + */ + +#include +#include +#include +#include +#include + +struct bridge_stats { + bool enable; +}; + +struct bridge_ctx { + struct fpga_bridge *bridge; + struct platform_device *pdev; + struct bridge_stats stats; +}; + +static int op_enable_set(struct fpga_bridge *bridge, bool enable) +{ + struct bridge_stats *stats = bridge->priv; + + stats->enable = enable; + + return 0; +} + +/* + * Fake Bridge that implements only the enable_set op to track + * the state. + */ +static const struct fpga_bridge_ops fake_bridge_ops = { + .enable_set = op_enable_set +}; + +/** + * register_test_bridge() - Register a fake Bridge for testing. + * @test: KUnit test context object. + * + * Return: Context of the newly registered Bridge. + */ +static struct bridge_ctx *register_test_bridge(struct kunit *test) +{ + struct bridge_ctx *ctx; + + ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); + + ctx->pdev = platform_device_register_simple("bridge_pdev", PLATFORM_DEVID_AUTO, NULL, 0); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->pdev); + + ctx->bridge = fpga_bridge_register(&ctx->pdev->dev, "Fake FPGA Bridge", &fake_bridge_ops, + &ctx->stats); + KUNIT_ASSERT_FALSE(test, IS_ERR_OR_NULL(ctx->bridge)); + + return ctx; +} + +static void unregister_test_bridge(struct bridge_ctx *ctx) +{ + fpga_bridge_unregister(ctx->bridge); + platform_device_unregister(ctx->pdev); +} + +static void fpga_bridge_test_get(struct kunit *test) +{ + struct bridge_ctx *ctx = test->priv; + struct fpga_bridge *bridge; + + bridge = fpga_bridge_get(&ctx->pdev->dev, NULL); + KUNIT_EXPECT_PTR_EQ(test, bridge, ctx->bridge); + + bridge = fpga_bridge_get(&ctx->pdev->dev, NULL); + KUNIT_EXPECT_EQ(test, PTR_ERR(bridge), -EBUSY); + + fpga_bridge_put(ctx->bridge); +} + +static void fpga_bridge_test_toggle(struct kunit *test) +{ + struct bridge_ctx *ctx = test->priv; + int ret; + + ret = fpga_bridge_disable(ctx->bridge); + KUNIT_EXPECT_EQ(test, ret, 0); + KUNIT_EXPECT_FALSE(test, ctx->stats.enable); + + ret = fpga_bridge_enable(ctx->bridge); + KUNIT_EXPECT_EQ(test, ret, 0); + KUNIT_EXPECT_TRUE(test, ctx->stats.enable); +} + +/* Test the functions for getting and controlling a list of bridges */ +static void fpga_bridge_test_get_put_list(struct kunit *test) +{ + struct list_head bridge_list; + struct bridge_ctx *ctx_0, *ctx_1; + int ret; + + ctx_0 = test->priv; + ctx_1 = register_test_bridge(test); + + INIT_LIST_HEAD(&bridge_list); + + /* Get bridge 0 and add it to the list */ + ret = fpga_bridge_get_to_list(&ctx_0->pdev->dev, NULL, &bridge_list); + KUNIT_EXPECT_EQ(test, ret, 0); + + KUNIT_EXPECT_PTR_EQ(test, ctx_0->bridge, + list_first_entry_or_null(&bridge_list, struct fpga_bridge, node)); + + /* Get bridge 1 and add it to the list */ + ret = fpga_bridge_get_to_list(&ctx_1->pdev->dev, NULL, &bridge_list); + KUNIT_EXPECT_EQ(test, ret, 0); + + KUNIT_EXPECT_PTR_EQ(test, ctx_1->bridge, + list_first_entry_or_null(&bridge_list, struct fpga_bridge, node)); + + /* Disable an then enable both bridges from the list */ + ret = fpga_bridges_disable(&bridge_list); + KUNIT_EXPECT_EQ(test, ret, 0); + + KUNIT_EXPECT_FALSE(test, ctx_0->stats.enable); + KUNIT_EXPECT_FALSE(test, ctx_1->stats.enable); + + ret = fpga_bridges_enable(&bridge_list); + KUNIT_EXPECT_EQ(test, ret, 0); + + KUNIT_EXPECT_TRUE(test, ctx_0->stats.enable); + KUNIT_EXPECT_TRUE(test, ctx_1->stats.enable); + + /* Put and remove both bridges from the list */ + fpga_bridges_put(&bridge_list); + + KUNIT_EXPECT_TRUE(test, list_empty(&bridge_list)); + + unregister_test_bridge(ctx_1); +} + +static int fpga_bridge_test_init(struct kunit *test) +{ + test->priv = register_test_bridge(test); + + return 0; +} + +static void fpga_bridge_test_exit(struct kunit *test) +{ + unregister_test_bridge(test->priv); +} + +static struct kunit_case fpga_bridge_test_cases[] = { + KUNIT_CASE(fpga_bridge_test_get), + KUNIT_CASE(fpga_bridge_test_toggle), + KUNIT_CASE(fpga_bridge_test_get_put_list), + {} +}; + +static struct kunit_suite fpga_bridge_suite = { + .name = "fpga_bridge", + .init = fpga_bridge_test_init, + .exit = fpga_bridge_test_exit, + .test_cases = fpga_bridge_test_cases, +}; + +kunit_test_suite(fpga_bridge_suite); + +MODULE_LICENSE("GPL"); From patchwork Fri Jun 16 15:44:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Pagani X-Patchwork-Id: 109228 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1447625vqr; Fri, 16 Jun 2023 09:03:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5fGxEUfAhwQKXkcNHkH/ST19BIO5BHN3XgvJkqzMNDSw7N9NyxOV29M3MCi9UP+OBRyzhn X-Received: by 2002:a17:902:7487:b0:1b0:307c:e6fe with SMTP id h7-20020a170902748700b001b0307ce6femr2121269pll.10.1686931391755; Fri, 16 Jun 2023 09:03:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686931391; cv=none; d=google.com; s=arc-20160816; b=ETdDqGKvYhMksasKcU04w2KDGaoyw4T15JqiwvrAE9fIzD8zLUfbEG0jZPpg8CDwUY 8qZ9gZMwpOzTRMSKXOCWUSS9yxRSMImZRGkur1EAFixXpYF86E6IrDkRm3785wyYdiKF Kw9TowRVJrbi7sZsCXPAuyUPjsu8GjAyJ/mOzR1zFTrrMbLN1GQPdCRerXP2FXVTEKi7 4OPHKRPDSTvxw8k6AdgFCAUms73qthCPUww9ttHLbjZsEmm49Oin43RJscWxKac4dUjj bYECphVEXViGgt546XgmKg0ZS2TjX4tj2L5YX2n6ko9D4D4aHC2brOI/JoKy8CGvZArn hD9g== 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:cc:to:from :dkim-signature; bh=rk/GX/Fw44kAlHIKlENLzG4S82eDoKHx4BfoPDKJcsI=; b=pEfVapgkyjEPcfaruKh/vjb3kKg41xgYKelJuKRGc56It/wpIre+xFpEts9WqOexxD AzI0lNP68kD9pHJ5okHq6CFDVHbQQ6MhKGVt0eJKVFzGSe1007jau9XIx/nLXvcZFop+ nxX8Ym4JyYtm2eXwOKcp8NOIaRgXYqSMennwYk1aO4Ikx9Pzg1Eu/EFtPALQBdFOb5wl htiN/u/zllZe2kbxs4ccEvIAP+Eq4JVtJbNHN8J3JsKpCc9jXDDKXYCZ+fFuj3uX3ahj Yh91uCAA6+yZS7qUrdLRjDx8efDcSSia1yw3nl9MD3cHvFlcMQKOryZJYdpVnH/ExsHx SdXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WMqQ1Nry; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h10-20020a170902f54a00b001b23d02a0c7si2522916plf.272.2023.06.16.09.02.56; Fri, 16 Jun 2023 09:03:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WMqQ1Nry; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346117AbjFPPpj (ORCPT + 99 others); Fri, 16 Jun 2023 11:45:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345881AbjFPPpd (ORCPT ); Fri, 16 Jun 2023 11:45:33 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FFDC30D1 for ; Fri, 16 Jun 2023 08:44:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686930285; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rk/GX/Fw44kAlHIKlENLzG4S82eDoKHx4BfoPDKJcsI=; b=WMqQ1Nryrn0BAHDikYUZJQmW6r/rSSpjKxrcBxPY2v4PDmlZnmRNd39NaIIAG4WLXZSD6I B87N6c34rzHKJgh4jHBjZZ5VAgh6SaXs+DHoOi9XXleMKZt8WnSOumWHkbG4N7mgaIO3Te 7nMCKs6TRJJIK/RWFAzj1JgiLQfVcU8= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-22-YQh0AJLJMGWEivkPpMNNkw-1; Fri, 16 Jun 2023 11:44:43 -0400 X-MC-Unique: YQh0AJLJMGWEivkPpMNNkw-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-762318ecdd1so95559585a.0 for ; Fri, 16 Jun 2023 08:44:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686930283; x=1689522283; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rk/GX/Fw44kAlHIKlENLzG4S82eDoKHx4BfoPDKJcsI=; b=VtyOJEY0+pHo00nnZoWwHOaCI9WQWDHzs6JxZ8RfSKNEaRowWWBzrmsuUQtp7bvQHV 4+bvqij5YNKa3PXmPe3eJQf4q4dW6Uotz37tJuH+vjk+FTw/77MmJP5hE3n+7Hhigll1 Z4jDw0b3GoNRPH5VC8bW19aiEoB0pMzISX05amlSyKjPFHaspU35zh/0rrZAoLwTUjJK a0eRutukMOWemJy7rXP+MBefd7PizaRhyxBbJVuEAKze8JMpe1Wy5zqN4moqlDR17Op8 wEJjKoAFvNHSct/BxZitroB3gEFYvaAaj2Wre8/d0X1WI8YalNWD9XURm6/nRdxchexV TlWw== X-Gm-Message-State: AC+VfDxEb/LiKJP9t/tsAQvQ6rWvZd+jx8Kmig5TkEJ87oU9yvBbAwFt TTw8tvLu6zkuC1HYVEMy0evluAriPNEzcLfJ4z8jFFbF7duftMO2oJeMFxMTDZkePpjWZOdl9yZ iSzCYM7h2LmckTJhbz1arDyMM+ZRjoD0= X-Received: by 2002:a05:620a:8b14:b0:75b:23a0:e7da with SMTP id qw20-20020a05620a8b1400b0075b23a0e7damr1926707qkn.59.1686930283070; Fri, 16 Jun 2023 08:44:43 -0700 (PDT) X-Received: by 2002:a05:620a:8b14:b0:75b:23a0:e7da with SMTP id qw20-20020a05620a8b1400b0075b23a0e7damr1926698qkn.59.1686930282819; Fri, 16 Jun 2023 08:44:42 -0700 (PDT) Received: from klayman.redhat.com (net-2-34-28-201.cust.vodafonedsl.it. [2.34.28.201]) by smtp.gmail.com with ESMTPSA id 27-20020a05620a079b00b007607ecd58ecsm4436931qka.59.2023.06.16.08.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 08:44:42 -0700 (PDT) From: Marco Pagani To: Moritz Fischer , Wu Hao , Xu Yilun , Tom Rix Cc: Marco Pagani , linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v7 3/4] fpga: add an initial KUnit suite for the FPGA Region Date: Fri, 16 Jun 2023 17:44:04 +0200 Message-Id: <20230616154405.220502-4-marpagan@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230616154405.220502-1-marpagan@redhat.com> References: <20230616154405.220502-1-marpagan@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, 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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768875771237909741?= X-GMAIL-MSGID: =?utf-8?q?1768875771237909741?= The suite tests the basic behaviors of the FPGA Region including the programming and the function for finding a specific Region. Signed-off-by: Marco Pagani Acked-by: Xu Yilun --- drivers/fpga/tests/fpga-region-test.c | 211 ++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 drivers/fpga/tests/fpga-region-test.c diff --git a/drivers/fpga/tests/fpga-region-test.c b/drivers/fpga/tests/fpga-region-test.c new file mode 100644 index 000000000000..a502f3f2560d --- /dev/null +++ b/drivers/fpga/tests/fpga-region-test.c @@ -0,0 +1,211 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit test for the FPGA Region + * + * Copyright (C) 2023 Red Hat, Inc. + * + * Author: Marco Pagani + */ + +#include +#include +#include +#include +#include +#include +#include + +struct mgr_stats { + u32 write_count; +}; + +struct bridge_stats { + bool enable; + u32 cycles_count; +}; + +struct test_ctx { + struct fpga_manager *mgr; + struct platform_device *mgr_pdev; + struct fpga_bridge *bridge; + struct platform_device *bridge_pdev; + struct fpga_region *region; + struct platform_device *region_pdev; + struct bridge_stats bridge_stats; + struct mgr_stats mgr_stats; +}; + +static int op_write(struct fpga_manager *mgr, const char *buf, size_t count) +{ + struct mgr_stats *stats = mgr->priv; + + stats->write_count++; + + return 0; +} + +/* + * Fake Manager that implements only the write op to count the number of + * programming cycles. The internals of the programming sequence are + * tested in the Manager suite since they are outside the responsibility + * of the Region. + */ +static const struct fpga_manager_ops fake_mgr_ops = { + .write = op_write, +}; + +static int op_enable_set(struct fpga_bridge *bridge, bool enable) +{ + struct bridge_stats *stats = bridge->priv; + + if (!stats->enable && enable) + stats->cycles_count++; + + stats->enable = enable; + + return 0; +} + +/* + * Fake Bridge that implements only enable_set op to count the number of + * activation cycles. + */ +static const struct fpga_bridge_ops fake_bridge_ops = { + .enable_set = op_enable_set +}; + +static int fake_region_get_bridges(struct fpga_region *region) +{ + struct fpga_bridge *bridge = region->priv; + + return fpga_bridge_get_to_list(bridge->dev.parent, region->info, ®ion->bridge_list); +} + +static int fake_region_match(struct device *dev, const void *data) +{ + return dev->parent == data; +} + +static void fpga_region_test_class_find(struct kunit *test) +{ + struct test_ctx *ctx = test->priv; + struct fpga_region *region; + + region = fpga_region_class_find(NULL, &ctx->region_pdev->dev, fake_region_match); + KUNIT_EXPECT_PTR_EQ(test, region, ctx->region); +} + +/* + * Region programming test. The Region must call get_bridges() to get and + * control the bridges, and then the Manager for the actual programming. + */ +static void fpga_region_test_program_fpga(struct kunit *test) +{ + struct test_ctx *ctx = test->priv; + struct fpga_image_info *img_info; + char img_buf[4]; + int ret; + + img_info = fpga_image_info_alloc(&ctx->mgr_pdev->dev); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, img_info); + + img_info->buf = img_buf; + img_info->count = sizeof(img_buf); + + ctx->region->info = img_info; + ret = fpga_region_program_fpga(ctx->region); + KUNIT_ASSERT_EQ(test, ret, 0); + + KUNIT_EXPECT_EQ(test, 1, ctx->mgr_stats.write_count); + KUNIT_EXPECT_EQ(test, 1, ctx->bridge_stats.cycles_count); + + fpga_bridges_put(&ctx->region->bridge_list); + + ret = fpga_region_program_fpga(ctx->region); + KUNIT_ASSERT_EQ(test, ret, 0); + + KUNIT_EXPECT_EQ(test, 2, ctx->mgr_stats.write_count); + KUNIT_EXPECT_EQ(test, 2, ctx->bridge_stats.cycles_count); + + fpga_bridges_put(&ctx->region->bridge_list); + + fpga_image_info_free(img_info); +} + +/* + * The configuration used in this test suite uses a single bridge to + * limit the code under test to a single unit. The functions used by the + * Region for getting and controlling bridges are tested (with a list of + * multiple bridges) in the Bridge suite. + */ +static int fpga_region_test_init(struct kunit *test) +{ + struct test_ctx *ctx; + struct fpga_region_info region_info = { 0 }; + + ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); + + ctx->mgr_pdev = platform_device_register_simple("mgr_pdev", PLATFORM_DEVID_AUTO, NULL, 0); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->mgr_pdev); + + ctx->mgr = devm_fpga_mgr_register(&ctx->mgr_pdev->dev, "Fake FPGA Manager", &fake_mgr_ops, + &ctx->mgr_stats); + KUNIT_ASSERT_FALSE(test, IS_ERR_OR_NULL(ctx->mgr)); + + ctx->bridge_pdev = platform_device_register_simple("bridge_pdev", PLATFORM_DEVID_AUTO, + NULL, 0); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->bridge_pdev); + + ctx->bridge = fpga_bridge_register(&ctx->bridge_pdev->dev, "Fake FPGA Bridge", + &fake_bridge_ops, &ctx->bridge_stats); + KUNIT_ASSERT_FALSE(test, IS_ERR_OR_NULL(ctx->bridge)); + + ctx->bridge_stats.enable = true; + + ctx->region_pdev = platform_device_register_simple("region_pdev", PLATFORM_DEVID_AUTO, + NULL, 0); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->region_pdev); + + region_info.mgr = ctx->mgr; + region_info.priv = ctx->bridge; + region_info.get_bridges = fake_region_get_bridges; + + ctx->region = fpga_region_register_full(&ctx->region_pdev->dev, ®ion_info); + KUNIT_ASSERT_FALSE(test, IS_ERR_OR_NULL(ctx->region)); + + test->priv = ctx; + + return 0; +} + +static void fpga_region_test_exit(struct kunit *test) +{ + struct test_ctx *ctx = test->priv; + + fpga_region_unregister(ctx->region); + platform_device_unregister(ctx->region_pdev); + + fpga_bridge_unregister(ctx->bridge); + platform_device_unregister(ctx->bridge_pdev); + + platform_device_unregister(ctx->mgr_pdev); +} + +static struct kunit_case fpga_region_test_cases[] = { + KUNIT_CASE(fpga_region_test_class_find), + KUNIT_CASE(fpga_region_test_program_fpga), + + {} +}; + +static struct kunit_suite fpga_region_suite = { + .name = "fpga_mgr", + .init = fpga_region_test_init, + .exit = fpga_region_test_exit, + .test_cases = fpga_region_test_cases, +}; + +kunit_test_suite(fpga_region_suite); + +MODULE_LICENSE("GPL"); From patchwork Fri Jun 16 15:44:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Pagani X-Patchwork-Id: 109226 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1447260vqr; Fri, 16 Jun 2023 09:02:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7/vE6MxEomwq2iQp9yfvs/XfKPDHhPcEgFWqCOl2uKKiMhO9EgolHlk0jsDJske9ObQIeG X-Received: by 2002:a05:6a00:2d09:b0:656:e7a2:5322 with SMTP id fa9-20020a056a002d0900b00656e7a25322mr2709595pfb.26.1686931366908; Fri, 16 Jun 2023 09:02:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686931366; cv=none; d=google.com; s=arc-20160816; b=gxlp8+45FlFa8/UlC8P45t9ColdqsLCwGIAXStld5VRb+ZjDxEj0/8weZyH21ruNYv 8daHK/VWIXV8mBgJlJi2VI+wdG/lXcBwkIzW8vZqyETXIBlkDZ/vHRpVy1tvc3mJif2u JLsd9J9WIToejJaCLfInW0RC+mkKn36t8Ks4kGd7Hb927/flZDgiG9+hlJ8MLefTc+UD sgrmMEksOo46NpzVWAxwHFQjv02NHG8rjGh5nr/abG7ZEuzFXzZhsxiQ0TJMPxEgY/gu x4klEcl/rbI0WNj/+81I0e9dMSdO8waArV+nubmhKgKlHu7NHDhYeZU3mXnxfWNmUAAg zkMg== 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:cc:to:from :dkim-signature; bh=DLxKEahzszph04pP7LNvqbtOeyVOwQumdUKeU8imaG0=; b=fAtdRHTTwRnxwQADumuA5EQKyPLqoLMuDD3Rhx+PS9FG55GakyPffiqvLX/y4X7wYa mcVILozWt7fsYa6JzEjBbbpAFaSGfdJxFcNsCinnNQZPZ6et4LTGykLxuvNXqesqeiOm rJ4op78WxSLH0XlT3aK3xwB4LpikCgReVDdpO1wY4IG159PE342n5TccRMUATDRvR46A uP703HCLxh6qx+D4KaF71RkF7hQQUNcnQJPkjeMt/kKpsuvWVzggH9CGSBfR18xC0+Nd wqHEskbJHXe+6ckgwdC4W2ZqOf0zeE6CUUKBw2yHC/YgxpTFHsAHEgx6iJ7/4eu9jq2N 3Ddw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aQ84qE93; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b3-20020a62cf03000000b0064354230c2asi1184399pfg.367.2023.06.16.09.02.24; Fri, 16 Jun 2023 09:02:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aQ84qE93; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346116AbjFPPpt (ORCPT + 99 others); Fri, 16 Jun 2023 11:45:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346109AbjFPPpl (ORCPT ); Fri, 16 Jun 2023 11:45:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ECE8359D for ; Fri, 16 Jun 2023 08:44:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686930293; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DLxKEahzszph04pP7LNvqbtOeyVOwQumdUKeU8imaG0=; b=aQ84qE93pQ9w9q5r/0ci9Gkcm2VpO4I+cuzFzZzs99W26fjRk/4azZnQKgnvfhRieG+sUM 9CCBb4njqwd/lgWLFRxgUybIM9fp8afvgwanmAWIJNuERv4EHKzvfaQZqn/ZK+1lLMbadh rLFr+fdDKqJNoNEyL/Lzlw1/6Ql1er8= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-410-51t3TrQNM7GvWbulLT-mlQ-1; Fri, 16 Jun 2023 11:44:52 -0400 X-MC-Unique: 51t3TrQNM7GvWbulLT-mlQ-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-762225d3df8so82172885a.0 for ; Fri, 16 Jun 2023 08:44:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686930292; x=1689522292; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DLxKEahzszph04pP7LNvqbtOeyVOwQumdUKeU8imaG0=; b=I9N41MpJ4cA7jluYRNLAbBBqbG2tKGkwtmCbvZ0rQAbk5IKFiDposNAm7KmKKlVYuS lK8NYJ+dbE1yi1+P9TRXy66JKZjLw3maS/aHUPix4CHRU/dQIa1JW4476/N7syCfWdL0 8VoTX5QxxNMxEQjDkg+4Z6z1zxA3mMXcwDMOhj2F+aWocOS+X6zndHYNAAIZCWMw6JDM yNKP5FHQFqSxCngLPNZufWuQn9GrVlPmfrsHaZfMq7MsXwlNJmhIoLPEhpaRoJn/Sd+f clBHlrMeIu2UB9FtZaeza+Vif1wS10RgW3/lMrLqX079ktLXOxW7cprNr0lDcedwjTOO Ox3w== X-Gm-Message-State: AC+VfDw6V0e6LPhlCO8xj6h3Z4UjF2gLJ97bqmmpdMfqHQbPr7GkmzGM oXaqfVKBt05y7aka6corqBXAq67JNXEA8gB93mdnpobt9zlYjzaDDG56tWj0LiKkIcudUDl/NR1 092dw9WUtFi45hCtYsoCHX0Y= X-Received: by 2002:a05:620a:2910:b0:75e:d264:fdb5 with SMTP id m16-20020a05620a291000b0075ed264fdb5mr2361403qkp.24.1686930291895; Fri, 16 Jun 2023 08:44:51 -0700 (PDT) X-Received: by 2002:a05:620a:2910:b0:75e:d264:fdb5 with SMTP id m16-20020a05620a291000b0075ed264fdb5mr2361388qkp.24.1686930291661; Fri, 16 Jun 2023 08:44:51 -0700 (PDT) Received: from klayman.redhat.com (net-2-34-28-201.cust.vodafonedsl.it. [2.34.28.201]) by smtp.gmail.com with ESMTPSA id 27-20020a05620a079b00b007607ecd58ecsm4436931qka.59.2023.06.16.08.44.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 08:44:51 -0700 (PDT) From: Marco Pagani To: Moritz Fischer , Wu Hao , Xu Yilun , Tom Rix Cc: Marco Pagani , linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v7 4/4] fpga: add configuration for the FPGA KUnit test suites. Date: Fri, 16 Jun 2023 17:44:05 +0200 Message-Id: <20230616154405.220502-5-marpagan@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230616154405.220502-1-marpagan@redhat.com> References: <20230616154405.220502-1-marpagan@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, 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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768875744481230963?= X-GMAIL-MSGID: =?utf-8?q?1768875744481230963?= Add configuration for the KUnit test suites for the core components of the FPGA subsystem. Signed-off-by: Marco Pagani --- drivers/fpga/Kconfig | 2 ++ drivers/fpga/Makefile | 3 +++ drivers/fpga/tests/.kunitconfig | 5 +++++ drivers/fpga/tests/Kconfig | 11 +++++++++++ drivers/fpga/tests/Makefile | 5 +++++ 5 files changed, 26 insertions(+) create mode 100644 drivers/fpga/tests/.kunitconfig create mode 100644 drivers/fpga/tests/Kconfig create mode 100644 drivers/fpga/tests/Makefile diff --git a/drivers/fpga/Kconfig b/drivers/fpga/Kconfig index 0a00763b9f28..2f689ac4ba3a 100644 --- a/drivers/fpga/Kconfig +++ b/drivers/fpga/Kconfig @@ -276,4 +276,6 @@ config FPGA_MGR_LATTICE_SYSCONFIG_SPI FPGA manager driver support for Lattice FPGAs programming over slave SPI sysCONFIG interface. +source "drivers/fpga/tests/Kconfig" + endif # FPGA diff --git a/drivers/fpga/Makefile b/drivers/fpga/Makefile index 72e554b4d2f7..352a2612623e 100644 --- a/drivers/fpga/Makefile +++ b/drivers/fpga/Makefile @@ -55,3 +55,6 @@ obj-$(CONFIG_FPGA_DFL_NIOS_INTEL_PAC_N3000) += dfl-n3000-nios.o # Drivers for FPGAs which implement DFL obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.o + +# KUnit tests +obj-$(CONFIG_FPGA_KUNIT_TESTS) += tests/ diff --git a/drivers/fpga/tests/.kunitconfig b/drivers/fpga/tests/.kunitconfig new file mode 100644 index 000000000000..a1c2a2974c39 --- /dev/null +++ b/drivers/fpga/tests/.kunitconfig @@ -0,0 +1,5 @@ +CONFIG_KUNIT=y +CONFIG_FPGA=y +CONFIG_FPGA_REGION=y +CONFIG_FPGA_BRIDGE=y +CONFIG_FPGA_KUNIT_TESTS=y diff --git a/drivers/fpga/tests/Kconfig b/drivers/fpga/tests/Kconfig new file mode 100644 index 000000000000..e4a64815f16d --- /dev/null +++ b/drivers/fpga/tests/Kconfig @@ -0,0 +1,11 @@ +config FPGA_KUNIT_TESTS + tristate "KUnit test for the FPGA subsystem" if !KUNIT_ALL_TESTS + depends on FPGA && FPGA_REGION && FPGA_BRIDGE && KUNIT=y + default KUNIT_ALL_TESTS + help + This builds unit tests for the FPGA subsystem + + For more information on KUnit and unit tests in general, + please refer to the KUnit documentation in Documentation/dev-tools/kunit/. + + If unsure, say N. diff --git a/drivers/fpga/tests/Makefile b/drivers/fpga/tests/Makefile new file mode 100644 index 000000000000..faa5fa230ab0 --- /dev/null +++ b/drivers/fpga/tests/Makefile @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_FPGA_KUNIT_TESTS) += fpga-mgr-test.o +obj-$(CONFIG_FPGA_KUNIT_TESTS) += fpga-bridge-test.o +obj-$(CONFIG_FPGA_KUNIT_TESTS) += fpga-region-test.o