Skip to content

Commit 49937cd

Browse files
valschneiderYuryNorov
authored andcommitted
lib/test_cpumask: Add for_each_cpu_and(not) tests
Following the recent introduction of for_each_andnot(), add some tests to ensure for_each_cpu_and(not) results in the same as iterating over the result of cpumask_and(not)(). Suggested-by: Yury Norov <yury.norov@gmail.com> Signed-off-by: Valentin Schneider <vschneid@redhat.com>
1 parent 5f75ff2 commit 49937cd

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/cpumask_kunit.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@
3333
KUNIT_EXPECT_EQ_MSG((test), nr_cpu_ids - mask_weight, iter, MASK_MSG(mask)); \
3434
} while (0)
3535

36+
#define EXPECT_FOR_EACH_CPU_OP_EQ(test, op, mask1, mask2) \
37+
do { \
38+
const cpumask_t *m1 = (mask1); \
39+
const cpumask_t *m2 = (mask2); \
40+
int weight; \
41+
int cpu, iter = 0; \
42+
cpumask_##op(&mask_tmp, m1, m2); \
43+
weight = cpumask_weight(&mask_tmp); \
44+
for_each_cpu_##op(cpu, mask1, mask2) \
45+
iter++; \
46+
KUNIT_EXPECT_EQ((test), weight, iter); \
47+
} while (0)
48+
3649
#define EXPECT_FOR_EACH_CPU_WRAP_EQ(test, mask) \
3750
do { \
3851
const cpumask_t *m = (mask); \
@@ -54,6 +67,7 @@
5467

5568
static cpumask_t mask_empty;
5669
static cpumask_t mask_all;
70+
static cpumask_t mask_tmp;
5771

5872
static void test_cpumask_weight(struct kunit *test)
5973
{
@@ -101,10 +115,15 @@ static void test_cpumask_iterators(struct kunit *test)
101115
EXPECT_FOR_EACH_CPU_EQ(test, &mask_empty);
102116
EXPECT_FOR_EACH_CPU_NOT_EQ(test, &mask_empty);
103117
EXPECT_FOR_EACH_CPU_WRAP_EQ(test, &mask_empty);
118+
EXPECT_FOR_EACH_CPU_OP_EQ(test, and, &mask_empty, &mask_empty);
119+
EXPECT_FOR_EACH_CPU_OP_EQ(test, and, cpu_possible_mask, &mask_empty);
120+
EXPECT_FOR_EACH_CPU_OP_EQ(test, andnot, &mask_empty, &mask_empty);
104121

105122
EXPECT_FOR_EACH_CPU_EQ(test, cpu_possible_mask);
106123
EXPECT_FOR_EACH_CPU_NOT_EQ(test, cpu_possible_mask);
107124
EXPECT_FOR_EACH_CPU_WRAP_EQ(test, cpu_possible_mask);
125+
EXPECT_FOR_EACH_CPU_OP_EQ(test, and, cpu_possible_mask, cpu_possible_mask);
126+
EXPECT_FOR_EACH_CPU_OP_EQ(test, andnot, cpu_possible_mask, &mask_empty);
108127
}
109128

110129
static void test_cpumask_iterators_builtin(struct kunit *test)

0 commit comments

Comments
 (0)