Skip to contentSkip to conversation

lib: Convert test_hexdump.c to KUnit

PATCH Superseded Arpitha Raghunandan 4 participants 5 messages Aug 6, 2020 – Aug 9, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: Convert test_hexdump.c to KUnit

Converts test lib/test_hexdump.c to KUnit.
More information about KUnit can be found at
https://www.kernel.org/doc/html/latest/dev-tools/kunit/index.html.
KUnit provides a common framework for unit tests in the kernel.

---
 lib/Kconfig.debug                       |  7 ++-
 lib/Makefile                            |  2 +-
 lib/{test_hexdump.c => hexdump_kunit.c} | 81 ++++++++++---------------
 3 files changed, 36 insertions(+), 54 deletions(-)
 rename lib/{test_hexdump.c => hexdump_kunit.c} (74%)
lib/Kconfig.debug +4 -3
index a164785c3b48..20efea177e02 100644
@@ -2003,9 +2003,6 @@ config ASYNC_RAID6_TEST
 
 	  If unsure, say N.
 
-config TEST_HEXDUMP
-	tristate "Test functions located in the hexdump module at runtime"
-
 config TEST_STRING_HELPERS
 	tristate "Test functions located in the string_helpers module at runtime"
 
@@ -2224,6 +2221,10 @@ config LINEAR_RANGES_TEST
 
 	  If unsure, say N.
 
+config HEXDUMP_KUNIT_TEST
+	tristate "KUnit test for functions located in the hexdump module at runtime"
+	depends on KUNIT
+
 config TEST_UDELAY
 	tristate "udelay test driver"
 	help
lib/Makefile +1 -1
index 435f7f13b8aa..3819d42a4681 100644
@@ -54,7 +54,6 @@ obj-$(CONFIG_STRING_SELFTEST) += test_string.o
 obj-y += string_helpers.o
 obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o
 obj-y += hexdump.o
-obj-$(CONFIG_TEST_HEXDUMP) += test_hexdump.o
 obj-y += kstrtox.o
 obj-$(CONFIG_FIND_BIT_BENCHMARK) += find_bit_benchmark.o
 obj-$(CONFIG_TEST_BPF) += test_bpf.o
@@ -346,3 +345,4 @@ obj-$(CONFIG_PLDMFW) += pldmfw/
 # KUnit tests
 obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o
 obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o
+obj-$(CONFIG_HEXDUMP_KUNIT_TEST) += hexdump_kunit.o
lib/hexdump_kunit.c renamed from lib/test_hexdump.c +31 -50

156 lines not on this page · raw message

Signature · 6 lines
2.25.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#1 lore raw

lib/Kconfig.debug config ASYNC_RAID6_TEST · line 2007

Quoted 8 lines · Arpitha Raghunandan

Converts test lib/test_hexdump.c to KUnit.
More information about KUnit can be found at
https://www.kernel.org/doc/html/latest/dev-tools/kunit/index.html.
KUnit provides a common framework for unit tests in the kernel.

lib/Kconfig.debug +0 -2
-config TEST_HEXDUMP
-       tristate "Test functions located in the hexdump module at runtime"

We have a nice collection of tests starting with TEST_ in the configuration, now it's gone.
I'm strongly against this change.
Code itself okay, but without addressing above - NAK.

Signature · 6 lines
With Best Regards,
Andy Shevchenko
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#3 lore raw
In reply to Arpitha Raghunandan
Quoted 4 lines · Arpitha Raghunandan

Converts test lib/test_hexdump.c to KUnit.
More information about KUnit can be found at
https://www.kernel.org/doc/html/latest/dev-tools/kunit/index.html.
KUnit provides a common framework for unit tests in the kernel.

...

lib/hexdump_kunit.c static void __init test_hexdump(size_t len, int rowsize, int groupsize, · line 137

Quoted 7 lines
lib/hexdump_kunit.c renamed from lib/test_hexdump.c +1 -6
-	if (memcmp(test, real, TEST_HEXDUMP_BUF_SIZE)) {
-		pr_err("Len: %zu row: %d group: %d\n", len, rowsize, groupsize);
-		pr_err("Result: '%s'\n", real);
-		pr_err("Expect: '%s'\n", test);
-		failed_tests++;
-	}
+	KUNIT_EXPECT_EQ(kunittest, 0, memcmp(test, real, TEST_HEXDUMP_BUF_SIZE));

Ah, can you explain how user will see now what is being expected and what is in reality in the buffer? I'm not gonna accept such changes without showing in explicitly that user is not going to suffer of this change.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Arpitha Raghunandan

Converts test lib/test_hexdump.c to KUnit.
More information about KUnit can be found at
https://www.kernel.org/doc/html/latest/dev-tools/kunit/index.html.
KUnit provides a common framework for unit tests in the kernel.

Quoted 8 lines

lib/Kconfig.debug config ASYNC_RAID6_TEST · line 2007

Quoted 2 lines
lib/Kconfig.debug +0 -2
-config TEST_HEXDUMP
-       tristate "Test functions located in the hexdump module at runtime"

We have a nice collection of tests starting with TEST_ in the configuration, now it's gone.
I'm strongly against this change.
Code itself okay, but without addressing above - NAK.

This change is to make the test naming compliant with the proposed
KUnit test naming guidelines:
- https://lore.kernel.org/linux-kselftest/[email protected]/

The hope is that tests built on KUnit will all end up with the same [x]_KUNIT_TEST config options (which at least preserves the consistency of the test naming, even if they'll not all sort together), and should make it easier for people to know that the test results will be in a common format, and that the test can also be run using the KUnit tools.

The naming guidelines haven't been upstreamed yet, though, so we'd definitely appreciate input on that thread if you've got comments more broadly than for this particular patch. Ultimately, I don't think it matters too much what we end up using, but having some consistency is the goal.

#4 lore raw
In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
Quoted 4 lines · Arpitha Raghunandan

Converts test lib/test_hexdump.c to KUnit.
More information about KUnit can be found at
https://www.kernel.org/doc/html/latest/dev-tools/kunit/index.html.
KUnit provides a common framework for unit tests in the kernel.

...

Quoted 13 lines

lib/hexdump_kunit.c static void __init test_hexdump(size_t len, int rowsize, int groupsize, · line 137

Quoted 7 lines
lib/hexdump_kunit.c renamed from lib/test_hexdump.c +1 -6
-	if (memcmp(test, real, TEST_HEXDUMP_BUF_SIZE)) {
-		pr_err("Len: %zu row: %d group: %d\n", len, rowsize, groupsize);
-		pr_err("Result: '%s'\n", real);
-		pr_err("Expect: '%s'\n", test);
-		failed_tests++;
-	}
+	KUNIT_EXPECT_EQ(kunittest, 0, memcmp(test, real, TEST_HEXDUMP_BUF_SIZE));

Ah, can you explain how user will see now what is being expected and what is in reality in the buffer? I'm not gonna accept such changes without showing in explicitly that user is not going to suffer of this change.

I have sent another patch replacing KUNIT_EXPECT_EQ() with KUNIT_EXPECT_EQ_MSG() and KUNIT_EXPECT_NE() with KUNIT_EXPECT_NE_MSG(). These methods log what is being expected and what is in reality in the buffer in case of test failure similar to the original test.