From nobody Sun Feb 8 12:14:47 2026 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 7930817A2EA for ; Sun, 21 Dec 2025 13:36:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766324196; cv=none; b=NA/RAeZAxpX1YEZt0S7btUT1AiZOFViSwYbJWxKQa2mTRDSfxHyNjAlYN0qZjrsC3QPo60YWSELOfFgN0dndt364MGc5XsZ2ZSaV1sa/2wk0o0hqUCC05+GG1FQJ/e7H2rkqE/BANnfQoLxLPrbih8ZjrSDhuWh0UZ/MXLbjNyw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766324196; c=relaxed/simple; bh=FF67CIKQ4pWzbg5PDRQMTb0+aU2oIxQgJm56RZuIRhY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=SNkKyDuo0gzHVb7tti/txF1qcwV+HCGqYlZDpG4xe0Am8FvK/wNtH47uNVby1lWorIgjc10q47zBN6FJmiCiZMMywDm/nqScdH1nr67RCb2nDq77bQb0zKDqDR/ktpQASH8vk5n+bh1zJD0p+bVtKNr4qBLjHZzaK0uI6Rzxe1M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VPTGPzqU; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VPTGPzqU" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2a12ebe4b74so54393475ad.0 for ; Sun, 21 Dec 2025 05:36:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766324193; x=1766928993; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Iz05lrFDHX7bPnXxoen6Rj9JfUGpg3+qlcHztXx2BwM=; b=VPTGPzqUxpMhbw5nfkLQF7oks8AeookaphLOpnWJn1SEJd+xTEE6ieNT7RTMVGWn6M aURZweEWSt9fRR9TPRADXI5dOpmQIgWVTbS69+JPDghMSkMAiX8gtVRXhRjqJL5tMzpD GuFrF7AQZW9dJ9qSFVTk1Cg9mHZ0EPcmDMhBBfaEpm0U1iLdKB+ye6AocFo6bqyvEh7j 3mL48JTgCIWQucmQG0vp8n2JDpGsJ+4J05V9gUoKkcGgijPaAWbOP0m6qpbek2BXpAMW JzSXVyRHeYztBs8+NtT1n4Xn2Qtb0/tlZuvVH2Mv1p/ljLS5txRJyV1okZnq/O5sPPus g/iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766324193; x=1766928993; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Iz05lrFDHX7bPnXxoen6Rj9JfUGpg3+qlcHztXx2BwM=; b=VF6i64Psks4v6jKBklF2YkXFdS2flKBgCvcwiyONJtRL9KxeH+r+rvbsYBpzoPCPZm hRbueU1lOf2vIh6hO1XQ6IuCXWVT+z7l7GkI8MWrlN5zW76F3VtHeSmbo0PcP3H+2zIq RB5QHNL9MCeAe2MMoU/p1Kv7eGj+mxcsbo3tLV8p2XRtVZkKlWCVMnwG96TlgE2S1ppK mnABLwPXZGWLEzIMX1EKwwUq1kUFs8QSspOG6MljZ2485SbsBwu4eZo3Ids6nW/4EmE2 1+eBa63r0DBwpwpgEh9lwuQWp2IxoHjHhNiJSXq9h4yrXH2ZhCg0k1RYQ8TYNvn5tiy5 STGQ== X-Forwarded-Encrypted: i=1; AJvYcCV/c8djWcMEUY5X+Uob82oaoktUhVER8ztbs60GqRD3u8/uJ5fgcgQsTOzeABGtdbFsmOhUrJ4qVstVGbU=@vger.kernel.org X-Gm-Message-State: AOJu0YxxY852VCAJt3xppJ4R0kyocrOdWbGMfXZzLFEdl+I1Ljd20vao P687pDwqaN2TG79g/ULV2wp+ZY/TV8hU4F1/XC1g3qvDPv5ZZWzvPp9Z X-Gm-Gg: AY/fxX5Gpl7I49tzr4vvJ2JuT1VQsITGtTDxqqQMus49VK7swOMqINgoWD7qh1SycJc mQTesdzFlMmchQKgJwVVxvB/b/vyqYeUqIvS2vcnyTEYubcQi5PsUlSTj9sny5WgQ0PCLn2cTcg xg6i2deEgdkSPkoZ2129WGSO1VSukYoZ29V66av9AO7PWUef4eJoHYKhxO8NpHe3elzmax4J1/I XsQ5aVJ2LB7OhvfP3nqPcSvzFxCnSph2cNmRJyN6OMZ1yuxvTJ+H3N81QimmyOt5LYfPS9B1ZYN GuKBpjbni6qvKum2h8G7QluioAEh6WREbiXk/9Q/HIPb9XyjW9YY4QFWOt5GrQlDo9EFQhQ5tsC Lbea27H0XBfwUFhN7mKATEw5rff5jT3ZhWEaSr0hrMA3pUsoR5DjdyKPUZyFCEHMdXqmTOui4Gm LalSL5AoG6520ijUZ42tdB2+GCmAt3oxB4Jp4R5w== X-Google-Smtp-Source: AGHT+IFf0RO86X/m3ILt7yy6ehJhGgGb5NvrJ9JBs31jrQ7MpiAb436tkfk11gSxNySPm18eskHt/Q== X-Received: by 2002:a17:902:f542:b0:2a0:c20e:e4d6 with SMTP id d9443c01a7336-2a2f283de1amr74717455ad.39.1766324192384; Sun, 21 Dec 2025 05:36:32 -0800 (PST) Received: from localhost.localdomain ([210.228.119.9]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a2f3c66629sm72037955ad.14.2025.12.21.05.36.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Dec 2025 05:36:31 -0800 (PST) From: Ryota Sakamoto To: Andrew Morton Cc: Kuan-Wei Chiu , Geert Uytterhoeven , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , David Gow , linux-kernel@vger.kernel.org, Ryota Sakamoto Subject: [PATCH] lib/tests: convert test_min_heap module to KUnit Date: Sun, 21 Dec 2025 13:35:16 +0000 Message-Id: <20251221133516.321846-1-sakamo.ryota@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move lib/test_min_heap.c to lib/tests/min_heap_kunit.c and convert it to use KUnit. This change switches the ad-hoc test code to standard KUnit test cases. The test data remains the same, but the verification logic is updated to use KUNIT_EXPECT_* macros. Also remove CONFIG_TEST_MIN_HEAP from arch/*/configs/* because it is no longer used. The new CONFIG_MIN_HEAP_KUNIT_TEST will be automatically enabled by CONFIG_KUNIT_ALL_TESTS. Signed-off-by: Ryota Sakamoto Acked-by: Kuan-Wei Chiu --- MAINTAINERS | 2 +- arch/m68k/configs/amiga_defconfig | 1 - arch/m68k/configs/apollo_defconfig | 1 - arch/m68k/configs/atari_defconfig | 1 - arch/m68k/configs/bvme6000_defconfig | 1 - arch/m68k/configs/hp300_defconfig | 1 - arch/m68k/configs/mac_defconfig | 1 - arch/m68k/configs/multi_defconfig | 1 - arch/m68k/configs/mvme147_defconfig | 1 - arch/m68k/configs/mvme16x_defconfig | 1 - arch/m68k/configs/q40_defconfig | 1 - arch/m68k/configs/sun3_defconfig | 1 - arch/m68k/configs/sun3x_defconfig | 1 - arch/powerpc/configs/ppc64_defconfig | 1 - arch/s390/configs/debug_defconfig | 2 +- lib/Kconfig.debug | 21 +-- lib/Makefile | 1 - lib/tests/Makefile | 1 + .../min_heap_kunit.c} | 147 ++++++++---------- 19 files changed, 81 insertions(+), 106 deletions(-) rename lib/{test_min_heap.c =3D> tests/min_heap_kunit.c} (58%) diff --git a/MAINTAINERS b/MAINTAINERS index dc731d37c8fe..b56106383ccc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -17443,7 +17443,7 @@ S: Maintained F: Documentation/core-api/min_heap.rst F: include/linux/min_heap.h F: lib/min_heap.c -F: lib/test_min_heap.c +F: lib/tests/min_heap_kunit.c =20 MIPI CCS, SMIA AND SMIA++ IMAGE SENSOR DRIVER M: Sakari Ailus diff --git a/arch/m68k/configs/amiga_defconfig b/arch/m68k/configs/amiga_de= fconfig index bfc1ee7c8158..902bec313c79 100644 --- a/arch/m68k/configs/amiga_defconfig +++ b/arch/m68k/configs/amiga_defconfig @@ -609,7 +609,6 @@ CONFIG_EARLY_PRINTK=3Dy CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm -CONFIG_TEST_MIN_HEAP=3Dm CONFIG_TEST_DIV64=3Dm CONFIG_TEST_MULDIV64=3Dm CONFIG_REED_SOLOMON_TEST=3Dm diff --git a/arch/m68k/configs/apollo_defconfig b/arch/m68k/configs/apollo_= defconfig index d9d1f3c4c70d..0bd3d944fc02 100644 --- a/arch/m68k/configs/apollo_defconfig +++ b/arch/m68k/configs/apollo_defconfig @@ -566,7 +566,6 @@ CONFIG_EARLY_PRINTK=3Dy CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm -CONFIG_TEST_MIN_HEAP=3Dm CONFIG_TEST_DIV64=3Dm CONFIG_TEST_MULDIV64=3Dm CONFIG_REED_SOLOMON_TEST=3Dm diff --git a/arch/m68k/configs/atari_defconfig b/arch/m68k/configs/atari_de= fconfig index 523205adccc8..9db566fc3281 100644 --- a/arch/m68k/configs/atari_defconfig +++ b/arch/m68k/configs/atari_defconfig @@ -586,7 +586,6 @@ CONFIG_EARLY_PRINTK=3Dy CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm -CONFIG_TEST_MIN_HEAP=3Dm CONFIG_TEST_DIV64=3Dm CONFIG_TEST_MULDIV64=3Dm CONFIG_REED_SOLOMON_TEST=3Dm diff --git a/arch/m68k/configs/bvme6000_defconfig b/arch/m68k/configs/bvme6= 000_defconfig index 7b0a4ef0b010..9f927a87efd1 100644 --- a/arch/m68k/configs/bvme6000_defconfig +++ b/arch/m68k/configs/bvme6000_defconfig @@ -558,7 +558,6 @@ CONFIG_EARLY_PRINTK=3Dy CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm -CONFIG_TEST_MIN_HEAP=3Dm CONFIG_TEST_DIV64=3Dm CONFIG_TEST_MULDIV64=3Dm CONFIG_REED_SOLOMON_TEST=3Dm diff --git a/arch/m68k/configs/hp300_defconfig b/arch/m68k/configs/hp300_de= fconfig index 089c5c394c62..b8993c80199e 100644 --- a/arch/m68k/configs/hp300_defconfig +++ b/arch/m68k/configs/hp300_defconfig @@ -568,7 +568,6 @@ CONFIG_EARLY_PRINTK=3Dy CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm -CONFIG_TEST_MIN_HEAP=3Dm CONFIG_TEST_DIV64=3Dm CONFIG_TEST_MULDIV64=3Dm CONFIG_REED_SOLOMON_TEST=3Dm diff --git a/arch/m68k/configs/mac_defconfig b/arch/m68k/configs/mac_defcon= fig index 5f2484c36733..d1c1eb9cfbb0 100644 --- a/arch/m68k/configs/mac_defconfig +++ b/arch/m68k/configs/mac_defconfig @@ -585,7 +585,6 @@ CONFIG_EARLY_PRINTK=3Dy CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm -CONFIG_TEST_MIN_HEAP=3Dm CONFIG_TEST_DIV64=3Dm CONFIG_TEST_MULDIV64=3Dm CONFIG_REED_SOLOMON_TEST=3Dm diff --git a/arch/m68k/configs/multi_defconfig b/arch/m68k/configs/multi_de= fconfig index 74f0a1f6d871..e2b76fe694af 100644 --- a/arch/m68k/configs/multi_defconfig +++ b/arch/m68k/configs/multi_defconfig @@ -672,7 +672,6 @@ CONFIG_EARLY_PRINTK=3Dy CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm -CONFIG_TEST_MIN_HEAP=3Dm CONFIG_TEST_DIV64=3Dm CONFIG_TEST_MULDIV64=3Dm CONFIG_REED_SOLOMON_TEST=3Dm diff --git a/arch/m68k/configs/mvme147_defconfig b/arch/m68k/configs/mvme14= 7_defconfig index 4bee18c820e4..d9cfa59cb2ba 100644 --- a/arch/m68k/configs/mvme147_defconfig +++ b/arch/m68k/configs/mvme147_defconfig @@ -558,7 +558,6 @@ CONFIG_EARLY_PRINTK=3Dy CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm -CONFIG_TEST_MIN_HEAP=3Dm CONFIG_TEST_DIV64=3Dm CONFIG_TEST_MULDIV64=3Dm CONFIG_REED_SOLOMON_TEST=3Dm diff --git a/arch/m68k/configs/mvme16x_defconfig b/arch/m68k/configs/mvme16= x_defconfig index 322c17e55c9a..6f77ca6d8fb4 100644 --- a/arch/m68k/configs/mvme16x_defconfig +++ b/arch/m68k/configs/mvme16x_defconfig @@ -559,7 +559,6 @@ CONFIG_EARLY_PRINTK=3Dy CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm -CONFIG_TEST_MIN_HEAP=3Dm CONFIG_TEST_DIV64=3Dm CONFIG_TEST_MULDIV64=3Dm CONFIG_REED_SOLOMON_TEST=3Dm diff --git a/arch/m68k/configs/q40_defconfig b/arch/m68k/configs/q40_defcon= fig index 82f9baab8fea..1729b63b1095 100644 --- a/arch/m68k/configs/q40_defconfig +++ b/arch/m68k/configs/q40_defconfig @@ -575,7 +575,6 @@ CONFIG_EARLY_PRINTK=3Dy CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm -CONFIG_TEST_MIN_HEAP=3Dm CONFIG_TEST_DIV64=3Dm CONFIG_TEST_MULDIV64=3Dm CONFIG_REED_SOLOMON_TEST=3Dm diff --git a/arch/m68k/configs/sun3_defconfig b/arch/m68k/configs/sun3_defc= onfig index f94ad226cb5b..ff18caa6d5f8 100644 --- a/arch/m68k/configs/sun3_defconfig +++ b/arch/m68k/configs/sun3_defconfig @@ -555,7 +555,6 @@ CONFIG_WW_MUTEX_SELFTEST=3Dm CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm -CONFIG_TEST_MIN_HEAP=3Dm CONFIG_TEST_DIV64=3Dm CONFIG_TEST_MULDIV64=3Dm CONFIG_REED_SOLOMON_TEST=3Dm diff --git a/arch/m68k/configs/sun3x_defconfig b/arch/m68k/configs/sun3x_de= fconfig index a5ecfc505ab2..b8bbdd9564aa 100644 --- a/arch/m68k/configs/sun3x_defconfig +++ b/arch/m68k/configs/sun3x_defconfig @@ -556,7 +556,6 @@ CONFIG_EARLY_PRINTK=3Dy CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_TEST_DHRY=3Dm -CONFIG_TEST_MIN_HEAP=3Dm CONFIG_TEST_DIV64=3Dm CONFIG_TEST_MULDIV64=3Dm CONFIG_REED_SOLOMON_TEST=3Dm diff --git a/arch/powerpc/configs/ppc64_defconfig b/arch/powerpc/configs/pp= c64_defconfig index 2d92c11eea7e..226b6233cccb 100644 --- a/arch/powerpc/configs/ppc64_defconfig +++ b/arch/powerpc/configs/ppc64_defconfig @@ -426,7 +426,6 @@ CONFIG_BOOTX_TEXT=3Dy CONFIG_KUNIT=3Dm CONFIG_KUNIT_ALL_TESTS=3Dm CONFIG_LKDTM=3Dm -CONFIG_TEST_MIN_HEAP=3Dm CONFIG_TEST_DIV64=3Dm CONFIG_BACKTRACE_SELF_TEST=3Dm CONFIG_TEST_REF_TRACKER=3Dm diff --git a/arch/s390/configs/debug_defconfig b/arch/s390/configs/debug_de= fconfig index 0713914b25b4..4be3a7540909 100644 --- a/arch/s390/configs/debug_defconfig +++ b/arch/s390/configs/debug_defconfig @@ -921,7 +921,7 @@ CONFIG_FAULT_INJECTION_DEBUG_FS=3Dy CONFIG_FAULT_INJECTION_CONFIGFS=3Dy CONFIG_FAULT_INJECTION_STACKTRACE_FILTER=3Dy CONFIG_LKDTM=3Dm -CONFIG_TEST_MIN_HEAP=3Dy +CONFIG_MIN_HEAP_KUNIT_TEST=3Dm CONFIG_KPROBES_SANITY_TEST=3Dm CONFIG_RBTREE_TEST=3Dy CONFIG_INTERVAL_TREE_TEST=3Dm diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index ba36939fda79..20ba718473c5 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2277,16 +2277,6 @@ config TEST_LIST_SORT =20 If unsure, say N. =20 -config TEST_MIN_HEAP - tristate "Min heap test" - depends on DEBUG_KERNEL || m - help - Enable this to turn on min heap function tests. This test is - executed only once during system boot (so affects only boot time), - or at module load time. - - If unsure, say N. - config TEST_SORT tristate "Array-based sort test" if !KUNIT_ALL_TESTS depends on KUNIT @@ -2880,6 +2870,17 @@ config MEMCPY_KUNIT_TEST =20 If unsure, say N. =20 +config MIN_HEAP_KUNIT_TEST + tristate "Min heap test" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS + help + This option enables the KUnit test suite for the min heap library + which provides functions for creating and managing min heaps. + The test suite checks the functionality of the min heap library. + + If unsure, say N + config IS_SIGNED_TYPE_KUNIT_TEST tristate "Test is_signed_type() macro" if !KUNIT_ALL_TESTS depends on KUNIT diff --git a/lib/Makefile b/lib/Makefile index aaf677cf4527..d876ca8d347d 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -75,7 +75,6 @@ obj-$(CONFIG_TEST_UBSAN) +=3D test_ubsan.o CFLAGS_test_ubsan.o +=3D $(call cc-disable-warning, unused-but-set-variabl= e) UBSAN_SANITIZE_test_ubsan.o :=3D y obj-$(CONFIG_TEST_KSTRTOX) +=3D test-kstrtox.o -obj-$(CONFIG_TEST_MIN_HEAP) +=3D test_min_heap.o obj-$(CONFIG_TEST_LKM) +=3D test_module.o obj-$(CONFIG_TEST_VMALLOC) +=3D test_vmalloc.o obj-$(CONFIG_TEST_RHASHTABLE) +=3D test_rhashtable.o diff --git a/lib/tests/Makefile b/lib/tests/Makefile index 601dba4b7d96..11c416488c2e 100644 --- a/lib/tests/Makefile +++ b/lib/tests/Makefile @@ -33,6 +33,7 @@ CFLAGS_longest_symbol_kunit.o +=3D $(call cc-disable-warn= ing, missing-prototypes) obj-$(CONFIG_LONGEST_SYM_KUNIT_TEST) +=3D longest_symbol_kunit.o =20 obj-$(CONFIG_MEMCPY_KUNIT_TEST) +=3D memcpy_kunit.o +obj-$(CONFIG_MIN_HEAP_KUNIT_TEST) +=3D min_heap_kunit.o CFLAGS_overflow_kunit.o =3D $(call cc-disable-warning, tautological-consta= nt-out-of-range-compare) obj-$(CONFIG_OVERFLOW_KUNIT_TEST) +=3D overflow_kunit.o obj-$(CONFIG_PRINTF_KUNIT_TEST) +=3D printf_kunit.o diff --git a/lib/test_min_heap.c b/lib/tests/min_heap_kunit.c similarity index 58% rename from lib/test_min_heap.c rename to lib/tests/min_heap_kunit.c index a9c4a74d3898..9c1122661698 100644 --- a/lib/test_min_heap.c +++ b/lib/tests/min_heap_kunit.c @@ -1,60 +1,66 @@ // SPDX-License-Identifier: GPL-2.0-only -#define pr_fmt(fmt) "min_heap_test: " fmt - /* * Test cases for the min max heap. */ =20 -#include +#include #include #include -#include #include =20 +struct min_heap_test_case { + const char *str; + bool min_heap; +}; + +static struct min_heap_test_case min_heap_cases[] =3D { + { + .str =3D "min", + .min_heap =3D true, + }, + { + .str =3D "max", + .min_heap =3D false, + }, +}; + +KUNIT_ARRAY_PARAM_DESC(min_heap, min_heap_cases, str); + DEFINE_MIN_HEAP(int, min_heap_test); =20 -static __init bool less_than(const void *lhs, const void *rhs, void __alwa= ys_unused *args) +static bool less_than(const void *lhs, const void *rhs, void __always_unus= ed *args) { return *(int *)lhs < *(int *)rhs; } =20 -static __init bool greater_than(const void *lhs, const void *rhs, void __a= lways_unused *args) +static bool greater_than(const void *lhs, const void *rhs, void __always_u= nused *args) { return *(int *)lhs > *(int *)rhs; } =20 -static __init int pop_verify_heap(bool min_heap, - struct min_heap_test *heap, - const struct min_heap_callbacks *funcs) +static void pop_verify_heap(struct kunit *test, + bool min_heap, + struct min_heap_test *heap, + const struct min_heap_callbacks *funcs) { int *values =3D heap->data; - int err =3D 0; int last; =20 last =3D values[0]; min_heap_pop_inline(heap, funcs, NULL); while (heap->nr > 0) { - if (min_heap) { - if (last > values[0]) { - pr_err("error: expected %d <=3D %d\n", last, - values[0]); - err++; - } - } else { - if (last < values[0]) { - pr_err("error: expected %d >=3D %d\n", last, - values[0]); - err++; - } - } + if (min_heap) + KUNIT_EXPECT_LE(test, last, values[0]); + else + KUNIT_EXPECT_GE(test, last, values[0]); last =3D values[0]; min_heap_pop_inline(heap, funcs, NULL); } - return err; } =20 -static __init int test_heapify_all(bool min_heap) +static void test_heapify_all(struct kunit *test) { + const struct min_heap_test_case *params =3D test->param_value; int values[] =3D { 3, 1, 2, 4, 0x8000000, 0x7FFFFFF, 0, -3, -1, -2, -4, 0x8000000, 0x7FFFFFF }; struct min_heap_test heap =3D { @@ -63,15 +69,14 @@ static __init int test_heapify_all(bool min_heap) .size =3D ARRAY_SIZE(values), }; struct min_heap_callbacks funcs =3D { - .less =3D min_heap ? less_than : greater_than, + .less =3D params->min_heap ? less_than : greater_than, .swp =3D NULL, }; - int i, err; + int i; =20 /* Test with known set of values. */ min_heapify_all_inline(&heap, &funcs, NULL); - err =3D pop_verify_heap(min_heap, &heap, &funcs); - + pop_verify_heap(test, params->min_heap, &heap, &funcs); =20 /* Test with randomly generated values. */ heap.nr =3D ARRAY_SIZE(values); @@ -79,13 +84,12 @@ static __init int test_heapify_all(bool min_heap) values[i] =3D get_random_u32(); =20 min_heapify_all_inline(&heap, &funcs, NULL); - err +=3D pop_verify_heap(min_heap, &heap, &funcs); - - return err; + pop_verify_heap(test, params->min_heap, &heap, &funcs); } =20 -static __init int test_heap_push(bool min_heap) +static void test_heap_push(struct kunit *test) { + const struct min_heap_test_case *params =3D test->param_value; const int data[] =3D { 3, 1, 2, 4, 0x80000000, 0x7FFFFFFF, 0, -3, -1, -2, -4, 0x80000000, 0x7FFFFFFF }; int values[ARRAY_SIZE(data)]; @@ -95,29 +99,28 @@ static __init int test_heap_push(bool min_heap) .size =3D ARRAY_SIZE(values), }; struct min_heap_callbacks funcs =3D { - .less =3D min_heap ? less_than : greater_than, + .less =3D params->min_heap ? less_than : greater_than, .swp =3D NULL, }; - int i, temp, err; + int i, temp; =20 /* Test with known set of values copied from data. */ for (i =3D 0; i < ARRAY_SIZE(data); i++) min_heap_push_inline(&heap, &data[i], &funcs, NULL); =20 - err =3D pop_verify_heap(min_heap, &heap, &funcs); + pop_verify_heap(test, params->min_heap, &heap, &funcs); =20 /* Test with randomly generated values. */ while (heap.nr < heap.size) { temp =3D get_random_u32(); min_heap_push_inline(&heap, &temp, &funcs, NULL); } - err +=3D pop_verify_heap(min_heap, &heap, &funcs); - - return err; + pop_verify_heap(test, params->min_heap, &heap, &funcs); } =20 -static __init int test_heap_pop_push(bool min_heap) +static void test_heap_pop_push(struct kunit *test) { + const struct min_heap_test_case *params =3D test->param_value; const int data[] =3D { 3, 1, 2, 4, 0x80000000, 0x7FFFFFFF, 0, -3, -1, -2, -4, 0x80000000, 0x7FFFFFFF }; int values[ARRAY_SIZE(data)]; @@ -127,13 +130,13 @@ static __init int test_heap_pop_push(bool min_heap) .size =3D ARRAY_SIZE(values), }; struct min_heap_callbacks funcs =3D { - .less =3D min_heap ? less_than : greater_than, + .less =3D params->min_heap ? less_than : greater_than, .swp =3D NULL, }; - int i, temp, err; + int i, temp; =20 /* Fill values with data to pop and replace. */ - temp =3D min_heap ? 0x80000000 : 0x7FFFFFFF; + temp =3D params->min_heap ? 0x80000000 : 0x7FFFFFFF; for (i =3D 0; i < ARRAY_SIZE(data); i++) min_heap_push_inline(&heap, &temp, &funcs, NULL); =20 @@ -141,7 +144,7 @@ static __init int test_heap_pop_push(bool min_heap) for (i =3D 0; i < ARRAY_SIZE(data); i++) min_heap_pop_push_inline(&heap, &data[i], &funcs, NULL); =20 - err =3D pop_verify_heap(min_heap, &heap, &funcs); + pop_verify_heap(test, params->min_heap, &heap, &funcs); =20 heap.nr =3D 0; for (i =3D 0; i < ARRAY_SIZE(data); i++) @@ -152,13 +155,12 @@ static __init int test_heap_pop_push(bool min_heap) temp =3D get_random_u32(); min_heap_pop_push_inline(&heap, &temp, &funcs, NULL); } - err +=3D pop_verify_heap(min_heap, &heap, &funcs); - - return err; + pop_verify_heap(test, params->min_heap, &heap, &funcs); } =20 -static __init int test_heap_del(bool min_heap) +static void test_heap_del(struct kunit *test) { + const struct min_heap_test_case *params =3D test->param_value; int values[] =3D { 3, 1, 2, 4, 0x8000000, 0x7FFFFFF, 0, -3, -1, -2, -4, 0x8000000, 0x7FFFFFF }; struct min_heap_test heap; @@ -166,17 +168,16 @@ static __init int test_heap_del(bool min_heap) min_heap_init_inline(&heap, values, ARRAY_SIZE(values)); heap.nr =3D ARRAY_SIZE(values); struct min_heap_callbacks funcs =3D { - .less =3D min_heap ? less_than : greater_than, + .less =3D params->min_heap ? less_than : greater_than, .swp =3D NULL, }; - int i, err; + int i; =20 /* Test with known set of values. */ min_heapify_all_inline(&heap, &funcs, NULL); for (i =3D 0; i < ARRAY_SIZE(values) / 2; i++) min_heap_del_inline(&heap, get_random_u32() % heap.nr, &funcs, NULL); - err =3D pop_verify_heap(min_heap, &heap, &funcs); - + pop_verify_heap(test, params->min_heap, &heap, &funcs); =20 /* Test with randomly generated values. */ heap.nr =3D ARRAY_SIZE(values); @@ -186,37 +187,23 @@ static __init int test_heap_del(bool min_heap) =20 for (i =3D 0; i < ARRAY_SIZE(values) / 2; i++) min_heap_del_inline(&heap, get_random_u32() % heap.nr, &funcs, NULL); - err +=3D pop_verify_heap(min_heap, &heap, &funcs); - - return err; + pop_verify_heap(test, params->min_heap, &heap, &funcs); } =20 -static int __init test_min_heap_init(void) -{ - int err =3D 0; - - err +=3D test_heapify_all(true); - err +=3D test_heapify_all(false); - err +=3D test_heap_push(true); - err +=3D test_heap_push(false); - err +=3D test_heap_pop_push(true); - err +=3D test_heap_pop_push(false); - err +=3D test_heap_del(true); - err +=3D test_heap_del(false); - if (err) { - pr_err("test failed with %d errors\n", err); - return -EINVAL; - } - pr_info("test passed\n"); - return 0; -} -module_init(test_min_heap_init); +static struct kunit_case min_heap_test_cases[] =3D { + KUNIT_CASE_PARAM(test_heapify_all, min_heap_gen_params), + KUNIT_CASE_PARAM(test_heap_push, min_heap_gen_params), + KUNIT_CASE_PARAM(test_heap_pop_push, min_heap_gen_params), + KUNIT_CASE_PARAM(test_heap_del, min_heap_gen_params), + {}, +}; =20 -static void __exit test_min_heap_exit(void) -{ - /* do nothing */ -} -module_exit(test_min_heap_exit); +static struct kunit_suite min_heap_test_suite =3D { + .name =3D "min_heap", + .test_cases =3D min_heap_test_cases, +}; + +kunit_test_suite(min_heap_test_suite); =20 MODULE_DESCRIPTION("Test cases for the min max heap"); MODULE_LICENSE("GPL"); --=20 2.34.1