From nobody Sun Feb 8 13:09:15 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DEECEB64D7 for ; Fri, 30 Jun 2023 15:26:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232835AbjF3P0g (ORCPT ); Fri, 30 Jun 2023 11:26:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232773AbjF3P01 (ORCPT ); Fri, 30 Jun 2023 11:26:27 -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 BD66E3C13 for ; Fri, 30 Jun 2023 08:25:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688138732; 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=zXjaIp3quvzGHJKYiXEaqBpagYsnNdsPN+3R0EaT6vg=; b=K6G0GvSK2uCM1aMEtqL4z5zck1+y6BlpFZ7/0VCIpSezEdfHoKnsHsc7/6Ywh4X3Q6hDAQ 6x/iDhVGCLuy2IuTq34KEfywHd47MIEN9uwfIe93F3MqGuSc9FPyLRJ4VxMwOo21vWG8pw T7QjWxCuxOi2AgPaJybZzMYic9eJsQI= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-60-gfPIaUgMN9msZDd3AhzIZw-1; Fri, 30 Jun 2023 11:25:31 -0400 X-MC-Unique: gfPIaUgMN9msZDd3AhzIZw-1 Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-4fb76659d6cso2032370e87.2 for ; Fri, 30 Jun 2023 08:25:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688138728; x=1690730728; 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=zXjaIp3quvzGHJKYiXEaqBpagYsnNdsPN+3R0EaT6vg=; b=VlMMp0fMbXdRCBRO3Nq2trnKZShVQEgQSmmvzy4u+57AQL5JR0/ldj5/k58Wp770NL 1QWVzru+nZHPwrHcUE0NdAcksmia9I46cBDzC0tvQfxBaLYDMakpCo0qBuIGdGMiRDkz +mBBXdaSlM86YyFTLjTDpbZhT7csZd3kqjg/YXU+zVrzDe9WxWH9wXxfMn3Qhekggspi CooyEawAzEqaRP61IWNpGhJ8XnxO79BPOHvgTQ++VVNg6r/ESdd0i1OeVOd+NP+RuC6L NgDeJUErdv8/nAUcgles94t6DodoDB0/ypJXmjdxWm1KLF5gQ5e6rR/HuJ9lNl7LyG6p 9ksg== X-Gm-Message-State: ABy/qLZpPOmL6mvRKwn8Q7Jxa68rLRrmokp8uvQReFaW9IK8erGH1EGi gtOYVs+QifAFnvfOpLBwuaHBoqd9Qz4LDOFflc3HJP1s1qmK0GPOlT/Ad+USL8jMbN4OggO6voc SWg9Yut0QcrDEOhjrRBGgwJRS9NWlneM= X-Received: by 2002:ac2:4d92:0:b0:4fb:772a:af19 with SMTP id g18-20020ac24d92000000b004fb772aaf19mr2462449lfe.34.1688138728270; Fri, 30 Jun 2023 08:25:28 -0700 (PDT) X-Google-Smtp-Source: APBJJlEbUxLjgD1h419RafGNfBSv6WOwGJahUp4J0mtmHn4i7dmWKz3sOXXpFyp/fbt7U3V1bPhn6A== X-Received: by 2002:ac2:4d92:0:b0:4fb:772a:af19 with SMTP id g18-20020ac24d92000000b004fb772aaf19mr2462438lfe.34.1688138727930; Fri, 30 Jun 2023 08:25:27 -0700 (PDT) Received: from klayman.station (net-2-34-24-242.cust.vodafonedsl.it. [2.34.24.242]) by smtp.gmail.com with ESMTPSA id k24-20020aa7c398000000b0051def9be785sm813230edq.85.2023.06.30.08.25.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 08:25:27 -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 v8 1/4] fpga: add an initial KUnit suite for the FPGA Manager Date: Fri, 30 Jun 2023 17:25:04 +0200 Message-ID: <20230630152507.30219-2-marpagan@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230630152507.30219-1-marpagan@redhat.com> References: <20230630152507.30219-1-marpagan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 | 311 +++++++++++++++++++++++++++++ 1 file changed, 311 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-m= gr-test.c new file mode 100644 index 000000000000..6fd2e235f195 --- /dev/null +++ b/drivers/fpga/tests/fpga-mgr-test.c @@ -0,0 +1,311 @@ +// 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; + + KUNIT_ASSERT_GE(test, count, HEADER_SIZE); + + buf =3D kunit_kzalloc(test, count, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf); + + memset(buf, HEADER_FILL, HEADER_SIZE); + memset(buf + HEADER_SIZE, IMAGE_FILL, count - HEADER_SIZE); + + return buf; +} + +static int op_parse_header(struct fpga_manager *mgr, struct fpga_image_inf= o *info, + const char *buf, size_t count) +{ + struct mgr_stats *stats =3D mgr->priv; + size_t i; + + /* Set header_size and data_size for later */ + info->header_size =3D HEADER_SIZE; + info->data_size =3D info->count - HEADER_SIZE; + + stats->header_match =3D true; + + /* Check header */ + for (i =3D 0; i < info->header_size; i++) + if (buf[i] !=3D HEADER_FILL) + stats->header_match =3D false; + + stats->op_parse_header_state =3D mgr->state; + stats->op_parse_header_seq =3D 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 =3D mgr->priv; + + stats->op_write_init_state =3D mgr->state; + stats->op_write_init_seq =3D stats->seq_num++; + + return 0; +} + +static int op_write(struct fpga_manager *mgr, const char *buf, size_t coun= t) +{ + struct mgr_stats *stats =3D mgr->priv; + size_t i; + + /* Check the image */ + stats->image_match =3D true; + for (i =3D 0; i < count; i++) + if (buf[i] !=3D IMAGE_FILL) + stats->image_match =3D false; + + stats->op_write_state =3D mgr->state; + stats->op_write_seq =3D stats->seq_num++; + + return 0; +} + +static int op_write_sg(struct fpga_manager *mgr, struct sg_table *sgt) +{ + struct mgr_stats *stats =3D mgr->priv; + struct sg_mapping_iter miter; + char *img; + size_t i; + + /* + * Check the image, but first skip the header since write_sg will get + * the whole image in sg_table. + */ + stats->image_match =3D true; + sg_miter_start(&miter, sgt->sgl, sgt->nents, SG_MITER_FROM_SG); + + if (!sg_miter_skip(&miter, HEADER_SIZE)) + stats->image_match =3D false; + + while (sg_miter_next(&miter)) { + img =3D miter.addr; + for (i =3D 0; i < miter.length; i++) { + if (img[i] !=3D IMAGE_FILL) + stats->image_match =3D false; + } + } + + sg_miter_stop(&miter); + + stats->op_write_sg_state =3D mgr->state; + stats->op_write_sg_seq =3D stats->seq_num++; + + return 0; +} + +static int op_write_complete(struct fpga_manager *mgr, struct fpga_image_i= nfo *info) +{ + struct mgr_stats *stats =3D mgr->priv; + + stats->op_write_complete_state =3D mgr->state; + stats->op_write_complete_seq =3D 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 =3D { + .skip_header =3D true, + .parse_header =3D op_parse_header, + .write_init =3D op_write_init, + .write =3D op_write, + .write_sg =3D op_write_sg, + .write_complete =3D op_write_complete, +}; + +static void fpga_mgr_test_get(struct kunit *test) +{ + struct mgr_ctx *ctx =3D test->priv; + struct fpga_manager *mgr; + + mgr =3D 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 =3D test->priv; + int ret; + + ret =3D fpga_mgr_lock(ctx->mgr); + KUNIT_EXPECT_EQ(test, ret, 0); + + ret =3D 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 =3D test->priv; + char *img_buf; + int ret; + + img_buf =3D init_test_buffer(test, IMAGE_SIZE); + + ctx->img_info->count =3D IMAGE_SIZE; + ctx->img_info->buf =3D img_buf; + + ret =3D 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_PA= RSE_HEADER); + KUNIT_EXPECT_EQ(test, ctx->stats.op_write_init_state, FPGA_MGR_STATE_WRIT= E_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_h= eader_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_par= se_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 =3D test->priv; + struct sg_table *sgt; + char *img_buf; + int ret; + + img_buf =3D init_test_buffer(test, IMAGE_SIZE); + + sgt =3D kunit_kzalloc(test, sizeof(*sgt), GFP_KERNEL); + ret =3D 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 =3D sgt; + + ret =3D 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_PA= RSE_HEADER); + KUNIT_EXPECT_EQ(test, ctx->stats.op_write_init_state, FPGA_MGR_STATE_WRIT= E_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_h= eader_seq + 1); + KUNIT_EXPECT_EQ(test, ctx->stats.op_write_sg_seq, ctx->stats.op_parse_hea= der_seq + 2); + KUNIT_EXPECT_EQ(test, ctx->stats.op_write_complete_seq, ctx->stats.op_par= se_header_seq + 3); + + sg_free_table(ctx->img_info->sgt); +} + +static int fpga_mgr_test_init(struct kunit *test) +{ + struct mgr_ctx *ctx; + + ctx =3D kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); + + ctx->pdev =3D platform_device_register_simple("mgr_pdev", PLATFORM_DEVID_= AUTO, NULL, 0); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->pdev); + + ctx->mgr =3D 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 =3D fpga_image_info_alloc(&ctx->pdev->dev); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->img_info); + + test->priv =3D ctx; + + return 0; +} + +static void fpga_mgr_test_exit(struct kunit *test) +{ + struct mgr_ctx *ctx =3D test->priv; + + fpga_image_info_free(ctx->img_info); + platform_device_unregister(ctx->pdev); +} + +static struct kunit_case fpga_mgr_test_cases[] =3D { + 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 =3D { + .name =3D "fpga_mgr", + .init =3D fpga_mgr_test_init, + .exit =3D fpga_mgr_test_exit, + .test_cases =3D fpga_mgr_test_cases, +}; + +kunit_test_suite(fpga_mgr_suite); + +MODULE_LICENSE("GPL"); --=20 2.41.0 From nobody Sun Feb 8 13:09:15 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05A92EB64D7 for ; Fri, 30 Jun 2023 15:26:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232976AbjF3P0k (ORCPT ); Fri, 30 Jun 2023 11:26:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232809AbjF3P02 (ORCPT ); Fri, 30 Jun 2023 11:26:28 -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 481BD3C10 for ; Fri, 30 Jun 2023 08:25:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688138737; 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=YDJvffpbrPgNmPKLqywH3LAm8S873ODrHn5dEekELQE=; b=an2KLj6Gnc9/MlRE7mlpFS6T7GryuLi0gIVwPN+8nTMLb2oH38Vg13wHknXiSnvxQfaWwX oAQiFy8bNkVxL/evs1VnTuMGO6OFcoeR+Hzc2z1IcTqdfdc6Lw+xESKBVfocgp2z0yeifM G1YLKK/AT9U++oKMwnseAZ0fVFQkoow= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-241-_scam52eM9erYnoM1SRttg-1; Fri, 30 Jun 2023 11:25:36 -0400 X-MC-Unique: _scam52eM9erYnoM1SRttg-1 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-4fb736a7746so2029981e87.3 for ; Fri, 30 Jun 2023 08:25:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688138735; x=1690730735; 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=YDJvffpbrPgNmPKLqywH3LAm8S873ODrHn5dEekELQE=; b=GR2BF9J13TTc5AfuP/+jsDDGIgr2GKJRH1fmGWyB+KVKmTvcRtN7GtvtwJqXx8AEC6 BRMAjCCJZsrkb5gKsRvhSaP7OKwIpUWj9DD69VmVQj0iZJvigMwxGqexEToyiMFIKM2b fxT+bWVOrJv6VxeTlq3cQZ3ACVsLVzLyBPone2J2xOBW+u0xNejnik5IpSG+SqM+lnFF 6HrLrJHcxL6SMSW1pblp9Cd0j3TqB+gSsSMsV6caVhBL5pQo3tqYQla9OKW7iD0/fIzq HhZy5C7UgJbi22Lh5nyHn2vphhZA+8Toa6a+vDXIdiI2WVxK4h3bRX2whjNr+a8uOVbR QI0w== X-Gm-Message-State: ABy/qLYxrKwE+gubQDQ1Mrtc6vTmniKTbgBSzgWt5FhXwskxYWTAfWda xjz6N6aGhe4S++xxLAuq5Yu0YNxEWmo84kvappgObBGTmAh/YDhy1cABFZne8EZEmdiALpeO/v5 mYN5OeSgqJ3KaFjxjljkOm7s= X-Received: by 2002:a05:6512:312a:b0:4f8:587e:cbe0 with SMTP id p10-20020a056512312a00b004f8587ecbe0mr2451977lfd.52.1688138734744; Fri, 30 Jun 2023 08:25:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlFGrlqJEk8VJbET2xLYZ7VCs1DOk8qkErqnhagVRJZHTM/u0xLat6MsvHazE9/4C5SpKsFqWg== X-Received: by 2002:a05:6512:312a:b0:4f8:587e:cbe0 with SMTP id p10-20020a056512312a00b004f8587ecbe0mr2451970lfd.52.1688138734545; Fri, 30 Jun 2023 08:25:34 -0700 (PDT) Received: from klayman.station (net-2-34-24-242.cust.vodafonedsl.it. [2.34.24.242]) by smtp.gmail.com with ESMTPSA id k24-20020aa7c398000000b0051def9be785sm813230edq.85.2023.06.30.08.25.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 08:25:34 -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 v8 2/4] fpga: add an initial KUnit suite for the FPGA Bridge Date: Fri, 30 Jun 2023 17:25:05 +0200 Message-ID: <20230630152507.30219-3-marpagan@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230630152507.30219-1-marpagan@redhat.com> References: <20230630152507.30219-1-marpagan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/fpg= a-bridge-test.c new file mode 100644 index 000000000000..c69d451fee88 --- /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 =3D bridge->priv; + + stats->enable =3D 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 =3D { + .enable_set =3D 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 =3D kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); + + ctx->pdev =3D platform_device_register_simple("bridge_pdev", PLATFORM_DEV= ID_AUTO, NULL, 0); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->pdev); + + ctx->bridge =3D 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 =3D test->priv; + struct fpga_bridge *bridge; + + bridge =3D fpga_bridge_get(&ctx->pdev->dev, NULL); + KUNIT_EXPECT_PTR_EQ(test, bridge, ctx->bridge); + + bridge =3D 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 =3D test->priv; + int ret; + + ret =3D fpga_bridge_disable(ctx->bridge); + KUNIT_EXPECT_EQ(test, ret, 0); + KUNIT_EXPECT_FALSE(test, ctx->stats.enable); + + ret =3D 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 =3D test->priv; + ctx_1 =3D register_test_bridge(test); + + INIT_LIST_HEAD(&bridge_list); + + /* Get bridge 0 and add it to the list */ + ret =3D 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 =3D 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 =3D 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 =3D 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 =3D 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[] =3D { + 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 =3D { + .name =3D "fpga_bridge", + .init =3D fpga_bridge_test_init, + .exit =3D fpga_bridge_test_exit, + .test_cases =3D fpga_bridge_test_cases, +}; + +kunit_test_suite(fpga_bridge_suite); + +MODULE_LICENSE("GPL"); --=20 2.41.0 From nobody Sun Feb 8 13:09:15 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9894CEB64DD for ; Fri, 30 Jun 2023 15:27:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232428AbjF3P06 (ORCPT ); Fri, 30 Jun 2023 11:26:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231956AbjF3P0d (ORCPT ); Fri, 30 Jun 2023 11:26:33 -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 D300B2728 for ; Fri, 30 Jun 2023 08:25:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688138742; 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=AZt43Ky3719pMlaApXqVMD6ZwhsTjVdiVPLbUGmOVRw=; b=H8eNg4hrru7a6VAYb+vKrHitOeKotq0xmAF1cJ/ecW6uzE2eREjs94iXb3fNCbXD8tibZe YQiuLspneaE47zni0x+X841OA4g+xl6OW0rUUzfuKpsCCKCVFwqDtSU0lRg28zyvKENFKg ZxqW2S/viR5oqAR4slMxQNjhFxT4/E8= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-zanTvqVoP_2FzCbmPLJwCw-1; Fri, 30 Jun 2023 11:25:39 -0400 X-MC-Unique: zanTvqVoP_2FzCbmPLJwCw-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-51dd16f823bso1170760a12.0 for ; Fri, 30 Jun 2023 08:25:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688138738; x=1690730738; 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=AZt43Ky3719pMlaApXqVMD6ZwhsTjVdiVPLbUGmOVRw=; b=WbUbZTM4btE9jA56gqaI11U3HvxCb3Vgin5s67eylN2tdTUMOP8MRbbLvezSWulRTE +FAvT1+CGLu2sbmpp6jZfuLCNbFiLUcw+zkvDGYJPqUkxBLBP10HzVHi/+8JX6orXiym xGRvWJGqepqdh4pgIuqRZfcylDFxCeF4cc2Fx7fOXcryDPXDMQr0sYwwfgEkHCFymkHu roO7WfZSLzbVFaW29yneiGiIDAua2Al3XNKj52N0WW51BSuB+yeq69T5fdTE7grPFOKW YNPulxOGd7eC0RCyT91R34e2378VruNuqPMMNazcijykZBF7AwnwNEWOime43gxPGt5W YIng== X-Gm-Message-State: ABy/qLb8+KkRqVXtR7BRVgyWp9/dCiK2zOnbwsl1wE+0HljdbcJjGs7l 8cazo7JiEB2iby1tbcUKOKyjmmbVc06qsW7Y13vJ/uaOsjq0CAzca5rdEjgVrOdVRIMMpGAM3C+ I/2nzDM3CXOm/mXQz3rgQVZs= X-Received: by 2002:a05:6402:284:b0:51d:b963:4bd3 with SMTP id l4-20020a056402028400b0051db9634bd3mr2448025edv.31.1688138738456; Fri, 30 Jun 2023 08:25:38 -0700 (PDT) X-Google-Smtp-Source: APBJJlHdQs2DouSui7WkBs9UgpGj763b16U7P3l+G7aXnH6gG3XD2369/aeMPCYKs7ltT9fZfIsIZg== X-Received: by 2002:a05:6402:284:b0:51d:b963:4bd3 with SMTP id l4-20020a056402028400b0051db9634bd3mr2448013edv.31.1688138738179; Fri, 30 Jun 2023 08:25:38 -0700 (PDT) Received: from klayman.station (net-2-34-24-242.cust.vodafonedsl.it. [2.34.24.242]) by smtp.gmail.com with ESMTPSA id k24-20020aa7c398000000b0051def9be785sm813230edq.85.2023.06.30.08.25.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 08:25:37 -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 v8 3/4] fpga: add an initial KUnit suite for the FPGA Region Date: Fri, 30 Jun 2023 17:25:06 +0200 Message-ID: <20230630152507.30219-4-marpagan@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230630152507.30219-1-marpagan@redhat.com> References: <20230630152507.30219-1-marpagan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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/fpg= a-region-test.c new file mode 100644 index 000000000000..8a195d85a877 --- /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 coun= t) +{ + struct mgr_stats *stats =3D 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 =3D { + .write =3D op_write, +}; + +static int op_enable_set(struct fpga_bridge *bridge, bool enable) +{ + struct bridge_stats *stats =3D bridge->priv; + + if (!stats->enable && enable) + stats->cycles_count++; + + stats->enable =3D 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 =3D { + .enable_set =3D op_enable_set, +}; + +static int fake_region_get_bridges(struct fpga_region *region) +{ + struct fpga_bridge *bridge =3D 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 =3D=3D data; +} + +static void fpga_region_test_class_find(struct kunit *test) +{ + struct test_ctx *ctx =3D test->priv; + struct fpga_region *region; + + region =3D fpga_region_class_find(NULL, &ctx->region_pdev->dev, fake_regi= on_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 =3D test->priv; + struct fpga_image_info *img_info; + char img_buf[4]; + int ret; + + img_info =3D fpga_image_info_alloc(&ctx->mgr_pdev->dev); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, img_info); + + img_info->buf =3D img_buf; + img_info->count =3D sizeof(img_buf); + + ctx->region->info =3D img_info; + ret =3D 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 =3D 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 =3D { 0 }; + + ctx =3D kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); + + ctx->mgr_pdev =3D platform_device_register_simple("mgr_pdev", PLATFORM_DE= VID_AUTO, NULL, 0); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->mgr_pdev); + + ctx->mgr =3D devm_fpga_mgr_register(&ctx->mgr_pdev->dev, "Fake FPGA Manag= er", &fake_mgr_ops, + &ctx->mgr_stats); + KUNIT_ASSERT_FALSE(test, IS_ERR_OR_NULL(ctx->mgr)); + + ctx->bridge_pdev =3D platform_device_register_simple("bridge_pdev", PLATF= ORM_DEVID_AUTO, + NULL, 0); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->bridge_pdev); + + ctx->bridge =3D fpga_bridge_register(&ctx->bridge_pdev->dev, "Fake FPGA B= ridge", + &fake_bridge_ops, &ctx->bridge_stats); + KUNIT_ASSERT_FALSE(test, IS_ERR_OR_NULL(ctx->bridge)); + + ctx->bridge_stats.enable =3D true; + + ctx->region_pdev =3D platform_device_register_simple("region_pdev", PLATF= ORM_DEVID_AUTO, + NULL, 0); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->region_pdev); + + region_info.mgr =3D ctx->mgr; + region_info.priv =3D ctx->bridge; + region_info.get_bridges =3D fake_region_get_bridges; + + ctx->region =3D fpga_region_register_full(&ctx->region_pdev->dev, ®ion= _info); + KUNIT_ASSERT_FALSE(test, IS_ERR_OR_NULL(ctx->region)); + + test->priv =3D ctx; + + return 0; +} + +static void fpga_region_test_exit(struct kunit *test) +{ + struct test_ctx *ctx =3D 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[] =3D { + KUNIT_CASE(fpga_region_test_class_find), + KUNIT_CASE(fpga_region_test_program_fpga), + + {} +}; + +static struct kunit_suite fpga_region_suite =3D { + .name =3D "fpga_mgr", + .init =3D fpga_region_test_init, + .exit =3D fpga_region_test_exit, + .test_cases =3D fpga_region_test_cases, +}; + +kunit_test_suite(fpga_region_suite); + +MODULE_LICENSE("GPL"); --=20 2.41.0 From nobody Sun Feb 8 13:09:15 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5183CEB64DA for ; Fri, 30 Jun 2023 15:27:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232631AbjF3P1d (ORCPT ); Fri, 30 Jun 2023 11:27:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232819AbjF3P1G (ORCPT ); Fri, 30 Jun 2023 11:27:06 -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 7FD773C24 for ; Fri, 30 Jun 2023 08:25:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688138749; 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=rGGDOW/9MqaKjCCuoAeyhkddjPlv60nFOxRpD56k1bo=; b=H0L/nkTpTx+ltJts17I1eS9YrdAD+ocoxAilt0XnN+WxxElkhFpluOJ2LjNFpQr1G35Xa9 naAxxJMA+tsGs3Wc+Svmu1kc2cWU0MP67BRcREvDS7GuR4x00tFWlqmecp/YbjVh3mu/Ao NDl0xZu8aLdZ4RVQcKB1feeHq7agXrc= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-391-HzwFi0sIOeazPhXvtt4jyQ-1; Fri, 30 Jun 2023 11:25:46 -0400 X-MC-Unique: HzwFi0sIOeazPhXvtt4jyQ-1 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-51dd5868fddso2389312a12.1 for ; Fri, 30 Jun 2023 08:25:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688138745; x=1690730745; 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=rGGDOW/9MqaKjCCuoAeyhkddjPlv60nFOxRpD56k1bo=; b=AXG2Ym8lPZ0UsADMJbdvoROIgKJFG/t1W8+Rb7QSyMcMJkeyBISDxwZcuWFoWecboS hd+wvFhUhT8YEE4Y+z2cW7WOjdhuTkMeBhqTWyC2XnhQgkswpIBKTxp1tmRpjEt5PzcN 3ccD4jkrOS5apkgPe5OIWJxm3dw6Cb5d8Yds1vu+WIqWHd+sfSfWCYK8/8yKy4DQ0YPA rNE6VKoS4zCWKtaYVMJRsrYEogKqt/L3mWUgM3iM0euF6j2h3j3wpeV+vooYI+WC2Gec JtTSd7tbXmzHuFSrbUxuRvH8eBuQYSE4wcKoKqgecT14Gxcm/UsCi2hbOOibzo7DszyE EZJA== X-Gm-Message-State: ABy/qLabqtk4beuZd9/X/l79eaqDBQq2D60Rjt1WKxB70llCvPjAH4uH 0YuTdg2JIBvAxYnaTa9cyTUlKbhmTcAcoRQMEfJTB2QPvqe3/ioxMPUGNazHcO33MkX+IvlcbSI aYGzsc/nk51bKRtQ8sXHWJG0= X-Received: by 2002:aa7:c398:0:b0:51d:e2ee:33ff with SMTP id k24-20020aa7c398000000b0051de2ee33ffmr3567015edq.7.1688138745274; Fri, 30 Jun 2023 08:25:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlFXxmvZEGcnejUR+XfxT+Fn8P/5pYATOMHIPPdbQMd40IijySgfCOV/OB4B0eMkCQcsZpst2w== X-Received: by 2002:aa7:c398:0:b0:51d:e2ee:33ff with SMTP id k24-20020aa7c398000000b0051de2ee33ffmr3567000edq.7.1688138745060; Fri, 30 Jun 2023 08:25:45 -0700 (PDT) Received: from klayman.station (net-2-34-24-242.cust.vodafonedsl.it. [2.34.24.242]) by smtp.gmail.com with ESMTPSA id k24-20020aa7c398000000b0051def9be785sm813230edq.85.2023.06.30.08.25.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 08:25:44 -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 v8 4/4] fpga: add configuration for the FPGA KUnit test suites. Date: Fri, 30 Jun 2023 17:25:07 +0200 Message-ID: <20230630152507.30219-5-marpagan@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230630152507.30219-1-marpagan@redhat.com> References: <20230630152507.30219-1-marpagan@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 | 6 ++++++ 5 files changed, 27 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. =20 +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) +=3D dfl-n300= 0-nios.o =20 # Drivers for FPGAs which implement DFL obj-$(CONFIG_FPGA_DFL_PCI) +=3D dfl-pci.o + +# KUnit tests +obj-$(CONFIG_FPGA_KUNIT_TESTS) +=3D tests/ diff --git a/drivers/fpga/tests/.kunitconfig b/drivers/fpga/tests/.kunitcon= fig new file mode 100644 index 000000000000..a1c2a2974c39 --- /dev/null +++ b/drivers/fpga/tests/.kunitconfig @@ -0,0 +1,5 @@ +CONFIG_KUNIT=3Dy +CONFIG_FPGA=3Dy +CONFIG_FPGA_REGION=3Dy +CONFIG_FPGA_BRIDGE=3Dy +CONFIG_FPGA_KUNIT_TESTS=3Dy 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=3Dy + 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-too= ls/kunit/. + + If unsure, say N. diff --git a/drivers/fpga/tests/Makefile b/drivers/fpga/tests/Makefile new file mode 100644 index 000000000000..bb78215c645c --- /dev/null +++ b/drivers/fpga/tests/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for KUnit test suites for the FPGA subsystem +# + +obj-$(CONFIG_FPGA_KUNIT_TESTS) +=3D fpga-mgr-test.o fpga-bridge-test.o fpg= a-region-test.o --=20 2.41.0