mm: Add KUNIT test for ptval_bytes_to_hex_str()
Subsystems (2)
RFC 1/1 mm: Add KUNIT test for ptval_bytes_to_hex_str()
Add KUnit tests for ptval_bytes_to_hex_str() to verify conversion of 32-bit 64-bit, and 128-bit (when supported) page table entry values into printable hexadecimal strings.
Add a new PTVAL_HEX_STR_KUNIT_TEST option to enable the tests.
---
This patch applies on v7.3-rc5 after the following series
https://lore.kernel.org/linux-mm/[email protected]/
mm/Kconfig | 11 +++ mm/Makefile | 1 + mm/tests/ptval_hex_string_kunit.c | 111 ++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 mm/tests/ptval_hex_string_kunit.c
mm/Kconfig +11 -0
@@ -1511,6 +1511,17 @@ config LAZY_MMU_MODE_KUNIT_TEST If unsure, say N. +config PTVAL_HEX_STR_KUNIT_TEST + bool "KUnit tests for pgtable entry string conversion" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS + help + Enable this option to check that ptval_bytes_to_hex_str() is able + convert given pgtable entry value in bytes into hex strings which + could be printed. + + If unsure, say N. + source "mm/damon/Kconfig" endmenu
mm/Makefile +1 -0
@@ -147,4 +147,5 @@ obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o obj-$(CONFIG_EXECMEM) += execmem.o obj-$(CONFIG_TMPFS_QUOTA) += shmem_quota.o obj-$(CONFIG_LAZY_MMU_MODE_KUNIT_TEST) += tests/lazy_mmu_mode_kunit.o +obj-$(CONFIG_PTVAL_HEX_STR_KUNIT_TEST) += tests/ptval_hex_string_kunit.o obj-$(CONFIG_MEM_ALLOC_PROFILING) += alloc_tag.o
mm/tests/ptval_hex_string_kunit.c new file +111 -0
111 lines not on this page · raw message
Signature · 1 line
2.43.0
David Hildenbrand (Arm)
maintainerQuoted 31 lines · Anshuman Khandual
Add KUnit tests for
ptval_bytes_to_hex_str()to verify conversion of 32-bit 64-bit, and 128-bit (when supported) page table entry values into printable hexadecimal strings.Add a new
PTVAL_HEX_STR_KUNIT_TESToption to enable the tests.Cc Andrew Morton <[email protected]>Cc David Hildenbrand <[email protected]>Cc Lorenzo Stoakes <[email protected]>Signed-off-by Anshuman Khandual <[email protected]>---
This patch applies on v7.3-rc5 after the following serieshttps://lore.kernel.org/linux-mm/[email protected]/
mm/Kconfig | 11 +++ mm/Makefile | 1 + mm/tests/ptval_hex_string_kunit.c | 111 ++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 mm/tests/ptval_hex_string_kunit.cmm/Kconfig +0
-0@@ -1511,6 +1511,17 @@ config LAZY_MMU_MODE_KUNIT_TEST If unsure, say N.
mm/Kconfig config LAZY_MMU_MODE_KUNIT_TEST · line 1523
Quoted 10 lines
mm/Kconfig +10
-0+config PTVAL_HEX_STR_KUNIT_TEST + bool "KUnit tests for pgtable entry string conversion" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS + help + Enable this option to check that ptval_bytes_to_hex_str() is able + convert given pgtable entry value in bytes into hex strings which + could be printed. + + If unsure, say N.
That's a bit fine grained :)
Could we somehow pack this under another existing / more generic test? We don't want one new test for every new function :)
An alternative would be to use mm/debug_vm_pgtable.c to just run 3 tests at runtime as well.
Quoted 22 lines
mm/Kconfig +1
-0+ source "mm/damon/Kconfig" endmenumm/Makefile +1
-0@@ -147,4 +147,5 @@ obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o obj-$(CONFIG_EXECMEM) += execmem.o obj-$(CONFIG_TMPFS_QUOTA) += shmem_quota.o obj-$(CONFIG_LAZY_MMU_MODE_KUNIT_TEST) += tests/lazy_mmu_mode_kunit.o +obj-$(CONFIG_PTVAL_HEX_STR_KUNIT_TEST) += tests/ptval_hex_string_kunit.o obj-$(CONFIG_MEM_ALLOC_PROFILING) += alloc_tag.omm/tests/ptval_hex_string_kunit.c new file +2
-0@@ -0,0 +1,111 @@ +// SPDX-License-Identifier: GPL-2.0 +
mm/tests/ptval_hex_string_kunit.c line 12
Quoted 10 lines
mm/tests/ptval_hex_string_kunit.c new file +10
-0+#include <kunit/test.h> +#include <linux/pgtable.h> + +struct ptval_str { +u64 val; +const char *str; +}; + +static struct ptval_str ptval_u32_tests[] = { + { .val =0x1234abcd , .str ="1234abcd" },
Isn't a single test like this enough. Why would we need the other ones?
So I think this could all get condensed quite a bit (including the test functions, a single one should be sufficient if we really only end up with 3 tests).
Signature · 3 lines
Cheers, David
Quoted 45 lines · David Hildenbrand (Arm)
Quoted 31 lines · Anshuman Khandual
Add KUnit tests for
ptval_bytes_to_hex_str()to verify conversion of 32-bit 64-bit, and 128-bit (when supported) page table entry values into printable hexadecimal strings.Add a new
PTVAL_HEX_STR_KUNIT_TESToption to enable the tests.Cc Andrew Morton <[email protected]>Cc David Hildenbrand <[email protected]>Cc Lorenzo Stoakes <[email protected]>Signed-off-by Anshuman Khandual <[email protected]>---
This patch applies on v7.3-rc5 after the following serieshttps://lore.kernel.org/linux-mm/[email protected]/
mm/Kconfig | 11 +++ mm/Makefile | 1 + mm/tests/ptval_hex_string_kunit.c | 111 ++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 mm/tests/ptval_hex_string_kunit.cmm/Kconfig +0
-0@@ -1511,6 +1511,17 @@ config LAZY_MMU_MODE_KUNIT_TEST If unsure, say N.mm/Kconfig config LAZY_MMU_MODE_KUNIT_TEST · line 1523
Quoted 10 lines
mm/Kconfig +10
-0+config PTVAL_HEX_STR_KUNIT_TEST + bool "KUnit tests for pgtable entry string conversion" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS + help + Enable this option to check that ptval_bytes_to_hex_str() is able + convert given pgtable entry value in bytes into hex strings which + could be printed. + + If unsure, say N.That's a bit fine grained :)
Quoted 2 lines
Could we somehow pack this under another existing / more generic test? We don't want one new test for every new function :)
Probably right. We don't need one test for each new function.
Quoted 3 lines
An alternative would be to use
mm/debug_vm_pgtable.cto just run 3 tests at runtime as well.
Yes - that could work as well given its printing pgtable entries but those tests would not be KUNIT based any more I guess. Although just like the existing VM_WARN_ON() check, new tests should be sufficient.
Quoted 36 lines
Quoted 23 lines
mm/Kconfig +1
-0+ source "mm/damon/Kconfig" endmenumm/Makefile +1
-0@@ -147,4 +147,5 @@ obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o obj-$(CONFIG_EXECMEM) += execmem.o obj-$(CONFIG_TMPFS_QUOTA) += shmem_quota.o obj-$(CONFIG_LAZY_MMU_MODE_KUNIT_TEST) += tests/lazy_mmu_mode_kunit.o +obj-$(CONFIG_PTVAL_HEX_STR_KUNIT_TEST) += tests/ptval_hex_string_kunit.o obj-$(CONFIG_MEM_ALLOC_PROFILING) += alloc_tag.omm/tests/ptval_hex_string_kunit.c new file +2
-0@@ -0,0 +1,111 @@ +// SPDX-License-Identifier: GPL-2.0 +mm/tests/ptval_hex_string_kunit.c line 12
Quoted 10 lines
mm/tests/ptval_hex_string_kunit.c new file +10
-0+#include <kunit/test.h> +#include <linux/pgtable.h> + +struct ptval_str { +u64 val; +const char *str; +}; + +static struct ptval_str ptval_u32_tests[] = { + { .val =0x1234abcd , .str ="1234abcd" },Isn't a single test like this enough. Why would we need the other ones?
Quoted 2 lines
So I think this could all get condensed quite a bit (including the test functions, a single one should be sufficient if we really only end up with 3 tests).
If we continue with KUNIT framework, probably all three tests are still required to distingish them but in mm/debug_vm_pgatble.c based approach a single test can combine all these tests via VM_WARN_ON().
Quoted 5 lines
Signature · 4 lines
-- Cheers, David