public inbox for linux-arm-kernel@lists.infradead.org 
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst•de>
To: Andrew Morton <akpm@linux-foundation•org>
Cc: Catalin Marinas <catalin.marinas@arm•com>,
	Will Deacon <will@kernel•org>, Ard Biesheuvel <ardb@kernel•org>,
	Huacai Chen <chenhuacai@kernel•org>,
	WANG Xuerui <kernel@xen0n•name>,
	Madhavan Srinivasan <maddy@linux•ibm.com>,
	Michael Ellerman <mpe@ellerman•id.au>,
	Nicholas Piggin <npiggin@gmail•com>,
	"Christophe Leroy (CS GROUP)" <chleroy@kernel•org>,
	Paul Walmsley <pjw@kernel•org>,
	Palmer Dabbelt <palmer@dabbelt•com>,
	Albert Ou <aou@eecs•berkeley.edu>,
	Alexandre Ghiti <alex@ghiti•fr>,
	Heiko Carstens <hca@linux•ibm.com>,
	Vasily Gorbik <gor@linux•ibm.com>,
	Alexander Gordeev <agordeev@linux•ibm.com>,
	Christian Borntraeger <borntraeger@linux•ibm.com>,
	Sven Schnelle <svens@linux•ibm.com>,
	Thomas Gleixner <tglx@kernel•org>, Ingo Molnar <mingo@redhat•com>,
	Borislav Petkov <bp@alien8•de>,
	Dave Hansen <dave.hansen@linux•intel.com>,
	x86@kernel•org, "H. Peter Anvin" <hpa@zytor•com>,
	Herbert Xu <herbert@gondor•apana.org.au>,
	Dan Williams <dan.j.williams@intel•com>, Chris Mason <clm@fb•com>,
	David Sterba <dsterba@suse•com>, Arnd Bergmann <arnd@arndb•de>,
	Song Liu <song@kernel•org>, Yu Kuai <yukuai@fnnas•com>,
	Li Nan <linan122@huawei•com>,
	linux-kernel@vger•kernel.org,
	linux-arm-kernel@lists•infradead.org, loongarch@lists•linux.dev,
	linuxppc-dev@lists•ozlabs.org, linux-riscv@lists•infradead.org,
	linux-s390@vger•kernel.org, linux-crypto@vger•kernel.org,
	linux-btrfs@vger•kernel.org, linux-arch@vger•kernel.org,
	linux-raid@vger•kernel.org
Subject: [PATCH 14/19] raid6_kunit: use KUNIT_CASE_PARAM
Date: Tue, 12 May 2026 07:20:54 +0200	[thread overview]
Message-ID: <20260512052230.2947683-15-hch@lst.de> (raw)
In-Reply-To: <20260512052230.2947683-1-hch@lst.de>

The raid6 test combines various generation and recovery algorithms.  Use
KUNIT_CASE_PARAM and provide a generator that iterates over the possible
combinations instead of looping inside a single test instance.

Signed-off-by: Christoph Hellwig <hch@lst•de>
---
 lib/raid/raid6/tests/raid6_kunit.c | 120 ++++++++++++++++-------------
 1 file changed, 68 insertions(+), 52 deletions(-)

