Skip to content

Commit 373eff5

Browse files
committed
Merge tag 'bitmap-6.0-rc3' of github.com:/norov/linux
Pull bitmap fixes from Yury Norov: "Fix the reported issues, and implements the suggested improvements, for the version of the cpumask tests [1] that was merged with commit c41e886 ("lib/test: introduce cpumask KUnit test suite"). These changes include fixes for the tests, and better alignment with the KUnit style guidelines" * tag 'bitmap-6.0-rc3' of github.com:/norov/linux: lib/cpumask_kunit: add tests file to MAINTAINERS lib/cpumask_kunit: log mask contents lib/test_cpumask: follow KUnit style guidelines lib/test_cpumask: fix cpu_possible_mask last test lib/test_cpumask: drop cpu_possible_mask full test
2 parents 8379c0b + 5d7fef0 commit 373eff5

File tree

4 files changed

+38
-24
lines changed

4 files changed

+38
-24
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3612,6 +3612,7 @@ F: include/linux/find.h
36123612
F: include/linux/nodemask.h
36133613
F: lib/bitmap.c
36143614
F: lib/cpumask.c
3615+
F: lib/cpumask_kunit.c
36153616
F: lib/find_bit.c
36163617
F: lib/find_bit_benchmark.c
36173618
F: lib/test_bitmap.c

lib/Kconfig.debug

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,13 +2029,16 @@ config LKDTM
20292029
Documentation on how to use the module can be found in
20302030
Documentation/fault-injection/provoke-crashes.rst
20312031

2032-
config TEST_CPUMASK
2033-
tristate "cpumask tests" if !KUNIT_ALL_TESTS
2032+
config CPUMASK_KUNIT_TEST
2033+
tristate "KUnit test for cpumask" if !KUNIT_ALL_TESTS
20342034
depends on KUNIT
20352035
default KUNIT_ALL_TESTS
20362036
help
20372037
Enable to turn on cpumask tests, running at boot or module load time.
20382038

2039+
For more information on KUnit and unit tests in general, please refer
2040+
to the KUnit documentation in Documentation/dev-tools/kunit/.
2041+
20392042
If unsure, say N.
20402043

20412044
config TEST_LIST_SORT

lib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ obj-$(CONFIG_TEST_BPF) += test_bpf.o
6060
obj-$(CONFIG_TEST_FIRMWARE) += test_firmware.o
6161
obj-$(CONFIG_TEST_BITOPS) += test_bitops.o
6262
CFLAGS_test_bitops.o += -Werror
63+
obj-$(CONFIG_CPUMASK_KUNIT_TEST) += cpumask_kunit.o
6364
obj-$(CONFIG_TEST_SYSCTL) += test_sysctl.o
6465
obj-$(CONFIG_TEST_SIPHASH) += test_siphash.o
6566
obj-$(CONFIG_HASH_KUNIT_TEST) += test_hash.o
@@ -100,7 +101,6 @@ obj-$(CONFIG_TEST_HMM) += test_hmm.o
100101
obj-$(CONFIG_TEST_FREE_PAGES) += test_free_pages.o
101102
obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o
102103
obj-$(CONFIG_TEST_REF_TRACKER) += test_ref_tracker.o
103-
obj-$(CONFIG_TEST_CPUMASK) += test_cpumask.o
104104
CFLAGS_test_fprobe.o += $(CC_FLAGS_FTRACE)
105105
obj-$(CONFIG_FPROBE_SANITY_TEST) += test_fprobe.o
106106
#

lib/test_cpumask.c renamed to lib/cpumask_kunit.c

Lines changed: 31 additions & 21 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,45 +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(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));
5962

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));
6367
}
6468

6569
static void test_cpumask_first(struct kunit *test)
6670
{
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));
6973

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));
7277
}
7378

7479
static void test_cpumask_last(struct kunit *test)
7580
{
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));
7885
}
7986

8087
static void test_cpumask_next(struct kunit *test)
8188
{
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));
8797
}
8898

8999
static void test_cpumask_iterators(struct kunit *test)

0 commit comments

Comments
 (0)