From patchwork Sun Mar 3 07:48:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10836985 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C162A1575 for ; Sun, 3 Mar 2019 07:48:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC20A2A52D for ; Sun, 3 Mar 2019 07:48:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E52A2A52F; Sun, 3 Mar 2019 07:48:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 304432A52D for ; Sun, 3 Mar 2019 07:48:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2W94OZMPcH2ptpAzoAEWY+ygJCv7fiy5KF/I6aVgz4o=; b=iV+KAJZhTS1nB3 kDAzsaVHTXAkWCj+fijWNKCndWi8/DMkQhMQgt4X3g3MWWkLZ1tFRO4waTYopLIUKbN+/iCZAhIYZ ZGmPK7xqus2Z74shYFiMxrKIJlUkNZ7LRHz6MHjYyXebNShnAX/3IeDAHMTagdatG21Q+EROZIwEU /KkF5lRZ3Rf3HnCSvwQIkmapS3VH6fLD1BOO/nEsWjagC98/7WcZRTDAmYnQb8Wz36EO+2BxT0x5Y 0mw54a5Llm8HWer9XYtuyx8DZ4Yq2NWUp4rgmk8bJkGaKIVY8FNUaoclmIVNhKh5F195Uma26sr8t t254ntaFZqIxTqfUxvrg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0Lqz-0008SE-EH; Sun, 03 Mar 2019 07:48:09 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0Lqw-0008RS-Db for linux-arm-kernel@lists.infradead.org; Sun, 03 Mar 2019 07:48:08 +0000 Received: by mail-pg1-x544.google.com with SMTP id r124so1030244pgr.3 for ; Sat, 02 Mar 2019 23:48:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ElsNjzQ7K98lI/bHz/nS5DIDC37ffsppngWHxCUh4y8=; b=Pg2kb3SyiFiHaFONBSKyoKCSYn7k0JkY9T1bWjWkklQDuMf7SeigsW9psZ0MXIdi0o OIjXZv3fYQ/Ned1bAUGm6ZmxS2HgRyHUikRiaL2i5+EuW2s1G7iQUAH+2fKJj5hhHW2b oXEnxot/6EFeD5V/BpKdXCN+bDX3f36684GL654E0rOJqZ/IukC/xTI3ve8ElTjKg5pY pvcE71lkFAXer8x8c9B+KU6KYARhGjUuPp6yjelZyUh8NBStcprLtne1/NOPSFB3Gstn IKuVYH1uBrArLWTwbucdd8FvOOACQ5GvwG15V2BCugcj8A+OUjv2j14psCvQkvUSv+ER rOnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ElsNjzQ7K98lI/bHz/nS5DIDC37ffsppngWHxCUh4y8=; b=XkWdNiTh/WRhlIaopZf/V421CdVFIZ4ZOqT8XKj/XbMpcrq0yOx3M2ZwjROAH7Ias5 UHsWxWhewqzpEJnlrfqbAz0Ec6HSyP9gafeS7Am7le+IsNi3rBerCBAu6i+D9iOBs+qb KohXtPrLS1b9Hg+Z7daas7aq4z4XoORiQUm3m+5b+qtA3FqhYpiZ2AOUnHmGoc9+BEwS KPqNjc33XI6UdZoXmhu6QVT9prkagDlKRc9xCO3wU44JK/XozF7z98Zkmge1MrzrO+0K 9j+sprmHt8/K9SctMuPY4+R8bNXJspm7yi6DdIC4z0MjNhY3f30weahjH/1u81a+g3nh BfOQ== X-Gm-Message-State: APjAAAXykkW/XB210RPkO9BrkohdIlbn9Sbk4Wa8Jd6yXnd/uDC+VRWa 0+9U/W25axMglxNpehjH7Gg= X-Google-Smtp-Source: APXvYqwSltqoEw9JKp+yIsusA5L0KKE4BlpoSKKUPKWyfM62T0xKFe79n2gcx85OxQve/J1AyinmKA== X-Received: by 2002:a63:d49:: with SMTP id 9mr12937777pgn.27.1551599285644; Sat, 02 Mar 2019 23:48:05 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a5:3b5c:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id b7sm4572950pfi.36.2019.03.02.23.48.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Mar 2019 23:48:05 -0800 (PST) From: William Breathitt Gray To: linus.walleij@linaro.org Subject: [PATCH v9 2/9] lib/test_bitmap.c: Add for_each_set_clump8 test cases Date: Sun, 3 Mar 2019 16:48:54 +0900 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190302_234806_454573_8A561CB4 X-CRM114-Status: GOOD ( 14.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, yamada.masahiro@socionext.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, Andy Shevchenko , bgolaszewski@baylibre.com, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The introduction of the for_each_set_clump8 macro warrants test cases to verify the implementation. This patch adds test case checks for whether an out-of-bounds clump index is returned, a zero clump is returned, or the returned clump value differs from the expected clump value. Cc: Andrew Morton Cc: Rasmus Villemoes Reviewed-by: Andy Shevchenko Reviewed-by: Linus Walleij Signed-off-by: William Breathitt Gray --- lib/test_bitmap.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index 6cd7d0740005..66ddb3fb98cb 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -88,6 +88,36 @@ __check_eq_u32_array(const char *srcfile, unsigned int line, return true; } +static bool __init __check_eq_clump8(const char *srcfile, unsigned int line, + const unsigned int offset, + const unsigned int size, + const unsigned char *const clump_exp, + const unsigned long *const clump) +{ + unsigned long exp; + + if (offset >= size) { + pr_warn("[%s:%u] bit offset for clump out-of-bounds: expected less than %u, got %u\n", + srcfile, line, size, offset); + return false; + } + + exp = clump_exp[offset / 8]; + if (!exp) { + pr_warn("[%s:%u] bit offset for zero clump: expected nonzero clump, got bit offset %u with clump value 0", + srcfile, line, offset); + return false; + } + + if (*clump != exp) { + pr_warn("[%s:%u] expected clump value of 0x%lX, got clump value of 0x%lX", + srcfile, line, exp, *clump); + return false; + } + + return true; +} + #define __expect_eq(suffix, ...) \ ({ \ int result = 0; \ @@ -104,6 +134,7 @@ __check_eq_u32_array(const char *srcfile, unsigned int line, #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__) +#define expect_eq_clump8(...) __expect_eq(clump8, ##__VA_ARGS__) static void __init test_zero_clear(void) { @@ -361,6 +392,39 @@ static void noinline __init test_mem_optimisations(void) } } +static const unsigned char clump_exp[] __initconst = { + 0x01, /* 1 bit set */ + 0x02, /* non-edge 1 bit set */ + 0x00, /* zero bits set */ + 0x28, /* 3 bits set across 4-bit boundary */ + 0x28, /* Repeated clump */ + 0x0F, /* 4 bits set */ + 0xFF, /* all bits set */ + 0x05, /* non-adjacent 2 bits set */ +}; + +static void __init test_for_each_set_clump8(void) +{ +#define CLUMP_EXP_NUMBITS 64 + DECLARE_BITMAP(bits, CLUMP_EXP_NUMBITS); + unsigned int start; + unsigned long clump; + + /* set bitmap to test case */ + bitmap_zero(bits, CLUMP_EXP_NUMBITS); + bitmap_set(bits, 0, 1); /* 0x01 */ + bitmap_set(bits, 8, 1); /* 0x02 */ + bitmap_set(bits, 27, 3); /* 0x28 */ + bitmap_set(bits, 35, 3); /* 0x28 */ + bitmap_set(bits, 40, 4); /* 0x0F */ + bitmap_set(bits, 48, 8); /* 0xFF */ + bitmap_set(bits, 56, 1); /* 0x05 - part 1 */ + bitmap_set(bits, 58, 1); /* 0x05 - part 2 */ + + for_each_set_clump8(start, clump, bits, CLUMP_EXP_NUMBITS) + expect_eq_clump8(start, CLUMP_EXP_NUMBITS, clump_exp, &clump); +} + static int __init test_bitmap_init(void) { test_zero_clear(); @@ -369,6 +433,7 @@ static int __init test_bitmap_init(void) test_bitmap_arr32(); test_bitmap_parselist(); test_mem_optimisations(); + test_for_each_set_clump8(); if (failed_tests == 0) pr_info("all %u tests passed\n", total_tests);