Skip to contentSkip to conversation

iio: osf: add KUnit coverage

PATCH New Jinseob Kim 1 participant 3 messages Oct 19 IIO

lore
Share & tools
lore
#0 lore raw

v12 cover iio: osf: add KUnit coverage

Jonathan asked for the updated KUnit patches, replacing the two pending v11 test patches. The six v11 production patches are already applied and are not included again. This KUnit-only v12 maps patch 1/2 to v11 7/8 and patch 2/2 to v11 8/8. The separately submitted kfifo RAW-cache fix is not part of this series.

Allow tests in the existing OSF composite when the driver is a module, without exporting internal symbols or creating a separate test module. The supported configurations are OSF=y/KUNIT=y/TEST=y, OSF=m/KUNIT=y/TEST=y and OSF=m/KUNIT=m/TEST=y. Add deferred mutex cleanup for pending sessions, receive serialization and IIO fixtures, and require producer/configuration handshakes before checking concurrent state.

The unchanged OSF/test sources previously passed all 16 core and 2 IIO cases, GCC and Clang W=1 builds, KASAN, lockdep and debug mutex checks. Actual module load/run/unload validation covered built-in and modular KUnit. With built-in KUnit, 200 production and 200 test-module reloads exercised 20,000 buffer toggles; modular KUnit completed 20 of each reload and 2,000 toggles. Local assertion-abort validation checked seven cleanup paths. These are reused results for identical sources, not new v12 runs. Existing upstream compiler warnings are retained in the validation logs.

The immutable signed commits retain the original IIO testing snapshot:
6a27f3a7d1063aec5aa3d9370161e850fc3a85dd
Runtime unregister concurrency validation used that base plus mainline commit 84bb0fc46ccf6a545b8fdf57cda83770186ed8dd
("iio: buffer: serialize buffer teardown with mode claims"). The fix is a runtime prerequisite, not a patch in this series.

Current IIO testing, fetched for this preparation, is:
19c5db3507633edc21b4172d99f573c2dfbf42b1
Its rewritten OSF commits have identical patch IDs and OSF source blobs, and it now contains 84bb0fc46ccf. Both patches apply cleanly there as well as to the original base, with unchanged OSF/test content. The base-commit below deliberately identifies the original signed series base; the new testing application check is not a claim of a fresh kernel runtime run.

Previous patches, now marked superseded in Patchwork:
https://lore.kernel.org/linux-iio/[email protected]/
https://lore.kernel.org/linux-iio/[email protected]/

Jonathan's request for updated patches:
https://lore.kernel.org/linux-iio/20261018190454.054d3385@jic23-hlaptop/

Changes since v11:
- Send only the two replacement tests; omit the six applied driver patches.
- Allow the supported composite module configurations with a bool selector.
- Add deferred destruction for pending-session, receive and IIO mutexes.
- Strengthen producer/configuration worker entry synchronization.
- Document the IIO core unregister prerequisite and validation base split.

Jinseob Kim (2):
iio: osf: add core KUnit tests
iio: osf: add IIO KUnit tests

 drivers/iio/sensorhubs/osf/Kconfig         |   16 +
 drivers/iio/sensorhubs/osf/Makefile        |    1 +
 drivers/iio/sensorhubs/osf/osf_core_test.c | 1064 ++++++++++++++++++++
 drivers/iio/sensorhubs/osf/osf_iio_test.c  |  395 ++++++++
 4 files changed, 1476 insertions(+)
 create mode 100644 drivers/iio/sensorhubs/osf/osf_core_test.c
 create mode 100644 drivers/iio/sensorhubs/osf/osf_iio_test.c

base-commit: 6a27f3a7d1063aec5aa3d9370161e850fc3a85dd

#1 lore raw

PATCH v12 1/2 iio: osf: add core KUnit tests

Exercise capability discovery, complete repeated inventories, sample-cache admission, exact lengths, reserved wire bytes and session faults. Protect producer lifetime with deferred cleanup and close the session mutex lifecycle before reinitialization.

Include the tests in the existing composite driver so they also run when OSF is a module, without exporting driver internals. Keep the test selector boolean because it controls membership in that composite object, and exclude a built-in driver with a modular KUnit framework.

Destroy pending-session and producer-serialization mutexes through KUnit cleanup actions after their users have finished, including assertion exits.

Assisted-by LLM
---
 drivers/iio/sensorhubs/osf/Kconfig         |   16 +
 drivers/iio/sensorhubs/osf/Makefile        |    1 +
 drivers/iio/sensorhubs/osf/osf_core_test.c | 1064 ++++++++++++++++++++
 3 files changed, 1081 insertions(+)
 create mode 100644 drivers/iio/sensorhubs/osf/osf_core_test.c
