Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2672756imn; Tue, 2 Aug 2022 11:35:17 -0700 (PDT) X-Google-Smtp-Source: AA6agR5jJlx+mayqx08gc/GKQ/6zvKSZ6+kKCFTWEMPLl7Gl/NGRJMpreyLngc9BfBWSl+NIG24H X-Received: by 2002:a17:906:8a6d:b0:730:9cd5:6688 with SMTP id hy13-20020a1709068a6d00b007309cd56688mr4572277ejc.158.1659465316820; Tue, 02 Aug 2022 11:35:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659465316; cv=none; d=google.com; s=arc-20160816; b=YP7b//HLz/WOFclNs8iEKP9w4OdXN6J8QBpNsZzMQGX8HWnniXgYbOlPjQcdc6/7u8 EiT2gmxXTnYcLTWVPn8DGVsJmZFR0JKprbAlE+UDPgLKuh0D3e09CB7CCZ6S4bKTZ87v jESXbYz0c9dfk07iqHilb8WE67EwKlTHikmWAlh+M241JzuV1JvMk4jJezB8p6H76xTW /+0mh0eSyiNxmIaPSjkxVWBU+Iv8ynLoQtJ+y/YZbQ9a9atmlFch0bcpJ0jRSXNENa33 ODYAbzqEvll9/AV6bIyD2WBWHdNdQ3SfoFMx6IxHFFXuEk/CpqryQSikRtqaawFoK7Cr pjTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=6BbJfTjdzqSyIyJ/BwNHDar8lvGvNh9tJJcETlMgsi8=; b=C4YB4JConyPkDjUqK1zbQhvE2gKvkA6oY5uAh29ywIaXL1YodU2I0t9sO91nWbJ7wi OZ848zBkCp9QDEuNH6RHQ4sZTgDi8zn8yrV0310aY83KfFt+54LW/0IcVHrFL0qJ5feQ +ME3JAlINgODpK98s8EIYJIT/o9yuEbdG5kUBc0K14MJXh1GjRJlePE57QYbpoRwZODn IFxJCFKlYrrVSleqxXjhW2FNyRxLwdpOOPoOl/bz0S76GLTw4B1HGn4B592xUukKfTav BjfLGI5mKShSANpNw25OYFBmJ35QZjZu8YDn/INQM3XG1Mw+LkgAWtRRnuiIx0Jum3Zw 831g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=AAm3jF6Y; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x19-20020a1709064bd300b0072b9b9c2a74si12527527ejv.251.2022.08.02.11.34.51; Tue, 02 Aug 2022 11:35: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=@google.com header.s=20210112 header.b=AAm3jF6Y; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229532AbiHBSPw (ORCPT + 99 others); Tue, 2 Aug 2022 14:15:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233188AbiHBSPo (ORCPT ); Tue, 2 Aug 2022 14:15:44 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F6FD31223 for ; Tue, 2 Aug 2022 11:15:43 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id dc19so4654415ejb.12 for ; Tue, 02 Aug 2022 11:15:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=6BbJfTjdzqSyIyJ/BwNHDar8lvGvNh9tJJcETlMgsi8=; b=AAm3jF6Yv/WSrJVDzBAi32ZllaD6WcLJcAjOtSKJnri4173VklMNnvUGnSpWaK8DbH b0cFJX9FlGlpz0WmeNBTElE1kknA3giOGd3CuRBPwIYTa9DbVr9/SsakzgOpBwQ/A/Co /vqesB4IHMRKbZcq+VGsjIUB7i0oyDkJYQ8j6U+XiB6GiKf0O3Avb/HmbPDH/Mi9fmq1 /T8pMTA6xmFLBVSHCZPCpr6dXdsjiE6JTJhEVtDdiCVZ9gDl/Fo9Thp76i2nJg+zEeoQ ALTdb322dXjVYojGkBb1TNx9zg+gwLP6yD+hnJEITarXNppZCv/iNe1rISks8mTSUWQh BrXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=6BbJfTjdzqSyIyJ/BwNHDar8lvGvNh9tJJcETlMgsi8=; b=Vefluvw4IBwPjuERdG0KIMSjGu7aKA5fU+aLVymqBtdqayllnVvjsso5KfL4SoeJMw VWzvgU6b2urmPDIWPcgzc7FtxrsaZlEOuC/vM49/V9IDX0Klc7WJSLh9I0Q6PGVydQ2Z UaVmQ0heCHqplwml/5dQiP0/WplRW3A9d8EskYK/NJN97StRo3Nha0woA9NaquPxBn1q 5JmdTj6TxIhVRI4tTr/wENdDAIlZBsoFoGOKerE+3nt69aIOCtymRRDvtKxeFx6A/xPa ZnulZ5ozyscuDuKLjIthj5eU+jN0mKUdyKKV3BrkasHoF2m8qn/M18wVT7HoO+9C02G7 VUNQ== X-Gm-Message-State: ACgBeo2w6VOmRQVBiRd/IPegfMETTrEG/qhH1HEocKkh3zZVopSBXY57 aC66oGov/Y4e1v1rVXbpYKuvSfMU4NlZIL9ErysaHQ== X-Received: by 2002:a17:907:2719:b0:730:a688:f1e4 with SMTP id w25-20020a170907271900b00730a688f1e4mr1756493ejk.425.1659464141758; Tue, 02 Aug 2022 11:15:41 -0700 (PDT) MIME-Version: 1.0 References: <20220802161206.228707-1-mairacanal@riseup.net> <20220802161206.228707-3-mairacanal@riseup.net> <5c9038fd-a247-d0d3-841c-ba1e606bc309@riseup.net> In-Reply-To: <5c9038fd-a247-d0d3-841c-ba1e606bc309@riseup.net> From: Daniel Latypov Date: Tue, 2 Aug 2022 11:15:30 -0700 Message-ID: Subject: Re: [PATCH 2/3] kunit: add KUnit array assertions to the example_all_expect_macros_test To: =?UTF-8?Q?Andr=C3=A9_Almeida?= Cc: =?UTF-8?B?TWHDrXJhIENhbmFs?= , melissa.srw@gmail.com, daniel@ffwll.ch, javierm@redhat.com, siqueirajordao@riseup.net, Isabella Basso , jose.exposito89@gmail.com, magalilemes00@gmail.com, tales.aparecida@gmail.com, davidgow@google.com, davem@davemloft.net, Brendan Higgins , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, airlied@linux.ie, kuba@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Tue, Aug 2, 2022 at 9:19 AM Andr=C3=A9 Almeida = wrote: > =C3=80s 13:12 de 02/08/22, Ma=C3=ADra Canal escreveu: > > Increament the example_all_expect_macros_test with the > > KUNIT_EXPECT_ARREQ and KUNIT_EXPECT_ARRNEQ macros by creating a test > > with array assertions. > > > > Signed-off-by: Ma=C3=ADra Canal > > --- > > lib/kunit/kunit-example-test.c | 7 +++++++ > > 1 file changed, 7 insertions(+) > > > > diff --git a/lib/kunit/kunit-example-test.c b/lib/kunit/kunit-example-t= est.c > > index f8fe582c9e36..fc81a45d9cbc 100644 > > --- a/lib/kunit/kunit-example-test.c > > +++ b/lib/kunit/kunit-example-test.c > > @@ -86,6 +86,9 @@ static void example_mark_skipped_test(struct kunit *t= est) > > */ > > static void example_all_expect_macros_test(struct kunit *test) > > { > > + const u32 array[] =3D { 0x0F, 0xFF }; > > + const u32 expected[] =3D { 0x1F, 0xFF }; Given the distance between the definition and their use, perhaps we can give them clearer names. E.g. array + diff_array, or array1 + array2, etc. I think something to indicate they're arrays and that they're different. The current name `expected` is a bit unclear. > > + > > /* Boolean assertions */ > > KUNIT_EXPECT_TRUE(test, true); > > KUNIT_EXPECT_FALSE(test, false); > > @@ -109,6 +112,10 @@ static void example_all_expect_macros_test(struct = kunit *test) > > KUNIT_EXPECT_STREQ(test, "hi", "hi"); > > KUNIT_EXPECT_STRNEQ(test, "hi", "bye"); > > > > + /* Array assertions */ > > + KUNIT_EXPECT_ARREQ(test, expected, expected, 2); > > + KUNIT_EXPECT_ARRNEQ(test, array, expected, 2); > > ARRAY_SIZE() is usually better than constants is this case. Note: that's actually incorrect! Ah right, this was the other blocker I had in mind. I wasn't sure how we'd handle the size parameter. Users might think ARRAY_SIZE() is fine and copy-paste it. But the size parameter is in units of bytes, not array elements! If the element types are not 1 byte, it'll silently not compare the full ar= ray. We'd want people to use KUNIT_EXPECT_ARREQ(test, expected, expected, sizeof(expected)); But this doesn't work for `u32 *array`, since it'll silently just compare 1 byte if people get them mixed up. I don't know how we make a maximally fool-proof version of this macro :\