Linux Documentation
 help / color / mirror / Atom feed
From: Mark <broonie@kernel.org>
To: Simon Trimmer <simont@opensource.cirrus.com>,
	 Charles Keepax <ckeepax@opensource.cirrus.com>,
	 Richard Fitzgerald <rf@opensource.cirrus.com>,
	 Brendan Higgins <brendan.higgins@linux.dev>,
	David Gow <david@davidgow.net>,  Rae Moar <raemoar63@gmail.com>,
	Jonathan Corbet <corbet@lwn.net>,
	 Shuah Khan <skhan@linuxfoundation.org>,
	 Randy Dunlap <rdunlap@infradead.org>,
	Theodore Ts'o <tytso@mit.edu>,
	 Andreas Dilger <adilger.kernel@dilger.ca>,
	 Baokun Li <libaokun@linux.alibaba.com>, Jan Kara <jack@suse.cz>,
	 Ojaswin Mujoo <ojaswin@linux.ibm.com>,
	 "Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
	 Zhang Yi <yi.zhang@huawei.com>,
	David Rhodes <david.rhodes@cirrus.com>,
	 Liam Girdwood <lgirdwood@gmail.com>,
	Jaroslav Kysela <perex@perex.cz>,  Takashi Iwai <tiwai@suse.com>
Cc: patches@opensource.cirrus.com, linux-kernel@vger.kernel.org,
	 linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
	 linux-doc@vger.kernel.org, linux-ext4@vger.kernel.org,
	 linux-sound@vger.kernel.org, Mark Brown <broonie@kernel.org>
Subject: [PATCH 2/9] kunit: Add KUNIT_CASE_PARAM_UNIQUE() and KUNIT_CASE_PARAM_WITH_INIT_UNIQUE()
Date: Tue, 13 Oct 2026 00:10:12 +0100	[thread overview]
Message-ID: <20261013-kunit-param-names-v1-2-4b22ec5b85b9@kernel.org> (raw)
In-Reply-To: <20261013-kunit-param-names-v1-0-4b22ec5b85b9@kernel.org>

KUNIT_CASE_PARAM() and KUNIT_CASE_PARAM_WITH_INIT() name the test case
after the test function. Several suites reuse one test function with
more than one parameter generator or param_init() function, listing it
once per set of parameters, which leads to multiple tests being created
with the same name. Same-named cases cannot be told apart in the results
and cannot be selected individually with kunit.filter_glob=, so kunit.py
--run_isolated=test boots a kernel for every entry and each kernel runs
all of the same-named cases.

We could fix this by having the KUNIT_CASE_PARAM() macros always include
the parameter name but this would not only rename all existing users but
also result in some awkwardly named tests. Instead introduce some new
macros for use in cases where we need to disambiguate.

Add KUNIT_CASE_PARAM_UNIQUE() and KUNIT_CASE_PARAM_WITH_INIT_UNIQUE()
which behave identically to the existing macros but include the name of
the parameter generator or the param_init() function in the name of
the case, giving names such as sha1_test-sha1_gen_params. The
param_init() function is used for the WITH_INIT variant since currently
all the tests which register parameter arrays from param_init() all
share the generic kunit_array_gen_params() generator.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 Documentation/dev-tools/kunit/usage.rst |  9 ++++++++
 include/kunit/test.h                    | 41 +++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-tools/kunit/usage.rst
index 1c78dfff94e8..193233fd2925 100644
--- a/Documentation/dev-tools/kunit/usage.rst
+++ b/Documentation/dev-tools/kunit/usage.rst
@@ -662,6 +662,15 @@ Custom Parameter Generator Function:
    You can pass the generator function to the ``KUNIT_CASE_PARAM``
    or ``KUNIT_CASE_PARAM_WITH_INIT`` macros.
 
+   These macros name the test case after the test function. If the same test
+   function is listed in a suite with more than one generator (or, for
+   ``KUNIT_CASE_PARAM_WITH_INIT``, more than one ``param_init()`` function)
+   use ``KUNIT_CASE_PARAM_UNIQUE`` or ``KUNIT_CASE_PARAM_WITH_INIT_UNIQUE``
+   instead. These also include the name of the generator or ``param_init()``
+   function in the test case name, for example ``sha1_test-sha1_gen_params``,
+   so that each case has a distinct name which can be selected with
+   ``kunit.filter_glob=``.
+
    The function receives the previously generated parameter as the ``prev`` argument
    (which is ``NULL`` on the first call) and can also access the parameterized
    test context passed as the ``test`` argument. KUnit calls this function
diff --git a/include/kunit/test.h b/include/kunit/test.h
index da5312e0dfa5..e43f5e007f20 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -209,6 +209,24 @@ static inline char *kunit_status_to_ok_not_ok(enum kunit_status status)
 		{ .run_case = test_name, .name = #test_name,	\
 		  .generate_params = gen_params, .module_name = KBUILD_MODNAME}
 
