Message ID | 20221025231043.115295-1-mairacanal@riseup.net |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1265745wru; Tue, 25 Oct 2022 16:12:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6QD2cp6+XcvPjOyLmR0o73Fe7i3BF3fAvnUGAkEW/gshaDKOEsavSQWlsnPZVfgRzX6lu4 X-Received: by 2002:a05:6a00:430c:b0:562:6897:7668 with SMTP id cb12-20020a056a00430c00b0056268977668mr41405166pfb.23.1666739567658; Tue, 25 Oct 2022 16:12:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666739567; cv=none; d=google.com; s=arc-20160816; b=DZth5Ykxd1LOyuyMi5bTGkoVEWePgUm5/r/VEFGkbaJ2T0wSK6DghQQzylJIEheJOb 6vHoSLo/kAJKLrB97pE2tAYXgNG14SdpvONC25MrECfu9G5CRGs1oIRXokC90vs5mK17 c0xouTvCbyotq8GfbA6L9YFAX0I6RCaOQvimVCh6ll4GKjn7AIffwIkBAwYCp52B7PYV pAvi4kqYSYwnY6EoUaoimyRfowPnkKQ4am3L0aIw2iwEz4oCG58QPUGsNreH/JAB4MqX kVQb3E9D+0qeZhi2d6YWPEB20X2RSC53LoRVAXEL6E/DmkKvn09Q4VpbMlf5OFcwwdjj G7yw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=SDLC3CAxUOUVURK8zku0ivFV46wiVXqXHGjiamoUxA0=; b=R4uzfkMqAh/f2njTKESSrKiOvMYL7957X1e5YcxtwpVtLYBSMJ68EIKZLAwmE82oA0 WtktmtnfFeB9Dm26OHL8b+9G8U8afSbJViChmTODcMOS4ccI9/E62dw763/cmPTk7D1y KMJCPdyCJvcr2LnxnkZZ/T2AaYez5piDwFSosjwqJPArmehV+ykvd9FfWrvU1+S5uf4q gbIX3zw2qLyCwVRrkuDOBaieZtaGo382fUeJyZGreky1SyYiDTAlatiqZmgJvSsI36vU exVh0UQbUp52c9s3ikew3/b0pYrOznd2oa0VAagtc4SMjqTVl2JKFpBCxU2vA+yPKD9i Z1Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@riseup.net header.s=squak header.b=GVJQsrY1; 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=riseup.net Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k8-20020a170902694800b00186b069c0e1si3924672plt.282.2022.10.25.16.12.33; Tue, 25 Oct 2022 16:12:47 -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=@riseup.net header.s=squak header.b=GVJQsrY1; 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=riseup.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231696AbiJYXLL (ORCPT <rfc822;pwkd43@gmail.com> + 99 others); Tue, 25 Oct 2022 19:11:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229952AbiJYXLI (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 25 Oct 2022 19:11:08 -0400 Received: from mx1.riseup.net (mx1.riseup.net [198.252.153.129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76D38CF874; Tue, 25 Oct 2022 16:11:07 -0700 (PDT) Received: from fews2.riseup.net (fews2-pn.riseup.net [10.0.1.84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail.riseup.net", Issuer "R3" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4Mxnk21dYqzDqs8; Tue, 25 Oct 2022 23:11:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1666739466; bh=KKHR24rPQxFu1YA5ld6wDOQ/gCh3kJrbD7p3rWeW2Tg=; h=From:To:Cc:Subject:Date:From; b=GVJQsrY1HzfiJfux+/dhic0R4jUYqYXHr38lir4sSk2NO9//jrTWPBkSmpEvO4RFS DbGoeo0PfZJoCR+e3D4vavQc6G3zJVjJ4t2c0BuAio8jIbGsUijXH5eJgMWwiADfXm eFJZimPDgaowT6ZxWVomOneiri3Do+VfQy3Kdvc8= X-Riseup-User-ID: EF1CFFE6C67DC1ABFA3A5A31252CC2AD9978F88F1CF011EF5CD6A589F715F482 Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews2.riseup.net (Postfix) with ESMTPSA id 4Mxnjv0gL0z1yRB; Tue, 25 Oct 2022 23:10:58 +0000 (UTC) From: =?utf-8?q?Ma=C3=ADra_Canal?= <mairacanal@riseup.net> To: Brendan Higgins <brendanhiggins@google.com>, davidgow@google.com, Daniel Latypov <dlatypov@google.com>, airlied@gmail.com, daniel@ffwll.ch, davem@davemloft.net, kuba@kernel.org, jose.exposito89@gmail.com, javierm@redhat.com Cc: andrealmeid@riseup.net, melissa.srw@gmail.com, siqueirajordao@riseup.net, Isabella Basso <isabbasso@riseup.net>, magalilemes00@gmail.com, tales.aparecida@gmail.com, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, =?utf-8?q?Ma?= =?utf-8?q?=C3=ADra_Canal?= <mairacanal@riseup.net> Subject: [PATCH v7 0/3] Introduce KUNIT_EXPECT_MEMEQ and KUNIT_EXPECT_MEMNEQ macros Date: Tue, 25 Oct 2022 20:10:40 -0300 Message-Id: <20221025231043.115295-1-mairacanal@riseup.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, URIBL_BLOCKED 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747703109231509447?= X-GMAIL-MSGID: =?utf-8?q?1747703109231509447?= |
Series |
Introduce KUNIT_EXPECT_MEMEQ and KUNIT_EXPECT_MEMNEQ macros
|
|
Message
Maira Canal
Oct. 25, 2022, 11:10 p.m. UTC
Currently, in order to compare memory blocks in KUnit, the KUNIT_EXPECT_EQ or KUNIT_EXPECT_FALSE macros are used in conjunction with the memcmp function, such as: KUNIT_EXPECT_EQ(test, memcmp(foo, bar, size), 0); Although this usage produces correct results for the test cases, if the expectation fails the error message is not very helpful, indicating only the return of the memcmp function. Therefore, create a new set of macros KUNIT_EXPECT_MEMEQ and KUNIT_EXPECT_MEMNEQ that compare memory blocks until a determined size. In case of expectation failure, those macros print the hex dump of the memory blocks, making it easier to debug test failures for memory blocks. The v7 has some formatting changes on the first patch and it was rebased on top of the mainline (due to 7089003304c6). The first patch of the series introduces the KUNIT_EXPECT_MEMEQ and KUNIT_EXPECT_MEMNEQ. The second patch adds an example of memory block expectations on the kunit-example-test.c. And the last patch replaces the KUNIT_EXPECT_EQ for KUNIT_EXPECT_MEMEQ on the existing occurrences. Best Regards, - Maíra Canal v1 -> v2: https://lore.kernel.org/linux-kselftest/2a0dcd75-5461-5266-2749-808f638f4c50@riseup.net/T/#m402cc72eb01fb3b88d6706cf7d1705fdd51e5da2 - Change "determinated" to "specified" (Daniel Latypov). - Change the macro KUNIT_EXPECT_ARREQ to KUNIT_EXPECT_MEMEQ, in order to make it easier for users to infer the right size unit (Daniel Latypov). - Mark the different bytes on the failure message with a <> (Daniel Latypov). - Replace a constant number of array elements for ARRAY_SIZE() (André Almeida). - Rename "array" and "expected" variables to "array1" and "array2" (Daniel Latypov). v2 -> v3: https://lore.kernel.org/linux-kselftest/20220802212621.420840-1-mairacanal@riseup.net/T/#t - Make the bytes aligned at output. - Add KUNIT_SUBSUBTEST_INDENT to the output for the indentation (Daniel Latypov). - Line up the trailing \ at macros using tabs (Daniel Latypov). - Line up the params to the functions (Daniel Latypov). - Change "Increament" to "Augment" (Daniel Latypov). - Use sizeof() for array sizes (Daniel Latypov). - Add Daniel Latypov's tags. v3 -> v4: https://lore.kernel.org/linux-kselftest/CABVgOSm_59Yr82deQm2C=18jjSv_akmn66zs4jxx3hfziXPeHg@mail.gmail.com/T/#t - Fix wrapped lines by the mail client (David Gow). - Mention on documentation that KUNIT_EXPECT_MEMEQ is not recommended for structured data (David Gow). - Add Muhammad Usama Anjum's tag. v4 -> v5: https://lore.kernel.org/linux-kselftest/20220808125237.277126-1-mairacanal@riseup.net/ - Rebase on top of drm-misc-next. - Add David Gow's tags. v5 -> v6: https://lore.kernel.org/linux-kselftest/20220921014515.113062-1-mairacanal@riseup.net/ - Rebase on top of Linux 6.1. - Change KUNIT_ASSERTION macro to _KUNIT_FAILED. v6 -> v7: https://lore.kernel.org/linux-kselftest/20221018190541.189780-1-mairacanal@riseup.net/ - Format nits (David Gow). - Rebase on top of Linux 6.1-rc2. Maíra Canal (3): kunit: Introduce KUNIT_EXPECT_MEMEQ and KUNIT_EXPECT_MEMNEQ macros kunit: Add KUnit memory block assertions to the example_all_expect_macros_test kunit: Use KUNIT_EXPECT_MEMEQ macro .../gpu/drm/tests/drm_format_helper_test.c | 12 +-- include/kunit/assert.h | 33 +++++++ include/kunit/test.h | 87 +++++++++++++++++++ lib/kunit/assert.c | 56 ++++++++++++ lib/kunit/kunit-example-test.c | 7 ++ net/core/dev_addr_lists_test.c | 4 +- 6 files changed, 191 insertions(+), 8 deletions(-)
Comments
On Wed, Oct 26, 2022 at 7:11 AM Maíra Canal <mairacanal@riseup.net> wrote: > > Currently, in order to compare memory blocks in KUnit, the KUNIT_EXPECT_EQ or > KUNIT_EXPECT_FALSE macros are used in conjunction with the memcmp function, > such as: > KUNIT_EXPECT_EQ(test, memcmp(foo, bar, size), 0); > > Although this usage produces correct results for the test cases, if the > expectation fails the error message is not very helpful, indicating only the > return of the memcmp function. > > Therefore, create a new set of macros KUNIT_EXPECT_MEMEQ and > KUNIT_EXPECT_MEMNEQ that compare memory blocks until a determined size. In > case of expectation failure, those macros print the hex dump of the memory > blocks, making it easier to debug test failures for memory blocks. > > The v7 has some formatting changes on the first patch and it was rebased on > top of the mainline (due to 7089003304c6). > > The first patch of the series introduces the KUNIT_EXPECT_MEMEQ and > KUNIT_EXPECT_MEMNEQ. The second patch adds an example of memory block > expectations on the kunit-example-test.c. And the last patch replaces the > KUNIT_EXPECT_EQ for KUNIT_EXPECT_MEMEQ on the existing occurrences. > > Best Regards, > - Maíra Canal > > v1 -> v2: https://lore.kernel.org/linux-kselftest/2a0dcd75-5461-5266-2749-808f638f4c50@riseup.net/T/#m402cc72eb01fb3b88d6706cf7d1705fdd51e5da2 > > - Change "determinated" to "specified" (Daniel Latypov). > - Change the macro KUNIT_EXPECT_ARREQ to KUNIT_EXPECT_MEMEQ, in order to make > it easier for users to infer the right size unit (Daniel Latypov). > - Mark the different bytes on the failure message with a <> (Daniel Latypov). > - Replace a constant number of array elements for ARRAY_SIZE() (André Almeida). > - Rename "array" and "expected" variables to "array1" and "array2" (Daniel Latypov). > > v2 -> v3: https://lore.kernel.org/linux-kselftest/20220802212621.420840-1-mairacanal@riseup.net/T/#t > > - Make the bytes aligned at output. > - Add KUNIT_SUBSUBTEST_INDENT to the output for the indentation (Daniel Latypov). > - Line up the trailing \ at macros using tabs (Daniel Latypov). > - Line up the params to the functions (Daniel Latypov). > - Change "Increament" to "Augment" (Daniel Latypov). > - Use sizeof() for array sizes (Daniel Latypov). > - Add Daniel Latypov's tags. > > v3 -> v4: https://lore.kernel.org/linux-kselftest/CABVgOSm_59Yr82deQm2C=18jjSv_akmn66zs4jxx3hfziXPeHg@mail.gmail.com/T/#t > > - Fix wrapped lines by the mail client (David Gow). > - Mention on documentation that KUNIT_EXPECT_MEMEQ is not recommended for > structured data (David Gow). > - Add Muhammad Usama Anjum's tag. > > v4 -> v5: https://lore.kernel.org/linux-kselftest/20220808125237.277126-1-mairacanal@riseup.net/ > > - Rebase on top of drm-misc-next. > - Add David Gow's tags. > > v5 -> v6: https://lore.kernel.org/linux-kselftest/20220921014515.113062-1-mairacanal@riseup.net/ > > - Rebase on top of Linux 6.1. > - Change KUNIT_ASSERTION macro to _KUNIT_FAILED. > > v6 -> v7: https://lore.kernel.org/linux-kselftest/20221018190541.189780-1-mairacanal@riseup.net/ > > - Format nits (David Gow). > - Rebase on top of Linux 6.1-rc2. > > Maíra Canal (3): > kunit: Introduce KUNIT_EXPECT_MEMEQ and KUNIT_EXPECT_MEMNEQ macros > kunit: Add KUnit memory block assertions to the example_all_expect_macros_test > kunit: Use KUNIT_EXPECT_MEMEQ macro > > .../gpu/drm/tests/drm_format_helper_test.c | 12 +-- > include/kunit/assert.h | 33 +++++++ > include/kunit/test.h | 87 +++++++++++++++++++ > lib/kunit/assert.c | 56 ++++++++++++ > lib/kunit/kunit-example-test.c | 7 ++ > net/core/dev_addr_lists_test.c | 4 +- > 6 files changed, 191 insertions(+), 8 deletions(-) > Thanks very much -- this works here, and be good to go into 6.2. Cheers, -- David