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 0BAA7C001DD for ; Thu, 13 Jul 2023 12:58:03 +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:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=GvrK63U5yibSZPSVnSp7AXVmefmYs2iuNKuTMFpOgCA=; b=0XJWlFsDKJ/aRqS0lgMGbs2rGl hwsX+3WS9w8YFmctuSJRFiRLKmmgii0+8rfEoweriALiLkNiZrJ5G7Np2UqnKgWxWJDY9IN72Vu0K JPFa71/C3xvwb75oGeyX52NaunPD1r4ihSB+r6SzBtc7rjOsF1VevZGoVfxPJuVGrD8l5XfK4PH6b un/9viYE5OTgYhtZyaLgfzF9fuwUZarL34JZW5iMch6O6K6EnvHWXDTZa30s8/4YDIMkhQZrvBU9D FXKAkGqMMg4WwXvg8mAxdWsMjdsBZjLq9lFiN7J1koMI7CFVZFo9QLtCd68cLLbdv1Z1XOSK6zgup xNxKsDvQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qJvt3-003Jib-21; Thu, 13 Jul 2023 12:57:37 +0000 Received: from mail-ed1-x54a.google.com ([2a00:1450:4864:20::54a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qJvt0-003Jgz-1U for linux-arm-kernel@lists.infradead.org; Thu, 13 Jul 2023 12:57:35 +0000 Received: by mail-ed1-x54a.google.com with SMTP id 4fb4d7f45d1cf-51dd16f823bso431047a12.0 for ; Thu, 13 Jul 2023 05:57:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689253052; x=1691845052; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jmq0b/Ecy0ZNTUuWhSR14tYQI4JHnYovo+aDrld9UN0=; b=CgGc1u5qyG9QHrPLJIfRm5/iPctCseTN5qUO7jdfNfbBcVi7VSxsjYA0omtf3+hxMV cXIv7arRK7gICiBo+wRZ0QeyQM5TkdW7LR6MVSqklD70rENHC3Kn/OtihQiIfy9xaTzN wW1b3m2v3U+lURK1LCBKW57m2ukspaRu3Y2VcJaSk1BrbVheIGUBDjMQNvUI6bj/s6Gn nguC8zsoqWo8SifiF54s/ew9mLcz7zKfklVijPUvCFpOFSCLihYXTnHFenJclDY06PxO /stMdLKDH8TjLnFVY9UeQTLsN2IhCEKY0G+QXw3TBsoATXET5UrQenfGfZNKL2ULWiKi IhoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689253052; x=1691845052; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jmq0b/Ecy0ZNTUuWhSR14tYQI4JHnYovo+aDrld9UN0=; b=eqADR8mWvk4umS9O7TMaM20SXxnfPWxI5Gm1g5Mk8qNUFbYQgn2gxImu9Y1QAt6661 SWpaxVuEs4M8Vunt/hnZKA3MjAGXUmM+PSiXSNccoOiLNnZQcWUrpmrXZXkyL3hvRuS7 3R4hTu9c2PAOCiCfaVWcoG9H7fkRIJP6kP0YLrmq7Z61BSgZ52t8WS9ngHYsnLH0/sUt qkDixctaic1vA+TKnUYT8010Zw5CvcqeVj0VdiA4WqrlIxLsBNpQBfemKJZStqtofZf3 2EBhwLIVuBn3lTLAVn82kmoLE66pBqqWJtwKdLXxOzZEccSe02Z+8tq+fWI1DRn6/1fT nFMA== X-Gm-Message-State: ABy/qLaXojxYqJz4vYzG3y2Y0cCXZm7tnTVI+fFmucPH3rTnaryzDbcz vlADfWpeqig71QqvGOZw2FQlDlEXP7I= X-Google-Smtp-Source: APBJJlHeRD8uLG+3QTCDR74WA5gMF3fPZWDdb23eDq3tUHkrau4iIYKWhnpbLYG6CkJUYvO244cOyYRq2s0= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:7a88:66b7:31e5:7d85]) (user=glider job=sendgmr) by 2002:a50:f688:0:b0:51e:23e9:5c85 with SMTP id d8-20020a50f688000000b0051e23e95c85mr7587edn.6.1689253052246; Thu, 13 Jul 2023 05:57:32 -0700 (PDT) Date: Thu, 13 Jul 2023 14:57:02 +0200 In-Reply-To: <20230713125706.2884502-1-glider@google.com> Mime-Version: 1.0 References: <20230713125706.2884502-1-glider@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230713125706.2884502-3-glider@google.com> Subject: [v2 2/5] lib/test_bitmap: add tests for bitmap_{set,get}_value_unaligned From: Alexander Potapenko To: glider@google.com, catalin.marinas@arm.com, will@kernel.org, pcc@google.com, andreyknvl@gmail.com, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yury.norov@gmail.com Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, eugenis@google.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230713_055734_498686_3B785759 X-CRM114-Status: GOOD ( 12.13 ) 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 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 --- lib/test_bitmap.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index 187f5b2db4cf1..8ca61f6e7f26e 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -71,6 +71,17 @@ __check_eq_uint(const char *srcfile, unsigned int line, return true; } +static bool __init +__check_eq_ulong(const char *srcfile, unsigned int line, + const unsigned long exp_ulong, unsigned long x) +{ + if (exp_ulong != x) { + pr_err("[%s:%u] expected %lu, got %lu\n", + srcfile, line, exp_ulong, x); + return false; + } + return true; +} static bool __init __check_eq_bitmap(const char *srcfile, unsigned int line, @@ -186,6 +197,7 @@ __check_eq_str(const char *srcfile, unsigned int line, }) #define expect_eq_uint(...) __expect_eq(uint, ##__VA_ARGS__) +#define expect_eq_ulong(...) __expect_eq(ulong, ##__VA_ARGS__) #define expect_eq_bitmap(...) __expect_eq(bitmap, ##__VA_ARGS__) #define expect_eq_pbl(...) __expect_eq(pbl, ##__VA_ARGS__) #define expect_eq_u32_array(...) __expect_eq(u32_array, ##__VA_ARGS__) @@ -1222,6 +1234,26 @@ static void __init test_bitmap_const_eval(void) BUILD_BUG_ON(~var != ~BIT(25)); } +static void __init test_set_get_value_unaligned(void) +{ + DECLARE_BITMAP(bitmap, BITS_PER_LONG * 2); + unsigned long val; + int i; + + for (i = 0; i < BITS_PER_LONG * 2 - 7; i++) { + bitmap_zero(bitmap, BITS_PER_LONG * 2); + bitmap_set_value_unaligned(bitmap, 0b10101UL, i, 5); + val = bitmap_get_value_unaligned(bitmap, i, 5); + expect_eq_ulong(0b10101UL, val); + bitmap_set_value_unaligned(bitmap, 0b101UL, i + 5, 3); + val = bitmap_get_value_unaligned(bitmap, i + 5, 3); + expect_eq_ulong(0b101UL, val); + val = bitmap_get_value_unaligned(bitmap, i, 8); + expect_eq_ulong(0b10101101UL, val); + } +} + + static void __init selftest(void) { test_zero_clear(); @@ -1249,6 +1281,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_unaligned(); } KSTM_MODULE_LOADERS(test_bitmap); -- 2.41.0.255.g8b1d071c50-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel