Skip to contentSkip to conversation

Add KUnit tests for kfifo

PATCH Superseded Diego Vieira 2 participants 3 messages Jul 22, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add KUnit tests for kfifo

From: diegodvv <[email protected]>

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 kfifo data structure, defined in include/linux/kfifo.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

Diego Vieira (1):
lib/kfifo-test.c: add tests for the kfifo structure

 lib/Kconfig.debug |  14 +++
 lib/Makefile      |   1 +
 lib/kfifo-test.c  | 222 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 237 insertions(+)
 create mode 100644 lib/kfifo-test.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/1 lib/kfifo-test.c: add tests for the kfifo structure

Add KUnit tests for the kfifo data structure. They test the vast majority of macros defined in the kfifo header (include/linux/kfifo.h).

These are inspired by the existing tests for the 'list' doubly linked in lib/list-test.c [1].

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

---
 lib/Kconfig.debug |  14 +++
 lib/Makefile      |   1 +
 lib/kfifo-test.c  | 222 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 237 insertions(+)
 create mode 100644 lib/kfifo-test.c
lib/Kconfig.debug +14 -0
index 59b6765d86b8..d7a4b996d731 100644
@@ -2646,6 +2646,20 @@ config SYSCTL_KUNIT_TEST
 
 	  If unsure, say N.
 
+config KFIFO_KUNIT_TEST
+	tristate "KUnit Test for the generic kernel FIFO implementation" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  This builds the generic FIFO implementation KUnit test suite.
+	  It tests that the API and basic functionality of the kfifo 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 LIST_KUNIT_TEST
 	tristate "KUnit Test for Kernel Linked-list structures" if !KUNIT_ALL_TESTS
 	depends on KUNIT
lib/Makefile +1 -0
index 3b1769045651..db8dc4cb1b47 100644
@@ -370,6 +370,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_KFIFO_KUNIT_TEST) += kfifo-test.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/kfifo-test.c new file +222 -0

222 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/1] lib/kfifo-test.c: add tests for the kfifo structure

Quoted 16 lines · Diego Vieira

Add KUnit tests for the kfifo data structure. They test the vast majority of macros defined in the kfifo header (include/linux/kfifo.h).

These are inspired by the existing tests for the 'list' doubly linked in lib/list-test.c [1].

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

---
  lib/Kconfig.debug |  14 +++
  lib/Makefile      |   1 +
  lib/kfifo-test.c  | 222 ++++++++++++++++++++++++++++++++++++++++++++++
  3 files changed, 237 insertions(+)

create mode 100644 lib/kfifo-test.c

...

Quoted 1 line

+MODULE_LICENSE("GPL");

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