Skip to contentSkip to conversation

Add module build support for KUnit IIO tests

PATCH In review Liam Beguin 2 participants 7 messages Jul 10, 2022 – Jul 16, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Add module build support for KUnit IIO tests

KUnit tests can be built as modules allowing to execute them at runtime by simply loading the modules.

Module build support is added with the following steps:
- add MODULE_* in the KUnit test drivers,
- export namespace symbols from the iio-rescale, and
- drop Kconfig built-in only constraints,

Along with the module build changes, this series also addresses minor touch ups such as:
- rename IIO_TEST_FORMAT Kconfig to match naming conventions,
- use tabs to indent the IIO_FORMAT_KUNIT_TEST Kconfig,
- drop ARCH=um mention from the IIO_RESCALE_KUNIT_TEST Kconfig help section,
- add IIO_FORMAT_KUNIT_TEST Kconfig help section,
- update dependency on KUNIT_ALL_TESTS to match the documentation.

All these are done in commit 05/05. I could rework the commit, but given that these changes are pretty minor, it seemed okay to do it all at once.

Cheers,
Liam

Liam Beguin (5):
iio: test: rescale: add MODULE_* information
iio: test: format: add MODULE_* information
iio: test: format: follow CONFIG_ naming convention
iio: afe: rescale: export symbols used during testing
iio: test: rework Kconfig to support modules

 drivers/iio/afe/iio-rescale.c       |  2 ++
 drivers/iio/test/Kconfig            | 26 ++++++++++++++++++--------
 drivers/iio/test/Makefile           |  2 +-
 drivers/iio/test/iio-test-format.c  |  4 ++++
 drivers/iio/test/iio-test-rescale.c |  5 +++++
 5 files changed, 30 insertions(+), 9 deletions(-)

base-commit: b1c428b6c3684ee8ddf4137d68b3e8d51d2a700f

Signature · 1 line
2.35.1.4.g5d01301f2b86
#1 lore raw

PATCH 1/5 iio: test: rescale: add MODULE_* information

In preparation for module support, add missing MODULE_* information.

---
 drivers/iio/test/iio-test-rescale.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/iio/test/iio-test-rescale.c +4 -0
index 0b6699bfd553..735e2f97af18 100644
@@ -708,3 +708,7 @@ static struct kunit_suite iio_rescale_test_suite = {
 	.test_cases = iio_rescale_test_cases,
 };
 kunit_test_suite(iio_rescale_test_suite);
+
+MODULE_AUTHOR("Liam Beguin <[email protected]>");
+MODULE_DESCRIPTION("Test IIO rescale conversion functions");
+MODULE_LICENSE("GPL v2");
Signature · 1 line
2.35.1.4.g5d01301f2b86
#2 lore raw

PATCH 2/5 iio: test: format: add MODULE_* information

In reply to Liam Beguin

In preparation for module support, add missing MODULE_* information.

---
 drivers/iio/test/iio-test-format.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/iio/test/iio-test-format.c +4 -0
index 237321436b83..fc67e6b73df7 100644
@@ -265,3 +265,7 @@ static struct kunit_suite iio_format_test_suite = {
 	.test_cases = iio_format_test_cases,
 };
 kunit_test_suite(iio_format_test_suite);
+
+MODULE_AUTHOR("Lars-Peter Clausen <[email protected]>");
+MODULE_DESCRIPTION("Test IIO formatting functions");
+MODULE_LICENSE("GPL v2");
Signature · 1 line
2.35.1.4.g5d01301f2b86
#3 lore raw

PATCH 3/5 iio: test: format: follow CONFIG_ naming convention

In reply to Liam Beguin

The KUnit documentation indicates that all KUnit Kconfig entries must match CONFIG_<name>_KUNIT_TEST: where <name> is the name of the test suite. Rename the IIO_TEST_FORMAT configuration accordingly.

---
 drivers/iio/test/Kconfig  | 2 +-
 drivers/iio/test/Makefile | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/iio/test/Kconfig +1 -1
index 4c66c3f18c34..7dbf51bc4934 100644
@@ -14,6 +14,6 @@ config IIO_RESCALE_KUNIT_TEST
 	  This takes advantage of ARCH=um to run tests and should be used by
 	  developers to tests their changes to the rescaling logic.
 
-config IIO_TEST_FORMAT
+config IIO_FORMAT_KUNIT_TEST
         bool "Test IIO formatting functions"
         depends on KUNIT=y
drivers/iio/test/Makefile +1 -1
index 880360f8d02c..d76eaf36da82 100644
@@ -5,5 +5,5 @@
 
 # Keep in alphabetical order
 obj-$(CONFIG_IIO_RESCALE_KUNIT_TEST) += iio-test-rescale.o
-obj-$(CONFIG_IIO_TEST_FORMAT) += iio-test-format.o
+obj-$(CONFIG_IIO_FORMAT_KUNIT_TEST) += iio-test-format.o
 CFLAGS_iio-test-format.o += $(DISABLE_STRUCTLEAK_PLUGIN)
