From nobody Wed Dec 17 10:44:40 2025 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 158221922E3 for ; Wed, 10 Jul 2024 17:06:32 +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=1720631195; cv=none; b=LONXrYLPZjh11Sf23Kc6Hss0JdjwRZeJXyr+7nYaxVje2/aUaWKbr6eLSNudZqXluCQVr7hSXfShq68tJWjF/w37bjl9/kA71Sb39elp2logoqtuf9FqqNzCM8xJG0t0yys98zjhMl9iIMIUwI1WlwuehbctJ6mA+NAu6h83kjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720631195; c=relaxed/simple; bh=4wT2jC6PAkErIVyGGjb3mnQZSgwRN62Cp3V1tfbR5v0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=t61NcCKF3yUDRJMeTo/N//dPb64Y4Xream7z2Cr7tZE/jHAdouPRx0li9T+7V6UnhemmzR6RSUGi1uqtKnag83lFXDEq8S+qmuypZsXJ+U1QheosDxE6pgI3yJfSwggpUuAesr7owOhEAN0zTjQQ4xd2Y/Y0YJd9QBEYUnK78pU= 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=mCM42+K9; 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="mCM42+K9" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e0561513c21so975421276.0 for ; Wed, 10 Jul 2024 10:06:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720631192; x=1721235992; 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=0HbPsmQ0gN/q3U8COOHnxX2fTOdZkrHtTrBhyd2/ae4=; b=mCM42+K9eLzedGLr0PvjQ1xZ3Lw0rfCggM5MF85K8mdVB3zTA95unoZW2u+f5pN7n2 BvNSbD4psijHPVF4aUVyLxEoo8fPcWIr3Fmqd0ZYc3uEn7Yf/wRtFhVzRNq3M8Aygpre HkDQ14UZo7YczdMzPoZj2KMLx7EUpWYB5ihw2WrLjugcnMB8bq8uncXIbAtL2ZAUDCm0 1TpjA6JWeefqbn5rmdvcTqd5JSzzlnFr/BdUMN3LeAdUMTeMrjXdCmvBir/j8UuOV6fr t/soGLeZv6yli4c/waNaBxvlkjUzS6vlQbWfOKxe0of9twiWTMzvxZB1Veecz33qynWx dnFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720631192; x=1721235992; 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=0HbPsmQ0gN/q3U8COOHnxX2fTOdZkrHtTrBhyd2/ae4=; b=w5jeNUKOggu9T50LVywmdeUBB2LHkToZNvbiQAxNH9iMlGz7N2qzZPbDSMIr1Kvc+Z oOLBr+4GxtQJg2cltN0mKS4m+T9SfW83uoHXo8qS56bQ9HdBS72qSupyr9U3r0O8b1aj RTq9DJPuVoPt4N5ssfbEHx/U9mwEoj9YB1Cpy7TXkJQzGPPUKVCpBHN7XHvlo0ckPnHi KCyjDwwzQ5SRjpv9df+LhM8eDZDrmUCxL6rjGieftnElKTpNn5xN/Da0/pKPQ8WaEzgG /wIX7vVbYZKwMjAlr2dtVyL5XvKT9CrP8ObaT26bbJDzAUyyMYTaTPE55BI2HuA4dvUS 8e/Q== X-Forwarded-Encrypted: i=1; AJvYcCWqPVuPAnC7pIidVGo+gAkaKwUjQWKtNAjDk085FdcrJNT9WO2kkDBSuE0IS7j1V6xAx6nAFfYjnSAFi/PIc9AkbMBR3T0EUGruiceO X-Gm-Message-State: AOJu0YzWc2IUyY1kDChIcER37ZQpclrNsX7EeSMhtMNRRiq1hLiXDCyl nnpf1888UvaxbGKnXseb+QgJx9ur6XNw7VhffNfMVkNzg0ZaZ95IknZjKqaS0urTqI6mLgNIEh3 kWwVlNGAsIJpKh7D2YQ== X-Google-Smtp-Source: AGHT+IFrIOvkkPKpRQh+/bL3Bjds/gNme8/diuIke7SGwoMFYK93/GkFdth9JHVvr6t2O2es4BoqOqb855CwFjvG X-Received: from ericchancf.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:4139]) (user=ericchancf job=sendgmr) by 2002:a05:6902:1002:b0:e02:f35c:d398 with SMTP id 3f1490d57ef6-e0577cd7b4fmr5197276.0.1720631192033; Wed, 10 Jul 2024 10:06:32 -0700 (PDT) Date: Wed, 10 Jul 2024 17:06:25 +0000 In-Reply-To: <20240710170448.1399967-1-ericchancf@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240710170448.1399967-1-ericchancf@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240710170625.1400724-1-ericchancf@google.com> Subject: [PATCH 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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__) =20 /** - * KUNIT_ASSERT_STRNEQ() - Expects that strings @left and @right are not e= qual. + * 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 stri= ng. * @right: an arbitrary expression that evaluates to a null terminated str= ing. * - * Sets an expectation that the values that @left and @right evaluate to a= re + * 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_T= RUE() * for more information. --=20 2.45.2.803.g4e1b14247a-goog From nobody Wed Dec 17 10:44:40 2025 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 EE7DF195B33 for ; Wed, 10 Jul 2024 17:06:49 +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=1720631211; cv=none; b=psDz4MUKB9tcxgYymq+1FpJWgY2LFjtsJePXCLx1nX9e/4/nlN33jjg6rY8aHfdNnUs/ISqE0hi1SOMgWOUCCCfZ1W+jTKRv+w5zVEJLKdYEPfe2AQmeR653RE13Ez3wk92+ajmC//bJOCrf7q5LRLfG+Ii4Iy8+SjnhIybP198= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720631211; c=relaxed/simple; bh=55IgR9SW1v2kkYXqH0kYD4+uvDouI7DdE0FHu/jM0R0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=oJaB2mVsZArEXKz2YYEDGb60hcMYivcOoWXzoU9Ib9tiMrYGEGH1/qZ9goEB8lVgNjvoFP72NHTx45yYq9PMHOlztz3xj/MRSKdWf6m0LdGkB7K1mEtpjlwMqvl6neK307DHY62B78cYf8VQQVRs/QoRp0yRjkVAXTW00MvEU9Y= 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=B1Kg3oww; 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="B1Kg3oww" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e039fe0346eso11658344276.1 for ; Wed, 10 Jul 2024 10:06:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720631209; x=1721236009; 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=HEsXihW5jwk6/3bgpeafAIIwL8vXDyFBDI7gKiAkO+8=; b=B1Kg3owwOJCFLyekFvKzfMGY0w4B0je/8/WbpfO5FBfAQOKPaga5/MtWoTbzYyH00/ bvQYSFYlDUrYtdna0vEYQB3rraVBlV8kPxp1i0Gwmh5ThKb5afdu795zvITSCU+mTD+p GLBBPg49AWnq7QNXMuJdqT0JmZ/I92Ml6Xyw0mhXetrxNDZf4Jyo6nwi7cA1kDfJciDT YSX3vnAJ1dBI05sx7Hvah+ZtIpMg4WU0HwaSKn93viCEwsJe8wdN8IlWTIgn3ocKO7e5 CmP4YcJDXW+s5ZGDVuS6+OphI2lzzK086LRGFWWNJdxuJ2YckFvg5Qx0sv3nBlhCgJ8G zobA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720631209; x=1721236009; 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=HEsXihW5jwk6/3bgpeafAIIwL8vXDyFBDI7gKiAkO+8=; b=vCcFOdWTNqhVUG5e5cQYWoSZ/jzPSvMyqwZoBH3gVHABd4BT/TXPy0OJv4J5ls8DtO RVGE0i67mNp+XlrvKHSfoapav9B1WnKLZWL3AMHN+ptqyrTDIt2aWE1n1LQZYB6OuKdl 8MedN25DOow//d2pgDBJ1LoP1iU/NUVKmLXFNZYtQnehtWQLKpfCwGGcNUtJ7PkBnTBx LiUhLEKldXx/nCwa/j1uDQ8dQ1/+rrxWSryFtAXrHhFI5CtN3nBncKftUKD0tCkFo5wb vZ9zUPLjG9dciEdyWz46HUj/zEEVrficJyUHruyIS9JeydPhuU1IFkOhkI5gI95Ij11V nqpA== X-Forwarded-Encrypted: i=1; AJvYcCXI48q2ZZt7m8aVsDr1sPcPaXDF3copTvqoZU0gLvx9vMkKc6R4ZQlwenEMscXk4sN3HwzBDDwI9igj66UxszT0LT5Fruqtfx83csqJ X-Gm-Message-State: AOJu0Yy+wpwDS6cHvm7Z4fQIh88h/TGOGCbHb6MZyVFwkLQfUTbjfHKe 9C3tStxWvRjcQLNXjc8I5hq/0+zZfAzf/Y0mpjMV5lNJDYRg4ItnrnN88/RJ0pUmghvr+HEZPax iyttpNtbiBq7HQIGRJw== X-Google-Smtp-Source: AGHT+IEq/wR5+VeC8A5+fxYk+p1J3dHwGgRcpRCuVIqTPzMyO+vneMFxBdM5MYtCfrduY0GmcBLkw8kc8I7DT8vj X-Received: from ericchancf.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:4139]) (user=ericchancf job=sendgmr) by 2002:a05:6902:138d:b0:e02:c84e:61a3 with SMTP id 3f1490d57ef6-e041b05317bmr12250276.6.1720631209022; Wed, 10 Jul 2024 10:06:49 -0700 (PDT) Date: Wed, 10 Jul 2024 17:06:43 +0000 In-Reply-To: <20240710170448.1399967-1-ericchancf@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240710170448.1399967-1-ericchancf@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240710170643.1401358-1-ericchancf@google.com> Subject: [PATCH 2/3] kunit: Rename KUNIT_ASSERT_FAILURE to KUNIT_ASSERT 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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_ASSERT. Makes the naming consistent, with KUNIT_FAIL and KUNIT_ASSERT being symmetrical. Additionally, an explanation for KUNIT_ASSERT has been added to clarify its usage. Signed-off-by: Eric Chan --- 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_t= est.c index 2fa5b725ae0a..cbab24a265fa 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 =3D input_register_device(input_dev); if (ret) { input_free_device(input_dev); - KUNIT_ASSERT_FAILURE(test, "Register device failed: %d", ret); + KUNIT_ASSERT(test, "Register device failed: %d", ret); } =20 test->priv =3D input_dev; diff --git a/include/kunit/assert.h b/include/kunit/assert.h index 24c2b9fa61e8..02c6f7bb1d26 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/assertio= n. * @assert: The parent of this type. * - * Represents a simple KUNIT_FAIL/KUNIT_ASSERT_FAILURE that always fails. + * Represents a simple KUNIT_FAIL/KUNIT_ASSERT 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..d1b085fd5dc3 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -1193,7 +1193,18 @@ do { \ fmt, \ ##__VA_ARGS__) =20 -#define KUNIT_ASSERT_FAILURE(test, fmt, ...) \ +/** + * KUNIT_ASSERT() - Always causes a test to assert 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 assert when evaluated. See KUNIT_ASSERT_= TRUE() + * for more information. + */ +#define KUNIT_ASSERT(test, fmt, ...) \ KUNIT_FAIL_ASSERTION(test, KUNIT_ASSERTION, fmt, ##__VA_ARGS__) =20 /** --=20 2.45.2.803.g4e1b14247a-goog From nobody Wed Dec 17 10:44:40 2025 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 3D1A3194C6A for ; Wed, 10 Jul 2024 17:07:06 +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=1720631227; cv=none; b=rNBlMG3IrVVZAhqonl7gxwRx3nq0XZ9/Q+tu7K2aqQXiQ79mSwEi37mdr+kaHPZ/2blNVSwm9w/EFZ5GXPA5JSZxRcXN7ovqeEkc6aKPPc/ImEhur6YW+C+pNHfKaTMHG/+7+gADqlti+w9MvwitCf4erIFGaajySkSMHjSbR/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720631227; c=relaxed/simple; bh=i5uDpxJn8lGXZBfDUqgPSGzmiwpXROrGnB6v1/kDFNs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Cztc3ug+otj2Hd2zr7yyXtw7IxenVkW3XUgM7iHo1SWSEqRF79E3MZ9lO1FJdW0piZJTlGzs/Dd5Wv5ANBbI6t2wWIyC8T4WpsvwwtyAavQPrCHMeAdI/0Y89UWwySUoAWQhPXAFN+u2eHyFiYgHP4qqctCwyUDUr4sRLMMA3oQ= 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=pe4Ux1HZ; 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="pe4Ux1HZ" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-65026e6285eso106999867b3.3 for ; Wed, 10 Jul 2024 10:07:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720631225; x=1721236025; 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=rdXM5tSTVLgVD6pOaOrVugKKH4Crf9pI4FNGQGLq9Pw=; b=pe4Ux1HZBQKM9wRYlkAlqdgeBXGgDTYdGez68NrR/dLcPmDA253Qb1juYj7wrXVIsd xymBVjO5Si1YGXLyDfYCbTzKnZUcK166TOnXze9WUO5SZ6EWi7v6WZ9gGkVM+UzQStD4 C0lzCblSgdGJnzglwKFoPRY2uVRbs/Ocg0FS5lB0pjWoJodszoC8/P1AtRQLxVsbKIa6 gOStv+b9m813ESurN7FpjGrVAYQGMOqyfkK+PITmAltG7MTYhKy0I1ymt4fTIeJLpYn5 C3KJtrvGd79mg90hlP2DsHUPSUgsiWkXgFDwECt72IupH5j+W8HHKJ8KZQqc/tMXfubV 3uTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720631225; x=1721236025; 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=rdXM5tSTVLgVD6pOaOrVugKKH4Crf9pI4FNGQGLq9Pw=; b=uRbr2N8oN8oXBx7mC49vGmKKJXBoMPd1wMvyUMsE5Sv2q9tmvbHcLRo7+7AS1UXN6S HrzJ1sfqjnWSbx1IJI96b1p8+RHy69EQAjr6zytTxmt6gvht6/XReddT7bWCeXvswENz 5D4ELAj04VYiFJk560bIR5oaDkPQ9BfYPX0+NasSQ07Jt59ij6tEk1yVN4XoCwpIv+TT d4g/RWbUY+SO9cisNIxCfZ+/6pjKdYheGZe61F/etptnFr7G2tXjIG4skwnKoEpyToM+ 6LavQP3vzw41hTQOztHOlAT0wtZyTZVtIzvLvVVK8EawvBptR6sd8CUkyuBz+tZCXhn7 tYHQ== X-Forwarded-Encrypted: i=1; AJvYcCXKg4DbxSBRnJdovj0Y5mcks+NSZEUQZGdyScrax8fy8CL0r03Dciw0ZpE+xX+0KlAMee5g8bbXLp19IFYCfOlXBLnnrMjhsOwkXjlJ X-Gm-Message-State: AOJu0YzD60syNZZuuZ2OV4uwMxtEh7ZyYQ0MaKpXZI0h8b4zJy+JxAgr eXPHQuM3M0eXlfS8q+mlHSTnftGnVx/Fzs1UjOoNfDuokSCqoUhAtjqPDI/ZtZtOX0K47xD2QHU KM2MM08XhJuMhXiWLcw== X-Google-Smtp-Source: AGHT+IGgxHOkY64Jyi/bUvq82+S3Z45vzDAUlZ7FDf3Cmd4kyTEHEwajQRskDY6gPPrkHYUSfcHrOOeL6zQ8nFfq X-Received: from ericchancf.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:4139]) (user=ericchancf job=sendgmr) by 2002:a05:6902:2b0d:b0:e03:3cfa:1aa9 with SMTP id 3f1490d57ef6-e041b1134afmr14166276.8.1720631225297; Wed, 10 Jul 2024 10:07:05 -0700 (PDT) Date: Wed, 10 Jul 2024 17:06:59 +0000 In-Reply-To: <20240710170448.1399967-1-ericchancf@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240710170448.1399967-1-ericchancf@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240710170659.1402746-1-ericchancf@google.com> Subject: [PATCH 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 d1b085fd5dc3..52bd50d2b150 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -1451,6 +1451,60 @@ do { \ fmt, \ ##__VA_ARGS__) =20 +/** + * 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 recommend= ed + * 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, =3D=3D, 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 recommend= ed + * 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, !=3D, right, \ + size, \ + fmt, \ + ##__VA_ARGS__) + /** * KUNIT_ASSERT_NULL() - Asserts that pointers @ptr is null. * @test: The test context object. --=20 2.45.2.803.g4e1b14247a-goog