Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2632455imn; Tue, 2 Aug 2022 10:03:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR6EhCi7G6FnXpjd5TaKD1c1d3+9X48C4IaBcGGvPwBrBpaHme+SbwtV7kgHdKxJwYI71/mF X-Received: by 2002:a17:906:1dd2:b0:730:9a59:3894 with SMTP id v18-20020a1709061dd200b007309a593894mr5058871ejh.485.1659459805908; Tue, 02 Aug 2022 10:03:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659459805; cv=none; d=google.com; s=arc-20160816; b=v7Cm71of+U4H1ZCYR82TkjpxQHgYqavVW6Q1sm3khw56aJ5ygvSYbEGJyoc4i1Na/+ viXd/usgeNJwbHrhBfduG9aNECPslAfYyy4/DrROnN3Op9uN0kLohS45JlcrE013PH+g i7sHHEYjUD4j93Lcp0WRWCcx9Oly04IDaFttQQbhfYLR3yxh/p8D7DM0I6oDPgvFXZYo rC3JZnxht0P2WIkzSyyLm7434QvS3ECduhHC6V9XfdOXlqpBj40mi0KQVuAMGEqgfuTe JbJ3E5vF2gIVZl2ZP77yFkclB4RASndwMHNNAhXT67izGWlhCxcrsElqL7FbKnC/coWU rlvg== 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=2w9j9LaZJjOKyMxreP7PDQG5d151R4IhaLjK01Lb1iM=; b=s1tPfTloPKxbZJWH9ZKG++Htbn++eYh0eCUk7QygRMOoJ0KCwF/iqPyWkb9uG1BaBE OdHGuPV7XQQrG7f2zggn8/q2tTq6cIvk+2mPpqdPlfOpnU8gL+ucyk7OM0BnHJ/sO6Iq zlv/sR7G2dbPmhPHZn1Qdi/uSAwMv2U292JZLVihxT4lGrDNZsLiALPJOrs9QMIMNCE1 xxzPIWAAc20ncqBkfDGawByRSLlq9UDekxZyzXy+SIllJlIy4MntmXFsNIPiQ5AY13Ei A7Sy6HYzyCpAb4ZEzUHCpem4iRORgaInnq4Rq4HFqOO4iS9WdKSwlGSi/JTz2I61PDqX RKFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Iua2tMz9; 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 z15-20020a1709063a0f00b0072aebf9cc60si12500810eje.619.2022.08.02.10.03.00; Tue, 02 Aug 2022 10:03:25 -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=Iua2tMz9; 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 S232429AbiHBRAV (ORCPT + 99 others); Tue, 2 Aug 2022 13:00:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229933AbiHBRAO (ORCPT ); Tue, 2 Aug 2022 13:00:14 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E85FFC3D for ; Tue, 2 Aug 2022 10:00:12 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id kb8so12473022ejc.4 for ; Tue, 02 Aug 2022 10:00:12 -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=2w9j9LaZJjOKyMxreP7PDQG5d151R4IhaLjK01Lb1iM=; b=Iua2tMz9VCggF2zvbuaciSSrSdIzA6LZwUpp1N894iDucV1kOI7qdYGfmfKDClT2IE f2UgcD9N78KSCyczFLpt4gpc3fEw+lpAMY2ctYeN+7a1QLskAiRER1ucVyHk/2/fhtfR rfMjdQ5aPIgxJ00Y5WNVwhd47T8BjWPFOzshujn5+knc605IMjbOkmMz3XcoTbXOt/cg mpu49YAP3pdjXirKKYgt6noUtvlxJ279lQfM//iGDWqPwxIvR2nXb9mq9Qawf7nKe+24 s2vcHKHPNhUvqLtEr7OsnpId++WidGeGPmCCinwuiyRHzy+PQXwHJxhQ4g7pW0zfDgD4 87gg== 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=2w9j9LaZJjOKyMxreP7PDQG5d151R4IhaLjK01Lb1iM=; b=Rb2cA28d2ds1NU635jJX6qQIqqs0A0fi7GQodNyIjV3heKU4ivEwfDOxCJ9lg47rBp njMIs1C1F5SFgPMSXKVy0kqf3PyE/oN1M7aU5/tMmoc5zTcRka4kyKyaozXdL7xYAJOq /9FPUA5WKDJxM0st4NSExnrw6Hyyg786JoIxuSBkf0gObtbqOAaR31uuL4sytawOEqcr WA+fVIrPnnmIyvijd+iTc0zc0zcZwcHw7w9LKyekRZ0h3UFRwLjVlsmjtyzy8D9WZUh6 dRRrAftQKq2kCDPto6nLg2bBlzC8JGMM97ojO8qjJqxJu99QO8j+VzqmEfllJ8tgsDMy 2gmw== X-Gm-Message-State: ACgBeo35Udunnp+LyNvgZcclUNlMQ9wxqatASBkv0mZ22hNoWWv4jj7h 9W2P5LL0vdW+sMTkcy6z94ssm0nwRodt3YgBJNtxSQ== X-Received: by 2002:a17:907:6da8:b0:730:8ed5:2df8 with SMTP id sb40-20020a1709076da800b007308ed52df8mr7232187ejc.75.1659459611056; Tue, 02 Aug 2022 10:00:11 -0700 (PDT) MIME-Version: 1.0 References: <20220802161206.228707-1-mairacanal@riseup.net> In-Reply-To: <20220802161206.228707-1-mairacanal@riseup.net> From: Daniel Latypov Date: Tue, 2 Aug 2022 09:59:59 -0700 Message-ID: Subject: Re: [PATCH 0/3] Introduce KUNIT_EXPECT_ARREQ and KUNIT_EXPECT_ARRNEQ macros To: =?UTF-8?B?TWHDrXJhIENhbmFs?= Cc: Brendan Higgins , davidgow@google.com, airlied@linux.ie, daniel@ffwll.ch, davem@davemloft.net, kuba@kernel.org, jose.exposito89@gmail.com, javierm@redhat.com, andrealmeid@riseup.net, melissa.srw@gmail.com, siqueirajordao@riseup.net, Isabella Basso , magalilemes00@gmail.com, tales.aparecida@gmail.com, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.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=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 Tue, Aug 2, 2022 at 9:12 AM Ma=C3=ADra Canal wro= te: > > Currently, in order to compare arrays in KUnit, the KUNIT_EXPECT_EQ or > KUNIT_EXPECT_FALSE macros are used in conjunction with the memcmp functio= n, > 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_ARREQ and > KUNIT_EXPECT_ARRNEQ that compare memory blocks until a determined size. I= n > case of expectation failure, those macros print the hex dump of the memor= y > blocks, making it easier to debug test failures for arrays. I totally agree with this. The only reason I hadn't sent an RFC out for this so far is * we didn't have enough use cases quite yet (now resolved) * I wasn't sure how we'd want to format the failure message. For the latter, right now this series produces dst =3D=3D 00000000: 33 0a 60 12 00 a8 00 00 00 00 8e 6b 33 0a 60 12 00000010: 00 00 00 00 00 a8 8e 6b 33 0a 00 00 00 00 result->expected =3D=3D 00000000: 31 0a 60 12 00 a8 00 00 00 00 81 6b 33 0a 60 12 00000010: 00 00 00 00 01 a8 8e 6b 33 0a 00 00 00 00 I was thinking something like what KASAN produces would be nice, e.g. from https://www.kernel.org/doc/html/v5.19/dev-tools/kasan.html#error-repor= ts (I'll paste the bit here, but my email client doesn't support monospaced fonts, so it won't look nice on my end) Memory state around the buggy address: ffff8801f44ec200: fc fc fc fc fc fc fc fc fb fb fb fb fb fb fb fb ffff8801f44ec280: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc >ffff8801f44ec300: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 ^ I just wasn't quite sure how to do it for a diff, since this only really works well when showing one bad byte. If we blindly followed that approach, we get dst =3D=3D >00000000: 33 0a 60 12 00 a8 00 00 00 00 8e 6b 33 0a 60 12 ^ >00000010: 00 00 00 00 00 a8 8e 6b 33 0a 00 00 00 00 ^ result->expected =3D=3D >00000000: 31 0a 60 12 00 a8 00 00 00 00 81 6b 33 0a 60 12 ^ >00000010: 00 00 00 00 01 a8 8e 6b 33 0a 00 00 00 00 ^ But perhaps we could instead highlight the bad bytes with something like dst =3D=3D 00000000: 33 0a 60 12 00 a8 00 00 00 00 <8e> 6b 33 0a 60 12 00000010: 00 00 00 00 <00> a8 8e 6b 33 0a 00 00 00 00 result->expected =3D=3D 00000000: 31 0a 60 12 00 a8 00 00 00 00 <81> 6b 33 0a 60 12 00000010: 00 00 00 00 <01> a8 8e 6b 33 0a 00 00 00 00 Thoughts, suggestions?