Skip to contentSkip to conversation

KUnit tests for the IIO GTS helpers

PATCH Superseded Matti Vaittinen 3 participants 8 messages Jan 10, 2024 – Jan 15, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Matti Vaittinen

author maintainer
#0 lore raw

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.

Matti Vaittinen (3):
iio: gts-helper: Fix division loop
iio: test: test gain-time-scale helpers
MAINTAINERS: add IIO GTS tests

 MAINTAINERS                           |   1 +
 drivers/iio/industrialio-gts-helper.c |   5 +-
 drivers/iio/test/Kconfig              |  14 +
 drivers/iio/test/Makefile             |   1 +
 drivers/iio/test/iio-test-gts.c       | 517 ++++++++++++++++++++++++++
 5 files changed, 535 insertions(+), 3 deletions(-)
 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 2/3 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:
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 | 517 ++++++++++++++++++++++++++++++++
 3 files changed, 532 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 +517 -0

517 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
#6 lore raw

PATCH 3/3 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 =] 
author maintainer
#7 lore raw
In reply to Matti Vaittinen
Quoted 1 line · Matti Vaittinen

Add some KUnit tests for the IIO GTS helpers.

...

Quoted 2 lines

Matti Vaittinen (3):
iio: gts-helper: Fix division loop

Please ignore the patch 1/3 above. It has been already merged. Unfortunately I noticed this commit being in the series only after sending the cover-letter. In order to not consumer reviewer's time, I omitted sending the 1/3 - so it's missing the series on purpose. Subsequent versions won't include this patch anymore.

Quoted 4 lines

iio: test: test gain-time-scale helper > MAINTAINERS: add IIO GTS tests

  MAINTAINERS                           |   1 +
  drivers/iio/industrialio-gts-helper.c |   5 +-

Also, this file is not changed by patches 2/3 and 3/3.

Sorry!

Yours,
-- Matti

Signature · 5 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~
maintainer
#2 lore raw

Re: [PATCH 2/3] iio: test: test gain-time-scale helpers

In reply to Matti Vaittinen
Quoted 16 lines · On Wed, 10 Jan 2024 12:12:55 +0200 Matti Vaittinen <[email protected]>…

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.

Quoted 8 lines

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.

Hi Matti,

All seems reasonable to me. Some trivial formatting things inline
+ I'm not planning to check the maths as you are the expert in all of this so I'll just trust you!

Also if this fails you get to pick up the pieces :)

Jonathan

Quoted 7 lines

CFLAGS_iio-test-format.o += $(DISABLE_STRUCTLEAK_PLUGIN)

drivers/iio/test/iio-test-gts.c new file +0 -0
new file mode 100644
index 000000000000..4d5271b0c7bc
@@ -0,0 +1,517 @@

...

