cpumask: KUnit test suite fixes and improvements
Subsystems (2)
v2 cover cpumask: KUnit test suite fixes and improvements
This series fixes the reported issues, and implements the suggested improvements, for the version of the cpumask tests [1] that was merged with commit c41e8866c28c ("lib/test: introduce cpumask KUnit test suite").
These changes include fixes for the tests, and better alignment with the KUnit style guidelines.
Changes since v1:
- Collect tags
- Rewrite commit message of "lib/test_cpumask: drop cpu_possible_mask full test"
- Also CC KUnit mailing list
Sander Vanheule (5):
lib/test_cpumask: drop cpu_possible_mask full test lib/test_cpumask: fix cpu_possible_mask last test lib/test_cpumask: follow KUnit style guidelines lib/cpumask_kunit: log mask contents lib/cpumask_kunit: add tests file to MAINTAINERS
MAINTAINERS | 1 +
lib/Kconfig.debug | 7 +++++--
lib/Makefile | 2 +-
lib/{test_cpumask.c => cpumask_kunit.c} | 13 +++++++++++--
4 files changed, 18 insertions(+), 5 deletions(-)
rename lib/{test_cpumask.c => cpumask_kunit.c} (90%)Signature · 1 line
2.37.2
PATCH v2 1/5 lib/test_cpumask: drop cpu_possible_mask full test
When the number of CPUs that can possibly be brought online is known at boot time, e.g. when HOTPLUG is disabled, nr_cpu_ids may be smaller than NR_CPUS. In that case, cpu_possible_mask would not be completely filled, and cpumask_full(cpu_possible_mask) can return false for valid system configurations.
---
Changes in v2:
Rewrite commit message to explain why this test is wrong
lib/test_cpumask.c | 1 - 1 file changed, 1 deletion(-)
lib/test_cpumask.c +0 -1
@@ -54,7 +54,6 @@ static cpumask_t mask_all;static void test_cpumask_weight (struct kunit *test) {KUNIT_EXPECT_TRUE (test,cpumask_empty (&mask_empty)); -KUNIT_EXPECT_TRUE (test,cpumask_full (cpu_possible_mask));KUNIT_EXPECT_TRUE (test,cpumask_full (&mask_all));KUNIT_EXPECT_EQ (test,0 ,cpumask_weight (&mask_empty));
Signature · 1 line
2.37.2
PATCH v2 3/5 lib/test_cpumask: follow KUnit style guidelines
In reply to Sander VanheuleThe cpumask test suite doesn't follow the KUnit style guidelines, as laid out in Documentation/dev-tools/kunit/style.rst. The file is renamed to lib/cpumask_kunit.c to clearly distinguish it from other, non-KUnit, tests.
---
lib/Kconfig.debug | 7 +++++--
lib/Makefile | 2 +-
lib/{test_cpumask.c => cpumask_kunit.c} | 0
3 files changed, 6 insertions(+), 3 deletions(-)
rename lib/{test_cpumask.c => cpumask_kunit.c} (100%)lib/Kconfig.debug +5 -2
@@ -2029,13 +2029,16 @@ config LKDTM Documentation on how to use the module can be found in Documentation/fault-injection/provoke-crashes.rst -config TEST_CPUMASK - tristate "cpumask tests" if !KUNIT_ALL_TESTS +config CPUMASK_KUNIT_TEST + tristate "KUnit test for cpumask" if !KUNIT_ALL_TESTS depends on KUNIT default KUNIT_ALL_TESTS help Enable to turn on cpumask tests, running at boot or module load time. + 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 TEST_LIST_SORT
lib/Makefile +1 -1
@@ -60,6 +60,7 @@ obj-$(CONFIG_TEST_BPF) += test_bpf.o obj-$(CONFIG_TEST_FIRMWARE) += test_firmware.o obj-$(CONFIG_TEST_BITOPS) += test_bitops.o CFLAGS_test_bitops.o += -Werror +obj-$(CONFIG_CPUMASK_KUNIT_TEST) += cpumask_kunit.o obj-$(CONFIG_TEST_SYSCTL) += test_sysctl.o obj-$(CONFIG_TEST_SIPHASH) += test_siphash.o obj-$(CONFIG_HASH_KUNIT_TEST) += test_hash.o
@@ -100,7 +101,6 @@ obj-$(CONFIG_TEST_HMM) += test_hmm.o obj-$(CONFIG_TEST_FREE_PAGES) += test_free_pages.o obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o obj-$(CONFIG_TEST_REF_TRACKER) += test_ref_tracker.o -obj-$(CONFIG_TEST_CPUMASK) += test_cpumask.o CFLAGS_test_fprobe.o += $(CC_FLAGS_FTRACE) obj-$(CONFIG_FPROBE_SANITY_TEST) += test_fprobe.o #
lib/cpumask_kunit.c renamed from lib/test_cpumask.c +0 -0
Signature · 1 line
2.37.2
PATCH v2 2/5 lib/test_cpumask: fix cpu_possible_mask last test
In reply to Sander VanheuleSince cpumask_first() on the cpu_possible_mask must return at most nr_cpu_ids - 1 for a valid result, cpumask_last() cannot return anything larger than this value. As test_cpumask_weight() also verifies that the total weight of cpu_possible_mask must equal nr_cpu_ids, the last bit set in this mask must be at nr_cpu_ids - 1.
--- lib/test_cpumask.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/test_cpumask.c +1 -1
@@ -73,7 +73,7 @@ static void test_cpumask_first(struct kunit *test)static void test_cpumask_last (struct kunit *test) {KUNIT_EXPECT_LE (test, nr_cpumask_bits,cpumask_last (&mask_empty)); -KUNIT_EXPECT_EQ (test, nr_cpumask_bits -1 ,cpumask_last (cpu_possible_mask)); +KUNIT_EXPECT_EQ (test, nr_cpu_ids -1 ,cpumask_last (cpu_possible_mask)); }static void test_cpumask_next (struct kunit *test)
Signature · 1 line
2.37.2
PATCH v2 4/5 lib/cpumask_kunit: log mask contents
In reply to Sander VanheuleFor extra context, log the contents of the masks under test. This should help with finding out why a certain test fails.
--- lib/cpumask_kunit.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
lib/cpumask_kunit.c +10 -0
@@ -51,6 +51,10 @@static cpumask_t mask_empty;static cpumask_t mask_all; +#define STR_MASK (m) #m +#define TEST_CPUMASK_PRINT (test, mask) \ + kunit_info(test, "%s = '%*pbl'\n", STR_MASK(mask), nr_cpumask_bits, cpumask_bits(mask)) +static void test_cpumask_weight (struct kunit *test) {KUNIT_EXPECT_TRUE (test,cpumask_empty (&mask_empty));
@@ -103,6 +107,9 @@ static void test_cpumask_iterators_builtin(struct kunit *test)/* Ensure the dynamic masks are stable while running the tests */ cpu_hotplug_disable (); +TEST_CPUMASK_PRINT (test, cpu_online_mask); +TEST_CPUMASK_PRINT (test, cpu_present_mask); +EXPECT_FOR_EACH_CPU_BUILTIN_EQ (test, online);EXPECT_FOR_EACH_CPU_BUILTIN_EQ (test, present);
@@ -114,6 +121,9 @@ static int test_cpumask_init(struct kunit *test)cpumask_clear (&mask_empty);cpumask_setall (&mask_all); +TEST_CPUMASK_PRINT (test, &mask_all); +TEST_CPUMASK_PRINT (test, cpu_possible_mask); +return 0 ; }
Signature · 1 line
2.37.2
PATCH v2 5/5 lib/cpumask_kunit: add tests file to MAINTAINERS
In reply to Sander Vanheulecpumask related files are listed under the BITMAP API section, so file with the tests for cpumask should be added to that list.
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -3612,6 +3612,7 @@ F: include/linux/find.h F: include/linux/nodemask.h F: lib/bitmap.c F: lib/cpumask.c +F: lib/cpumask_kunit.c F: lib/find_bit.c F: lib/find_bit_benchmark.c F: lib/test_bitmap.c
Signature · 1 line
2.37.2
Re: [PATCH v2 1/5] lib/test_cpumask: drop cpu_possible_mask full test
In reply to Sander VanheuleQuoted 5 lines · Sander Vanheule
When the number of CPUs that can possibly be brought online is known at boot time, e.g. when HOTPLUG is disabled,
nr_cpu_idsmay be smaller thanNR_CPUS. In that case,cpu_possible_maskwould not be completely filled, andcpumask_full(cpu_possible_mask)can return false for valid system configurations.
It doesn't mean we can just give up. You can check validity of possible cpumask like this:
KUNIT_EXPECT_EQ(test, nr_cpu_ids, cpumask_first_zero(&mask_all)) KUNIT_EXPECT_EQ(test, NR_CPUS, cpumask_first(&mask_all))
Quoted 27 lines
Fixes c41e8866c28c ("lib/test: introduce cpumask KUnit test suite")Reported-by Maíra Canal <[email protected]>Signed-off-by Sander Vanheule <[email protected]>Tested-by Maíra Canal <[email protected]>Reviewed-by David Gow <[email protected]>---
Changes in v2:
Rewrite commit message to explain why this test is wronglib/test_cpumask.c | 1 - 1 file changed, 1 deletion(-)lib/test_cpumask.c +0
-1@@ -54,7 +54,6 @@ static cpumask_t mask_all;static void test_cpumask_weight (struct kunit *test) {KUNIT_EXPECT_TRUE (test,cpumask_empty (&mask_empty)); -KUNIT_EXPECT_TRUE (test,cpumask_full (cpu_possible_mask));KUNIT_EXPECT_TRUE (test,cpumask_full (&mask_all));KUNIT_EXPECT_EQ (test,0 ,cpumask_weight (&mask_empty));Signature · 1 line
2.37.2
Re: [PATCH v2 4/5] lib/cpumask_kunit: log mask contents
In reply to Sander VanheuleQuoted 37 lines · Sander Vanheule
For extra context, log the contents of the masks under test. This should help with finding out why a certain test fails.
Link https://lore.kernel.org/lkml/CABVgOSkPXBc-PWk1zBZRQ_Tt+Sz1ruFHBj3ixojymZF=Vi4tpQ@mail.gmail.com/ open hereSuggested-by David Gow <[email protected]>Signed-off-by Sander Vanheule <[email protected]>Reviewed-by David Gow <[email protected]>--- lib/cpumask_kunit.c | 10 ++++++++++ 1 file changed, 10 insertions(+)lib/cpumask_kunit.c +7
-0@@ -51,6 +51,10 @@static cpumask_t mask_empty;static cpumask_t mask_all; +#define STR_MASK (m) #m +#define TEST_CPUMASK_PRINT (test, mask) \ + kunit_info(test, "%s = '%*pbl'\n", STR_MASK(mask), nr_cpumask_bits, cpumask_bits(mask)) +static void test_cpumask_weight (struct kunit *test) {KUNIT_EXPECT_TRUE (test,cpumask_empty (&mask_empty));@@ -103,6 +107,9 @@ static void test_cpumask_iterators_builtin(struct kunit *test)/* Ensure the dynamic masks are stable while running the tests */ cpu_hotplug_disable (); +TEST_CPUMASK_PRINT (test, cpu_online_mask); +TEST_CPUMASK_PRINT (test, cpu_present_mask); +EXPECT_FOR_EACH_CPU_BUILTIN_EQ (test, online);EXPECT_FOR_EACH_CPU_BUILTIN_EQ (test, present);
lib/cpumask_kunit.c static int test_cpumask_init(struct kunit *test) · line 126
Quoted 6 lines
lib/cpumask_kunit.c +3
-0@@ -114,6 +121,9 @@ static int test_cpumask_init(struct kunit *test)cpumask_clear (&mask_empty);cpumask_setall (&mask_all); +TEST_CPUMASK_PRINT (test, &mask_all); +TEST_CPUMASK_PRINT (test, cpu_possible_mask); +
It sort of breaks the rule of silence. Can you make this print conditional on a test failure? If everything is OK, who wants to look into details?
Quoted 5 lines
lib/cpumask_kunit.c +0
-0return 0 ; }Signature · 1 line
2.37.2
Quoted 7 lines · Sander Vanheule
This series fixes the reported issues, and implements the suggested improvements, for the version of the cpumask tests [1] that was merged with commit
c41e8866c28c("lib/test: introduce cpumask KUnit test suite").These changes include fixes for the tests, and better alignment with the KUnit style guidelines.
I wrote a couple comments, but the series looks OK to me in general. So for 2, 3 and 5:
It's named as 'fix', but it fixes a test, and the kernel code itself looks correct. So, do you want to take it into 6.0-rc, or in 6.1?
I'm OK to do it this way or another, but for later -rc's it may look too noisy. And I'm not sure where to put a threshold.
Thanks,
Yury
Quoted 25 lines
Changes since v1:
- Collect tags
- Rewrite commit message of "lib/test_cpumask: dropcpu_possible_maskfull test"
- Also CC KUnit mailing listSander Vanheule (5):
lib/test_cpumask: dropcpu_possible_maskfull testlib/test_cpumask: fixcpu_possible_masklast testlib/test_cpumask: follow KUnit style guidelineslib/cpumask_kunit: log mask contentslib/cpumask_kunit: add tests file toMAINTAINERSMAINTAINERS | 1 + lib/Kconfig.debug | 7 +++++-- lib/Makefile | 2 +- lib/{test_cpumask.c => cpumask_kunit.c} | 13 +++++++++++-- 4 files changed, 18 insertions(+), 5 deletions(-) rename lib/{test_cpumask.c => cpumask_kunit.c} (90%)Signature · 1 line
2.37.2
Re: [PATCH v2 1/5] lib/test_cpumask: drop cpu_possible_mask full test
In reply to Yury NorovHi Yury,
Quoted 11 lines · Yury Norov
Quoted 5 lines · Sander Vanheule
When the number of CPUs that can possibly be brought online is known at boot time, e.g. when HOTPLUG is disabled,
nr_cpu_idsmay be smaller thanNR_CPUS. In that case,cpu_possible_maskwould not be completely filled, andcpumask_full(cpu_possible_mask)can return false for valid system configurations.It doesn't mean we can just give up. You can check validity of possible cpumask like this:
KUNIT_EXPECT_EQ(test, nr_cpu_ids, cpumask_first_zero(&mask_all))KUNIT_EXPECT_EQ(test, NR_CPUS, cpumask_first(&mask_all))
Did you mean cpu_possible_mask, or mask_all?
For cpu_possible_mask, these tests are in test_cpumask_first(), albeit under a slightly different form. Together with the tests in test_cpumask_weight() and test_cpumask_last(), cpu_possible_mask is already one of the more constrained masks.
For mask_all, the mask is filled up with nr_cpumask_bits <= NR_CPUS. I could add cpumask_first(), cpumask_first_zero(), and cpumask_last() tests though.
More tests could be also added for cpu_all_mask, since this does have all NR_CPUS bits set, but I think that belongs in a separate patch.
I think the extra mask_all and cpu_all_mask test are out of scope for this patch, but they could be added in another patch (for 6.1).
Best,
Sander
Quoted 29 lines
Quoted 28 lines
Fixes c41e8866c28c ("lib/test: introduce cpumask KUnit test suite")Link:
https://lore.kernel.org/lkml/[email protected]/Reported-by Maíra Canal <[email protected]>Signed-off-by Sander Vanheule <[email protected]>Tested-by Maíra Canal <[email protected]>Reviewed-by David Gow <[email protected]>---
Changes in v2:
Rewrite commit message to explain why this test is wronglib/test_cpumask.c | 1 -
1 file changed, 1 deletion(-)lib/test_cpumask.c +0
-1@@ -54,7 +54,6 @@ static cpumask_t mask_all; static void test_cpumask_weight(struct kunit *test) { KUNIT_EXPECT_TRUE(test, cpumask_empty(&mask_empty)); - KUNIT_EXPECT_TRUE(test, cpumask_full(cpu_possible_mask)); KUNIT_EXPECT_TRUE(test, cpumask_full(&mask_all));
KUNIT_EXPECT_EQ(test, 0,cpumask_weight(&mask_empty));Signature · 1 line
2.37.2
Re: [PATCH v2 4/5] lib/cpumask_kunit: log mask contents
In reply to Yury NorovQuoted 42 lines · Yury Norov
Quoted 41 lines · Sander Vanheule
For extra context, log the contents of the masks under test. This should help with finding out why a certain test fails.
Link:
https://lore.kernel.org/lkml/CABVgOSkPXBc-PWk1zBZRQ_Tt+Sz1ruFHBj3ixojymZF=Vi4tpQ@mail.gmail.com/Suggested-by David Gow <[email protected]>Signed-off-by Sander Vanheule <[email protected]>Reviewed-by David Gow <[email protected]>---
lib/cpumask_kunit.c | 10 ++++++++++1 file changed, 10 insertions(+)lib/cpumask_kunit.c +0
-0@@ -51,6 +51,10 @@ static cpumask_t mask_empty; static cpumask_t mask_all;lib/cpumask_kunit.c +3
-0+#define STR_MASK (m) #m +#define TEST_CPUMASK_PRINT (test, mask) \ + kunit_info(test, "%s = '%*pbl'\n", STR_MASK(mask), nr_cpumask_bits,
cpumask_bits(mask))
+
static voidtest_cpumask_weight(struct kunit *test){
KUNIT_EXPECT_TRUE(test,cpumask_empty(&mask_empty));lib/cpumask_kunit.c +0
-0@@ -103,6 +107,9 @@ static void test_cpumask_iterators_builtin(struct kunit *test) /* Ensure the dynamic masks are stable while running the tests */ cpu_hotplug_disable();
+ TEST_CPUMASK_PRINT(test,cpu_online_mask); + TEST_CPUMASK_PRINT(test,cpu_present_mask); +
EXPECT_FOR_EACH_CPU_BUILTIN_EQ(test, online);EXPECT_FOR_EACH_CPU_BUILTIN_EQ(test, present);lib/cpumask_kunit.c +0
-0@@ -114,6 +121,9 @@ static int test_cpumask_init(struct kunit *test) cpumask_clear(&mask_empty);
Quoted 8 lines
Quoted 5 lines
lib/cpumask_kunit.c +0
-0cpumask_setall(&mask_all);
+ TEST_CPUMASK_PRINT(test,&mask_all); + TEST_CPUMASK_PRINT(test,cpu_possible_mask); +It sort of breaks the rule of silence. Can you make this print conditional on a test failure? If everything is OK, who wants to look into details?
I will change the macros to the _MSG versions, and log the mask there.
I implemented this with kunit_info() as David proposed. AFAICT I can't call kunit_info() only when the test fails, because the EXPECT_ macros don't return any result.
Best,
Sander
Quoted 6 lines
Quoted 6 lines
return 0;
}Signature · 1 line
2.37.2
Hi Yury,
Quoted 11 lines · Yury Norov
Quoted 7 lines · Sander Vanheule
This series fixes the reported issues, and implements the suggested improvements, for the version of the cpumask tests [1] that was merged with commit
c41e8866c28c("lib/test: introduce cpumask KUnit test suite").These changes include fixes for the tests, and better alignment with the KUnit style guidelines.
I wrote a couple comments, but the series looks OK to me in general. So for 2, 3 and 5:
Quoted 7 lines
Acked-by Yury Norov <[email protected]>It's named as 'fix', but it fixes a test, and the kernel code itself looks correct. So, do you want to take it into 6.0-rc, or in 6.1?
I'm OK to do it this way or another, but for later -rc's it may look too noisy. And I'm not sure where to put a threshold.
Broken tests are worse than no tests IMHO, so I would at least like patches 1 and 2 to be merged for 6.0-rc. I don't want people to end up with false positives, like Maíra did, for an entire release cycle.
Preferably I would also like to see 3 in 6.0-rc, so no renames will be needed in 6.1 anymore. Not that I expect anything to depend on this symbol (or filename) by then, but I feel it's better not to risk that by waiting for 6.1.
Patches 4 and 5 can go with 6.1, as far as I'm concerned. Especially as the mask logging patch (4) may need some work still.
Best,
Sander
Re: [PATCH v2 1/5] lib/test_cpumask: drop cpu_possible_mask full test
In reply to a message not in the archiveHi Yury,
Replying back in plaintext, as you sent an HTML message.
Quoted 35 lines · Yury Norov
Quoted 10 lines · On Sun, Aug 21, 2022, 09:08 Sander Vanheule <[email protected]> wrote:
Hi Yury,
Quoted 7 lines · Yury Norov
Quoted 5 lines · Sander Vanheule
When the number of CPUs that can possibly be brought online is known at boot time, e.g. when HOTPLUG is disabled,
nr_cpu_idsmay be smaller thanNR_CPUS. In that case,cpu_possible_maskwould not be completely filled, andcpumask_full(cpu_possible_mask)can return false for valid system configurations.Quoted 6 lines
Quoted 4 lines
It doesn't mean we can just give up. You can check validity of possible cpumask like this:
KUNIT_EXPECT_EQ(test, nr_cpu_ids, cpumask_first_zero(&mask_all))KUNIT_EXPECT_EQ(test, NR_CPUS, cpumask_first(&mask_all))Did you mean
cpu_possible_mask, ormask_all?
cpu_possble_asof curse.Quoted 13 lines
For
cpu_possible_mask, these tests are intest_cpumask_first(), albeit under a
slightly different form. Together with the tests intest_cpumask_weight()andtest_cpumask_last(),cpu_possible_maskis already one of the more constrained
masks.For
mask_all, the mask is filled up withnr_cpumask_bits<=NR_CPUS. I could addcpumask_first(),cpumask_first_zero(), andcpumask_last()tests though.
Quoted 8 lines
Quoted 5 lines
More tests could be also added for
cpu_all_mask, since this does have allNR_CPUSbits set, but I think that belongs in a separate patch.I think the extra
mask_allandcpu_all_masktest are out of scope for this patch, but they could be added in another patch (for 6.1).If you think that possible mask is tested by other parts, then can you notice that in comments?
Sure, I'll update the commit message to note the other constraints on cpu_possible_mask.
Best,
Sander
Re: [PATCH v2 4/5] lib/cpumask_kunit: log mask contents
In reply to Sander VanheuleQuoted 52 lines · Sander Vanheule
Quoted 42 lines · Yury Norov
Quoted 41 lines · Sander Vanheule
For extra context, log the contents of the masks under test. This should help with finding out why a certain test fails.
Link:
https://lore.kernel.org/lkml/CABVgOSkPXBc-PWk1zBZRQ_Tt+Sz1ruFHBj3ixojymZF=Vi4tpQ@mail.gmail.com/Suggested-by David Gow <[email protected]>Signed-off-by Sander Vanheule <[email protected]>Reviewed-by David Gow <[email protected]>---
lib/cpumask_kunit.c | 10 ++++++++++1 file changed, 10 insertions(+)lib/cpumask_kunit.c +0
-0@@ -51,6 +51,10 @@ static cpumask_t mask_empty; static cpumask_t mask_all;lib/cpumask_kunit.c +3
-0+#define STR_MASK (m) #m +#define TEST_CPUMASK_PRINT (test, mask) \ + kunit_info(test, "%s = '%*pbl'\n", STR_MASK(mask), nr_cpumask_bits,
cpumask_bits(mask))
+
static voidtest_cpumask_weight(struct kunit *test){
KUNIT_EXPECT_TRUE(test,cpumask_empty(&mask_empty));lib/cpumask_kunit.c +0
-0@@ -103,6 +107,9 @@ static void test_cpumask_iterators_builtin(struct kunit *test) /* Ensure the dynamic masks are stable while running the tests */ cpu_hotplug_disable();
+ TEST_CPUMASK_PRINT(test,cpu_online_mask); + TEST_CPUMASK_PRINT(test,cpu_present_mask); +
EXPECT_FOR_EACH_CPU_BUILTIN_EQ(test, online);EXPECT_FOR_EACH_CPU_BUILTIN_EQ(test, present);lib/cpumask_kunit.c +0
-0@@ -114,6 +121,9 @@ static int test_cpumask_init(struct kunit *test) cpumask_clear(&mask_empty);Quoted 8 lines
Quoted 5 lines
lib/cpumask_kunit.c +0
-0cpumask_setall(&mask_all);
+ TEST_CPUMASK_PRINT(test,&mask_all); + TEST_CPUMASK_PRINT(test,cpu_possible_mask); +It sort of breaks the rule of silence. Can you make this print conditional on a test failure? If everything is OK, who wants to look into details?
Quoted 5 lines
I will change the macros to the
_MSGversions, and log the mask there.I implemented this with
kunit_info()as David proposed. AFAICT I can't callkunit_info()only when the test fails, because theEXPECT_macros don't return any result.
Maybe you can use KUNIT_EXPECT_EQ_MSG to print a more detailed error and avoid printing the info when the test doesn't fail.
Best Regards,
- Maíra Canal
Quoted 11 lines
Best,
SanderQuoted 6 lines
Quoted 6 lines
return 0;
}Signature · 1 line
2.37.2
Re: [PATCH v2 4/5] lib/cpumask_kunit: log mask contents
Hi Maíra,
Quoted 60 lines · Maíra Canal
Quoted 57 lines · Sander Vanheule
Quoted 45 lines · Yury Norov
Quoted 44 lines · Sander Vanheule
For extra context, log the contents of the masks under test. This should help with finding out why a certain test fails.
Link:
https://lore.kernel.org/lkml/CABVgOSkPXBc-PWk1zBZRQ_Tt+Sz1ruFHBj3ixojymZF=Vi4tpQ@mail.gmail.com/Suggested-by David Gow <[email protected]>Signed-off-by Sander Vanheule <[email protected]>Reviewed-by David Gow <[email protected]>---
lib/cpumask_kunit.c | 10 ++++++++++1 file changed, 10 insertions(+)lib/cpumask_kunit.c +0
-0@@ -51,6 +51,10 @@ static cpumask_t mask_empty; static cpumask_t mask_all;lib/cpumask_kunit.c +3
-0+#define STR_MASK (m) #m +#define TEST_CPUMASK_PRINT (test, mask) \ + kunit_info(test, "%s = '%*pbl'\n", STR_MASK(mask),
nr_cpumask_bits,cpumask_bits(mask))
+
static voidtest_cpumask_weight(struct kunit *test){
KUNIT_EXPECT_TRUE(test,cpumask_empty(&mask_empty));lib/cpumask_kunit.c +0
-0@@ -103,6 +107,9 @@ static void test_cpumask_iterators_builtin(structkunit
*test)
/* Ensure the dynamic masks are stable while running the tests */
cpu_hotplug_disable();
+ TEST_CPUMASK_PRINT(test,cpu_online_mask);
+ TEST_CPUMASK_PRINT(test,cpu_present_mask);
+
EXPECT_FOR_EACH_CPU_BUILTIN_EQ(test, online);EXPECT_FOR_EACH_CPU_BUILTIN_EQ(test, present);lib/cpumask_kunit.c +0
-0@@ -114,6 +121,9 @@ static int test_cpumask_init(struct kunit *test) cpumask_clear(&mask_empty);Quoted 8 lines
Quoted 5 lines
lib/cpumask_kunit.c +0
-0cpumask_setall(&mask_all);
+ TEST_CPUMASK_PRINT(test,&mask_all); + TEST_CPUMASK_PRINT(test,cpu_possible_mask); +It sort of breaks the rule of silence. Can you make this print conditional on a test failure? If everything is OK, who wants to look into details?
I will change the macros to the
_MSGversions, and log the mask there.
Quoted 7 lines
Quoted 4 lines
I implemented this with
kunit_info()as David proposed. AFAICT I can't callkunit_info()only when the test fails, because theEXPECT_macros don't return
any result.Maybe you can use
KUNIT_EXPECT_EQ_MSGto print a more detailed error and avoid printing the info when the test doesn't fail.
Yes, this is what I currently have for use with the _MSG() variants of the macros:
+#define MASK_MSG(m) \
+ "%s contains %sCPUs %*pbl", #m, (cpumask_weight(m) ? "" : "no "), nr_cpumask_bits, cpumask_bits(m)
+
For example, with (bogus) KUNIT_EXPECT_TRUE_MSG(test, ..., MASK_MSG(mask)) this becomes (trimmed):
$ ./tools/testing/kunit/kunit.py run --build_dir=build-um cpumask [...] [18:15:33] # test_cpumask_weight: EXPECTATION FAILED at lib/cpumask_kunit.c:60 [18:15:33] Expected cpumask_empty(((struct cpumask *)(1 ? (cpu_all_bits) : (void *)sizeof(__check_is_bitmap(cpu_all_bits))))) to be true, but is false [18:15:33] [18:15:33] cpu_all_mask contains CPUs 0 [18:15:33] # test_cpumask_weight: EXPECTATION FAILED at lib/cpumask_kunit.c:61 [18:15:33] Expected cpumask_full(&mask_empty) to be true, but is false [18:15:33] [18:15:33] &mask_empty contains no CPUs [18:15:33] not ok 1 - test_cpumask_weight [18:15:33] [FAILED] test_cpumask_weight [...]
Or on a real system:
[ 1.246805] # test_cpumask_weight: EXPECTATION FAILED at lib/cpumask_kunit.c:59 [ 1.246805] Expected cpumask_empty(((struct cpumask *)(1 ? (cpu_all_bits) : (void *)sizeof(__check_is_bitmap(cpu_all_bits))))) to be true, but is false [ 1.246805] [ 1.246805] cpu_all_mask contains CPUs 0-1 [ 1.249756] not ok 1 - test_cpumask_weight
I will send an updated series tomorrow, in case David or others have more more comments.
Best,
Sander