|
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); \
|
15 | 19 | int mask_weight = cpumask_weight(m); \
|
16 | 20 | int cpu, iter = 0; \
|
17 | 21 | for_each_cpu(cpu, m) \
|
18 | 22 | iter++; \
|
19 |
| - KUNIT_EXPECT_EQ((test), mask_weight, iter); \ |
| 23 | + KUNIT_EXPECT_EQ_MSG((test), mask_weight, iter, MASK_MSG(mask)); \ |
20 | 24 | } while (0)
|
21 | 25 |
|
22 | 26 | #define EXPECT_FOR_EACH_CPU_NOT_EQ(test, mask) \
|
|
26 | 30 | int cpu, iter = 0; \
|
27 | 31 | for_each_cpu_not(cpu, m) \
|
28 | 32 | 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)); \ |
30 | 34 | } while (0)
|
31 | 35 |
|
32 | 36 | #define EXPECT_FOR_EACH_CPU_WRAP_EQ(test, mask) \
|
|
36 | 40 | int cpu, iter = 0; \
|
37 | 41 | for_each_cpu_wrap(cpu, m, nr_cpu_ids / 2) \
|
38 | 42 | iter++; \
|
39 |
| - KUNIT_EXPECT_EQ((test), mask_weight, iter); \ |
| 43 | + KUNIT_EXPECT_EQ_MSG((test), mask_weight, iter, MASK_MSG(mask)); \ |
40 | 44 | } while (0)
|
41 | 45 |
|
42 | 46 | #define EXPECT_FOR_EACH_CPU_BUILTIN_EQ(test, name) \
|
|
45 | 49 | int cpu, iter = 0; \
|
46 | 50 | for_each_##name##_cpu(cpu) \
|
47 | 51 | iter++; \
|
48 |
| - KUNIT_EXPECT_EQ((test), mask_weight, iter); \ |
| 52 | + KUNIT_EXPECT_EQ_MSG((test), mask_weight, iter, MASK_MSG(cpu_##name##_mask)); \ |
49 | 53 | } while (0)
|
50 | 54 |
|
51 | 55 | static cpumask_t mask_empty;
|
52 | 56 | static cpumask_t mask_all;
|
53 | 57 |
|
54 | 58 | static void test_cpumask_weight(struct kunit *test)
|
55 | 59 | {
|
56 |
| - KUNIT_EXPECT_TRUE(test, cpumask_empty(&mask_empty)); |
57 |
| - KUNIT_EXPECT_TRUE(test, cpumask_full(cpu_possible_mask)); |
58 |
| - 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)); |
59 | 62 |
|
60 |
| - KUNIT_EXPECT_EQ(test, 0, cpumask_weight(&mask_empty)); |
61 |
| - KUNIT_EXPECT_EQ(test, nr_cpu_ids, cpumask_weight(cpu_possible_mask)); |
62 |
| - 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)); |
63 | 67 | }
|
64 | 68 |
|
65 | 69 | static void test_cpumask_first(struct kunit *test)
|
66 | 70 | {
|
67 |
| - KUNIT_EXPECT_LE(test, nr_cpu_ids, cpumask_first(&mask_empty)); |
68 |
| - 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)); |
69 | 73 |
|
70 |
| - KUNIT_EXPECT_EQ(test, 0, cpumask_first_zero(&mask_empty)); |
71 |
| - 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)); |
72 | 77 | }
|
73 | 78 |
|
74 | 79 | static void test_cpumask_last(struct kunit *test)
|
75 | 80 | {
|
76 |
| - KUNIT_EXPECT_LE(test, nr_cpumask_bits, cpumask_last(&mask_empty)); |
77 |
| - KUNIT_EXPECT_EQ(test, nr_cpumask_bits - 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)); |
78 | 85 | }
|
79 | 86 |
|
80 | 87 | static void test_cpumask_next(struct kunit *test)
|
81 | 88 | {
|
82 |
| - KUNIT_EXPECT_EQ(test, 0, cpumask_next_zero(-1, &mask_empty)); |
83 |
| - KUNIT_EXPECT_LE(test, nr_cpu_ids, cpumask_next_zero(-1, cpu_possible_mask)); |
84 |
| - |
85 |
| - KUNIT_EXPECT_LE(test, nr_cpu_ids, cpumask_next(-1, &mask_empty)); |
86 |
| - 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)); |
87 | 97 | }
|
88 | 98 |
|
89 | 99 | static void test_cpumask_iterators(struct kunit *test)
|
|
0 commit comments