Signature · 1 line
2.35.1.4.g5d01301f2b86
#4 lore raw

PATCH 4/5 iio: afe: rescale: export symbols used during testing

In reply to Liam Beguin

In preparation for module support, export symbols use during testing.

---
 drivers/iio/afe/iio-rescale.c       | 2 ++
 drivers/iio/test/iio-test-rescale.c | 1 +
 2 files changed, 3 insertions(+)
drivers/iio/afe/iio-rescale.c +2 -0
index 6949d2151025..1f280c360701 100644
@@ -107,6 +107,7 @@ int rescale_process_scale(struct rescale *rescale, int scale_type,
 		return -EOPNOTSUPP;
 	}
 }
+EXPORT_SYMBOL_NS_GPL(rescale_process_scale, IIO_RESCALE);
 
 int rescale_process_offset(struct rescale *rescale, int scale_type,
 			   int scale, int scale2, int schan_off,
@@ -140,6 +141,7 @@ int rescale_process_offset(struct rescale *rescale, int scale_type,
 		return -EOPNOTSUPP;
 	}
 }
+EXPORT_SYMBOL_NS_GPL(rescale_process_offset, IIO_RESCALE);
 
 static int rescale_read_raw(struct iio_dev *indio_dev,
 			    struct iio_chan_spec const *chan,
drivers/iio/test/iio-test-rescale.c +1 -0
index 735e2f97af18..cc782ccff880 100644
@@ -712,3 +712,4 @@ kunit_test_suite(iio_rescale_test_suite);
 MODULE_AUTHOR("Liam Beguin <[email protected]>");
 MODULE_DESCRIPTION("Test IIO rescale conversion functions");
 MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(IIO_RESCALE);
Signature · 1 line
2.35.1.4.g5d01301f2b86
#5 lore raw

PATCH 5/5 iio: test: rework Kconfig to support modules

In reply to Liam Beguin

Rework the IIO test Kconfig to support building KUnit tests as modules. This lets users execute tests at runtime in addition to the usual tools/testing/kunit/kunit.py script.

---
 drivers/iio/test/Kconfig | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
drivers/iio/test/Kconfig +17 -7
index 7dbf51bc4934..82924727b2cc 100644
@@ -5,15 +5,25 @@
 
 # Keep in alphabetical order
 config IIO_RESCALE_KUNIT_TEST
-	bool "Test IIO rescale conversion functions"
-	depends on KUNIT=y && IIO_RESCALE=y
+	tristate "Test IIO rescale conversion functions" if !KUNIT_ALL_TESTS
+	depends on KUNIT && IIO_RESCALE
 	default KUNIT_ALL_TESTS
 	help
-	  If you want to run tests on the iio-rescale code say Y here.
+	  build unit tests for the iio-rescale code.
 
-	  This takes advantage of ARCH=um to run tests and should be used by
-	  developers to tests their changes to the rescaling logic.
+	  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 IIO_FORMAT_KUNIT_TEST
-        bool "Test IIO formatting functions"
-        depends on KUNIT=y
+	tristate "Test IIO formatting functions" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  build unit tests for the IIO formatting functions.
+
+	  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.
Signature · 1 line
2.35.1.4.g5d01301f2b86
maintainer
#6 lore raw

Re: [PATCH v1 5/5] iio: test: rework Kconfig to support modules

Quoted 5 lines · On Sat, 9 Jul 2022 21:31:09 -0400 Liam Beguin <[email protected]> wrote:

Rework the IIO test Kconfig to support building KUnit tests as modules. This lets users execute tests at runtime in addition to the usual tools/testing/kunit/kunit.py script.

One trivial comment inline. Fixed that up and applied to the togreg branch of iio.git. Not I'll only push out as testing for now as will be rebasing the tree after rc1.

Jonathan

Quoted 10 lines
---
 drivers/iio/test/Kconfig | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
drivers/iio/test/Kconfig +0 -0
index 7dbf51bc4934..82924727b2cc 100644
@@ -5,15 +5,25 @@
 

drivers/iio/test/Kconfig line 12

Quoted 10 lines
drivers/iio/test/Kconfig +3 -3
 # Keep in alphabetical order
 config IIO_RESCALE_KUNIT_TEST
-	bool "Test IIO rescale conversion functions"
-	depends on KUNIT=y && IIO_RESCALE=y
+	tristate "Test IIO rescale conversion functions" if !KUNIT_ALL_TESTS
+	depends on KUNIT && IIO_RESCALE
 	default KUNIT_ALL_TESTS
 	help
-	  If you want to run tests on the iio-rescale code say Y here.
+	  build unit tests for the iio-rescale code.

Build

Quoted 21 lines
drivers/iio/test/Kconfig +14 -4
-	  This takes advantage of ARCH=um to run tests and should be used by
-	  developers to tests their changes to the rescaling logic.
+	  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 IIO_FORMAT_KUNIT_TEST
-        bool "Test IIO formatting functions"
-        depends on KUNIT=y
+	tristate "Test IIO formatting functions" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  build unit tests for the IIO formatting functions.
+
+	  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.