+/**
+ * KUNIT_CASE_PARAM_UNIQUE - A helper for creating a parameterized &struct
+ * kunit_case named after both the test and its parameter generator
+ *
+ * @test_name: a reference to a test case function.
+ * @gen_params: a reference to a parameter generator function.
+ *
+ * Identical to KUNIT_CASE_PARAM() except that the case is named
+ * "test_name-gen_params" rather than "test_name". Use this when the same
+ * test function is listed in a suite with more than one parameter generator,
+ * where KUNIT_CASE_PARAM() would give every instance the same name. Test
+ * names must be unique within a suite for the results to be unambiguous and
+ * for filters such as kunit.filter_glob= to be able to select a single case.
+ */
+#define KUNIT_CASE_PARAM_UNIQUE(test_name, gen_params)				\
+		{ .run_case = test_name, .name = #test_name "-" #gen_params,	\
+		  .generate_params = gen_params, .module_name = KBUILD_MODNAME}
+
 /**
  * KUNIT_CASE_PARAM_ATTR - A helper for creating a parameterized &struct
  * kunit_case with attributes
@@ -248,6 +266,29 @@ static inline char *kunit_status_to_ok_not_ok(enum kunit_status status)
 		  .param_init = init, .param_exit = exit,			\
 		  .module_name = KBUILD_MODNAME}
 
+/**
+ * KUNIT_CASE_PARAM_WITH_INIT_UNIQUE - Define a parameterized KUnit test case
+ * with custom param_init() and param_exit() functions, named after both the
+ * test and its param_init() function.
+ * @test_name: The function implementing the test case.
+ * @gen_params: The function to generate parameters for the test case.
+ * @init: A reference to the param_init() function to run before a parameterized test.
+ * @exit: A reference to the param_exit() function to run after a parameterized test.
+ *
+ * Identical to KUNIT_CASE_PARAM_WITH_INIT() except that the case is named
+ * "test_name-init" rather than "test_name". Use this when the same test
+ * function is listed in a suite with more than one param_init() function,
+ * where KUNIT_CASE_PARAM_WITH_INIT() would give every instance the same
+ * name. The param_init() function is used rather than the generator since
+ * tests registering parameter arrays in param_init() all share the generic
+ * kunit_array_gen_params() generator.
+ */
+#define KUNIT_CASE_PARAM_WITH_INIT_UNIQUE(test_name, gen_params, init, exit)	\
+		{ .run_case = test_name, .name = #test_name "-" #init,		\
+		  .generate_params = gen_params,				\
+		  .param_init = init, .param_exit = exit,			\
+		  .module_name = KBUILD_MODNAME}
+
 /**
  * struct kunit_suite - describes a related collection of &struct kunit_case
  *

-- 
2.47.3


  parent reply	other threads:[~2026-10-12 23:12 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 23:10 [PATCH 0/9] kunit: Add KUNIT_CASE_PARAM_UNIQUE() and KUNIT_CASE_PARAM_WITH_INIT_UNIQUE() Mark
2026-10-12 23:10 ` [PATCH 1/9] firmware: cs_dsp: Run the wmfw payload error tests with invalid block types Mark
2026-10-13  9:17   ` Richard Fitzgerald
2026-10-12 23:10 ` Mark [this message]
2026-10-12 23:10 ` [PATCH 3/9] ext4: Give the extents KUnit cases distinct names Mark
2026-10-12 23:10 ` [PATCH 4/9] firmware: cs_dsp: Give the control read/write " Mark
2026-10-13  9:49   ` Richard Fitzgerald
2026-10-12 23:10 ` [PATCH 5/9] firmware: cs_dsp: Give the control cache " Mark
2026-10-13  9:55   ` Richard Fitzgerald
2026-10-12 23:10 ` [PATCH 6/9] firmware: cs_dsp: Give the wmfw block error " Mark
2026-10-13  9:58   ` Richard Fitzgerald
2026-10-12 23:10 ` [PATCH 7/9] firmware: cs_dsp: Give the bin file " Mark
2026-10-13 10:10   ` Richard Fitzgerald
2026-10-12 23:10 ` [PATCH 8/9] ASoC: cs35l56: Give the speaker ID pad config " Mark Brown
2026-10-13  9:51   ` Richard Fitzgerald
2026-10-12 23:10 ` [PATCH 9/9] ASoC: wm_adsp: Give the firmware search order " Mark
2026-10-13  9:19   ` Richard Fitzgerald

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261013-kunit-param-names-v1-2-4b22ec5b85b9@kernel.org \
    --to=broonie@kernel.org \
    --cc=adilger.kernel@dilger.ca \
    --cc=brendan.higgins@linux.dev \
    --cc=ckeepax@opensource.cirrus.com \
    --cc=corbet@lwn.net \
    --cc=david.rhodes@cirrus.com \
    --cc=david@davidgow.net \
    --cc=jack@suse.cz \
    --cc=kunit-dev@googlegroups.com \
    --cc=lgirdwood@gmail.com \
    --cc=libaokun@linux.alibaba.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=ojaswin@linux.ibm.com \
    --cc=patches@opensource.cirrus.com \
    --cc=perex@perex.cz \
    --cc=raemoar63@gmail.com \
    --cc=rdunlap@infradead.org \
    --cc=rf@opensource.cirrus.com \
    --cc=ritesh.list@gmail.com \
    --cc=simont@opensource.cirrus.com \
    --cc=skhan@linuxfoundation.org \
    --cc=tiwai@suse.com \
    --cc=tytso@mit.edu \
    --cc=yi.zhang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox