iio: test: iio-test-format: add test case for char format
PATCH 1/1 iio: test: iio-test-format: add test case for char format
IIO_VAL_CHAR is used by thermocouple drivers to report the thermocouple type, but iio_format_value() has no test for it.
Add a test case that checks a single character is printed followed by a newline.
---
Tested with KUnit on arm64 QEMU: all 8 iio-format cases pass.
--- drivers/iio/test/iio-test-format.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
drivers/iio/test/iio-test-format.c +23 -0
@@ -197,6 +197,28 @@ static void iio_test_iio_format_value_multiple(struct kunit *test)IIO_TEST_FORMAT_EXPECT_EQ (test, buf, ret,"1 -2 3 -4 5 \n" ); } +static void iio_test_iio_format_value_char (struct kunit *test) +{ +char *buf; +int val; +int ret; + + buf =kunit_kmalloc (test,PAGE_SIZE ,GFP_KERNEL ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, buf); + + val ='K' ; + ret =iio_format_value (buf,IIO_VAL_CHAR ,1 , &val); +IIO_TEST_FORMAT_EXPECT_EQ (test, buf, ret,"K\n" ); + + val ='j' ; + ret =iio_format_value (buf,IIO_VAL_CHAR ,1 , &val); +IIO_TEST_FORMAT_EXPECT_EQ (test, buf, ret,"j\n" ); + + val ='0' ; + ret =iio_format_value (buf,IIO_VAL_CHAR ,1 , &val); +IIO_TEST_FORMAT_EXPECT_EQ (test, buf, ret,"0\n" ); +} +static void iio_test_iio_format_value_integer_64 (struct kunit *test) {int values[2 ];
@@ -308,6 +330,7 @@ static struct kunit_case iio_format_test_cases[] = {KUNIT_CASE (iio_test_iio_format_value_fractional),KUNIT_CASE (iio_test_iio_format_value_fractional_log2),KUNIT_CASE (iio_test_iio_format_value_multiple), +KUNIT_CASE (iio_test_iio_format_value_char),KUNIT_CASE (iio_test_iio_format_value_integer_64), KUNIT_CASE(iio_test_iio_format_value_decimal_64), { }
---
base-commit: c9dbe2a47f635465c9985b7af74d2ae310e98125
change-id: 20261025-iio-test-format-char-8a17fbf9a201
Best regards,
Signature · 1 line
Raffaele Tranfaglia <[email protected]>
Quoted 9 lines · On Sun, Oct 25, 2026 at 04:59:41PM +0000, Raffaele Tranfaglia via B4 Relay…
From: Raffaele Tranfaglia <[email protected]>
IIO_VAL_CHARis used by thermocouple drivers to report the thermocouple type, butiio_format_value()has no test for it.Add a test case that checks a single character is printed followed by a newline.
Assisted-by LLM
Already outdated tag, please drop. Instead mention the AI usage in the comment block (after '---' line).
Quoted 1 line
Signed-off-by Raffaele Tranfaglia <[email protected]>
...
Quoted 11 lines
drivers/iio/test/iio-test-format.c +11
-0+static void iio_test_iio_format_value_char (struct kunit *test) +{ +char *buf; +int val; +int ret; + + buf =kunit_kmalloc (test,PAGE_SIZE ,GFP_KERNEL ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, buf); + + val ='K' ; + ret =iio_format_value (buf,IIO_VAL_CHAR ,1 , &val);
drivers/iio/test/iio-test-format.c static void iio_test_iio_format_value_multiple(struct kunit *test) · line 220
Quoted 10 lines
drivers/iio/test/iio-test-format.c +10
-0+IIO_TEST_FORMAT_EXPECT_EQ (test, buf, ret,"K\n" ); + + val ='j' ; + ret =iio_format_value (buf,IIO_VAL_CHAR ,1 , &val); +IIO_TEST_FORMAT_EXPECT_EQ (test, buf, ret,"j\n" ); + + val ='0' ; + ret =iio_format_value (buf,IIO_VAL_CHAR ,1 , &val); +IIO_TEST_FORMAT_EXPECT_EQ (test, buf, ret,"0\n" ); +}
Add non-printable, special, et cetera test cases.
Make sure that IIO_TEST_FORMAT_EXPECT_EQ() check the entire buffer against poison so we will know that iio_format_value() in the case of IIO_VAL_CHAR doesn't write more than it is supposed to.
Signature · 2 lines
With Best Regards, Andy Shevchenko