From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EB94AC001B0 for ; Sun, 23 Jul 2023 02:30:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=N5KniiQio41iEPElYjxAhn59a6m1fz5fvCHStsF+ONQ=; b=FpYv3o2HqA9bie 1RnI5fDV/oYdnovOnBLjNRfByNT3E8bjGL1HYIF8lUQPZ/wnGBcByXkrOOWR4BIvfqNNwfcB8KbYr Js8TmX1OTk/fFnEnz4JcfgoJlaPN8QiHn62y7kpSqVf3dLpDZRRyLDq+2lEl5Jy6FGFQtkVBf3Obz IgG9D81gvuhD7s7R9dIaz5LWYlpd0tE0NGOhQPe4OMWeZ8wI47ZUO2/5zNJzEtQdbSt20CfKY+ZIO 3sqIbSBxYOsdy3WANTRBA2308S3/D6sGvnFQx0IVVRcMeXSAS7C5IKF9QfuBZhOubnfaaVb8S5oNY yYUFLwmKVWd9dLuuymbw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qNOr9-0006Fg-0G; Sun, 23 Jul 2023 02:29:59 +0000 Received: from mail-ot1-x32e.google.com ([2607:f8b0:4864:20::32e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qNOr4-0006Ec-2x for linux-arm-kernel@lists.infradead.org; Sun, 23 Jul 2023 02:29:57 +0000 Received: by mail-ot1-x32e.google.com with SMTP id 46e09a7af769-6b9b52724ccso2838261a34.1 for ; Sat, 22 Jul 2023 19:29:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690079383; x=1690684183; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=uaustwNzjZmVePWypLXeoTLylLeiPcQlbyLPn6f6Obw=; b=QLeT/VCnFDu7+iJJQ8Z9+xNUr22l4+J5EJq+ySm/BvTfkXYuP8mBuvYr7YDpCXWAin zbHNyIYS7CM0DwIEVwoBfYtZDckqKHqXPrftBCcCrJD61Mva1kgyTF02I9TLiZPoqslB ElTbMkbOIOTPcSgX43AgkxHPWh8EcYbO+4stZP1c1lwbNxqh1NUV3PTvK5rR15ryWXyR 3cBDNHXBgU7Rgi9CfbngokamJ/kgevWxeSCVwvWhLldh79012665j6P5WLPDqnCqYiWl yOX3cX00YdoamAzw7VeRymor4gAkWUxFgDkyT5gcn6MK1qn6Y5ghZqovbE1UsKktvRpU 6QWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690079383; x=1690684183; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=uaustwNzjZmVePWypLXeoTLylLeiPcQlbyLPn6f6Obw=; b=ediwNUsNrHTIAvVm4fFW6yzwJJQ36iTVwdJKV4gqkW3IR+kEgVXDiJRwlL8Zc9Z1qY hsA3QeWi7ohvGMAmqSdYlCag5jNv3a+xvVZAzf7W1hqqb73bEQypujyOMzGAZp4HwwlI dpKciPVfIv/H018TKXMtElZosKuJeJZkfilgo1blUAojpoYwh5r/0sp2t9btHQ1xYeWf aOZKk4JbnIiethpxYn56MISISRGt8CRlAyb6o+NtPLIrR5ecKAYLr4qO9+cLR3uH2+yI IahAYf90f7AIezcBn72CiIAEPJ7TGxyk/63Rtj/+6Dz7gONYSWdjIP9qI3VDa12d4+Ao Y4iw== X-Gm-Message-State: ABy/qLZAq+GVC2kIQLnQAyIK9oiZWxrDuqfJZyxLyBV/REMM7ZZNBVZ8 kEMxNOGWdU5CN4HYf+IEK8A= X-Google-Smtp-Source: APBJJlHOGKDXakiRWOhkcQkFS0r6ynD4QhW1NnQ+4sbefE3ZendQTqwKIoFyuFTbGzenaqDrpMdHXQ== X-Received: by 2002:a05:6830:19ce:b0:6b9:b985:2892 with SMTP id p14-20020a05683019ce00b006b9b9852892mr4352380otp.17.1690079383363; Sat, 22 Jul 2023 19:29:43 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id ji22-20020a170903325600b001bb9b87ac95sm62388plb.103.2023.07.22.19.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jul 2023 19:29:42 -0700 (PDT) Date: Sat, 22 Jul 2023 19:29:39 -0700 From: Yury Norov To: Alexander Potapenko Cc: catalin.marinas@arm.com, will@kernel.org, pcc@google.com, andreyknvl@gmail.com, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, eugenis@google.com, syednwaris@gmail.com, william.gray@linaro.org Subject: Re: [PATCH v4 2/5] lib/test_bitmap: add tests for bitmap_{set,get}_value() Message-ID: References: <20230720173956.3674987-1-glider@google.com> <20230720173956.3674987-3-glider@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230720173956.3674987-3-glider@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230722_192954_965005_638F58B1 X-CRM114-Status: GOOD ( 23.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Jul 20, 2023 at 07:39:53PM +0200, Alexander Potapenko wrote: > Add basic tests ensuring that values can be added at arbitrary positions > of the bitmap, including those spanning into the adjacent unsigned > longs. > > Signed-off-by: Alexander Potapenko > Reviewed-by: Andy Shevchenko [...] > +/* > + * Test bitmap should be big enough to include the cases when start is not in > + * the first word, and start+nbits lands in the following word. > + */ > +#define TEST_BIT_LEN (BITS_PER_LONG * 3) Why not just 1000? Is your code safe against unaligned bitmaps? > +#define TEST_BYTE_LEN (BITS_TO_LONGS(TEST_BIT_LEN) * sizeof(unsigned long)) BITS_TO_BYTES > +static void __init test_set_get_value(void) test_bitmap_read_write. Here, and in subjects for #1 and #2. > +{ > + DECLARE_BITMAP(bitmap, TEST_BIT_LEN); > + DECLARE_BITMAP(exp_bitmap, TEST_BIT_LEN); > + /* Prevent constant folding. */ > + volatile unsigned long zero_bits = 0; Use READ_ONCE() instead of volatile > + unsigned long val, bit; > + int i; > + > + /* Setting/getting zero bytes should not crash the kernel. */ > + bitmap_write(NULL, 0, 0, zero_bits); > + val = bitmap_read(NULL, 0, zero_bits); > + expect_eq_ulong(0, val); No, val is undefined. > + > + /* > + * Ensure that bitmap_read() reads the same value that was previously > + * written, and two consequent values are correctly merged. > + * The resulting bit pattern is asymmetric to rule out possible issues > + * with bit numeration order. > + */ > + for (i = 0; i < TEST_BIT_LEN - 7; i++) { Can you add some empty lines in the block below in sake of readability? Maybe after expect()? > + bitmap_zero(bitmap, TEST_BIT_LEN); > + bitmap_write(bitmap, 0b10101UL, i, 5); > + val = bitmap_read(bitmap, i, 5); > + expect_eq_ulong(0b10101UL, val); > + bitmap_write(bitmap, 0b101UL, i + 5, 3); > + val = bitmap_read(bitmap, i + 5, 3); > + expect_eq_ulong(0b101UL, val); > + val = bitmap_read(bitmap, i, 8); > + expect_eq_ulong(0b10110101UL, val); > + } > + > + /* > + * Check that setting a single bit does not accidentally touch the > + * adjacent bits. > + */ > + for (i = 0; i < TEST_BIT_LEN; i++) { > + /* > + * A 0b10101010 pattern to catch both 0s replaced to 1s and vice > + * versa. > + */ > + memset(bitmap, 0xaa, TEST_BYTE_LEN); > + memset(exp_bitmap, 0xaa, TEST_BYTE_LEN); > + for (bit = 0; bit <= 1; bit++) { > + bitmap_write(bitmap, bit, i, 1); > + __assign_bit(i, exp_bitmap, bit); > + expect_eq_bitmap(exp_bitmap, bitmap, TEST_BIT_LEN); > + } I suggested the other test: val = DEADBEEF; for (nbits = 1; nbits <= BITS_PER_LONG; nbits++) for (start = 0; start < 1000; i++) { if (start + nbits >= 1000) break;; v = val & GENMASK(nbits - 1, 0); memset(bitmap, 0xaa /* also 0xff and 0x00 */, TEST_BYTE_LEN); memset(exp_bitmap, 0xaa, TEST_BYTE_LEN); for (n = 0; n < nbits; n++) __assign_bit(v & BIT(n), exp_bitmap, start + n); bitmap_write(bitmap, v, start, nbits); expect_eq_bitmap(exp_bitmap, bitmap, 1000); r = bitmap_read(bitmap, start, nbits); expect_eq(r, v); } > + } > + > + /* Ensure setting 0 bits does not change anything. */ > + memset(bitmap, 0xaa, TEST_BYTE_LEN); > + memset(exp_bitmap, 0xaa, TEST_BYTE_LEN); > + for (i = 0; i < TEST_BIT_LEN; i++) { > + bitmap_write(bitmap, ~0UL, i, 0); > + expect_eq_bitmap(exp_bitmap, bitmap, TEST_BIT_LEN); > + } > +} > +#undef TEST_BYTE_LEN > +#undef TEST_BIT_LEN > + > static void __init selftest(void) > { > test_zero_clear(); > @@ -1249,6 +1328,8 @@ static void __init selftest(void) > test_for_each_clear_bitrange_from(); > test_for_each_set_clump8(); > test_for_each_set_bit_wrap(); > + > + test_set_get_value(); This should append the test_bitmap_* section Thanks, Yury _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel