From patchwork Thu Jul 11 19:39:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Chan X-Patchwork-Id: 13731028 X-Patchwork-Delegate: brendanhiggins@google.com Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BC8717CA01 for ; Thu, 11 Jul 2024 19:39:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720726765; cv=none; b=kb4CQRg5ykKVvvJDKEOrsMt+T9FBO0jxeeuzClIEbkR7xGerlevmPKF+q/DPvvvsYF0KVQNGKsthSzPIXZFWR0ChXMtPsZTcfCFwEIfvUiZDWLjyRMd13IbaqoLK3MM8it1OgsD7FbhYE3OJv0XRFJzKiyIDpYhr4ZKMZt5Q+A4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720726765; c=relaxed/simple; bh=77Fle0UxEK6EwAcqoaNanQHiVkg19YWm2CKEwPFrX+o=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=SiYGTWKckDNyYg7Sunuqt/6OVSJr4rDAwYMxnz7P0VDh7PGBU9yr6sIyqCAtktil6TL0XXCKOIYzSRA+V1ic2MWvi8EVJHXod9HEZxrpZtRxaEqeRe9tn7OTH6+a4x3nP4Cut/BXXA8dvVj+UJ1ViWbG1RBYhO9MzEf1UhyZoYA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ericchancf.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=rbrbjbZ7; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ericchancf.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rbrbjbZ7" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-654c14abdcfso22868557b3.1 for ; Thu, 11 Jul 2024 12:39:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720726763; x=1721331563; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jOuOZKjw/4Tx33ZawZRx4a+P5bBTfvgvLFnSHZM5EMU=; b=rbrbjbZ7GU6ThAd4loYZpzf9T5nChFt8bqFP0XYg7qzHgdI1xs9WtsMkJZ6/hKEyCa bQIhHAP3YVhrA5Owg10JSfhBpwVwvx4FN8xLjZmnhMIRdYGWJyagypxmdGeMb1W/7Vw2 7K23EZSa5oLFweeEJZJ98qspTQpzmma9L+IWxGuWY+LD+O2pzv43y0rNMBoMTbEmXIHK yXXMcYgZej05kU7zLTbU6ixC4ORLOrR4LuwptVRnrOgMzOb+UWi7KsGgGjcdf09J0X8o 99Eti/RCK8gm0yVluuqbACd2q2i6yhRFkQOSy1NOwM2T87EhueKudOoZPFlIxMY+JMT0 X2xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720726763; x=1721331563; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jOuOZKjw/4Tx33ZawZRx4a+P5bBTfvgvLFnSHZM5EMU=; b=EvleNDy2PSGHxD+SXjDKA21VFWnJuQ4M8gu3ZPwKMjqZCpiwVR59LUnMXHEomcORdF MO1URXXJjngQbe5kvebJhKL329EDg+7Z4yEFUJ1cSfHJKypn2sDFtPKmnrTD/t6xDmPE W4m2uAIQm5oHp1noqHd7249ROJ2cDXQR/Wf//YRLoVASXYpq/4nayxCnZgk4c8Gvn2J7 b9iMpdeofGzHbE1zh945c4zz6WrHK05C2YmypmSm6RlPd1iZ1y2Xc+SRJYYBkcz69yrH x6TvVGyV61fRfY328H63wa1Xyim8PHcjbrGETNVL+UIzBEqCoFtXGfmKKxU1b24ZM5SU ktEQ== X-Gm-Message-State: AOJu0YyJhm5Nh1xx2WKbHPLgpsVDI1LI6Uav4ssNQ39mK294cCm4WeL9 FI0r/NrQqIx1sz8JssamoSq5R9jkAqYiJw88BC5e/aZEtUtiyg2hjt9yrzRSVSIlKJCTbYNqAbV 643wIgu4qjk3Is/exlg== X-Google-Smtp-Source: AGHT+IH6KHs598qSeIBPsOGu8UPNk+DERfUoNF6Ncsl21ateD2j5KJKs5jvjqp/cn3t/zbMtdixdYO8tAx/HfDEZ X-Received: from ericchancf.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:4139]) (user=ericchancf job=sendgmr) by 2002:a25:8447:0:b0:e03:5e58:489b with SMTP id 3f1490d57ef6-e058a62eb69mr2360276.3.1720726763466; Thu, 11 Jul 2024 12:39:23 -0700 (PDT) Date: Thu, 11 Jul 2024 19:39:17 +0000 In-Reply-To: <20240711193729.108720-1-ericchancf@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240711193729.108720-1-ericchancf@google.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog Message-ID: <20240711193917.109380-1-ericchancf@google.com> Subject: [PATCH v2 1/3] kunit: Fix the comment of KUNIT_ASSERT_STRNEQ as assertion From: Eric Chan To: brendan.higgins@linux.dev, davidgow@google.com, rmoar@google.com Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, ericchancf@google.com The current comment for KUNIT_ASSERT_STRNEQ incorrectly describes it as an expectation. Since KUNIT_ASSERT_STRNEQ is an assertion, updates the comment to correctly refer to it as such. Signed-off-by: Eric Chan Reviewed-by: David Gow --- include/kunit/test.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/kunit/test.h b/include/kunit/test.h index 61637ef32302..87a232421089 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -1420,12 +1420,12 @@ do { \ ##__VA_ARGS__) /** - * KUNIT_ASSERT_STRNEQ() - Expects that strings @left and @right are not equal. + * KUNIT_ASSERT_STRNEQ() - An assertion that strings @left and @right are not equal. * @test: The test context object. * @left: an arbitrary expression that evaluates to a null terminated string. * @right: an arbitrary expression that evaluates to a null terminated string. * - * Sets an expectation that the values that @left and @right evaluate to are + * Sets an assertion that the values that @left and @right evaluate to are * not equal. This is semantically equivalent to * KUNIT_ASSERT_TRUE(@test, strcmp((@left), (@right))). See KUNIT_ASSERT_TRUE() * for more information. From patchwork Thu Jul 11 19:39:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Chan X-Patchwork-Id: 13731029 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5F2217CA01 for ; Thu, 11 Jul 2024 19:39:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720726779; cv=none; b=s2HK7vrQtc5o9PTGmDUAL17OG2aH6Kb1oz+jdfdTkkqzLW0vFKA2Dohzj7m7b0byHAAaqFWDxJgeO5lQ+srAKzjOtjPMFB/wAh3PPLAUDe6sJ1mKjlrn7Y4VglIkCvM04XufpdEC59G4PB3WUdJ+31o4mCIaD8uguHlM3OLAXhM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720726779; c=relaxed/simple; bh=zuv7aU9+6EwizhT7k58qrKHFO1TyJwLy/+7sOFS+/2I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=aNhMkP0ZIfItNNvAY/xuGBkE40g9WGO5TzPvvjBEdmFUsxBxY5Byy0yWL+F88icIXAwI+9wrEJwCm1zYowfspgyC9qMhhuEjqvRMcGY2IRJgmYul4qg+S8+96YNDT9MfTr8rMu4tOzsiSvuKyLOh55hbSvbWU0ajIvRoTIAhC40= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ericchancf.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2ZSXmeJv; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ericchancf.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2ZSXmeJv" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e03a59172dbso2060875276.3 for ; Thu, 11 Jul 2024 12:39:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720726777; x=1721331577; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Hgxac9QB2KM4ApAkhvoORMapcVhlUbyyyjsgT2eKMs0=; b=2ZSXmeJv3/glWt5cfhfLAvpaJ7XQSf8QjblA6qoh2sjh7975lKZHfvz6/nbiEE1AIW H7dAwJN8yZAmpqSZ7ONtFi8hVv6WXV27kUVCcBAHkMNs1zGyrmtGVJaNs5xlHiTLTHn9 dS0q9LyrQ2z4ffh2PzlS3pCC51MmgM4DC+esZcZGyhnnHeq5KPOGiP1ql6ZgLTzE/vGg 8gy6zXu6aF+HQDFcNpnIW5AlLfhWHYckaChpianGUm8Sqp2Qtx+lPHBIoXAQsrP+CYNJ 9w2Pd/H17P9ai/vlj9NnDuOf5AiBBKxhGZm9wsfF6l51o1VuoVVaVodT7lmAyXURFqPX lmVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720726777; x=1721331577; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Hgxac9QB2KM4ApAkhvoORMapcVhlUbyyyjsgT2eKMs0=; b=dwzuEJTXj9tDFGLcq0LU/XWSXZLGL6Kl1yNLL/koaVhvbwYf2VTQeB62CknG6OrdhJ nuYDzeUYRGGRFbVz0g/ylatztEPF2LRfcXvI2vNuLA4wGTDHUh0OM/VhZC0xG1U0eoeG B69aHwHGQDOPmN83JeLrpQlSWOro8V9f6IjQry9jcgOc1rb43gEDOFCLBH1nbmDMX8/f 5KRcAeW+MeRSH1kSBT5RqM/IEgAzBdM6wprVt2AajNFqQqcOVjKxAjt9yTHeSf4MM6V9 Z+ohUMvxQwSJbT4qRh2dpdwj0sqxeLaULmi4IpmjG7qQ1ACYLyCq+kMpDK35LOhaTqWp Z5dA== X-Gm-Message-State: AOJu0YxP0FWKmJx0drg9KQXt+X7thAxkUBRe7S4WIaPHdxSropdsnHaj qeqpeynBnfOU44iY9rjhRjdBhLyc+D0KVJV2UaGYy26onaGuZUyqJ3u78k6STthC2ducrCxWNd2 m06re1Yoka0hWgrrWOA== X-Google-Smtp-Source: AGHT+IFiZy3IJYTsIL2Alpwcdwku4C0/zoCvC/67nAo//ap35R2LErIX4igMHhNBKIedcgpWnliHinbXANx1eZYw X-Received: from ericchancf.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:4139]) (user=ericchancf job=sendgmr) by 2002:a05:6902:1ac1:b0:e03:62dc:63de with SMTP id 3f1490d57ef6-e041b0593efmr775705276.6.1720726777026; Thu, 11 Jul 2024 12:39:37 -0700 (PDT) Date: Thu, 11 Jul 2024 19:39:31 +0000 In-Reply-To: <20240711193729.108720-1-ericchancf@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240711193729.108720-1-ericchancf@google.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog Message-ID: <20240711193931.109771-1-ericchancf@google.com> Subject: [PATCH v2 2/3] kunit: Rename KUNIT_ASSERT_FAILURE to KUNIT_FAIL_AND_ABORT for readability From: Eric Chan To: brendan.higgins@linux.dev, davidgow@google.com, rmoar@google.com Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, ericchancf@google.com Both KUNIT_FAIL and KUNIT_ASSERT_FAILURE defined to KUNIT_FAIL_ASSERTION with different tpye of kunit_assert_type. The current naming of KUNIT_ASSERT_FAILURE and KUNIT_FAIL_ASSERTION is confusing due to their similarities. To improve readability and symmetry, renames KUNIT_ASSERT_FAILURE to KUNIT_FAIL_AND_ABORT. Makes the naming consistent, with KUNIT_FAIL and KUNIT_FAIL_AND_ABORT being symmetrical. Additionally, an explanation for KUNIT_FAIL_AND_ABORT has been added to clarify its usage. Signed-off-by: Eric Chan Reviewed-by: David Gow --- drivers/input/tests/input_test.c | 2 +- include/kunit/assert.h | 2 +- include/kunit/test.h | 13 ++++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/input/tests/input_test.c b/drivers/input/tests/input_test.c index 2fa5b725ae0a..9711ced180b8 100644 --- a/drivers/input/tests/input_test.c +++ b/drivers/input/tests/input_test.c @@ -31,7 +31,7 @@ static int input_test_init(struct kunit *test) ret = input_register_device(input_dev); if (ret) { input_free_device(input_dev); - KUNIT_ASSERT_FAILURE(test, "Register device failed: %d", ret); + KUNIT_FAIL_AND_ABORT(test, "Register device failed: %d", ret); } test->priv = input_dev; diff --git a/include/kunit/assert.h b/include/kunit/assert.h index 24c2b9fa61e8..9cc86a402c34 100644 --- a/include/kunit/assert.h +++ b/include/kunit/assert.h @@ -60,7 +60,7 @@ void kunit_assert_prologue(const struct kunit_loc *loc, * struct kunit_fail_assert - Represents a plain fail expectation/assertion. * @assert: The parent of this type. * - * Represents a simple KUNIT_FAIL/KUNIT_ASSERT_FAILURE that always fails. + * Represents a simple KUNIT_FAIL/KUNIT_FAIL_AND_ABORT that always fails. */ struct kunit_fail_assert { struct kunit_assert assert; diff --git a/include/kunit/test.h b/include/kunit/test.h index 87a232421089..774c42721412 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -1193,7 +1193,18 @@ do { \ fmt, \ ##__VA_ARGS__) -#define KUNIT_ASSERT_FAILURE(test, fmt, ...) \ +/** + * KUNIT_FAIL_AND_ABORT() - Always causes a test to fail and abort when evaluated. + * @test: The test context object. + * @fmt: an informational message to be printed when the assertion is made. + * @...: string format arguments. + * + * The opposite of KUNIT_SUCCEED(), it is an assertion that always fails. In + * other words, it always results in a failed assertion, and consequently + * always causes the test case to fail and abort when evaluated. + * See KUNIT_ASSERT_TRUE() for more information. + */ +#define KUNIT_FAIL_AND_ABORT(test, fmt, ...) \ KUNIT_FAIL_ASSERTION(test, KUNIT_ASSERTION, fmt, ##__VA_ARGS__) /** From patchwork Thu Jul 11 19:39:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Chan X-Patchwork-Id: 13731030 X-Patchwork-Delegate: brendanhiggins@google.com Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A36918732C for ; Thu, 11 Jul 2024 19:39:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720726794; cv=none; b=GVbiIJQQoWovRXW8BLDRVjSXFYBHDyC0A4g0iEDmuIYHZDFRvkAshMotY1kj68y9kkWMKqBywThr4+6mSbP32p0U9wSI74DMpoNZ38E2INLdjGkozlvV1KKXQwe7omFoc5Dm9xuH1pq7lxO73xoind4Mdx+KFrhRamaEkk8bwww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720726794; c=relaxed/simple; bh=6c9enNd5xXF7GHrH/1e8o7hHuPbsJhlGShC4QQsotxc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=E77bmgQo6hFC8hWvBOeA2VKA8l80tNaQCVydlrVSHy3+pplznkxWNgMTLkmYd1yQ8lIlKpWzJubtt6OuYsXqKGLqZ8ftaZfPFqiCuBmnPPOE2LnHvgndbAiJKLxbmE320q7ILZ5g6EewYM2AWUQQeMtTudFGgLfDvv/qd3n5UGE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ericchancf.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Fg5YMIR3; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ericchancf.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Fg5YMIR3" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e03a5534d58so1851619276.1 for ; Thu, 11 Jul 2024 12:39:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720726791; x=1721331591; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=XGX/U2MB6y0a+maZqAk3LokToAOteYrURf5ZQXwr7AQ=; b=Fg5YMIR3GvpHP4P6Lt0HMN9UZC3r7a5H0HJxlnaFY3V4fdXnehM/MrSyvTzermS98z /skwh3mZCEVMPk4+IU9fVmbD5uxxG5yLr1nndkxHf8ouRGgg973sSRIfOKwtOD/eAM20 KLv8lCG0mXCzZ4bwinxqkfIhP84iUk69hCR3qHv6sdYFXEXyimPQnIKYM0uqdPfFcF1a xykB4i7LaQnti8aDzbBb7dE8jAU0j+2YZbfljlwVMrLF2XrJBIkLjhiOegYHkC3CG537 AfZ9ly8pxMf1h7rLnZ693n5Mo3B+gqs0ahKM2Yg0FWvjxAbBsqRW6KumW00tACmIuZZn CP3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720726791; x=1721331591; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XGX/U2MB6y0a+maZqAk3LokToAOteYrURf5ZQXwr7AQ=; b=vXSM2FL51ZT9LP2Pf9Faevs+7v4+9adHxogX/nn00YLsLu/SX59ej7R3X8VgfY5GRX sTNPAHkaaenUo+L0ZG+y1sk9hVuKk6H2Nq6D8XQ0SUKhwC8v7AqsSrUZMVlJEpM95H1g sqzY9F0ThWZpbNhi7LlgJDj2Jaj5cMGklk7TYcY3dVPWp/jotkFDBSbEkJPQNupgBKNz i+g5tbw7PGLlyTO/v018vsmPFsNz5i5u6FiLOwTJhMRS7TbuxMULxcZLL9LbkAzrIHSf 4fs5lZ3sSZTVj2TO7qT4PZd3QD4ny3k5PodiZoU+EXWfnHp8My0JCERVAqkZuFX7d3LB q1jg== X-Gm-Message-State: AOJu0Yzl1PorQBQBQr5bodqBvCbBss79K8CCID55koLxO5FyeZKJD6Q2 TGxNYu+w9BOV4oOJX+AUWRtjtoXo3jjKcDaa5IAAiRmt3c2vsKuMiZnIO+RjNc0ahOazw60pB/Z HQ0+BQkwkzFg3iASuhA== X-Google-Smtp-Source: AGHT+IFQhBj+gG4iTlqi9n6jzYom//iTBl4rGE2Zd1V1Jd14gBb2JQb/Ng5vfq+MIw6tBclm4kGizOa0PjvJNpJl X-Received: from ericchancf.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:4139]) (user=ericchancf job=sendgmr) by 2002:a05:6902:722:b0:e02:8473:82c4 with SMTP id 3f1490d57ef6-e041b17715amr17667276.11.1720726791048; Thu, 11 Jul 2024 12:39:51 -0700 (PDT) Date: Thu, 11 Jul 2024 19:39:45 +0000 In-Reply-To: <20240711193729.108720-1-ericchancf@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240711193729.108720-1-ericchancf@google.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog Message-ID: <20240711193945.110170-1-ericchancf@google.com> Subject: [PATCH v2 3/3] kunit: Introduce KUNIT_ASSERT_MEMEQ and KUNIT_ASSERT_MEMNEQ macros From: Eric Chan To: brendan.higgins@linux.dev, davidgow@google.com, rmoar@google.com Cc: linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, ericchancf@google.com Introduces KUNIT_ASSERT_MEMEQ and KUNIT_ASSERT_MEMNEQ macros to provide assert-type equivalents for memory comparison. While KUNIT_EXPECT_MEMEQ and KUNIT_EXPECT_MEMNEQ are available for expectations, the addition of these new macros ensures that assertions can also be used for memory comparisons, enhancing the consistency and completeness of the kunit framework. Signed-off-by: Eric Chan Reviewed-by: David Gow --- include/kunit/test.h | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/include/kunit/test.h b/include/kunit/test.h index 774c42721412..67ad0e026bbf 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -1451,6 +1451,60 @@ do { \ fmt, \ ##__VA_ARGS__) +/** + * KUNIT_ASSERT_MEMEQ() - Asserts that the first @size bytes of @left and @right are equal. + * @test: The test context object. + * @left: An arbitrary expression that evaluates to the specified size. + * @right: An arbitrary expression that evaluates to the specified size. + * @size: Number of bytes compared. + * + * Sets an assertion that the values that @left and @right evaluate to are + * equal. This is semantically equivalent to + * KUNIT_ASSERT_TRUE(@test, !memcmp((@left), (@right), (@size))). See + * KUNIT_ASSERT_TRUE() for more information. + * + * Although this assertion works for any memory block, it is not recommended + * for comparing more structured data, such as structs. This assertion is + * recommended for comparing, for example, data arrays. + */ +#define KUNIT_ASSERT_MEMEQ(test, left, right, size) \ + KUNIT_ASSERT_MEMEQ_MSG(test, left, right, size, NULL) + +#define KUNIT_ASSERT_MEMEQ_MSG(test, left, right, size, fmt, ...) \ + KUNIT_MEM_ASSERTION(test, \ + KUNIT_ASSERTION, \ + left, ==, right, \ + size, \ + fmt, \ + ##__VA_ARGS__) + +/** + * KUNIT_ASSERT_MEMNEQ() - Asserts that the first @size bytes of @left and @right are not equal. + * @test: The test context object. + * @left: An arbitrary expression that evaluates to the specified size. + * @right: An arbitrary expression that evaluates to the specified size. + * @size: Number of bytes compared. + * + * Sets an assertion that the values that @left and @right evaluate to are + * not equal. This is semantically equivalent to + * KUNIT_ASSERT_TRUE(@test, memcmp((@left), (@right), (@size))). See + * KUNIT_ASSERT_TRUE() for more information. + * + * Although this assertion works for any memory block, it is not recommended + * for comparing more structured data, such as structs. This assertion is + * recommended for comparing, for example, data arrays. + */ +#define KUNIT_ASSERT_MEMNEQ(test, left, right, size) \ + KUNIT_ASSERT_MEMNEQ_MSG(test, left, right, size, NULL) + +#define KUNIT_ASSERT_MEMNEQ_MSG(test, left, right, size, fmt, ...) \ + KUNIT_MEM_ASSERTION(test, \ + KUNIT_ASSERTION, \ + left, !=, right, \ + size, \ + fmt, \ + ##__VA_ARGS__) + /** * KUNIT_ASSERT_NULL() - Asserts that pointers @ptr is null. * @test: The test context object.