Quoted 35 lines
drivers/iio/test/iio-test-gts.c new file +35 -0
+
+static void test_iio_find_closest_gain_low(struct kunit *test)
+{
+	struct device *dev;
+	bool in_range;
+	int ret;
+
+	const struct iio_gain_sel_pair gts_test_gains_gain_low[] = {
+		GAIN_SCALE_GAIN(4, TEST_GSEL_4),
+		GAIN_SCALE_GAIN(16, TEST_GSEL_16),
+		GAIN_SCALE_GAIN(32, TEST_GSEL_32),
+	};
+
+	dev = test_init_iio_gain_scale(test, &gts);
+	if (!dev)
+		return;
+
+	ret = iio_find_closest_gain_low(&gts, 2, &in_range);
+	KUNIT_EXPECT_EQ(test, 1, ret);
+	KUNIT_EXPECT_EQ(test, true, in_range);
+
+	ret = iio_find_closest_gain_low(&gts, 1, &in_range);
+	KUNIT_EXPECT_EQ(test, 1, ret);
+	KUNIT_EXPECT_EQ(test, true, in_range);
+
+	ret = iio_find_closest_gain_low(&gts, 4095, &in_range);
+	KUNIT_EXPECT_EQ(test, 2048, ret);
+	KUNIT_EXPECT_EQ(test, true, in_range);
+
+	ret = iio_find_closest_gain_low(&gts, 4097, &in_range);
+	KUNIT_EXPECT_EQ(test, 4096, ret);
+	KUNIT_EXPECT_EQ(test, false, in_range);
+
+	kunit_device_unregister(test, dev);
+

drivers/iio/test/iio-test-gts.c line 346

Quoted 10 lines
drivers/iio/test/iio-test-gts.c new file +10 -0
+	dev = __test_init_iio_gain_scale(test, &gts, gts_test_gains_gain_low,
+				ARRAY_SIZE(gts_test_gains_gain_low),
+				gts_test_itimes, ARRAY_SIZE(gts_test_itimes));
+	if (!dev)
+		return;
+
+	ret = iio_find_closest_gain_low(&gts, 3, &in_range);
+	KUNIT_EXPECT_EQ(test, -EINVAL, ret);
+	KUNIT_EXPECT_EQ(test, false, in_range);
+

As below.

Quoted 17 lines
drivers/iio/test/iio-test-gts.c new file +17 -0
+}
+
+static void test_iio_gts_total_gain_to_scale(struct kunit *test)
+{
+	struct device *dev;
+	int ret, scale_int, scale_nano;
+
+	dev = test_init_iio_gain_scale(test, &gts);
+	if (!dev)
+		return;
+
+	ret = iio_gts_total_gain_to_scale(&gts, 1, &scale_int, &scale_nano);
+	KUNIT_EXPECT_EQ(test, 0, ret);
+	KUNIT_EXPECT_EQ(test, TEST_SCALE_1X, scale_int);
+	KUNIT_EXPECT_EQ(test, 0, scale_nano);
+
+	ret = iio_gts_total_gain_to_scale(&gts, 1, &scale_int, &scale_nano);

drivers/iio/test/iio-test-gts.c line 373

Quoted 10 lines
drivers/iio/test/iio-test-gts.c new file +10 -0
+	KUNIT_EXPECT_EQ(test, 0, ret);
+	KUNIT_EXPECT_EQ(test, TEST_SCALE_1X, scale_int);
+	KUNIT_EXPECT_EQ(test, 0, scale_nano);
+
+	ret = iio_gts_total_gain_to_scale(&gts, 4096 * 8, &scale_int,
+					  &scale_nano);
+	KUNIT_EXPECT_EQ(test, 0, ret);
+	KUNIT_EXPECT_EQ(test, 0, scale_int);
+	KUNIT_EXPECT_EQ(test, TEST_SCALE_NANO_4096X8, scale_nano);
+

No need for a blank line here.

drivers/iio/test/iio-test-gts.c line 394

Quoted 13 lines
drivers/iio/test/iio-test-gts.c new file +12 -0
+}
+
 
+static void test_iio_gts_chk_scales_all(struct kunit *test, struct iio_gts *gts,
+					const int *vals, int len)
+{
+	static const int gains[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512,
+				    1024, 2048, 4096, 4096 * 2, 4096 * 4,
+				    4096 * 8};
+
+	int expected[ARRAY_SIZE(gains) * 2];
+	int i, ret;
+	int exp_len = ARRAY_SIZE(gains) * 2;

Use this for expected[*] just above?

Quoted 78 lines
drivers/iio/test/iio-test-gts.c new file +77 -0
+
+	KUNIT_EXPECT_EQ(test, exp_len, len);
+	if (len != exp_len)
+		return;
+
+	for (i = 0; i < ARRAY_SIZE(gains); i++) {
+		ret = iio_gts_total_gain_to_scale(gts, gains[i],
+						  &expected[2 * i],
+						  &expected[2 * i + 1]);
+		KUNIT_EXPECT_EQ(test, 0, ret);
+		if (ret)
+			return;
+	}
+
+	for (i = 0; i < ARRAY_SIZE(expected); i++)
+		KUNIT_EXPECT_EQ(test, expected[i], vals[i]);
+}
 
