powerpc/xive: Add KUnit tests for xive_find_target_in_mask()
PATCH v2 1/1 powerpc/xive: Add KUnit tests for xive_find_target_in_mask()
Add comprehensive KUnit test suite for the xive_find_target_in_mask() function, which is responsible for selecting target CPUs for interrupt routing in the XIVE interrupt controller.
The test suite includes 8 test cases covering:
- Empty CPU mask handling (returns -1)
- Single CPU selection
- Multiple CPU selection with various mask sizes
- Fuzz parameter behavior and modulo arithmetic
- Large fuzz values exceeding mask weight
- Wrap-around behavior at mask boundaries
- System online CPU mask handling
- Edge case where fuzz equals mask weight
Two tests require multiple CPUs and will skip gracefully in single-CPU environments (e.g., QEMU default configuration). All tests pass without requiring modifications to production code.
The test can be run with:
./tools/testing/kunit/kunit.py run --arch=powerpc \
--kunitconfig=arch/powerpc/sysdev/xive --qemu_args="-smp 4"---
V1 -> V2:
- Updated commit message
V1: https://lore.kernel.org/all/[email protected]/
arch/powerpc/sysdev/xive/.kunitconfig | 4 + arch/powerpc/sysdev/xive/Kconfig | 9 + arch/powerpc/sysdev/xive/Makefile | 7 +- arch/powerpc/sysdev/xive/xive-test.c | 294 ++++++++++++++++++++++++++ 4 files changed, 311 insertions(+), 3 deletions(-) create mode 100644 arch/powerpc/sysdev/xive/.kunitconfig create mode 100644 arch/powerpc/sysdev/xive/xive-test.c
arch/powerpc/sysdev/xive/.kunitconfig new file +4 -0
@@ -0,0 +1,4 @@ +CONFIG_KUNIT=y +CONFIG_PPC_PSERIES=y +CONFIG_PPC_XIVE_SPAPR=y +CONFIG_PPC_XIVE_KUNIT_TEST=y
arch/powerpc/sysdev/xive/Kconfig +9 -0
@@ -12,3 +12,12 @@ config PPC_XIVE_NATIVE config PPC_XIVE_SPAPR bool select PPC_XIVE + +config PPC_XIVE_KUNIT_TEST + tristate "KUnit tests for XIVE interrupt controller" if !KUNIT_ALL_TESTS + depends on KUNIT && PPC_XIVE + default KUNIT_ALL_TESTS + help + This builds unit tests for the XIVE interrupt controller. + + If unsure, say N.
arch/powerpc/sysdev/xive/Makefile +4 -3
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-y += common.o -obj-$(CONFIG_PPC_XIVE_NATIVE) += native.o -obj-$(CONFIG_PPC_XIVE_SPAPR) += spapr.o +obj-y += common.o +obj-$(CONFIG_PPC_XIVE_NATIVE) += native.o +obj-$(CONFIG_PPC_XIVE_SPAPR) += spapr.o +obj-$(CONFIG_PPC_XIVE_KUNIT_TEST) += xive-test.o
arch/powerpc/sysdev/xive/xive-test.c new file +294 -0
294 lines not on this page · raw message
Signature · 1 line
2.53.0