Skip to contentSkip to conversation

KUnit tests for the IIO GTS helpers

PATCH In review Matti Vaittinen 2 participants 4 messages Jan 15, 2024 – Jan 21, 2024

Subsystems (2)
lore
Share & tools
lore

Matti Vaittinen

author maintainer
#0 lore raw

v2 cover KUnit tests for the IIO GTS helpers

Add some KUnit tests for the IIO GTS helpers.

These tests were originally part of the BU27034 ALS sensor driver series.
https://lore.kernel.org/all/[email protected]/

Merging the tests was postponed because we lacked of a good generic way of creating tests devices for testing the devm managed interfaces. Now we have kunit_device APIs being merged (seems like they'll be part of the v6.8-rc1) so precondition for merging these tests are (being) met.

The series is based on
commit ab27740f7665 ("Merge tag 'linux_kselftest-next-6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest")
in Linus' tree.

I can rebase and resend when v6.8-rc1 is out if needed.

Revision history:

v2:
- Drop already applied division loop fix patch
- Remove unnecessary empty lines

---

Matti Vaittinen (2):
iio: test: test gain-time-scale helpers
MAINTAINERS: add IIO GTS tests

 MAINTAINERS                     |   1 +
 drivers/iio/test/Kconfig        |  14 +
 drivers/iio/test/Makefile       |   1 +
 drivers/iio/test/iio-test-gts.c | 513 ++++++++++++++++++++++++++++++++
 4 files changed, 529 insertions(+)
 create mode 100644 drivers/iio/test/iio-test-gts.c

base-commit: ab27740f76654ed58dd32ac0ba0031c18a6dea3b

Signature · 14 lines
2.43.0


-- 
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =] 
author maintainer
#1 lore raw

PATCH v2 1/2 iio: test: test gain-time-scale helpers

Some light sensors can adjust both the HW-gain and integration time. There are cases where adjusting the integration time has similar impact to the scale of the reported values as gain setting has.

IIO users do typically expect to handle scale by a single writable 'scale' entry. Driver should then adjust the gain/time accordingly.

It however is difficult for a driver to know whether it should change gain or integration time to meet the requested scale. Usually it is preferred to have longer integration time which usually improves accuracy, but there may be use-cases where long measurement times can be an issue. Thus it can be preferable to allow also changing the integration time - but mitigate the scale impact by also changing the gain underneath. Eg, if integration time change doubles the measured values, the driver can reduce the HW-gain to half.

The theory of the computations of gain-time-scale is simple. However, some people (undersigned) got that implemented wrong for more than once. Hence some gain-time-scale helpers were introduced.

Add some simple tests to verify the most hairy functions.

---

This patch depends on the KUnit managed device APIs which seem to get merged to v6.8-rc1.

Changes:
v1 => v2: (As per the review by Jonathan)
- remove extra whitespaces

Below history uses numbering from the series which added the GTS helpers to the IIO - tree. The numbering was restarted as the GTS helpers series was applied while this patch was dropped as kunit_device support was not yet there.

v6 => v7:
- Fix available integration times to be expressed in seconds

v5 => v6:
- Use kunit root-device registration wrapper

v4 => v5:
- remove empty lines from Kconfig
- adapt to drop of the non devm iio_init
- test also init with couple of invalid tables

v3 => v4:
- use dummy device to test devm interfaces
- adapt to the new header location
- drop tests for dropped interfaces

v2 => v3:
- Use namespace for iio-gts-helpers

RFCv1 => v2:
- add tests for available scales/times helpers
- adapt to renamed iio-gts-helpers.h header

---
 drivers/iio/test/Kconfig        |  14 +
 drivers/iio/test/Makefile       |   1 +
 drivers/iio/test/iio-test-gts.c | 513 ++++++++++++++++++++++++++++++++
 3 files changed, 528 insertions(+)
 create mode 100644 drivers/iio/test/iio-test-gts.c
