Skip to contentSkip to conversation

Add KUnit tests for llist

PATCH Superseded Artur Alves 2 participants 4 messages Jul 21, 2024 – Jul 29, 2024

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Add KUnit tests for llist

Hi all,

This is part of a hackathon organized by LKCAMP[1], focused on writing tests using KUnit. We reached out a while ago asking for advice on what would be a useful contribution[2] and ended up choosing data structures that did not yet have tests.

This patch adds tests for the llist data structure, defined in include/linux/llist.h, and is inspired by the KUnit tests for the doubly linked list in lib/list-test.c[3].

[1] https://lkcamp.dev/about/
[2] https://lore.kernel.org/all/Zktnt7rjKryTh9-N@arch/
[3] https://elixir.bootlin.com/linux/latest/source/lib/list-test.c

Artur Alves (1):
lib/llist_kunit.c: add KUnit tests for llist

 lib/Kconfig.debug |  11 ++
 lib/Makefile      |   1 +
 lib/llist_kunit.c | 360 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 372 insertions(+)
 create mode 100644 lib/llist_kunit.c
Signature · 1 line
2.45.2
#1 lore raw

PATCH 1/1 lib/llist_kunit.c: add KUnit tests for llist

Add KUnit tests for the llist data structure. They test the vast majority of methods and macros defined in include/linux/llist.h.

These are inspired by the existing tests for the 'list' doubly linked in lib/list-test.c [1]. Each test case (llist_test_x) tests the behaviour of the llist function/macro 'x'.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/list-test.c

---
 lib/Kconfig.debug |  11 ++
 lib/Makefile      |   1 +
 lib/llist_kunit.c | 360 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 372 insertions(+)
 create mode 100644 lib/llist_kunit.c
lib/Kconfig.debug +11 -0
index 561e346f5cb0..f58649c6cce2 100644
@@ -2811,6 +2811,17 @@ config USERCOPY_KUNIT_TEST
 	  on the copy_to/from_user infrastructure, making sure basic
 	  user/kernel boundary testing is working.
 
+config LLIST_KUNIT_TEST
+	tristate "KUnit tests for lib/llist" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  This option builds the "llist_kunit" test module that
+	  helps to verify the correctness of the functions and
+	  macros defined in (<linux/llist.h>).
+
+	  If unsure, say N.
+
 config TEST_UDELAY
 	tristate "udelay test driver"
 	help
lib/Makefile +1 -0
index 322bb127b4dc..da5ebe56c33c 100644
@@ -370,6 +370,7 @@ CFLAGS_bitfield_kunit.o := $(DISABLE_STRUCTLEAK_PLUGIN)
 obj-$(CONFIG_BITFIELD_KUNIT) += bitfield_kunit.o
 obj-$(CONFIG_CHECKSUM_KUNIT) += checksum_kunit.o
 obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o
+obj-$(CONFIG_LLIST_KUNIT_TEST) += llist_kunit.o
 obj-$(CONFIG_HASHTABLE_KUNIT_TEST) += hashtable_test.o
 obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o
 obj-$(CONFIG_BITS_TEST) += test_bits.o
lib/llist_kunit.c new file +360 -0

360 lines not on this page · raw message

Signature · 1 line
2.45.2
#2 lore raw

Re: [PATCH 1/1] lib/llist_kunit.c: add KUnit tests for llist

Quoted 16 lines · Artur Alves

Add KUnit tests for the llist data structure. They test the vast majority of methods and macros defined in include/linux/llist.h.

These are inspired by the existing tests for the 'list' doubly linked in lib/list-test.c [1]. Each test case (llist_test_x) tests the behaviour of the llist function/macro 'x'.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/list-test.c

---
  lib/Kconfig.debug |  11 ++
  lib/Makefile      |   1 +
  lib/llist_kunit.c | 360 ++++++++++++++++++++++++++++++++++++++++++++++
  3 files changed, 372 insertions(+)

create mode 100644 lib/llist_kunit.c

...

Quoted 1 line

+MODULE_LICENSE("GPL v2");

Since commit 1fffe7a34c89 ("script: modpost: emit a warning when the description is missing") a module without a MODULE_DESCRIPTION() will result in a warning with make W=1.

Multiple developers, including myself, have been fixing the existing warnings for 6.11 so please don't introduce a new one :)

/jeff

#3 lore raw

Re: [PATCH 1/1] lib/llist_kunit.c: add KUnit tests for llist

Hi Jeff,

I was unaware of this commit, I'm going to fix this issue to ensure no warnings are introduced.

Now I'm also aware of two patches that reorganize KUnit tests ([1], [2]). I'll take these into account for the revised version.

Thanks for your reply.

Artur Alves

[1] https://lore.kernel.org/linux-kselftest/[email protected]/
[2] https://lore.kernel.org/linux-kselftest/[email protected]/