bitmap fixes for v6.0-rc3

Hi Linus,
 
 Please pull (hopefully) the last portion of fixes from Sander for his
 UP rework series. The original series came from -mm tree, and it was
 not the latest version, that's why we need follow-ups. It fixes only
 a test introduced by that series. The test fails under certain configs.
 
 From Sander:
 
 This series fixes the reported issues, and implements the suggested
 improvements, for the version of the cpumask tests [1] that was merged
 with commit c41e8866c2 ("lib/test: introduce cpumask KUnit test
 suite").
 
 These changes include fixes for the tests, and better alignment with the
 KUnit style guidelines.
 
 Thanks,
 Yury
 -----BEGIN PGP SIGNATURE-----
 
 iQGzBAABCgAdFiEEi8GdvG6xMhdgpu/4sUSA/TofvsgFAmMKYcoACgkQsUSA/Tof
 vsiceAv/TY+HTn1gmrNQwi7xC6VUD7mFYlVNZMtyMpZ23UYildz5SjFfuQV3UbXI
 H5yKgSao9VFsbwyDUXbhySgOaNR8auq17Ey3jSJuR2A76qO2u2d79Gdt4IjIkq5N
 IGOPv/pNOur7J+KSbiVhXasFeZGJ6Xi+xAobp5CK1uPCUI3oU1pAcm1iKkI+eWZ3
 tPsM3aWcYGCDec7tqtqcsiWO2x9imPnrpI+C91Pwwr+N40ObkMc4IPzuPrQRn2T2
 ECY9pgIWKOwOJ41jzgCVwZIHmuOn9dEgmaEGvE9Ah57OwuDlS43M4Ok3xy2+xS3t
 3naLG3p02sJy7sXabC+xH4VJVPNT9/qauMW27cntPeeI2i/+yZXuQSLlVOllrY7/
 LYxI8lVb1j50A90I/WrwXoDV0E68cfjhkiqhkgV33t1EamhSJvTG8GwCnF46WG8o
 LzLukvoohA9uIrPAH2YpkZtrvsuT6iQccCY0M+kXv6TuYTgygdE16muVHffDKvsG
 EIVdBGu6
 =oNmV
 -----END PGP SIGNATURE-----

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
  c41e8866c2 ("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
This commit is contained in:
Linus Torvalds 2022-08-28 14:36:27 -07:00
commit 373eff576e
4 changed files with 37 additions and 23 deletions

View File

@ -3612,6 +3612,7 @@ F: include/linux/find.h
F: include/linux/nodemask.h F: include/linux/nodemask.h
F: lib/bitmap.c F: lib/bitmap.c
F: lib/cpumask.c F: lib/cpumask.c
F: lib/cpumask_kunit.c
F: lib/find_bit.c F: lib/find_bit.c
F: lib/find_bit_benchmark.c F: lib/find_bit_benchmark.c
F: lib/test_bitmap.c F: lib/test_bitmap.c

View File

@ -2029,13 +2029,16 @@ config LKDTM
Documentation on how to use the module can be found in Documentation on how to use the module can be found in
Documentation/fault-injection/provoke-crashes.rst Documentation/fault-injection/provoke-crashes.rst
config TEST_CPUMASK config CPUMASK_KUNIT_TEST
tristate "cpumask tests" if !KUNIT_ALL_TESTS tristate "KUnit test for cpumask" if !KUNIT_ALL_TESTS
depends on KUNIT depends on KUNIT
default KUNIT_ALL_TESTS default KUNIT_ALL_TESTS
help help
Enable to turn on cpumask tests, running at boot or module load time. Enable to turn on cpumask tests, running at boot or module load time.
For more information on KUnit and unit tests in general, please refer
to the KUnit documentation in Documentation/dev-tools/kunit/.
If unsure, say N. If unsure, say N.
config TEST_LIST_SORT config TEST_LIST_SORT

View File

@ -60,6 +60,7 @@ obj-$(CONFIG_TEST_BPF) += test_bpf.o
obj-$(CONFIG_TEST_FIRMWARE) += test_firmware.o obj-$(CONFIG_TEST_FIRMWARE) += test_firmware.o
obj-$(CONFIG_TEST_BITOPS) += test_bitops.o obj-$(CONFIG_TEST_BITOPS) += test_bitops.o
CFLAGS_test_bitops.o += -Werror CFLAGS_test_bitops.o += -Werror
obj-$(CONFIG_CPUMASK_KUNIT_TEST) += cpumask_kunit.o
obj-$(CONFIG_TEST_SYSCTL) += test_sysctl.o obj-$(CONFIG_TEST_SYSCTL) += test_sysctl.o
obj-$(CONFIG_TEST_SIPHASH) += test_siphash.o obj-$(CONFIG_TEST_SIPHASH) += test_siphash.o
obj-$(CONFIG_HASH_KUNIT_TEST) += test_hash.o obj-$(CONFIG_HASH_KUNIT_TEST) += test_hash.o
@ -100,7 +101,6 @@ obj-$(CONFIG_TEST_HMM) += test_hmm.o
obj-$(CONFIG_TEST_FREE_PAGES) += test_free_pages.o obj-$(CONFIG_TEST_FREE_PAGES) += test_free_pages.o
obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o
obj-$(CONFIG_TEST_REF_TRACKER) += test_ref_tracker.o obj-$(CONFIG_TEST_REF_TRACKER) += test_ref_tracker.o
obj-$(CONFIG_TEST_CPUMASK) += test_cpumask.o
CFLAGS_test_fprobe.o += $(CC_FLAGS_FTRACE) CFLAGS_test_fprobe.o += $(CC_FLAGS_FTRACE)
obj-$(CONFIG_FPROBE_SANITY_TEST) += test_fprobe.o obj-$(CONFIG_FPROBE_SANITY_TEST) += test_fprobe.o
# #

View File

@ -9,6 +9,10 @@
#include <linux/cpu.h> #include <linux/cpu.h>
#include <linux/cpumask.h> #include <linux/cpumask.h>
#define MASK_MSG(m) \
"%s contains %sCPUs %*pbl", #m, (cpumask_weight(m) ? "" : "no "), \
nr_cpumask_bits, cpumask_bits(m)
#define EXPECT_FOR_EACH_CPU_EQ(test, mask) \ #define EXPECT_FOR_EACH_CPU_EQ(test, mask) \
do { \ do { \
const cpumask_t *m = (mask); \ const cpumask_t *m = (mask); \
@ -16,7 +20,7 @@
int cpu, iter = 0; \ int cpu, iter = 0; \
for_each_cpu(cpu, m) \ for_each_cpu(cpu, m) \
iter++; \ iter++; \
KUNIT_EXPECT_EQ((test), mask_weight, iter); \ KUNIT_EXPECT_EQ_MSG((test), mask_weight, iter, MASK_MSG(mask)); \
} while (0) } while (0)
#define EXPECT_FOR_EACH_CPU_NOT_EQ(test, mask) \ #define EXPECT_FOR_EACH_CPU_NOT_EQ(test, mask) \
@ -26,7 +30,7 @@
int cpu, iter = 0; \ int cpu, iter = 0; \
for_each_cpu_not(cpu, m) \ for_each_cpu_not(cpu, m) \
iter++; \ iter++; \
KUNIT_EXPECT_EQ((test), nr_cpu_ids - mask_weight, iter); \ KUNIT_EXPECT_EQ_MSG((test), nr_cpu_ids - mask_weight, iter, MASK_MSG(mask)); \
} while (0) } while (0)
#define EXPECT_FOR_EACH_CPU_WRAP_EQ(test, mask) \ #define EXPECT_FOR_EACH_CPU_WRAP_EQ(test, mask) \
@ -36,7 +40,7 @@
int cpu, iter = 0; \ int cpu, iter = 0; \
for_each_cpu_wrap(cpu, m, nr_cpu_ids / 2) \ for_each_cpu_wrap(cpu, m, nr_cpu_ids / 2) \
iter++; \ iter++; \
KUNIT_EXPECT_EQ((test), mask_weight, iter); \ KUNIT_EXPECT_EQ_MSG((test), mask_weight, iter, MASK_MSG(mask)); \
} while (0) } while (0)
#define EXPECT_FOR_EACH_CPU_BUILTIN_EQ(test, name) \ #define EXPECT_FOR_EACH_CPU_BUILTIN_EQ(test, name) \
@ -45,7 +49,7 @@
int cpu, iter = 0; \ int cpu, iter = 0; \
for_each_##name##_cpu(cpu) \ for_each_##name##_cpu(cpu) \
iter++; \ iter++; \
KUNIT_EXPECT_EQ((test), mask_weight, iter); \ KUNIT_EXPECT_EQ_MSG((test), mask_weight, iter, MASK_MSG(cpu_##name##_mask)); \
} while (0) } while (0)
static cpumask_t mask_empty; static cpumask_t mask_empty;
@ -53,37 +57,43 @@ static cpumask_t mask_all;
static void test_cpumask_weight(struct kunit *test) static void test_cpumask_weight(struct kunit *test)
{ {
KUNIT_EXPECT_TRUE(test, cpumask_empty(&mask_empty)); KUNIT_EXPECT_TRUE_MSG(test, cpumask_empty(&mask_empty), MASK_MSG(&mask_empty));
KUNIT_EXPECT_TRUE(test, cpumask_full(cpu_possible_mask)); KUNIT_EXPECT_TRUE_MSG(test, cpumask_full(&mask_all), MASK_MSG(&mask_all));
KUNIT_EXPECT_TRUE(test, cpumask_full(&mask_all));
KUNIT_EXPECT_EQ(test, 0, cpumask_weight(&mask_empty)); KUNIT_EXPECT_EQ_MSG(test, 0, cpumask_weight(&mask_empty), MASK_MSG(&mask_empty));
KUNIT_EXPECT_EQ(test, nr_cpu_ids, cpumask_weight(cpu_possible_mask)); KUNIT_EXPECT_EQ_MSG(test, nr_cpu_ids, cpumask_weight(cpu_possible_mask),
KUNIT_EXPECT_EQ(test, nr_cpumask_bits, cpumask_weight(&mask_all)); MASK_MSG(cpu_possible_mask));
KUNIT_EXPECT_EQ_MSG(test, nr_cpumask_bits, cpumask_weight(&mask_all), MASK_MSG(&mask_all));
} }
static void test_cpumask_first(struct kunit *test) static void test_cpumask_first(struct kunit *test)
{ {
KUNIT_EXPECT_LE(test, nr_cpu_ids, cpumask_first(&mask_empty)); KUNIT_EXPECT_LE_MSG(test, nr_cpu_ids, cpumask_first(&mask_empty), MASK_MSG(&mask_empty));
KUNIT_EXPECT_EQ(test, 0, cpumask_first(cpu_possible_mask)); KUNIT_EXPECT_EQ_MSG(test, 0, cpumask_first(cpu_possible_mask), MASK_MSG(cpu_possible_mask));
KUNIT_EXPECT_EQ(test, 0, cpumask_first_zero(&mask_empty)); KUNIT_EXPECT_EQ_MSG(test, 0, cpumask_first_zero(&mask_empty), MASK_MSG(&mask_empty));
KUNIT_EXPECT_LE(test, nr_cpu_ids, cpumask_first_zero(cpu_possible_mask)); KUNIT_EXPECT_LE_MSG(test, nr_cpu_ids, cpumask_first_zero(cpu_possible_mask),
MASK_MSG(cpu_possible_mask));
} }
static void test_cpumask_last(struct kunit *test) static void test_cpumask_last(struct kunit *test)
{ {
KUNIT_EXPECT_LE(test, nr_cpumask_bits, cpumask_last(&mask_empty)); KUNIT_EXPECT_LE_MSG(test, nr_cpumask_bits, cpumask_last(&mask_empty),
KUNIT_EXPECT_EQ(test, nr_cpumask_bits - 1, cpumask_last(cpu_possible_mask)); MASK_MSG(&mask_empty));
KUNIT_EXPECT_EQ_MSG(test, nr_cpu_ids - 1, cpumask_last(cpu_possible_mask),
MASK_MSG(cpu_possible_mask));
} }
static void test_cpumask_next(struct kunit *test) static void test_cpumask_next(struct kunit *test)
{ {
KUNIT_EXPECT_EQ(test, 0, cpumask_next_zero(-1, &mask_empty)); KUNIT_EXPECT_EQ_MSG(test, 0, cpumask_next_zero(-1, &mask_empty), MASK_MSG(&mask_empty));
KUNIT_EXPECT_LE(test, nr_cpu_ids, cpumask_next_zero(-1, cpu_possible_mask)); KUNIT_EXPECT_LE_MSG(test, nr_cpu_ids, cpumask_next_zero(-1, cpu_possible_mask),
MASK_MSG(cpu_possible_mask));
KUNIT_EXPECT_LE(test, nr_cpu_ids, cpumask_next(-1, &mask_empty)); KUNIT_EXPECT_LE_MSG(test, nr_cpu_ids, cpumask_next(-1, &mask_empty),
KUNIT_EXPECT_EQ(test, 0, cpumask_next(-1, cpu_possible_mask)); MASK_MSG(&mask_empty));
KUNIT_EXPECT_EQ_MSG(test, 0, cpumask_next(-1, cpu_possible_mask),
MASK_MSG(cpu_possible_mask));
} }
static void test_cpumask_iterators(struct kunit *test) static void test_cpumask_iterators(struct kunit *test)