drivers/iio/sensorhubs/osf/Kconfig +16 -0
index f955a1f2993d244369943efbd853b9d2c6d47139..6828b79c345092e20743b211b8ca753d51b3b80a 100644
@@ -13,3 +13,19 @@ config OPEN_SENSOR_FUSION
 	  registers IIO devices for supported capability entries. It exposes
 	  accelerometer, gyroscope, magnetometer, and temperature samples
 	  through IIO direct reads and software buffers.
+
+config OPEN_SENSOR_FUSION_KUNIT_TEST
+	bool "KUnit tests for Open Sensor Fusion" if !KUNIT_ALL_TESTS
+	depends on OPEN_SENSOR_FUSION && KUNIT
+	depends on KUNIT=y || OPEN_SENSOR_FUSION=m
+	default KUNIT_ALL_TESTS
+	help
+	  Build focused unit tests for the Open Sensor Fusion core sample
+	  acceptance, direct-read cache, and capability/session handling. The tests
+	  exercise accepted, ignored, and rejected sample handling without
+	  exposing additional production interfaces.
+
+	  The tests are included in the driver, either built-in or in the same
+	  module. A built-in driver requires KUnit to be built-in as well.
+
+	  If unsure, say N.
drivers/iio/sensorhubs/osf/Makefile +1 -0
index b4e03b80cfa4cca6a67e6cd8228a4776a38dcb72..c2f5ba065a62fef2a4897034239b405ccdd69250 100644
@@ -4,3 +4,4 @@ obj-$(CONFIG_OPEN_SENSOR_FUSION) += open-sensor-fusion.o
 
 open-sensor-fusion-y := osf_core.o osf_iio.o osf_protocol.o osf_serdev.o \
 			 osf_stream.o
+open-sensor-fusion-$(CONFIG_OPEN_SENSOR_FUSION_KUNIT_TEST) += osf_core_test.o
drivers/iio/sensorhubs/osf/osf_core_test.c new file +1064 -0

1,064 lines not on this page · raw message

#2 lore raw

PATCH v12 2/2 iio: osf: add IIO KUnit tests

In reply to Jinseob Kim

Exercise active-scan packing, timestamp alignment and producer quiescence during buffer reconfiguration and unregister. Retain device references and deferred worker, sensor and mutex cleanup on assertion exits. Require the producer and configuration handshakes before checking the claimed state.

The unregister race coverage requires the IIO core to serialize teardown with mode claims, as fixed by mainline commit 84bb0fc46ccf ("iio: buffer:
serialize buffer teardown with mode claims"). That fix is absent from this testing base and is a runtime prerequisite, not part of these test patches.

Assisted-by LLM
---
 drivers/iio/sensorhubs/osf/Kconfig        |   2 +-
 drivers/iio/sensorhubs/osf/Makefile       |   2 +-
 drivers/iio/sensorhubs/osf/osf_iio_test.c | 395 ++++++++++++++++++++++
 3 files changed, 397 insertions(+), 2 deletions(-)
 create mode 100644 drivers/iio/sensorhubs/osf/osf_iio_test.c
drivers/iio/sensorhubs/osf/Kconfig +1 -1
index 6828b79c345092e20743b211b8ca753d51b3b80a..b116e304e24c1549f80cd7a62c14047bfd22f08a 100644
@@ -21,7 +21,7 @@ config OPEN_SENSOR_FUSION_KUNIT_TEST
 	default KUNIT_ALL_TESTS
 	help
 	  Build focused unit tests for the Open Sensor Fusion core sample
-	  acceptance, direct-read cache, and capability/session handling. The tests
+	  acceptance, direct-read cache, and IIO buffer paths. The tests
 	  exercise accepted, ignored, and rejected sample handling without
 	  exposing additional production interfaces.
 
drivers/iio/sensorhubs/osf/Makefile +1 -1
index c2f5ba065a62fef2a4897034239b405ccdd69250..6a28b14cae1f358d485cea67f44df3647939a560 100644
@@ -4,4 +4,4 @@ obj-$(CONFIG_OPEN_SENSOR_FUSION) += open-sensor-fusion.o
 
 open-sensor-fusion-y := osf_core.o osf_iio.o osf_protocol.o osf_serdev.o \
 			 osf_stream.o
-open-sensor-fusion-$(CONFIG_OPEN_SENSOR_FUSION_KUNIT_TEST) += osf_core_test.o
+open-sensor-fusion-$(CONFIG_OPEN_SENSOR_FUSION_KUNIT_TEST) += osf_core_test.o osf_iio_test.o
drivers/iio/sensorhubs/osf/osf_iio_test.c new file +395 -0

395 lines not on this page · raw message