Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp989318rwd; Wed, 7 Jun 2023 09:25:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6acfzGNEa8Qg0MZ1TObgVGb1BxP4NGST2xPNJJ4svJWCrEHk42Fl9QMh0uJ7HDxUbEmbnf X-Received: by 2002:aca:6548:0:b0:398:59fe:6ee3 with SMTP id j8-20020aca6548000000b0039859fe6ee3mr5795471oiw.54.1686155116520; Wed, 07 Jun 2023 09:25:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686155116; cv=none; d=google.com; s=arc-20160816; b=sC1cmCmTMFsXKlhasJI6gyrbXBodepWs2kj7CCVe38LJklXGH+/0VtrIcQUvhvKCH2 raOPWno1HeVPwRVTVNZGkOmmQtEUdJ5i1Tia9c5L7C7v1SKaH43rbaQHldrQie4etmB0 mfrP9aM5BcOf+g/j3a0ltBkr7/xEJrNgcMdwNQ39q5gBpm0zn/5p/PSvc17hjaCqBvys g9XGLzCN1WuQkPV8kJqjvlfrImopHMPWmVHg4xesAkNocmYKYbHCPdyiy5aEK0MI4Sf1 DTLt63AgTlhJsM+DEX2w0SAdy2FwmxUxPMMVoHMN6RhH+zknN4BmIJmK6yLWkg9SGFYt j0CQ== 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=C/MZw4Z/A0OlIBZIMGEeANKIMkHTcvImJLw3vUuATHI=; b=TnwLEVWvikMWc+45wI5XRlJwCgwXWHQZeRQZ9jPgFVJboP6Ka8rssb9suwmm7M4njB kd8MVGixpumSKUds8+k1uFBD3USE5ml50pKIPhm1Smmiw18Hv8qZfSLFIFXfyhOORwbU pgRoxO+KH8sPn9DR28oYm+AzZU5TQ0xyzihrK207s22ZABeUZjcEM9o+utjbVN3jmgWu 2+68fYNZKzZB422/1mSoweZhzlckPiXVPXElEc0aD0VjWxMqigXwAdLADiUxTqv/9aqZ TlfvbSLCF8n4FsSf64y2LNE2avb/I5CXtcCkvIgX6VWGx375Tn/HYfLmgDJD98QcQDYW Cvjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="V9BL/shk"; 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 lw14-20020a17090b180e00b0024e184e5a53si1355736pjb.117.2023.06.07.09.25.01; Wed, 07 Jun 2023 09:25:16 -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="V9BL/shk"; 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 S239153AbjFGP60 (ORCPT + 99 others); Wed, 7 Jun 2023 11:58:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241191AbjFGP6X (ORCPT ); Wed, 7 Jun 2023 11:58:23 -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 171A91FF0 for ; Wed, 7 Jun 2023 08:57:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686153448; 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=C/MZw4Z/A0OlIBZIMGEeANKIMkHTcvImJLw3vUuATHI=; b=V9BL/shkcu2uA/N60A7W3VNzSuWs6XH7Bh0XLGrRWKQRvKUuFPKqn6BoOQ+m3Uwp2Jz4DU xJusRMhSKJoZgkxE2OngCOX7lZTfhliMY9Jrory7G6CLzyPhE7oJCsKL0uGZZI2MkzwNeX 8SpXnozB3A/br9/sx4+1wOQir3soQ08= 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-497-v22FFbDeOrSamtbNeuRJJg-1; Wed, 07 Jun 2023 11:57:27 -0400 X-MC-Unique: v22FFbDeOrSamtbNeuRJJg-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-75d54f2b6c4so469696685a.2 for ; Wed, 07 Jun 2023 08:57:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686153446; x=1688745446; 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=C/MZw4Z/A0OlIBZIMGEeANKIMkHTcvImJLw3vUuATHI=; b=Cuq9+cdgnhFuUyTMYOVJafyZFUUMH3+YuMDw1eh4YRUkxeUyDFZHEMkVluEGv38ksD ttLUZM7eajrMHdLtAyiNkcXDGwrf6l14UtnqDTUghJWo+VOKEEY2S2ZPPoWRmC7n35/u PW5biaasUDWaXdjEfO7XDbwCvhWLvOy1mO6QIVjjArxMFseN85wyz6Rsrq4uxNLxA20U zXha4Gd3wXkAgQAK86vSNPsEvBfW380Hu3qHhGg7Ob8DYzzQ2dySGSm94YxPsLVKSRTZ 53tIOYFyD6FWfk1G+c5UOIuduXazolP5iNRJQh2r4vr/ZFImrTuz6KR+asY1eBlDGgbu hcNQ== X-Gm-Message-State: AC+VfDwRT50y+76VFAyBluI+3XIEZWKO274yYNl1NELyYSG5lKU40i2u +N+I+bvW1SDL1NXzyeNnsfPWx/c/6KJKoLiaBagcFM/2b4LEq3iT3P5qnTYyq88V2DTq4PcyftT N+aCTdpk9IoA17ZNNG4A4s6aFMGrxgWE= X-Received: by 2002:a05:620a:2541:b0:75e:86bc:1620 with SMTP id s1-20020a05620a254100b0075e86bc1620mr2656391qko.69.1686153446421; Wed, 07 Jun 2023 08:57:26 -0700 (PDT) X-Received: by 2002:a05:620a:2541:b0:75e:86bc:1620 with SMTP id s1-20020a05620a254100b0075e86bc1620mr2656376qko.69.1686153446120; Wed, 07 Jun 2023 08:57:26 -0700 (PDT) Received: from [192.168.9.16] (net-2-34-28-201.cust.vodafonedsl.it. [2.34.28.201]) by smtp.gmail.com with ESMTPSA id d10-20020a05620a158a00b0075d031ba684sm1339920qkk.99.2023.06.07.08.57.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 07 Jun 2023 08:57:25 -0700 (PDT) Message-ID: Date: Wed, 7 Jun 2023 17:57:22 +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 v6 3/4] fpga: add an initial KUnit suite for the FPGA Region To: Xu Yilun Cc: Moritz Fischer , Wu Hao , Tom Rix , linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org References: <20230531095405.342080-1-marpagan@redhat.com> <20230531095405.342080-4-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=-2.2 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,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 On 2023-06-06 13:00, Xu Yilun wrote: > On 2023-06-05 at 18:58:56 +0200, Marco Pagani wrote: >> >> >> On 2023-06-03 21:11, Xu Yilun wrote: >>> On 2023-05-31 at 11:54:04 +0200, Marco Pagani wrote: >>>> The suite tests the programming of an FPGA Region with a Bridge >>>> and the function for finding a particular Region. >>>> >>>> Signed-off-by: Marco Pagani >>>> --- >>>> drivers/fpga/tests/fpga-region-test.c | 186 ++++++++++++++++++++++++++ >>>> 1 file changed, 186 insertions(+) >>>> create mode 100644 drivers/fpga/tests/fpga-region-test.c >> >> [...] >> >> >>> Maybe better just put all tests in one module, and have unified >>> fake_mgr_ops/mgr_stats/fake_bridge_ops/bridge_stats across all tests. >>> >>> In previous thread, I said I'm good to the self-contained test module >>> but I didn't actually follow the idea. Sorry for that. >>> >>> The concern is why in this region test, the write_count and only the >>> write_count is taken care of. >>> >>> Although fpga_mgr_load() test covers all mgr_ops, but does that >>> means these ops are still good for more complex case like >>> fpga_region_program_fpga()? And there is no guarantee >>> fpga_region_program_fpga() would always call mgr_ops the same way >>> as fpga_mgr_load() in future. >>> >>> Similar for fpga_bridge. Maybe a complete setup for fpga_region is >>> still necessary. >> >> I think that putting all tests in a single module (like in previous >> versions) goes against the principles of unit testing, making the >> code more similar to an integration test. >> >> Unit tests should be focused on a single behavior. The programming >> test case included in the Region's suite should test only the behavior >> of the Region itself. Specifically, that fpga_region_program_fpga() calls >> get_bridges(), to get and control bridges, and then the Manager for the >> actual programming. >> >> The programming sequence itself is outside the responsibilities of the >> Region, and its correctness is already ensured by the Manager suite. >> Similarly, the correctness of the Bridge's methods used by the Region >> for getting and controlling multiple bridges is already ensured by the >> Bridge test suite. >> >> For this reason, the Manager and Bridge fakes used in the Region suite >> implement only the minimal set of operations necessary to ensure the >> correctness of the Region's behavior. If I used a "full" Manager (and >> tested all mgr_ops), then the test case would have become an integration >> test rather than a unit test for the Region. > > I agree with you about a unit test should focus on a single behavior. But > I have concerns that each test suite uses different definitions of the > same structure, mgr/bridge stats, mgr/bridge ops, mgr/bridge ctx. Even > if we have full definitions for these structures to acommodate all > tests, it doesn't break the principle of unit test, just ignore the fields > and skip checks that you don't care. E.g. only checks mgr.write_count & > bridge.enable_count for region test. > > And a single module simplifies the implementation. > > struct mgr_stats { > ... > }; > > struct mgr_ctx { > struct fpga_image_info *img_info; > struct fpga_manager *mgr; > struct platform_device *pdev; > struct mgr_stats stats; > }; > > struct bridge_stats { > ... > }; > > struct bridge_ctx { > struct fpga_bridge *bridge; > struct platform_device *pdev; > struct bridge_stats stats; > }; > > struct region_ctx { > struct mgr_ctx mgr_ctx; > struct bridge_ctx bridge_ctx; > > struct fpga_region *region; > struct platform_device *region_pdev; > }; > > How do you think? > > Thanks, > Yilun > My concern with unified fakes having the same ops, stats, and context structs is that they would couple the test suites together. I think it's better to have multiple fakes, each with the single responsibility of providing minimal support for the component under test. Otherwise, we would end up having overcomplicated fakes that implement the union (in the set theory sense of the term) of all behaviors tested by all suites. By using these fakes, some test cases might implicitly exercise behaviors that are outside their scope (e.g., the Region programming test case calling all Manager ops). I feel this would go against the principle of limiting the amount of code under test to a single unit. Thanks, Marco >>> BTW: I like the way that fake drivers are removed. Looks much straight >>> forward. >> >> I appreciate that. >> >>> Thanks, >>> Yilun >>> >> >> Thanks, >> Marco >> >> [...] >> >