Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp1604994imb; Sat, 2 Mar 2019 23:49:01 -0800 (PST) X-Google-Smtp-Source: AHgI3IbAbJyzA85Q6cGsyWocSzmQs4vbSIut1sG+jT62BkLUuWEA/Eo3CSunFSMtgiswpZzDQvjr X-Received: by 2002:a62:f201:: with SMTP id m1mr14141119pfh.97.1551599341887; Sat, 02 Mar 2019 23:49:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551599341; cv=none; d=google.com; s=arc-20160816; b=MyhuHLMt3YW+DGjeESrYy9Ios7dlsEefam9NYAo+kHV+Nsjm34eOoOfjy95fW9vyvq PT13U2erg7jvMD8vAQfMRdKTh5gbaWgCWymeigPJ2xJslVAWi7tLQMiYVj+L+hoavpmt lAZqtvrMAJYH3Bp5mR7SF2YTOI7Kkea7Anr4fJ0hlz/ct1ibt/xGHdK4Uso7MU7KkEv4 1CO/PR1hZ9J8uLhPtsNnagdL0ZCrevcadvel2ByOEIx+4PNyzYY2yQbVW5VTgA5iIoiV 1Lz2WT5aKDuZGMuZzODRUPy29O1zfMdT70nNzNcL6OlpJcL9HVjTTmNIl1iT3JgsiIhx SFJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ElsNjzQ7K98lI/bHz/nS5DIDC37ffsppngWHxCUh4y8=; b=zzSDmo611zUw7VTQ60zpeg/xct0LE20ct5QW+88Ne+WVzPJGv78nue8+BcGIa2SgEG 89B+2yDbQayK6XDLPRzkriGKhc0KdCAiMNYefK9nVusDNCGNPALcLtU1h6uaRBzM463y QMAMHw1buZlenRD0v+dsRABkBE5jGW96ZgHgd+3CE31E3s7+wS0MHbhD+3dJ3NyuZjl/ J34l9epKNXJqSLhE0f5IYtfMaqBblucnpBJJfNlRSdMrkcD/fS0J1E1XkdXMpy6y6OuX YPop9TJIeq0VQH6NU4eRGYU4S6KHnshd45M61183Vnu6CJ0xQSjyo0uFpfOFGVrhFehp yMHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Pg2kb3Sy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id t1si2400909plz.247.2019.03.02.23.48.46; Sat, 02 Mar 2019 23:49:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Pg2kb3Sy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726094AbfCCHsH (ORCPT + 99 others); Sun, 3 Mar 2019 02:48:07 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:38120 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725877AbfCCHsG (ORCPT ); Sun, 3 Mar 2019 02:48:06 -0500 Received: by mail-pf1-f193.google.com with SMTP id n125so965548pfn.5; Sat, 02 Mar 2019 23:48:05 -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=rdXPNiKhR7rUV86of6uitz4hYnSKV+sim6utz68uckOH0K48EuvyVpDUNglIjj0Vkn V0waY8JUduHF0Q2BHvdRSiFAF1CF3zac/WbyXXB+OR3zMLuxIJRriB7Nn7sxxV0cU43U Up/UweAvMKV534oQeyLzzSAIVsNuwvm5taqzRSHoHKXa57Fo0qXjAV0QWo2+mwVTkay6 ndKok2uCkw+XLBNenr9aNa2bOUn4UyyE8XzlXEKsCLIkaJ6KfjyiAa9nYNOEIfNjkxHY KaBPyoTQdateOYCC02V8zyijh1Y47Ac1gywptyrTu+TuREFZXEQBKnoTg+E4lIIZf/VY T3BQ== X-Gm-Message-State: APjAAAVEuRo1pv0T41JOFUv8LPjKHCYR/ETecVwRtE7vnzG5nb2Ss+1o 96hQXkdjI6tMqs7WlmGLJ74= 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 Cc: akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, bgolaszewski@baylibre.com, linux-arm-kernel@lists.infradead.org, William Breathitt Gray , Andy Shevchenko 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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.21.0