Re: [PATCH v2 2/2] bits: Add tests of GENMASK

From: Geert Uytterhoeven
Date: Mon Jun 08 2020 - 03:33:20 EST


Hi Richard,

Thanks for your patch!

On Sun, Jun 7, 2020 at 10:35 PM Rikard Falkeborn
<rikard.falkeborn@xxxxxxxxx> wrote:
> Add tests of GENMASK and GENMASK_ULL.
>
> A few test cases that should fail compilation are provided under ifdef.

It doesn't hurt to mention the name of the #ifdef here.

> Suggested-by: Andy Shevchenko <andy.shevchenko@xxxxxxxxx>
> Signed-off-by: Rikard Falkeborn <rikard.falkeborn@xxxxxxxxx>

> --- /dev/null
> +++ b/lib/test_bits.c
> @@ -0,0 +1,73 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Test cases for functions and macrso in bits.h
> + */
> +
> +#include <kunit/test.h>
> +#include <linux/bits.h>
> +
> +
> +void genmask_test(struct kunit *test)
> +{
> + KUNIT_EXPECT_EQ(test, 1ul, GENMASK(0, 0));
> + KUNIT_EXPECT_EQ(test, 3ul, GENMASK(1, 0));
> + KUNIT_EXPECT_EQ(test, 6ul, GENMASK(2, 1));
> + KUNIT_EXPECT_EQ(test, 0xFFFFFFFFul, GENMASK(31, 0));
> +
> +#ifdef TEST_BITS_COMPILE

"#ifdef TEST_GENMASK_FAILURES"?

> + /* these should fail compilation */
> + GENMASK(0, 1);
> + GENMASK(0, 10);
> + GENMASK(9, 10);
> +#endif

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds