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 2DFCEC38142 for ; Sat, 28 Jan 2023 07:57:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233272AbjA1H5i (ORCPT ); Sat, 28 Jan 2023 02:57:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229973AbjA1H5f (ORCPT ); Sat, 28 Jan 2023 02:57:35 -0500 Received: from mail-vs1-xe36.google.com (mail-vs1-xe36.google.com [IPv6:2607:f8b0:4864:20::e36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41B9733455 for ; Fri, 27 Jan 2023 23:57:34 -0800 (PST) Received: by mail-vs1-xe36.google.com with SMTP id k6so7603699vsk.1 for ; Fri, 27 Jan 2023 23:57:34 -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=5GG1joCTDrG1daBv7ONaT8p65pfMidBlu/KkNjb9RXU=; b=AAzBLNxTk/X8s9ZFbo6BdVTOnsOkKQ0TFtEo+C68O4szWSMuGBgKfTArYjchjNXLyT BEOarHTbkq6JOeIowm5Qrp8P/+LXXYo9VcdDwo8lGL8bQAAcXgjb1JR77/1Os5nNWPAh l8N9BaB7JmK2/vfTsYptArBOJfunrVij21fGFlX+RhZro5dshbbvwflcemj2YlnfYqUY Zgaxtq8u7gwVjnc/ZaQ2+VawTFr2ght+e/uVlG2u+lket5BHfyNxAFKtvVd7h4cTEEe4 p6B+oizr8XLJ2JMtYwoDc82S9gf8nQ8F5qYcAUMCZufjEN5tJzH3NixoyXJ6q1D73SvC QITQ== 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=5GG1joCTDrG1daBv7ONaT8p65pfMidBlu/KkNjb9RXU=; b=JA69FNkb/156n1LvB6yV5JRkxbP+oM4Yll9HDwOyfQFJ4ZUIM4/FaewHggtC781IDt AUvrsrFEYsipLeHu+fuvtbPwHPew7tSLW7VhiMH+61K+a0bVDvfwo90jfgICPq+92UKU uM5ZFV3dvGiNguC6iL664hJpr1n9x9rVaekH5Hjkf9Uk46+53RVepUd20Dt4zgWvpiRf wLYJuXsgt9bcxLRhrNOhs/UHmzK9pigPkDyf3RPFBjrCgiac3ID6GRjQ1VA8QOCjmrgK 5lveE0e58TZQ1IwtepW4VXAJeY5jUABZkBq5LcJ88QIeB00XGFUYgO4ji5VFvSzPn96C xjRQ== X-Gm-Message-State: AO0yUKVxcOvcqDOqtBj4oYbPlLyah04vfkTs07zrIC895guHBzHmslNv +eGJw2L+kqF1jo4YzQ1oUYAoq9Nm1N43SUca513qUQ== X-Google-Smtp-Source: AK7set+iAC1O7VcJefkNLU+iAkowg6dLtYAv0wDfDSmWSjN0LAOMdOFF2U0W2cto4q6oFAOPlRj70oqd4400Vl3gCsU= X-Received: by 2002:a67:2686:0:b0:3eb:b8d8:6b3e with SMTP id m128-20020a672686000000b003ebb8d86b3emr1003951vsm.22.1674892653209; Fri, 27 Jan 2023 23:57:33 -0800 (PST) MIME-Version: 1.0 References: <20230127203950.781709-1-rmoar@google.com> In-Reply-To: <20230127203950.781709-1-rmoar@google.com> From: David Gow Date: Sat, 28 Jan 2023 15:57:21 +0800 Message-ID: Subject: Re: [PATCH v2] 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="000000000000a7606205f34e55db" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --000000000000a7606205f34e55db Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, 28 Jan 2023 at 04:40, 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. > > Fixes: b8a926bea8b1 ("kunit: Introduce KUNIT_EXPECT_MEMEQ and KUNIT_EXPEC= T_MEMNEQ macros") > > 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 > Reviewed-by: David Gow > --- > > Changes since v1: > - Fix formatting of backslashes > - Add Fixes: ... statement to commit message > Looks good to me, now. Thanks. =E2=80=94 David > include/kunit/test.h | 5 +++-- > lib/kunit/assert.c | 40 +++++++++++++++++++++++++--------------- > 2 files changed, 28 insertions(+), 17 deletions(-) > > diff --git a/include/kunit/test.h b/include/kunit/test.h > index 87ea90576b50..a20bff149bdf 100644 > --- a/include/kunit/test.h > +++ b/include/kunit/test.h > @@ -683,8 +683,9 @@ do { = \ > .right_text =3D #right, = \ > }; = \ > = \ > - if (likely(memcmp(__left, __right, __size) op 0)) = \ > - break; = \ > + if (likely(__left && __right)) = \ > + if (likely(memcmp(__left, __right, __size) op 0)) = \ > + break; = \ > = \ > _KUNIT_FAILED(test, = \ > assert_type, = \ > 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_ass= ert *assert, > mem_assert =3D 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 no= t 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 no= t 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 =3D=3D\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 =3D= =3D\n", > + mem_assert->text->left_text); > + kunit_assert_hexdump(stream, mem_assert->left_value, > + mem_assert->right_value, mem_asse= rt->size); > > - string_stream_add(stream, "\n"); > + string_stream_add(stream, "\n"); > > - string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s =3D=3D\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 =3D= =3D\n", > + mem_assert->text->right_text); > + kunit_assert_hexdump(stream, mem_assert->right_value, > + mem_assert->left_value, mem_asser= t->size); > > - kunit_assert_print_msg(message, stream); > + kunit_assert_print_msg(message, stream); > + } > } > EXPORT_SYMBOL_GPL(kunit_mem_assert_format); > > base-commit: 5835ffc27381c2d32c3f0d7b575cb3397555ab47 > -- > 2.39.1.456.gfc5497dd1b-goog > --000000000000a7606205f34e55db Content-Type: application/pkcs7-signature; name="smime.p7s" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="smime.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