Re: [PATCH v3 2/4] lib/test: Introduce cpumask KUnit test suite

From: Sander Vanheule
Date: Mon Jun 06 2022 - 08:22:30 EST


Hi Andy,

On Mon, 2022-06-06 at 13:36 +0300, Andy Shevchenko wrote:
> On Sun, Jun 05, 2022 at 08:22:39AM +0200, Sander Vanheule wrote:
> > Add a basic suite of tests for cpumask, providing some tests for empty
> > and completely filled cpumasks.
>
> Always in favour of a new test!
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>

Thanks!

>
> > Signed-off-by: Sander Vanheule <sander@xxxxxxxxxxxxx>
> > ---
> >
> > +#define EXPECT_FOR_EACH_CPU_BUILTIN_EQ(test, name)             \
> > +       do {                                                    \
> > +               const cpumask_t *m = cpu_##name##_mask;         \
> > +               int mask_weight = cpumask_weight(m);            \

Given the documentation for num_online_cpus(), I've replaced this with

int mask_weight = num_##name##_cpus();

and added guards around the test for the dynamic builtin masks.

> > +               int cpu, iter = 0;                              \
> > +               for_each_##name##_cpu(cpu)                      \
> > +                       iter++;                                 \
> > +               KUNIT_EXPECT_EQ((test), mask_weight, iter);     \
> > +       } while (0)
> >


> > +static void test_cpumask_iterators_builtin(struct kunit *test)
> > +{
> > +       EXPECT_FOR_EACH_CPU_BUILTIN_EQ(test, possible);

cpu_hotplug_disable();

> > +       EXPECT_FOR_EACH_CPU_BUILTIN_EQ(test, online);
> > +       EXPECT_FOR_EACH_CPU_BUILTIN_EQ(test, present);

cpu_hotplug_enable();

> > +}

This should ensure the tests will not randomly fail, if they happen to run while a CPU is going
online/offline.

Best,
Sander