Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4271CC54E94 for ; Wed, 25 Jan 2023 06:38:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233619AbjAYGiY (ORCPT ); Wed, 25 Jan 2023 01:38:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233434AbjAYGiW (ORCPT ); Wed, 25 Jan 2023 01:38:22 -0500 Received: from mail-ua1-x92e.google.com (mail-ua1-x92e.google.com [IPv6:2607:f8b0:4864:20::92e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E0A13B657 for ; Tue, 24 Jan 2023 22:38:21 -0800 (PST) Received: by mail-ua1-x92e.google.com with SMTP id u29so3462850uaa.8 for ; Tue, 24 Jan 2023 22:38:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=mNFG5ld86qrefZDsClfqnrcg2ULlQhutlrH8/TF8HwM=; b=Fx9ZF8iaEWd4LCekxoPCNzgQN0oJORPaiJEQtSKm5xC6zf21IeujNO8u3CyuJSCVsg J1bqgzZlsi9AHsJUTZ2xkA1kcIubfOhJJU8yq7kzjDOBcEozQ/iz3/yU4vkQlZltneMx UCJ3/Ost7dVzs1w7pW8tA0d9f2x+PU0BV0zgZkOw0UNQixHgOsy+Z7Uc9EMlTBfHBdNL pOzD/ES9yyJw9GE+y8M4jPHm2n2SmDbE9qiMTJlA+OXRWICqIjp692MK8Csb9vSBvzrF Dr/Ro8wTTB7Xi7vlFwGDOs8gUQ3R6lr8uZCxDsFRKy8IG5j+j5YOvUpyTcVYzYC8ai2z qBnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mNFG5ld86qrefZDsClfqnrcg2ULlQhutlrH8/TF8HwM=; b=CThsdIF8ukVnyVogveNmKAvYuLI/McteXvCJV2tVNTrXErOuKLsJhTBNK4BoDklTQ8 8uO7JkYwOMeWgk2KkxdTxfD4cWLCQLykOv8l/z7ZZFdzkGEJRXXdVe7V7Tj30jsqNqjf UebW1gLroGODD7JaKQUYBvmsJJYPGin3WgdgTWafuh8r+x+tfmVoEdvz3bdlXB7P1TeH QTXdHGMrOZGO9LiWsQYKqJrrfhuf05vwavkAtOWnFw2Eiw8Ro8L19nfTZoxp33t6r5v9 cWFY3AQMEWT32Simp8i94x2CUXMfC375DjEron/tpI3UqS2p79ThSFouyv/ZKe6r6SV7 GJkg== X-Gm-Message-State: AFqh2krntxcEpTnV54k0R3IW3YgTavqpJVwkjvM3sKkCEmUuh1EYw9Hi 8hPsHLXuR+DXe7sL95EN+9VOlywAsviYQFv0Ph+wTQ== X-Google-Smtp-Source: AMrXdXtrpm0DykpuTo8YHoJNv7Aw0k7FU59u9Oacd3hflPVW8jRLF6uHwTZ09IvWmOHGd/nvjKgdz/dnnHLlONgktPA= X-Received: by 2002:ab0:3155:0:b0:419:25c5:30dc with SMTP id e21-20020ab03155000000b0041925c530dcmr3745651uam.26.1674628700126; Tue, 24 Jan 2023 22:38:20 -0800 (PST) MIME-Version: 1.0 References: <20230125061927.141538-1-rmoar@google.com> In-Reply-To: <20230125061927.141538-1-rmoar@google.com> From: David Gow Date: Wed, 25 Jan 2023 14:38:08 +0800 Message-ID: Subject: Re: [PATCH v1] kunit: fix bug in KUNIT_EXPECT_MEMEQ To: Rae Moar Cc: brendanhiggins@google.com, dlatypov@google.com, skhan@linuxfoundation.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel test robot Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256; boundary="000000000000d1cf6a05f310e00c" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --000000000000d1cf6a05f310e00c Content-Type: text/plain; charset="UTF-8" On Wed, 25 Jan 2023 at 14:19, Rae Moar wrote: > > In KUNIT_EXPECT_MEMEQ and KUNIT_EXPECT_MEMNEQ, add check if one of the > inputs is NULL and fail if this is the case. > > Currently, the kernel crashes if one of the inputs is NULL. Instead, > fail the test and add an appropriate error message. > > This was found by the kernel test robot: > https://lore.kernel.org/all/202212191448.D6EDPdOh-lkp@intel.com/ > > Reported-by: kernel test robot > > Signed-off-by: Rae Moar > --- This looks good to me, modulo a small formatting issue with the continuation backslashes (see below). It might be worth considering this as a fix to the patch which first introduced the MEMEQ macros with a Fixes tag, e.g.: Fixes: b8a926bea8b1 ("kunit: Introduce KUNIT_EXPECT_MEMEQ and KUNIT_EXPECT_MEMNEQ macros") Otherwise, this is: Reviewed-by: David Gow Cheers, -- David > include/kunit/test.h | 7 ++++--- > lib/kunit/assert.c | 40 +++++++++++++++++++++++++--------------- > 2 files changed, 29 insertions(+), 18 deletions(-) > > diff --git a/include/kunit/test.h b/include/kunit/test.h > index 87ea90576b50..3c7045e22512 100644 > --- a/include/kunit/test.h > +++ b/include/kunit/test.h > @@ -683,9 +683,10 @@ do { \ > .right_text = #right, \ > }; \ > \ > - if (likely(memcmp(__left, __right, __size) op 0)) \ > - break; \ > - \ > + if (likely(__left && __right)) \ > + if (likely(memcmp(__left, __right, __size) op 0)) \ > + break; \ > + \ The backslashes no longer line up here. > _KUNIT_FAILED(test, \ > assert_type, \ > kunit_mem_assert, \ > diff --git a/lib/kunit/assert.c b/lib/kunit/assert.c > index f5b50babe38d..05a09652f5a1 100644 > --- a/lib/kunit/assert.c > +++ b/lib/kunit/assert.c > @@ -241,24 +241,34 @@ void kunit_mem_assert_format(const struct kunit_assert *assert, > mem_assert = container_of(assert, struct kunit_mem_assert, > assert); > > - string_stream_add(stream, > - KUNIT_SUBTEST_INDENT "Expected %s %s %s, but\n", > - mem_assert->text->left_text, > - mem_assert->text->operation, > - mem_assert->text->right_text); > + if (!mem_assert->left_value) { > + string_stream_add(stream, > + KUNIT_SUBTEST_INDENT "Expected %s is not null, but is\n", > + mem_assert->text->left_text); > + } else if (!mem_assert->right_value) { > + string_stream_add(stream, > + KUNIT_SUBTEST_INDENT "Expected %s is not null, but is\n", > + mem_assert->text->right_text); > + } else { > + string_stream_add(stream, > + KUNIT_SUBTEST_INDENT "Expected %s %s %s, but\n", > + mem_assert->text->left_text, > + mem_assert->text->operation, > + mem_assert->text->right_text); > > - string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s ==\n", > - mem_assert->text->left_text); > - kunit_assert_hexdump(stream, mem_assert->left_value, > - mem_assert->right_value, mem_assert->size); > + string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s ==\n", > + mem_assert->text->left_text); > + kunit_assert_hexdump(stream, mem_assert->left_value, > + mem_assert->right_value, mem_assert->size); > > - string_stream_add(stream, "\n"); > + string_stream_add(stream, "\n"); > > - string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s ==\n", > - mem_assert->text->right_text); > - kunit_assert_hexdump(stream, mem_assert->right_value, > - mem_assert->left_value, mem_assert->size); > + string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s ==\n", > + mem_assert->text->right_text); > + kunit_assert_hexdump(stream, mem_assert->right_value, > + mem_assert->left_value, mem_assert->size); > > - kunit_assert_print_msg(message, stream); > + kunit_assert_print_msg(message, stream); > + } > } > EXPORT_SYMBOL_GPL(kunit_mem_assert_format); > > base-commit: 5cb26c298ffde271d9bd1dd1b87ad028218f77fe > -- > 2.39.1.405.gd4c25cc71f-goog > --000000000000d1cf6a05f310e00c Content-Type: application/pkcs7-signature; name="smime.p7s" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="smime.p7s" Content-Description: S/MIME Cryptographic Signature MIIPnwYJKoZIhvcNAQcCoIIPkDCCD4wCAQExDzANBglghkgBZQMEAgEFADALBgkqhkiG9w0BBwGg ggz5MIIEtjCCA56gAwIBAgIQeAMYYHb81ngUVR0WyMTzqzANBgkqhkiG9w0BAQsFADBMMSAwHgYD VQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMzETMBEGA1UEChMKR2xvYmFsU2lnbjETMBEGA1UE AxMKR2xvYmFsU2lnbjAeFw0yMDA3MjgwMDAwMDBaFw0yOTAzMTgwMDAwMDBaMFQxCzAJBgNVBAYT AkJFMRkwFwYDVQQKExBHbG9iYWxTaWduIG52LXNhMSowKAYDVQQDEyFHbG9iYWxTaWduIEF0bGFz IFIzIFNNSU1FIENBIDIwMjAwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCvLe9xPU9W dpiHLAvX7kFnaFZPuJLey7LYaMO8P/xSngB9IN73mVc7YiLov12Fekdtn5kL8PjmDBEvTYmWsuQS 6VBo3vdlqqXZ0M9eMkjcKqijrmDRleudEoPDzTumwQ18VB/3I+vbN039HIaRQ5x+NHGiPHVfk6Rx c6KAbYceyeqqfuJEcq23vhTdium/Bf5hHqYUhuJwnBQ+dAUcFndUKMJrth6lHeoifkbw2bv81zxJ I9cvIy516+oUekqiSFGfzAqByv41OrgLV4fLGCDH3yRh1tj7EtV3l2TngqtrDLUs5R+sWIItPa/4 AJXB1Q3nGNl2tNjVpcSn0uJ7aFPbAgMBAAGjggGKMIIBhjAOBgNVHQ8BAf8EBAMCAYYwHQYDVR0l BBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMEMBIGA1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0OBBYEFHzM CmjXouseLHIb0c1dlW+N+/JjMB8GA1UdIwQYMBaAFI/wS3+oLkUkrk1Q+mOai97i3Ru8MHsGCCsG AQUFBwEBBG8wbTAuBggrBgEFBQcwAYYiaHR0cDov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