Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2365939rwd; Mon, 15 May 2023 10:36:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6UBd07/v7MbR5R66z/Pnl6B5T1wPsdYFMAcJqtv0ZPKuYyna2xxDKk7FOvTZ8yNwW6wsW8 X-Received: by 2002:a05:6a00:2e97:b0:64c:9b56:6215 with SMTP id fd23-20020a056a002e9700b0064c9b566215mr7778859pfb.25.1684172173809; Mon, 15 May 2023 10:36:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684172173; cv=none; d=google.com; s=arc-20160816; b=TK+z34JZ/vLT6GsJRnN3aw3F3jzURILyhX27q26p3l/Q+cC7B4dviI40lgNIBGCnCD +pxLVaQmlhyGO6mDq5dDLAJyeYu6RrGYUAuq1aSk0BKC0q+kEg34eadmFWLNMpkE8W8v 6RkN767Q7qQJp/4HhPxaEeEdg57fWUqR3uXexL50erCYRRVpDPUZaF6p/FIIhftqnUJi i0l0608MaEigzWPBMLTi2XLFD/Wi8/gnpv1B0yNKYDr6T5HMGFiKDsOkRxehronHaq/S o8RcFTMgWS0xNBiWBr59KJvG2aMxVCXdveTcIIw1iC71B6jPIV3pKO7Zpu83nbT/z4TX K4+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=WA/oTDONq4SSLwtY9ScAiCK010QAeUOXJ2/R7swknQM=; b=Do8mIIYOKUQd8+4mneyFKkCm97CFjnEfQUQKT6j27nlM2Rkn8WMaj4mJzygjZvoH3M RTeLdYILYh3xiAF/PlxNVEoI0ju9ciY62sP8YIdM0HRC8mz7KCJfgkqUuWS/omCdbAt9 6fhaEUs0rzZShjoKPC9IwitVxhnt+h1h3PHHvAiMg/WNJqroz8i8REfrSbk73OsnB/OZ P9l11Y6iCBE20wU7wrc0fC1rYKbdZENlXxhrQJkfPYO43iIJarwufaxANpT12gt7sER3 OKVuO3GmNkBFxEpDZmrSMByKYCOr9p+0TpIfcfpzGuesQiqOtVv3oIJrgrgMI4jtEKR8 X4Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Wwx188ga; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v135-20020a63618d000000b0053202120edesi5258439pgb.36.2023.05.15.10.35.59; Mon, 15 May 2023 10:36:13 -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=Wwx188ga; 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 S244242AbjEOR00 (ORCPT + 99 others); Mon, 15 May 2023 13:26:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244154AbjEOR0H (ORCPT ); Mon, 15 May 2023 13:26:07 -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 BEB9213299 for ; Mon, 15 May 2023 10:24:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684171451; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WA/oTDONq4SSLwtY9ScAiCK010QAeUOXJ2/R7swknQM=; b=Wwx188gahr/xltq4PEW9oQMuIPcLRnLTzYv+uwcP8GMnivLoFDXF3y22GSG9y0OokCBm8B 4+ADHNvaJ5p4AjShI0H3GmCGNtKeb+D1jGj+BHfN+ebhnpFNJPNmmyC29sXJ8y1QZBkoB3 INyXavUZ7ptukRPdd5BB2/DGh+Agims= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-496-bG6seQ-3Pt67mCaL1Ras2Q-1; Mon, 15 May 2023 13:24:10 -0400 X-MC-Unique: bG6seQ-3Pt67mCaL1Ras2Q-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-3f4231d7893so58050995e9.2 for ; Mon, 15 May 2023 10:24:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684171449; x=1686763449; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WA/oTDONq4SSLwtY9ScAiCK010QAeUOXJ2/R7swknQM=; b=IvE4boyUFGZAAHxPWx/aaWG9k2YDlK6n7shjFamAkaE0p1Ox/7A5QSD0vnya8Lyl4s 718ypqcCGkjI4X1qGUMjdyDTYOc33/fk22ZKsYC+91P4+n0p3OGGHCjKooU7mBThTEtV //o6mMBmzdEIUqD4dJae1gW5/LXLFeFK94ZYccBLYlpnQNOyrtvF6ULN2ovSAkm9w4lj Z9dZ3Wg9VHr7f5CSW1Uhb4z/MGx6Fibbxb85lZoIdVIc1i7jA2VNY+a0NAvFQiVea8T3 99IauWJTnQ40ArFto2WJHGHN9XKEP6NM7OqAttTvSb8ty60H/TGYIhAj2YN+KJarC6MP rZFg== X-Gm-Message-State: AC+VfDx0X+d6qXE/JhhPq8fxgaBTezKDtEgecyhVllxEJOrQ2hHYzNbv tg076twjuMf6Lxj5ppG7FpNmOf7RimFyUwDW9f33UGe2YPi3KZx15qJtnF5yQzr1oUhztppNKRP R6pX7geYlRZKMDP6H+nMFb3k= X-Received: by 2002:a05:600c:3658:b0:3f4:2374:3517 with SMTP id y24-20020a05600c365800b003f423743517mr18234014wmq.19.1684171449182; Mon, 15 May 2023 10:24:09 -0700 (PDT) X-Received: by 2002:a05:600c:3658:b0:3f4:2374:3517 with SMTP id y24-20020a05600c365800b003f423743517mr18233998wmq.19.1684171448794; Mon, 15 May 2023 10:24:08 -0700 (PDT) Received: from [192.168.9.16] (net-2-34-28-169.cust.vodafonedsl.it. [2.34.28.169]) by smtp.gmail.com with ESMTPSA id 1-20020a05600c230100b003f423508c6bsm15373wmo.44.2023.05.15.10.24.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 May 2023 10:24:08 -0700 (PDT) Message-ID: Date: Mon, 15 May 2023 19:24:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [RFC PATCH v5 4/4] fpga: add initial KUnit test suites To: Xu Yilun Cc: Moritz Fischer , Wu Hao , Tom Rix , linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org References: <20230511141922.437328-1-marpagan@redhat.com> <20230511141922.437328-5-marpagan@redhat.com> Content-Language: en-US From: Marco Pagani In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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 On 2023-05-13 19:40, Xu Yilun wrote: > On 2023-05-11 at 16:19:22 +0200, Marco Pagani wrote: >> Introduce initial KUnit tests for the FPGA subsystem. Tests are organized >> into three test suites. The first suite tests the FPGA Manager. >> The second suite tests the FPGA Bridge. Finally, the last test suite >> models a complete FPGA platform and tests static and partial reconfiguration. >> >> Signed-off-by: Marco Pagani [...] >> +static void fpga_bridge_test_get_put_list(struct kunit *test) >> +{ >> + struct list_head bridge_list; >> + struct fake_fpga_bridge *bridge_0_ctx, *bridge_1_ctx; >> + int ret; >> + >> + bridge_0_ctx = test->priv; >> + >> + /* Register another bridge for this test */ >> + bridge_1_ctx = fake_fpga_bridge_register(test, NULL); >> + KUNIT_ASSERT_FALSE(test, IS_ERR(bridge_1_ctx)); > > I think bridge_1 could also be initialized in test_init together with > bridge_0 I can do it, but it would remain unused in the previous test case. >> + >> + INIT_LIST_HEAD(&bridge_list); >> + >> + /* Get bridge_0 and add it to the list */ >> + ret = fpga_bridge_get_to_list(bridge_1_ctx->bridge->dev.parent, NULL, >> + &bridge_list); >> + KUNIT_EXPECT_EQ(test, ret, 0); >> + >> + KUNIT_EXPECT_PTR_EQ(test, bridge_1_ctx->bridge, >> + list_first_entry_or_null(&bridge_list, struct fpga_bridge, node)); > > Should operate on bridge_0_ctx? Yes, sorry. Code and comments are reversed. I'll fix it in the next version. >> + >> + /* Get bridge_1 and add it to the list */ >> + ret = fpga_bridge_get_to_list(bridge_0_ctx->bridge->dev.parent, NULL, >> + &bridge_list); >> + KUNIT_EXPECT_EQ(test, ret, 0); >> + >> + KUNIT_EXPECT_PTR_EQ(test, bridge_0_ctx->bridge, >> + list_first_entry_or_null(&bridge_list, struct fpga_bridge, node)); > > Should operate on bridge_1_ctx? Same. >> + >> + /* Disable an then enable both bridges from the list */ >> + KUNIT_EXPECT_TRUE(test, bridge_0_ctx->stats.enable); > > Why expect enable without fpga_bridges_enable()? To check that the bridge is initialized in the correct (enabled) state. [...] >> +static void fpga_test_partial_rcfg(struct kunit *test) >> +{ >> + struct fpga_base_ctx *base_ctx; >> + struct fake_fpga_region *sub_region_0_ctx, *sub_region_1_ctx; >> + struct fake_fpga_bridge *sub_bridge_0_ctx, *sub_bridge_1_ctx; >> + struct fpga_image_info *partial_img_info; >> + int ret; >> + >> + base_ctx = test->priv; >> + >> + /* >> + * Add two reconfigurable sub-regions, each controlled by a bridge. The >> + * reconfigurable sub-region are children of their bridges which are, >> + * in turn, children of the base region. For simplicity, the same image >> + * is used to configure reconfigurable regions >> + */ >> + sub_bridge_0_ctx = fake_fpga_bridge_register(test, >> + &base_ctx->region_ctx->region->dev); >> + KUNIT_ASSERT_FALSE(test, IS_ERR(sub_bridge_0_ctx)); >> + >> + sub_region_0_ctx = fake_fpga_region_register(test, base_ctx->mgr_ctx->mgr, >> + &sub_bridge_0_ctx->bridge->dev); >> + KUNIT_ASSERT_FALSE(test, IS_ERR(sub_region_0_ctx)); >> + >> + ret = fake_fpga_region_add_bridge(sub_region_0_ctx, sub_bridge_0_ctx->bridge); >> + KUNIT_ASSERT_EQ(test, ret, 0); >> + >> + sub_bridge_1_ctx = fake_fpga_bridge_register(test, >> + &base_ctx->region_ctx->region->dev); >> + KUNIT_ASSERT_FALSE(test, IS_ERR(sub_bridge_1_ctx)); >> + >> + sub_region_1_ctx = fake_fpga_region_register(test, base_ctx->mgr_ctx->mgr, >> + &sub_bridge_1_ctx->bridge->dev); >> + KUNIT_ASSERT_FALSE(test, IS_ERR(sub_region_1_ctx)); >> + >> + ret = fake_fpga_region_add_bridge(sub_region_1_ctx, sub_bridge_1_ctx->bridge); >> + KUNIT_ASSERT_EQ(test, ret, 0); > > I'm wondering if we need to construct the topology for partial > reconfiguration test. The FPGA core doesn't actually check the topology. > It is OK to do partial reconfiguration for a region without parents as > long as its associated FPGA manager device has the capability. > > Thanks, > Yilun I agree with you. Creating a hierarchical layout is rather unnecessary. Initially, the idea was to test that all components behave as expected in a complete setup, e.g., only the bridge of the specific reconfigurable region gets disabled during programming and then re-enabled. However, after some iterations, I'm starting to think that it would be better to restructure the whole test code into a set of self-contained test modules, one for each core component. In that way, each module would contain the implementation of the fake/mock low-level driver and the related tests. For instance, the manager module would contain the implementation of the fake manager and the test_img_load_buf and test_img_load_sgt test cases. Similarly, the bridge module would contain the fake/mock bridge implementation and the test_toggle and test_get_put_list cases. I think that in this way, the code would be simpler and more adherent to the unit testing methodology. The downside is that making tests that need multiple components would be more cumbersome and possibly lead to code duplication. For instance, testing the region's fpga_region_program_fpga() would require implementing additional local mock/fakes for the manager and bridge. What do you think? Thanks, Marco [...]