Skip to contentSkip to conversation

lib/list-test: add a test for the 'list' doubly linked list

PATCH Superseded David Gow 1 participant 1 message Oct 16, 2019

Subsystems (2)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

David Gow

author
#0 lore raw

PATCH v3 1/1 lib/list-test: add a test for the 'list' doubly linked list

Add a KUnit test for the kernel doubly linked list implementation in include/linux/list.h

Each test case (list_test_x) is focused on testing the behaviour of the list function/macro 'x'. None of the tests pass invalid lists to these macros, and so should behave identically with DEBUG_LIST enabled and disabled.

Note that, at present, it only tests the list_ types (not the singly-linked hlist_), and does not yet test all of the list_for_each_entry* macros (and some related things like list_prepare_entry).

---

Note: v2 can be found here:
https://lkml.org/lkml/2019/10/10/1011

This revision fixes some issues with the memory allocation in the 'list_test_list_init' test. In particular, it uses a KUnit assert to verify that the lists allocated with kmalloc() and kzalloc() are non-NULL (and also properly passes GFP_KERNEL to them).

Since this depends on KUnit, which is not yet upstream, it probably makes sense for it to go into the linux-kselftest/test branch alongside KUnit itself. v2 has ended up in the -mm tree, and is already in -next, though. I think it nevertheless makes sense to move this change to the linux-kselftest/test branch, as outlined here:
https://lore.kernel.org/linux-kselftest/CABVgOS=W4cfFoE=JT4mbk1zkUsreucrw_B81R2jwDCFPocomHQ@mail.gmail.com/T/#t

Thanks,
-- David

 MAINTAINERS       |   5 +
 lib/Kconfig.debug |  12 +
 lib/Makefile      |   3 +
 lib/list-test.c   | 740 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 760 insertions(+)
 create mode 100644 lib/list-test.c
MAINTAINERS +5 -0
index 7ef985e01457..9ccabdb25a26 100644
@@ -9504,6 +9504,11 @@ F:	Documentation/misc-devices/lis3lv02d.rst
 F:	drivers/misc/lis3lv02d/
 F:	drivers/platform/x86/hp_accel.c
 
+LIST UNIT TEST
+M:	David Gow <[email protected]>
+S:	Maintained
+F:	lib/list-test.c
+
 LIVE PATCHING
 M:	Josh Poimboeuf <[email protected]>
 M:	Jiri Kosina <[email protected]>
lib/Kconfig.debug +12 -0
index a3017a5dadcd..7b648141ff52 100644
@@ -1961,6 +1961,18 @@ config SYSCTL_KUNIT_TEST
 
 	  If unsure, say N.
 
+config LIST_TEST
+	bool "KUnit Test for Kernel Linked-list structures"
+	depends on KUNIT
+	help
+	  This builds the linked list unit test, which runs on boot.
+	  It tests that the API and basic functionality of the list_head type
+	  and associated macros.
+	  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 TEST_UDELAY
 	tristate "udelay test driver"
 	help
lib/Makefile +3 -0
index bba1fd5485f7..309e174ee35d 100644
@@ -292,3 +292,6 @@ obj-$(CONFIG_GENERIC_LIB_MULDI3) += muldi3.o
 obj-$(CONFIG_GENERIC_LIB_CMPDI2) += cmpdi2.o
 obj-$(CONFIG_GENERIC_LIB_UCMPDI2) += ucmpdi2.o
 obj-$(CONFIG_OBJAGG) += objagg.o
+
+# KUnit tests
+obj-$(CONFIG_LIST_TEST) += list-test.o
lib/list-test.c new file +740 -0

740 lines not on this page · raw message

Signature · 1 line
2.23.0.700.g56cf767bdb-goog