drivers/iio/test/Kconfig +14 -0
index 0b6e4e278a2f..33cca49c8058 100644
@@ -4,6 +4,20 @@
 #
 
 # Keep in alphabetical order
+config IIO_GTS_KUNIT_TEST
+	tristate "Test IIO formatting functions" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	select IIO_GTS_HELPER
+	select TEST_KUNIT_DEVICE_HELPERS
+	default KUNIT_ALL_TESTS
+	help
+	  build unit tests for the IIO light sensor gain-time-scale helpers.
+
+	  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. Keep in alphabetical order
+
 config IIO_RESCALE_KUNIT_TEST
 	tristate "Test IIO rescale conversion functions" if !KUNIT_ALL_TESTS
 	depends on KUNIT && IIO_RESCALE
drivers/iio/test/Makefile +1 -0
index d76eaf36da82..e9a4cf1ff57f 100644
@@ -6,4 +6,5 @@
 # Keep in alphabetical order
 obj-$(CONFIG_IIO_RESCALE_KUNIT_TEST) += iio-test-rescale.o
 obj-$(CONFIG_IIO_FORMAT_KUNIT_TEST) += iio-test-format.o
+obj-$(CONFIG_IIO_GTS_KUNIT_TEST) += iio-test-gts.o
 CFLAGS_iio-test-format.o += $(DISABLE_STRUCTLEAK_PLUGIN)
drivers/iio/test/iio-test-gts.c new file +513 -0

513 lines not on this page · raw message

Signature · 14 lines
2.43.0


-- 
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =] 
author maintainer
#2 lore raw

PATCH v2 2/2 MAINTAINERS: add IIO GTS tests

In reply to Matti Vaittinen

Add undersigned as a maintainer for IIO GTS helper's KUnit tests.

---
This may or may not conflict with the filename fix here:
https://lore.kernel.org/all/CAO=gReFVhp7QK_XZRBO5vbv6fmFb4BdsZeQPSzWvuiz9UeQekA@mail.gmail.com/

Conflict should be very trivial so I didn't wait for the above fix to get in IIO tree. I can rebase and resend if this appears to be a problem though.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index 40c754b4c39c..05c13e0f8c4d 100644
@@ -10310,6 +10310,7 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/iio/light/gain-time-scale-helper.c
 F:	drivers/iio/light/gain-time-scale-helper.h
+F:	drivers/iio/test/iio-test-gts.c
 
 IIO MULTIPLEXER
 M:	Peter Rosin <[email protected]>
Signature · 14 lines
2.43.0


-- 
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =] 
maintainer
#3 lore raw

Re: [PATCH v2 2/2] MAINTAINERS: add IIO GTS tests

Quoted 20 lines · On Mon, 15 Jan 2024 16:26:33 +0200 Matti Vaittinen <[email protected]>…

Add undersigned as a maintainer for IIO GTS helper's KUnit tests.

---
This may or may not conflict with the filename fix here:
https://lore.kernel.org/all/CAO=gReFVhp7QK_XZRBO5vbv6fmFb4BdsZeQPSzWvuiz9UeQekA@mail.gmail.com/

Conflict should be very trivial so I didn't wait for the above fix to get in IIO tree. I can rebase and resend if this appears to be a problem though.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +0 -0
index 40c754b4c39c..05c13e0f8c4d 100644

MAINTAINERS L: [email protected] · line 10313

Quoted 4 lines
MAINTAINERS +1 -0
@@ -10310,6 +10310,7 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/iio/light/gain-time-scale-helper.c
 F:	drivers/iio/light/gain-time-scale-helper.h
+F:	drivers/iio/test/iio-test-gts.c

This needed a manual merge as you pointed out.

Otherwise all lgtm and applied to the togreg branch of iio.git.

It's on an odd base as the moment though so I'll rebase on rc1 once available.

Thanks,

Jonathan

Quoted 3 lines
MAINTAINERS +0 -0
 IIO MULTIPLEXER
 M:	Peter Rosin <[email protected]>