Skip to contentSkip to conversation

lib-util_macros_kunit-add-kunit-test-for-util_macrosh.patch removed from -mm tree

merged mm-nonmm-stable Andrew Morton 1 participant 1 message Nov 12, 2024

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: lib: util_macros_kunit: add kunit test for util_macros.h
has been removed from the -mm tree. Its filename was
lib-util_macros_kunit-add-kunit-test-for-util_macrosh.patch

This patch was dropped because it was merged into the mm-nonmm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Alexandru Ardelean <[email protected]>
Subject: lib: util_macros_kunit: add kunit test for util_macros.h
Date: Tue, 5 Nov 2024 16:54:06 +0200

A bug was found in the find_closest() (find_closest_descending() is also affected after some testing), where for certain values with small progressions of 1, 2 & 3, the rounding (done by averaging 2 values) causes an incorrect index to be returned.

The bug is described in more detail in the commit which fixes the bug. This commit adds a kunit test to validate that the fix works correctly.

This kunit test adds some of the arrays (from the driver-sphere) that seem to produce issues with the 'find_closest()' macro. Specifically the one from ad7606 driver (with which the bug was found) and from the ina2xx drivers, which shows the quirk with 'find_closest()' with elements in a array that have an interval of 3.

For the find_closest_descending() tests, the same arrays are used as for the find_closest(), but in reverse; the idea is that 'find_closest_descending()' should return the sames indices as 'find_closest()' but in reverse.

For testing both macros, there are 4 special arrays created, one for testing find_closest{_descending}() for arrays of progressions 1, 2, 3 and
4. The idea is to show that (for progressions of 1, 2 & 3) the fix works as expected. When removing the fix, the issues should start to show up.

Then an extra array of negative and positive values is added. There are currently no such arrays within drivers, but one could expect that these macros behave correctly even for such arrays.

To run this kunit:
./tools/testing/kunit/kunit.py run "*util_macros*"

---

 lib/Kconfig.debug       |   17 ++
 lib/Makefile            |    1 
 lib/util_macros_kunit.c |  240 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 258 insertions(+)
lib/Kconfig.debug renamed from lib/Kconfig.debug~lib-util_macros_kunit-add-kunit-test-for-util_macrosh +17 -0
@@ -2630,6 +2630,23 @@ config CHECKSUM_KUNIT
 
 	  If unsure, say N.
 
+config UTIL_MACROS_KUNIT
+	tristate "KUnit test util_macros.h functions at runtime" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  Enable this option to test the util_macros.h function at boot.
+
+	  KUnit tests run during boot and output the results to the debug log
+	  in TAP format (http://testanything.org/). Only useful for kernel devs
+	  running the KUnit test harness, and not intended for inclusion into a
+	  production build.
+
+	  For more information on KUnit and unit tests in general please refer
+	  to the KUnit documentation in Documentation/dev-tools/kunit/.
+
+	  If unsure, say N.
+
 config HASH_KUNIT_TEST
 	tristate "KUnit Test for integer hash functions" if !KUNIT_ALL_TESTS
 	depends on KUNIT
lib/Makefile renamed from lib/Makefile~lib-util_macros_kunit-add-kunit-test-for-util_macrosh +1 -0
@@ -372,6 +372,7 @@ obj-$(CONFIG_PLDMFW) += pldmfw/
 CFLAGS_bitfield_kunit.o := $(DISABLE_STRUCTLEAK_PLUGIN)
 obj-$(CONFIG_BITFIELD_KUNIT) += bitfield_kunit.o
 obj-$(CONFIG_CHECKSUM_KUNIT) += checksum_kunit.o
+obj-$(CONFIG_UTIL_MACROS_KUNIT) += util_macros_kunit.o
 obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o
 obj-$(CONFIG_HASHTABLE_KUNIT_TEST) += hashtable_test.o
 obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o
lib/util_macros_kunit.c new file +240 -0

240 lines not on this page · raw message

_

Patches currently in -mm which might be from [email protected] are