+
+static void test_iio_gts_avail_test(struct kunit *test)
+{
+	struct device *dev;
+	int ret;
+	int type, len;
+	const int *vals;
+
+	dev = test_init_iio_gain_scale(test, &gts);
+	if (!dev)
+		return;
+
+	/* test table building for times and iio_gts_avail_times() */
+	ret = iio_gts_avail_times(&gts, &vals, &type, &len);
+	KUNIT_EXPECT_EQ(test, IIO_AVAIL_LIST, ret);
+	if (ret)
+		return;
+
+	KUNIT_EXPECT_EQ(test, IIO_VAL_INT_PLUS_MICRO, type);
+	KUNIT_EXPECT_EQ(test, 8, len);
+	if (len < 8)
+		return;
+
+	test_iio_gts_chk_times(test, vals);
+
+	/* Test table building for all scales and iio_gts_all_avail_scales() */
+	ret = iio_gts_all_avail_scales(&gts, &vals, &type, &len);
+	KUNIT_EXPECT_EQ(test, IIO_AVAIL_LIST, ret);
+	if (ret)
+		return;
+
+	KUNIT_EXPECT_EQ(test, IIO_VAL_INT_PLUS_NANO, type);
+
+	test_iio_gts_chk_scales_all(test, &gts, vals, len);
+
+	/*
+	 * Test table building for scales/time and
+	 * iio_gts_avail_scales_for_time()
+	 */
+	ret = iio_gts_avail_scales_for_time(&gts, 200000, &vals, &type, &len);
+	KUNIT_EXPECT_EQ(test, IIO_AVAIL_LIST, ret);
+	if (ret)
+		return;
+
+	KUNIT_EXPECT_EQ(test, IIO_VAL_INT_PLUS_NANO, type);
+	test_iio_gts_chk_scales_t200(test, &gts, vals, len);
+}
+
+static struct kunit_case iio_gts_test_cases[] = {
+	KUNIT_CASE(test_init_iio_gts_invalid),
+	KUNIT_CASE(test_iio_gts_find_gain_for_scale_using_time),
+	KUNIT_CASE(test_iio_gts_find_new_gain_sel_by_old_gain_time),
+	KUNIT_CASE(test_iio_find_closest_gain_low),
+	KUNIT_CASE(test_iio_gts_total_gain_to_scale),
+	KUNIT_CASE(test_iio_gts_avail_test),
+	{}
+};
+
+static struct kunit_suite iio_gts_test_suite = {
+	.name = "iio-gain-time-scale",

drivers/iio/test/iio-test-gts.c line 517

Quoted 10 lines
drivers/iio/test/iio-test-gts.c new file +10 -0
+	.test_cases = iio_gts_test_cases,
+};
+
+kunit_test_suite(iio_gts_test_suite);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Matti Vaittinen <[email protected]>");
+MODULE_DESCRIPTION("Test IIO light sensor gain-time-scale helpers");
+MODULE_IMPORT_NS(IIO_GTS_HELPER);
+

Looks like a bonus blank line at the end here.

Jonathan

author maintainer
#3 lore raw

Re: [PATCH 2/3] iio: test: test gain-time-scale helpers

Quoted 25 lines · Jonathan Cameron
Quoted 22 lines · On Wed, 10 Jan 2024 12:12:55 +0200 Matti Vaittinen <[email protected]>…

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.

Quoted 7 lines
Quoted 2 lines

Hi Matti,

All seems reasonable to me. Some trivial formatting things inline
+ I'm not planning to check the maths as you are the expert in all of this so I'll just trust you!

Well, all checking is always welcome. Still, I kind of understand that you won't verify everything you see... Oh, and thanks for the trust. :)

Quoted 1 line

Also if this fails you get to pick up the pieces :)

This sure helps to trust ;)

As for things you commented - Thanks! I'll fix them and respin.

Yours,
-- Matti

Signature · 5 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~
author maintainer
#4 lore raw

Re: [PATCH 2/3] iio: test: test gain-time-scale helpers

In reply to Jonathan Cameron
Quoted 27 lines · Jonathan Cameron
Quoted 24 lines · On Wed, 10 Jan 2024 12:12:55 +0200 Matti Vaittinen <[email protected]>…

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.

