From: Yury Norov <yury.norov@gmail.com>
To: Sander Vanheule <sander@svanheule.net>
Cc: Peter Zijlstra <peterz@infradead.org>,
Andrew Morton <akpm@linux-foundation.org>,
Valentin Schneider <vschneid@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Marco Elver <elver@google.com>,
linux-kernel@vger.kernel.org,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: Re: [PATCH v2 1/4] lib/test: Introduce cpumask KUnit test suite
Date: Sat, 4 Jun 2022 12:31:52 -0700 [thread overview]
Message-ID: <YpuzKLQdToIwBrSm@yury-laptop> (raw)
In-Reply-To: <5a55f41812dc18fccf66f8130682ff8e669e0c80.1654362935.git.sander@svanheule.net>
On Sat, Jun 04, 2022 at 07:15:56PM +0200, Sander Vanheule wrote:
> Add a basic suite of tests for cpumask, providing some tests for empty
> and completely filled cpumasks.
>
> Signed-off-by: Sander Vanheule <sander@svanheule.net>
The test must go after fix, so that it's doesn't cause regressions
while bisecting.
> ---
> lib/Kconfig.debug | 9 ++++
> lib/Makefile | 1 +
> lib/test_cpumask.c | 115 +++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 125 insertions(+)
> create mode 100644 lib/test_cpumask.c
[..]
> +#define FOR_EACH_ITER_EQ(_test, _iter, _expect, _loop) \
> + do { \
> + (_iter) = 0; \
> + _loop \
> + (_iter)++; \
> + KUNIT_EXPECT_EQ((_test), (_expect), (_iter)); \
> + } while (0)
This one is harder to use than it should be. Maybe like this? (not tested,
just an idea)
#define TEST_FOR_EACH_CPU_EQ(test, mask) \
do { \
cpumask_t *m = (mask); \
int iter = 0, cpu; \
for_each_cpu(cpu, m) \
iter++; \
KUNIT_EXPECT_EQ((test), cpumask_weight(m), iter); \
} while (0)
static void test_cpumask_iterators(struct kunit *test)
{
TEST_FOR_EACH_CPU(test, &mask_empty);
...
}
Similarly for NOT and WRAP.
Thanks,
Yury
> +static cpumask_t mask_empty;
> +static cpumask_t mask_all;
> +
> +static void test_cpumask_weight(struct kunit *test)
> +{
> + KUNIT_EXPECT_TRUE(test, cpumask_empty(&mask_empty));
> + KUNIT_EXPECT_TRUE(test, cpumask_full(cpu_possible_mask));
> + KUNIT_EXPECT_TRUE(test, cpumask_full(&mask_all));
> +
> + KUNIT_EXPECT_EQ(test, 0, cpumask_weight(&mask_empty));
> + KUNIT_EXPECT_EQ(test, nr_cpu_ids, cpumask_weight(cpu_possible_mask));
> + KUNIT_EXPECT_EQ(test, nr_cpumask_bits, cpumask_weight(&mask_all));
> +}
> +
> +static void test_cpumask_first(struct kunit *test)
> +{
> + KUNIT_EXPECT_LE(test, nr_cpu_ids, cpumask_first(&mask_empty));
> + KUNIT_EXPECT_EQ(test, 0, cpumask_first(cpu_possible_mask));
> +
> + KUNIT_EXPECT_EQ(test, 0, cpumask_first_zero(&mask_empty));
> + KUNIT_EXPECT_LE(test, nr_cpu_ids, cpumask_first_zero(cpu_possible_mask));
> +}
> +
> +static void test_cpumask_last(struct kunit *test)
> +{
> + KUNIT_EXPECT_LE(test, nr_cpumask_bits, cpumask_last(&mask_empty));
> + KUNIT_EXPECT_EQ(test, nr_cpumask_bits - 1, cpumask_last(cpu_possible_mask));
> +}
> +
> +static void test_cpumask_next(struct kunit *test)
> +{
> + KUNIT_EXPECT_EQ(test, 0, cpumask_next_zero(-1, &mask_empty));
> + KUNIT_EXPECT_LE(test, nr_cpu_ids, cpumask_next_zero(-1, cpu_possible_mask));
> +
> + KUNIT_EXPECT_LE(test, nr_cpu_ids, cpumask_next(-1, &mask_empty));
> + KUNIT_EXPECT_EQ(test, 0, cpumask_next(-1, cpu_possible_mask));
> +}
> +
> +static void test_cpumask_iterators(struct kunit *test)
> +{
> + unsigned int iterations;
> + int cpu;
> +
> + FOR_EACH_ITER_EQ(test, iterations, cpumask_weight(&mask_empty),
> + for_each_cpu(cpu, &mask_empty));
> + FOR_EACH_ITER_EQ(test, iterations, nr_cpu_ids - cpumask_weight(&mask_empty),
> + for_each_cpu_not(cpu, &mask_empty));
> + FOR_EACH_ITER_EQ(test, iterations, cpumask_weight(&mask_empty),
> + for_each_cpu_wrap(cpu, &mask_empty, nr_cpu_ids / 2));
> +
> + FOR_EACH_ITER_EQ(test, iterations, cpumask_weight(cpu_possible_mask),
> + for_each_cpu(cpu, cpu_possible_mask));
> + FOR_EACH_ITER_EQ(test, iterations, nr_cpu_ids - cpumask_weight(cpu_possible_mask),
> + for_each_cpu_not(cpu, cpu_possible_mask));
> + FOR_EACH_ITER_EQ(test, iterations, cpumask_weight(cpu_possible_mask),
> + for_each_cpu_wrap(cpu, cpu_possible_mask, nr_cpu_ids / 2));
> +}
> +
> +static void test_cpumask_iterators_builtin(struct kunit *test)
> +{
> + unsigned int iterations;
> + int cpu;
> +
> + FOR_EACH_ITER_EQ(test, iterations, nr_cpu_ids,
> + for_each_possible_cpu(cpu));
> + FOR_EACH_ITER_EQ(test, iterations, cpumask_weight(cpu_online_mask),
> + for_each_online_cpu(cpu));
> + FOR_EACH_ITER_EQ(test, iterations, cpumask_weight(cpu_present_mask),
> + for_each_present_cpu(cpu));
> +}
> +
> +static int test_cpumask_init(struct kunit *test)
> +{
> + cpumask_clear(&mask_empty);
> + cpumask_setall(&mask_all);
> +
> + return 0;
> +}
> +
> +static struct kunit_case test_cpumask_cases[] = {
> + KUNIT_CASE(test_cpumask_weight),
> + KUNIT_CASE(test_cpumask_first),
> + KUNIT_CASE(test_cpumask_last),
> + KUNIT_CASE(test_cpumask_next),
> + KUNIT_CASE(test_cpumask_iterators),
> + KUNIT_CASE(test_cpumask_iterators_builtin),
> + {}
> +};
> +
> +static struct kunit_suite test_cpumask_suite = {
> + .name = "cpumask",
> + .init = test_cpumask_init,
> + .test_cases = test_cpumask_cases,
> +};
> +kunit_test_suite(test_cpumask_suite);
> +
> +MODULE_LICENSE("GPL");
> --
> 2.36.1
next prev parent reply other threads:[~2022-06-04 19:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-04 17:15 [PATCH v2 0/4] cpumask: Fix invalid uniprocessor assumptions Sander Vanheule
2022-06-04 17:15 ` [PATCH v2 1/4] lib/test: Introduce cpumask KUnit test suite Sander Vanheule
2022-06-04 19:31 ` Yury Norov [this message]
2022-06-05 6:21 ` Sander Vanheule
2022-06-04 17:15 ` [PATCH v2 2/4] cpumask: Fix invalid uniprocessor mask assumption Sander Vanheule
2022-06-04 17:15 ` [PATCH v2 3/4] cpumask: Add UP optimised for_each_*_cpu versions Sander Vanheule
2022-06-04 17:15 ` [PATCH v2 4/4] cpumask: Update cpumask_next_wrap() signature Sander Vanheule
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YpuzKLQdToIwBrSm@yury-laptop \
--to=yury.norov@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=elver@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=sander@svanheule.net \
--cc=tglx@linutronix.de \
--cc=vschneid@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®