diff --git a/lib/raid/raid6/tests/raid6_kunit.c b/lib/raid/raid6/tests/raid6_kunit.c
index daaa28e96ff1..f55b081b6b13 100644
--- a/lib/raid/raid6/tests/raid6_kunit.c
+++ b/lib/raid/raid6/tests/raid6_kunit.c
@@ -21,6 +21,15 @@ static char data[NDISKS][PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
 static char recovi[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
 static char recovj[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
 
+struct test_args {
+	unsigned int recov_idx;
+	const struct raid6_recov_calls *recov;
+	unsigned int gen_idx;
+	const struct raid6_calls *gen;
+};
+
+static struct test_args args;
+
 static void makedata(int start, int stop)
 {
 	int i;
@@ -43,9 +52,10 @@ static char member_type(int d)
 	}
 }
 
-static void test_disks(struct kunit *test, const struct raid6_calls *calls,
-		const struct raid6_recov_calls *ra, int faila, int failb)
+static void test_recover(struct kunit *test, int faila, int failb)
 {
+	const struct test_args *ta = test->param_value;
+
 	memset(recovi, 0xf0, PAGE_SIZE);
 	memset(recovj, 0xba, PAGE_SIZE);
 
@@ -61,25 +71,23 @@ static void test_disks(struct kunit *test, const struct raid6_calls *calls,
 			goto skip;
 
 		/* P+Q failure.  Just rebuild the syndrome. */
-		calls->gen_syndrome(NDISKS, PAGE_SIZE, dataptrs);
+		ta->gen->gen_syndrome(NDISKS, PAGE_SIZE, dataptrs);
 	} else if (failb == NDISKS - 2) {
 		/* data+P failure. */
-		ra->datap(NDISKS, PAGE_SIZE, faila, dataptrs);
+		ta->recov->datap(NDISKS, PAGE_SIZE, faila, dataptrs);
 	} else {
 		/* data+data failure. */
-		ra->data2(NDISKS, PAGE_SIZE, faila, failb, dataptrs);
+		ta->recov->data2(NDISKS, PAGE_SIZE, faila, failb, dataptrs);
 	}
 
 	KUNIT_EXPECT_MEMEQ_MSG(test, data[faila], recovi, PAGE_SIZE,
-		"algo=%-8s/%-8s faila miscompared: %3d[%c] (failb=%3d[%c])\n",
-	       calls->name, ra->name,
-	       faila, member_type(faila),
-	       failb, member_type(failb));
+			"faila miscompared: %3d[%c] (failb=%3d[%c])\n",
+			faila, member_type(faila),
+			failb, member_type(failb));
 	KUNIT_EXPECT_MEMEQ_MSG(test, data[failb], recovj, PAGE_SIZE,
-		"algo=%-8s/%-8s failb miscompared: %3d[%c] (faila=%3d[%c])\n",
-	       calls->name, ra->name,
-	       failb, member_type(failb),
-	       faila, member_type(faila));
+			"failb miscompared: %3d[%c] (faila=%3d[%c])\n",
+			failb, member_type(failb),
+			faila, member_type(faila));
 
 skip:
 	dataptrs[faila] = data[faila];
@@ -88,58 +96,66 @@ static void test_disks(struct kunit *test, const struct raid6_calls *calls,
 
 static void raid6_test(struct kunit *test)
 {
+	const struct test_args *ta = test->param_value;
 	int i, j, p1, p2;
-	unsigned int r, g;
-
-	for (r = 0; ; r++) {
-		const struct raid6_recov_calls *ra = raid6_recov_algo_find(r);
-
-		if (!ra)
-			break;
-
-		for (g = 0; ; g++) {
-			const struct raid6_calls *calls = raid6_algo_find(g);
-
-			if (!calls)
-				break;
 
-			/* Nuke syndromes */
-			memset(data[NDISKS - 2], 0xee, PAGE_SIZE);
-			memset(data[NDISKS - 1], 0xee, PAGE_SIZE);
+	/* Nuke syndromes */
+	memset(data[NDISKS - 2], 0xee, PAGE_SIZE);
+	memset(data[NDISKS - 1], 0xee, PAGE_SIZE);
 
-			/* Generate assumed good syndrome */
-			calls->gen_syndrome(NDISKS, PAGE_SIZE,
-						(void **)&dataptrs);
+	/* Generate assumed good syndrome */
+	ta->gen->gen_syndrome(NDISKS, PAGE_SIZE, (void **)&dataptrs);
 
-			for (i = 0; i < NDISKS-1; i++)
-				for (j = i+1; j < NDISKS; j++)
-					test_disks(test, calls, ra, i, j);
+	for (i = 0; i < NDISKS - 1; i++)
+		for (j = i + 1; j < NDISKS; j++)
+			test_recover(test, i, j);
 
-			if (!calls->xor_syndrome)
-				continue;
+	if (!ta->gen->xor_syndrome)
+		return;
 
-			for (p1 = 0; p1 < NDISKS-2; p1++)
-				for (p2 = p1; p2 < NDISKS-2; p2++) {
+	for (p1 = 0; p1 < NDISKS - 2; p1++) {
+		for (p2 = p1; p2 < NDISKS - 2; p2++) {
+			/* Simulate rmw run */
+			ta->gen->xor_syndrome(NDISKS, p1, p2, PAGE_SIZE,
+					(void **)&dataptrs);
+			makedata(p1, p2);
+			ta->gen->xor_syndrome(NDISKS, p1, p2, PAGE_SIZE,
+					(void **)&dataptrs);
 
-					/* Simulate rmw run */
-					calls->xor_syndrome(NDISKS, p1, p2, PAGE_SIZE,
-								(void **)&dataptrs);
-					makedata(p1, p2);
-					calls->xor_syndrome(NDISKS, p1, p2, PAGE_SIZE,
-                                                                (void **)&dataptrs);
+			for (i = 0; i < NDISKS - 1; i++)
+				for (j = i + 1; j < NDISKS; j++)
+					test_recover(test, i, j);
+		}
+	}
+}
 
-					for (i = 0; i < NDISKS-1; i++)
-						for (j = i+1; j < NDISKS; j++)
-							test_disks(test, calls,
-									ra, i, j);
-				}
+static const void *raid6_gen_params(struct kunit *test, const void *prev,
+		char *desc)
+{
+	if (!prev) {
+		memset(&args, 0, sizeof(args));
+next_algo:
+		args.recov_idx = 0;
+		args.gen = raid6_algo_find(args.gen_idx);
+		if (!args.gen)
+			return NULL;
+	}
 
-		}
+	if (args.recov)
+		args.recov_idx++;
+	args.recov = raid6_recov_algo_find(args.recov_idx);
+	if (!args.recov) {
+		args.gen_idx++;
+		goto next_algo;
 	}
+
+	snprintf(desc, KUNIT_PARAM_DESC_SIZE, "gen=%s recov=%s",
+			args.gen->name, args.recov->name);
+	return &args;
 }
 
 static struct kunit_case raid6_test_cases[] = {
-	KUNIT_CASE(raid6_test),
+	KUNIT_CASE_PARAM(raid6_test, raid6_gen_params),
 	{},
 };
 
-- 
2.53.0



  parent reply	other threads:[~2026-05-12  5:25 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-12  5:20 cleanup the RAID6 P/Q library v2 Christoph Hellwig
2026-05-12  5:20 ` [PATCH 01/19] btrfs: require at least 4 devices for RAID 6 Christoph Hellwig
2026-05-12 11:42   ` David Sterba
2026-05-13  5:47     ` Christoph Hellwig
2026-05-13 20:19       ` David Sterba
2026-05-14 19:51       ` Goffredo Baroncelli
2026-05-14 19:57         ` H. Peter Anvin
2026-05-15  4:37           ` Christoph Hellwig
2026-05-15 14:51           ` David Sterba
2026-05-15  4:37         ` Christoph Hellwig
2026-05-15 16:50           ` Goffredo Baroncelli
2026-05-15 19:59           ` H. Peter Anvin
2026-05-18  5:12             ` Christoph Hellwig
2026-05-20  8:41               ` Qu Wenruo
2026-05-22  0:17                 ` Andrew Morton
2026-05-22  0:27                   ` Qu Wenruo
2026-05-13 16:14   ` H. Peter Anvin
2026-05-12  5:20 ` [PATCH 02/19] raid6: turn the userspace test harness into a kunit test Christoph Hellwig
2026-05-12  5:20 ` [PATCH 03/19] raid6: remove __KERNEL__ ifdefs Christoph Hellwig
2026-05-12  5:20 ` [PATCH 04/19] raid6: move to lib/raid/ Christoph Hellwig
2026-05-12  5:20 ` [PATCH 05/19] raid6: remove unused defines in pq.h Christoph Hellwig
2026-05-12  5:20 ` [PATCH 06/19] raid6: remove raid6_get_zero_page Christoph Hellwig
2026-05-12  5:20 ` [PATCH 07/19] raid6: use named initializers for struct raid6_calls Christoph Hellwig
2026-05-12  5:20 ` [PATCH 08/19] raid6: improve the public interface Christoph Hellwig
2026-05-12  5:20 ` [PATCH 09/19] raid6: hide internals Christoph Hellwig
2026-05-12  5:20 ` [PATCH 10/19] raid6: rework the init helpers Christoph Hellwig
2026-05-12  5:20 ` [PATCH 11/19] raid6: use static_call for gen_syndrom and xor_syndrom Christoph Hellwig
2026-05-12  5:20 ` [PATCH 12/19] raid6: use static_call for raid6_recov_2data and raid6_recov_datap Christoph Hellwig
2026-05-12  5:20 ` [PATCH 13/19] raid6: update top of file comments Christoph Hellwig
2026-05-12  5:20 ` Christoph Hellwig [this message]
2026-05-12  5:20 ` [PATCH 15/19] raid6_kunit: dynamically allocate data buffers using vmalloc Christoph Hellwig
2026-05-12  5:20 ` [PATCH 16/19] raid6_kunit: cleanup dataptr handling Christoph Hellwig
2026-05-12  5:20 ` [PATCH 17/19] raid6_kunit: randomize parameters and increase limits Christoph Hellwig
2026-05-12  5:20 ` [PATCH 18/19] " Christoph Hellwig
2026-05-12  5:20 ` [PATCH 19/19] raid6_kunit: randomize buffer alignment Christoph Hellwig
2026-05-12  9:50 ` cleanup the RAID6 P/Q library v2 Ard Biesheuvel

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=20260512052230.2947683-15-hch@lst.de \
    --to=hch@lst$(echo .)de \
    --cc=agordeev@linux$(echo .)ibm.com \
    --cc=akpm@linux-foundation$(echo .)org \
    --cc=alex@ghiti$(echo .)fr \
    --cc=aou@eecs$(echo .)berkeley.edu \
    --cc=ardb@kernel$(echo .)org \
    --cc=arnd@arndb$(echo .)de \
    --cc=borntraeger@linux$(echo .)ibm.com \
    --cc=bp@alien8$(echo .)de \
    --cc=catalin.marinas@arm$(echo .)com \
    --cc=chenhuacai@kernel$(echo .)org \
    --cc=chleroy@kernel$(echo .)org \
    --cc=clm@fb$(echo .)com \
    --cc=dan.j.williams@intel$(echo .)com \
    --cc=dave.hansen@linux$(echo .)intel.com \
    --cc=dsterba@suse$(echo .)com \
    --cc=gor@linux$(echo .)ibm.com \
    --cc=hca@linux$(echo .)ibm.com \
    --cc=herbert@gondor$(echo .)apana.org.au \
    --cc=hpa@zytor$(echo .)com \
    --cc=kernel@xen0n$(echo .)name \
    --cc=linan122@huawei$(echo .)com \
    --cc=linux-arch@vger$(echo .)kernel.org \
    --cc=linux-arm-kernel@lists$(echo .)infradead.org \
    --cc=linux-btrfs@vger$(echo .)kernel.org \
    --cc=linux-crypto@vger$(echo .)kernel.org \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=linux-raid@vger$(echo .)kernel.org \
    --cc=linux-riscv@lists$(echo .)infradead.org \
    --cc=linux-s390@vger$(echo .)kernel.org \
    --cc=linuxppc-dev@lists$(echo .)ozlabs.org \
    --cc=loongarch@lists$(echo .)linux.dev \
    --cc=maddy@linux$(echo .)ibm.com \
    --cc=mingo@redhat$(echo .)com \
    --cc=mpe@ellerman$(echo .)id.au \
    --cc=npiggin@gmail$(echo .)com \
    --cc=palmer@dabbelt$(echo .)com \
    --cc=pjw@kernel$(echo .)org \
    --cc=song@kernel$(echo .)org \
    --cc=svens@linux$(echo .)ibm.com \
    --cc=tglx@kernel$(echo .)org \
    --cc=will@kernel$(echo .)org \
    --cc=x86@kernel$(echo .)org \
    --cc=yukuai@fnnas$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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