...

Quoted 4 lines
Quoted 4 lines
drivers/iio/test/iio-test-gts.c new file +4 -0
+static void test_iio_gts_chk_scales_all(struct kunit *test, struct iio_gts *gts,
+					const int *vals, int len)
+{
+	static const int gains[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512,
Quoted 8 lines

drivers/iio/test/iio-test-gts.c line 394

Quoted 6 lines
drivers/iio/test/iio-test-gts.c new file +6 -0
+				    1024, 2048, 4096, 4096 * 2, 4096 * 4,
+				    4096 * 8};
+
+	int expected[ARRAY_SIZE(gains) * 2];
+	int i, ret;
+	int exp_len = ARRAY_SIZE(gains) * 2;

Use this for expected[*] just above?

Doing:
const int exp_len = ARRAY_SIZE(gains) * 2;
int expected[exp_len];

gives me:
warning: ISO C90 forbids variable length array ‘expected’ [-Wvla]

I could drop the whole exp_len variable, but I prefer test code which is as obvious as it gets if any of the checks fails. For me the check:

Quoted 3 lines

drivers/iio/test/iio-test-gts.c line 398

Quoted 3 lines
drivers/iio/test/iio-test-gts.c new file +3 -0
+	KUNIT_EXPECT_EQ(test, exp_len, len);
+	if (len != exp_len)
+		return;

is (very slightly) more obvious than:

	KUNIT_EXPECT_EQ(test, ARRAY_SIZE(gains) * 2, len);
	if (len != ARRAY_SIZE(gains) * 2)
		return;

I guess I'll leave this one as it is. Just kick me in v2 if I misunderstood you :)

Yours,
-- Matti

Signature · 5 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~
#5 lore raw

Re: [PATCH 2/3] iio: test: test gain-time-scale helpers

Quoted 44 lines · On Mon, 15 Jan 2024 15:01:32 +0200 Matti Vaittinen <[email protected]>…
Quoted 27 lines · Jonathan Cameron
Quoted 24 lines · On Wed, 10 Jan 2024 12:12:55 +0200 Matti Vaittinen <[email protected]>…

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.

...

Quoted 4 lines
Quoted 4 lines
drivers/iio/test/iio-test-gts.c new file +4 -0
+static void test_iio_gts_chk_scales_all(struct kunit *test, struct iio_gts *gts,
+					const int *vals, int len)
+{
+	static const int gains[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512,
Quoted 8 lines

drivers/iio/test/iio-test-gts.c line 394

Quoted 6 lines
drivers/iio/test/iio-test-gts.c new file +6 -0
+				    1024, 2048, 4096, 4096 * 2, 4096 * 4,
+				    4096 * 8};
+
+	int expected[ARRAY_SIZE(gains) * 2];
+	int i, ret;
+	int exp_len = ARRAY_SIZE(gains) * 2;  

Use this for expected[*] just above?

Quoted 6 lines

Doing:
const int exp_len = ARRAY_SIZE(gains) * 2;
int expected[exp_len];

gives me:
warning: ISO C90 forbids variable length array ‘expected’ [-Wvla]

Huh. That's a compiler being impressively stupid :(

Just leave it as it is - maybe add a comment to so no one tries to tidy this up in future.

Quoted 9 lines

I could drop the whole exp_len variable, but I prefer test code which is as obvious as it gets if any of the checks fails. For me the check:

Quoted 3 lines

drivers/iio/test/iio-test-gts.c line 398

Quoted 3 lines
drivers/iio/test/iio-test-gts.c new file +3 -0
+	KUNIT_EXPECT_EQ(test, exp_len, len);
+	if (len != exp_len)
+		return;  

is (very slightly) more obvious than:

Quoted 6 lines
	KUNIT_EXPECT_EQ(test, ARRAY_SIZE(gains) * 2, len);
	if (len != ARRAY_SIZE(gains) * 2)
		return;

I guess I'll leave this one as it is. Just kick me in v2 if I misunderstood you :)

yeah, leave it be. Annoying but such is life.

Quoted 4 lines

Yours,
-- Matti