Skip to content

Commit bf54135

Browse files
svanheuleYuryNorov
authored andcommitted
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 <[email protected]> Signed-off-by: Sander Vanheule <[email protected]> Signed-off-by: Yury Norov <[email protected]>
1 parent d3c0ca4 commit bf54135

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

lib/cpumask_kunit.c

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99
#include <linux/cpu.h>
1010
#include <linux/cpumask.h>
1111

12+
#define MASK_MSG(m) \
13+
"%s contains %sCPUs %*pbl", #m, (cpumask_weight(m) ? "" : "no "), \
14+
nr_cpumask_bits, cpumask_bits(m)
15+
1216
#define EXPECT_FOR_EACH_CPU_EQ(test, mask) \
1317
do { \
1418
const cpumask_t *m = (mask); \
1519
int mask_weight = cpumask_weight(m); \
1620
int cpu, iter = 0; \
1721
for_each_cpu(cpu, m) \
1822
iter++; \
19-
KUNIT_EXPECT_EQ((test), mask_weight, iter); \
23+
KUNIT_EXPECT_EQ_MSG((test), mask_weight, iter, MASK_MSG(mask)); \
2024
} while (0)
2125

2226
#define EXPECT_FOR_EACH_CPU_NOT_EQ(test, mask) \
@@ -26,7 +30,7 @@
2630
int cpu, iter = 0; \
2731
for_each_cpu_not(cpu, m) \
2832
iter++; \
29-
KUNIT_EXPECT_EQ((test), nr_cpu_ids - mask_weight, iter); \
33+
KUNIT_EXPECT_EQ_MSG((test), nr_cpu_ids - mask_weight, iter, MASK_MSG(mask)); \
3034
} while (0)
3135

3236
#define EXPECT_FOR_EACH_CPU_WRAP_EQ(test, mask) \
@@ -36,7 +40,7 @@
3640
int cpu, iter = 0; \
3741
for_each_cpu_wrap(cpu, m, nr_cpu_ids / 2) \
3842
iter++; \
39-
KUNIT_EXPECT_EQ((test), mask_weight, iter); \
43+
KUNIT_EXPECT_EQ_MSG((test), mask_weight, iter, MASK_MSG(mask)); \
4044
} while (0)
4145

4246
#define EXPECT_FOR_EACH_CPU_BUILTIN_EQ(test, name) \
@@ -45,44 +49,51 @@
4549
int cpu, iter = 0; \
4650
for_each_##name##_cpu(cpu) \
4751
iter++; \
48-
KUNIT_EXPECT_EQ((test), mask_weight, iter); \
52+
KUNIT_EXPECT_EQ_MSG((test), mask_weight, iter, MASK_MSG(cpu_##name##_mask)); \
4953
} while (0)
5054

5155
static cpumask_t mask_empty;
5256
static cpumask_t mask_all;
5357

5458
static void test_cpumask_weight(struct kunit *test)
5559
{
56-
KUNIT_EXPECT_TRUE(test, cpumask_empty(&mask_empty));
57-
KUNIT_EXPECT_TRUE(test, cpumask_full(&mask_all));
60+
KUNIT_EXPECT_TRUE_MSG(test, cpumask_empty(&mask_empty), MASK_MSG(&mask_empty));
61+
KUNIT_EXPECT_TRUE_MSG(test, cpumask_full(&mask_all), MASK_MSG(&mask_all));
5862

59-
KUNIT_EXPECT_EQ(test, 0, cpumask_weight(&mask_empty));
60-
KUNIT_EXPECT_EQ(test, nr_cpu_ids, cpumask_weight(cpu_possible_mask));
61-
KUNIT_EXPECT_EQ(test, nr_cpumask_bits, cpumask_weight(&mask_all));
63+
KUNIT_EXPECT_EQ_MSG(test, 0, cpumask_weight(&mask_empty), MASK_MSG(&mask_empty));
64+
KUNIT_EXPECT_EQ_MSG(test, nr_cpu_ids, cpumask_weight(cpu_possible_mask),
65+
MASK_MSG(cpu_possible_mask));
66+
KUNIT_EXPECT_EQ_MSG(test, nr_cpumask_bits, cpumask_weight(&mask_all), MASK_MSG(&mask_all));
6267
}
6368

6469
static void test_cpumask_first(struct kunit *test)
6570
{
66-
KUNIT_EXPECT_LE(test, nr_cpu_ids, cpumask_first(&mask_empty));
67-
KUNIT_EXPECT_EQ(test, 0, cpumask_first(cpu_possible_mask));
71+
KUNIT_EXPECT_LE_MSG(test, nr_cpu_ids, cpumask_first(&mask_empty), MASK_MSG(&mask_empty));
72+
KUNIT_EXPECT_EQ_MSG(test, 0, cpumask_first(cpu_possible_mask), MASK_MSG(cpu_possible_mask));
6873

69-
KUNIT_EXPECT_EQ(test, 0, cpumask_first_zero(&mask_empty));
70-
KUNIT_EXPECT_LE(test, nr_cpu_ids, cpumask_first_zero(cpu_possible_mask));
74+
KUNIT_EXPECT_EQ_MSG(test, 0, cpumask_first_zero(&mask_empty), MASK_MSG(&mask_empty));
75+
KUNIT_EXPECT_LE_MSG(test, nr_cpu_ids, cpumask_first_zero(cpu_possible_mask),
76+
MASK_MSG(cpu_possible_mask));
7177
}
7278

7379
static void test_cpumask_last(struct kunit *test)
7480
{
75-
KUNIT_EXPECT_LE(test, nr_cpumask_bits, cpumask_last(&mask_empty));
76-
KUNIT_EXPECT_EQ(test, nr_cpu_ids - 1, cpumask_last(cpu_possible_mask));
81+
KUNIT_EXPECT_LE_MSG(test, nr_cpumask_bits, cpumask_last(&mask_empty),
82+
MASK_MSG(&mask_empty));
83+
KUNIT_EXPECT_EQ_MSG(test, nr_cpu_ids - 1, cpumask_last(cpu_possible_mask),
84+
MASK_MSG(cpu_possible_mask));
7785
}
7886

7987
static void test_cpumask_next(struct kunit *test)
8088
{
81-
KUNIT_EXPECT_EQ(test, 0, cpumask_next_zero(-1, &mask_empty));
82-
KUNIT_EXPECT_LE(test, nr_cpu_ids, cpumask_next_zero(-1, cpu_possible_mask));
83-
84-
KUNIT_EXPECT_LE(test, nr_cpu_ids, cpumask_next(-1, &mask_empty));
85-
KUNIT_EXPECT_EQ(test, 0, cpumask_next(-1, cpu_possible_mask));
89+
KUNIT_EXPECT_EQ_MSG(test, 0, cpumask_next_zero(-1, &mask_empty), MASK_MSG(&mask_empty));
90+
KUNIT_EXPECT_LE_MSG(test, nr_cpu_ids, cpumask_next_zero(-1, cpu_possible_mask),
91+
MASK_MSG(cpu_possible_mask));
92+
93+
KUNIT_EXPECT_LE_MSG(test, nr_cpu_ids, cpumask_next(-1, &mask_empty),
94+
MASK_MSG(&mask_empty));
95+
KUNIT_EXPECT_EQ_MSG(test, 0, cpumask_next(-1, cpu_possible_mask),
96+
MASK_MSG(cpu_possible_mask));
8697
}
8798

8899
static void test_cpumask_iterators(struct kunit *test)

0 commit comments

Comments
 (0)