lib/cpumask_kunit: log mask contents

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 <davidgow@google.com>
Signed-off-by: Sander Vanheule <sander@svanheule.net>
Signed-off-by: Yury Norov <yury.norov@gmail.com>

authored by

Sander Vanheule and committed by
Yury Norov
bf541358 d3c0ca49

+30 -19
+30 -19
lib/cpumask_kunit.c
··· 9 9 #include <linux/cpu.h> 10 10 #include <linux/cpumask.h> 11 11 12 + #define MASK_MSG(m) \ 13 + "%s contains %sCPUs %*pbl", #m, (cpumask_weight(m) ? "" : "no "), \ 14 + nr_cpumask_bits, cpumask_bits(m) 15 + 12 16 #define EXPECT_FOR_EACH_CPU_EQ(test, mask) \ 13 17 do { \ 14 18 const cpumask_t *m = (mask); \ ··· 20 16 int cpu, iter = 0; \ 21 17 for_each_cpu(cpu, m) \ 22 18 iter++; \ 23 - KUNIT_EXPECT_EQ((test), mask_weight, iter); \ 19 + KUNIT_EXPECT_EQ_MSG((test), mask_weight, iter, MASK_MSG(mask)); \ 24 20 } while (0) 25 21 26 22 #define EXPECT_FOR_EACH_CPU_NOT_EQ(test, mask) \ ··· 30 26 int cpu, iter = 0; \ 31 27 for_each_cpu_not(cpu, m) \ 32 28 iter++; \ 33 - KUNIT_EXPECT_EQ((test), nr_cpu_ids - mask_weight, iter); \ 29 + KUNIT_EXPECT_EQ_MSG((test), nr_cpu_ids - mask_weight, iter, MASK_MSG(mask)); \ 34 30 } while (0) 35 31 36 32 #define EXPECT_FOR_EACH_CPU_WRAP_EQ(test, mask) \ ··· 40 36 int cpu, iter = 0; \ 41 37 for_each_cpu_wrap(cpu, m, nr_cpu_ids / 2) \ 42 38 iter++; \ 43 - KUNIT_EXPECT_EQ((test), mask_weight, iter); \ 39 + KUNIT_EXPECT_EQ_MSG((test), mask_weight, iter, MASK_MSG(mask)); \ 44 40 } while (0) 45 41 46 42 #define EXPECT_FOR_EACH_CPU_BUILTIN_EQ(test, name) \ ··· 49 45 int cpu, iter = 0; \ 50 46 for_each_##name##_cpu(cpu) \ 51 47 iter++; \ 52 - KUNIT_EXPECT_EQ((test), mask_weight, iter); \ 48 + KUNIT_EXPECT_EQ_MSG((test), mask_weight, iter, MASK_MSG(cpu_##name##_mask)); \ 53 49 } while (0) 54 50 55 51 static cpumask_t mask_empty; ··· 57 53 58 54 static void test_cpumask_weight(struct kunit *test) 59 55 { 60 - KUNIT_EXPECT_TRUE(test, cpumask_empty(&mask_empty)); 61 - KUNIT_EXPECT_TRUE(test, cpumask_full(&mask_all)); 56 + KUNIT_EXPECT_TRUE_MSG(test, cpumask_empty(&mask_empty), MASK_MSG(&mask_empty)); 57 + KUNIT_EXPECT_TRUE_MSG(test, cpumask_full(&mask_all), MASK_MSG(&mask_all)); 62 58 63 - KUNIT_EXPECT_EQ(test, 0, cpumask_weight(&mask_empty)); 64 - KUNIT_EXPECT_EQ(test, nr_cpu_ids, cpumask_weight(cpu_possible_mask)); 65 - KUNIT_EXPECT_EQ(test, nr_cpumask_bits, cpumask_weight(&mask_all)); 59 + KUNIT_EXPECT_EQ_MSG(test, 0, cpumask_weight(&mask_empty), MASK_MSG(&mask_empty)); 60 + KUNIT_EXPECT_EQ_MSG(test, nr_cpu_ids, cpumask_weight(cpu_possible_mask), 61 + MASK_MSG(cpu_possible_mask)); 62 + KUNIT_EXPECT_EQ_MSG(test, nr_cpumask_bits, cpumask_weight(&mask_all), MASK_MSG(&mask_all)); 66 63 } 67 64 68 65 static void test_cpumask_first(struct kunit *test) 69 66 { 70 - KUNIT_EXPECT_LE(test, nr_cpu_ids, cpumask_first(&mask_empty)); 71 - KUNIT_EXPECT_EQ(test, 0, cpumask_first(cpu_possible_mask)); 67 + KUNIT_EXPECT_LE_MSG(test, nr_cpu_ids, cpumask_first(&mask_empty), MASK_MSG(&mask_empty)); 68 + KUNIT_EXPECT_EQ_MSG(test, 0, cpumask_first(cpu_possible_mask), MASK_MSG(cpu_possible_mask)); 72 69 73 - KUNIT_EXPECT_EQ(test, 0, cpumask_first_zero(&mask_empty)); 74 - KUNIT_EXPECT_LE(test, nr_cpu_ids, cpumask_first_zero(cpu_possible_mask)); 70 + KUNIT_EXPECT_EQ_MSG(test, 0, cpumask_first_zero(&mask_empty), MASK_MSG(&mask_empty)); 71 + KUNIT_EXPECT_LE_MSG(test, nr_cpu_ids, cpumask_first_zero(cpu_possible_mask), 72 + MASK_MSG(cpu_possible_mask)); 75 73 } 76 74 77 75 static void test_cpumask_last(struct kunit *test) 78 76 { 79 - KUNIT_EXPECT_LE(test, nr_cpumask_bits, cpumask_last(&mask_empty)); 80 - KUNIT_EXPECT_EQ(test, nr_cpu_ids - 1, cpumask_last(cpu_possible_mask)); 77 + KUNIT_EXPECT_LE_MSG(test, nr_cpumask_bits, cpumask_last(&mask_empty), 78 + MASK_MSG(&mask_empty)); 79 + KUNIT_EXPECT_EQ_MSG(test, nr_cpu_ids - 1, cpumask_last(cpu_possible_mask), 80 + MASK_MSG(cpu_possible_mask)); 81 81 } 82 82 83 83 static void test_cpumask_next(struct kunit *test) 84 84 { 85 - KUNIT_EXPECT_EQ(test, 0, cpumask_next_zero(-1, &mask_empty)); 86 - KUNIT_EXPECT_LE(test, nr_cpu_ids, cpumask_next_zero(-1, cpu_possible_mask)); 85 + KUNIT_EXPECT_EQ_MSG(test, 0, cpumask_next_zero(-1, &mask_empty), MASK_MSG(&mask_empty)); 86 + KUNIT_EXPECT_LE_MSG(test, nr_cpu_ids, cpumask_next_zero(-1, cpu_possible_mask), 87 + MASK_MSG(cpu_possible_mask)); 87 88 88 - KUNIT_EXPECT_LE(test, nr_cpu_ids, cpumask_next(-1, &mask_empty)); 89 - KUNIT_EXPECT_EQ(test, 0, cpumask_next(-1, cpu_possible_mask)); 89 + KUNIT_EXPECT_LE_MSG(test, nr_cpu_ids, cpumask_next(-1, &mask_empty), 90 + MASK_MSG(&mask_empty)); 91 + KUNIT_EXPECT_EQ_MSG(test, 0, cpumask_next(-1, cpu_possible_mask), 92 + MASK_MSG(cpu_possible_mask)); 90 93 } 91 94 92 95 static void test_cpumask_iterators(struct kunit *test)