Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp553352ybg; Tue, 9 Jun 2020 07:14:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2NXkKBrqGtCTj/yoVkNuaPcD6OTDCKfgi2XyZOplGn6fwWoKV5iDFQKGl48JhUq4zqmgX X-Received: by 2002:a17:906:8253:: with SMTP id f19mr26493813ejx.470.1591712054100; Tue, 09 Jun 2020 07:14:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591712054; cv=none; d=google.com; s=arc-20160816; b=eeUgwdc8of3BICAGyTmoAQT9tZnynhTZJmx0G+vYMofcccvmzGd6G8++18CgPY4Hnh jzW074lCvbuFmD7X0QPoCvK9CKvCdVmmObhE4iwG9TCFS0MdJN++HfvaKPJmasssqcxY qzUbUzp7TtV2+LzwXnjLCBIIDEsYfWt1D9+wDbqIUYaHhIyKJMuVdBcEIP/DiSE6rinA /xMf8sobkLz2nnXiC1B9JSW360A3lWC3LBDSH8OEENbHfA4hxaeGYFgNkYCjsWRhDNyG BhUWeNHq3y17eQ3SRnF53NOk5sRGy02oSVDo2Tw8uEkAQd4vTHECYK2bkAburIiMdWBv Gg7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=nbjkRUfSxpIRE9L5muPwAXEXsssIxPhz/mzHngdljkU=; b=AUneVfAUy+qAblCsyQqG10s2WvN908G7fTNfroxr0UYNfqZf3umaKvF5dbyRebsEfJ 42bq11wm1K2omrj45ger9laSymHZ5xOtBet4JH+D5qLkf6mMZJi7y253gHW86FDJtmOP i7lUCmIJLJXRZLGU/JBh2lfMYkhiXGJLiG5gQB2u9bjIJkKU/ioHkDFSAVHeMJeY0ovU SRuZDHmwxGNL3AI3q/iITa9Q+Gc7VixPflp8mkfgB7j69yvxVy3Qo0Kce0po/LyjyFJA vKfMfBI1LfPHj8AOk78qAkNfQLr28acYGgsW+91L3TWYTH+HHyZYPb7R9/1iMqFJNbbe VuBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sRpl8CGO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q2si4378273ejf.33.2020.06.09.07.13.50; Tue, 09 Jun 2020 07:14:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sRpl8CGO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730089AbgFIOLi (ORCPT + 99 others); Tue, 9 Jun 2020 10:11:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728601AbgFIOLh (ORCPT ); Tue, 9 Jun 2020 10:11:37 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B39AC05BD1E; Tue, 9 Jun 2020 07:11:37 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id m2so1466162pjv.2; Tue, 09 Jun 2020 07:11:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nbjkRUfSxpIRE9L5muPwAXEXsssIxPhz/mzHngdljkU=; b=sRpl8CGOWQm3GO7DaHHkPpb/9FpBaD4iVeWbMU4EydSBchwheAOtjl940fZFnh+RYi NDzYwvO9oCwAIROiyKkXSzkOCDrWcifDn4ds6T/3T8s355i+4RGCs790Cc6UcBdj+vRS AmbzjJ9P9RBfiLv2Omhce9haa2cEOi/zGQ5x69bAf/fef5sxQ2Up3NkTnw8CMA6KhfZX wXMCTphw/EwBGAzXHla+rH5idT9EChPwsYNT/LeBp0pCUlxybyc3Nkd/BvUgc37N6OLQ 2dN8KWWyuaqJTuSG9fte5JdVsiNnu8usZHSG+UzZynbk21GI0xYrpdRVzYsU9vfmN55a xDog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nbjkRUfSxpIRE9L5muPwAXEXsssIxPhz/mzHngdljkU=; b=noQ1JBqKLCbSOQxDg4d6uIfjRG4jPhnhpZof4YA8bEfoVj3vtjtkhIwZ0Q0aHK3+Nq ikdYmsqUNusWNIXwPl8jGwxOEDFPMIOQ+/2eShYkVjAAchucBrEPfknFcX7iWHbnkiXB 8c1h1X7eh1tSn3ouWiQBQlkMPbwEkfrAez3KTJbdKrkobPVs9F9ZMXxguqiGzvNf+tFr asrlZzvHxtXsX78jG+WVmObrOiaPx40Vqh8L9U3kJsJfq/8PvJSvWESE8CgR29qS9OXt 80icqrNxa63n86UklOI7WFr1TQvFepZVsoMv4zo8gk78pqfvvdsDRGodAfcJzmTWACvy 75YA== X-Gm-Message-State: AOAM5333iiL+wZIOhhQYEjdgxjh8+IBxUDDweOV/OFxyi5FrHNU0eXoS zD7lDf6Xc2nhx3zoQ10Jsaq1B2lHR6VHFqEqwNbwHmjX+P0L6A== X-Received: by 2002:a17:90a:220f:: with SMTP id c15mr5287273pje.129.1591711896706; Tue, 09 Jun 2020 07:11:36 -0700 (PDT) MIME-Version: 1.0 References: <20200608184222.GA899@rikard> <20200608221823.35799-1-rikard.falkeborn@gmail.com> <20200608221823.35799-2-rikard.falkeborn@gmail.com> In-Reply-To: <20200608221823.35799-2-rikard.falkeborn@gmail.com> From: Andy Shevchenko Date: Tue, 9 Jun 2020 17:11:24 +0300 Message-ID: Subject: Re: [PATCH v3 2/2] bits: Add tests of GENMASK To: Rikard Falkeborn Cc: Andrew Morton , Arnd Bergmann , Emil Velikov , Geert Uytterhoeven , Kees Cook , Linus Walleij , Linux-Arch , Linux Kernel Mailing List , kbuild test robot , Syed Nayyar Waris , William Breathitt Gray , Masahiro Yamada Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 9, 2020 at 1:18 AM Rikard Falkeborn wrote: > > Add tests of GENMASK and GENMASK_ULL. > > A few test cases that should fail compilation are provided > under #ifdef TEST_GENMASK_FAILURES > LGTM, thanks! Reviewed-by: Andy Shevchenko > Suggested-by: Andy Shevchenko > Signed-off-by: Rikard Falkeborn > --- > I did not move it to test_bitops.c, because I think it makes more sense > that test_bitops.c tests bitops.h and test_bits.c tests bits.h, but if > you disagree, I can move it. We could do it later and actually other way around, since you are using KUnit, while the test_bitops.h doesn't. > > v2-v3 > Updated commit message and ifdef after suggestion fron Geert. Also fixed > a typo in the description of the file. > > v1-v2 > New patch. > > lib/Kconfig.debug | 11 +++++++ > lib/Makefile | 1 + > lib/test_bits.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 85 insertions(+) > create mode 100644 lib/test_bits.c > > diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug > index 333e878d8af9..9557cb570fb9 100644 > --- a/lib/Kconfig.debug > +++ b/lib/Kconfig.debug > @@ -2182,6 +2182,17 @@ config LINEAR_RANGES_TEST > > If unsure, say N. > > +config BITS_TEST > + tristate "KUnit test for bits.h" > + depends on KUNIT > + help > + This builds the bits unit test. > + Tests the logic of macros defined in bits.h. > + 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. > + > config TEST_UDELAY > tristate "udelay test driver" > help > diff --git a/lib/Makefile b/lib/Makefile > index 315516fa4ef4..2ce9892e3e63 100644 > --- a/lib/Makefile > +++ b/lib/Makefile > @@ -314,3 +314,4 @@ obj-$(CONFIG_OBJAGG) += objagg.o > # KUnit tests > obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o > obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o > +obj-$(CONFIG_BITS_TEST) += test_bits.o > diff --git a/lib/test_bits.c b/lib/test_bits.c > new file mode 100644 > index 000000000000..e2fcf24463bf > --- /dev/null > +++ b/lib/test_bits.c > @@ -0,0 +1,73 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Test cases for functions and macros in bits.h > + */ > + > +#include > +#include > + > + > +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_GENMASK_FAILURES > + /* these should fail compilation */ > + GENMASK(0, 1); > + GENMASK(0, 10); > + GENMASK(9, 10); > +#endif > + > + > +} > + > +void genmask_ull_test(struct kunit *test) > +{ > + KUNIT_EXPECT_EQ(test, 1ull, GENMASK_ULL(0, 0)); > + KUNIT_EXPECT_EQ(test, 3ull, GENMASK_ULL(1, 0)); > + KUNIT_EXPECT_EQ(test, 0x000000ffffe00000ull, GENMASK_ULL(39, 21)); > + KUNIT_EXPECT_EQ(test, 0xffffffffffffffffull, GENMASK_ULL(63, 0)); > + > +#ifdef TEST_GENMASK_FAILURES > + /* these should fail compilation */ > + GENMASK_ULL(0, 1); > + GENMASK_ULL(0, 10); > + GENMASK_ULL(9, 10); > +#endif > +} > + > +void genmask_input_check_test(struct kunit *test) > +{ > + unsigned int x, y; > + int z, w; > + > + /* Unknown input */ > + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(x, 0)); > + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(0, x)); > + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(x, y)); > + > + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(z, 0)); > + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(0, z)); > + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(z, w)); > + > + /* Valid input */ > + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(1, 1)); > + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(39, 21)); > +} > + > + > +static struct kunit_case bits_test_cases[] = { > + KUNIT_CASE(genmask_test), > + KUNIT_CASE(genmask_ull_test), > + KUNIT_CASE(genmask_input_check_test), > + {} > +}; > + > +static struct kunit_suite bits_test_suite = { > + .name = "bits-test", > + .test_cases = bits_test_cases, > +}; > +kunit_test_suite(bits_test_suite); > -- > 2.27.0 > -- With Best Regards, Andy Shevchenko