Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1216974imu; Fri, 11 Jan 2019 17:50:29 -0800 (PST) X-Google-Smtp-Source: ALg8bN6mVr7JjJuLR02KuFcFt9BKoI46G14mzgeKfnrhyvoL06c3NH81rui6Ev8Yo4qygCBrSlLo X-Received: by 2002:a17:902:30a3:: with SMTP id v32mr17056746plb.26.1547257829550; Fri, 11 Jan 2019 17:50:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547257829; cv=none; d=google.com; s=arc-20160816; b=CW5ZNTpNj3Ncxo5luA8yNcpMzjeTR62HFhmMji3N0S6g+g59fz7jgdf9TETrQuxlA1 dUew7flry71Bpjez0yG/zDW6QbIie55jerQUfzahWdtbJSEmIz3B0pucGxuW7eLVMQax S9pSK1qVrl8KoBOViuJAnuSVAelrn7GYnBITDT2hRqj5dbMVkascK1RLKGTxRl85O248 EWKeq4/kXK7A6HJnF/M5QqA4vZYlkurPSffIe/qWdFbDv5gAQe+4V4jB1g1CPKPFMUyO OjaYsGYAgH3bSzjUJtfRJPOLzbvgmsupDF3PXqHq8C+/CS1DSfdE1miPw1Wp1EIBp3ef tb0w== 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=xnUaejTO+RHAIQg3+66gxDXJKefuVgpBWyozPBW8nPI=; b=CBvlh3HVyz9OVCpENXsnicmhETqXgGOcovQnUJ8HPkU0Pmcll3k2TTHfRrxTCo+rV+ alr4Khop/2LcPSsIt6MgrJM+qw2ptEImZX2cpZ4gNAzHTvBjsB2wil3fktslJQGjge79 Clu8j805IR/kJ89DbCRfeb1pzQk52DJtRR2xMnisPVzeAh3bg1PBotQup74vLv3viz7T FRKW6iypmU1AxH+9omysp8uGvTrwxLLgdVB8xATF67BzExRAed20B1Q2mP/Pd1fQyTdk YMJzO4yw1Sz5pcdSmM0PuT6sI8McE/JC6fMINPYpw761mpNgpmqToPVfNBBhJRKt9a5I O2kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=o3K+Q70d; 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 35si7427933pgn.278.2019.01.11.17.50.14; Fri, 11 Jan 2019 17:50:29 -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=o3K+Q70d; 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 S1726542AbfALBrt (ORCPT + 99 others); Fri, 11 Jan 2019 20:47:49 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:34516 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726433AbfALBrt (ORCPT ); Fri, 11 Jan 2019 20:47:49 -0500 Received: by mail-pf1-f195.google.com with SMTP id h3so7770114pfg.1; Fri, 11 Jan 2019 17:47:48 -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=xnUaejTO+RHAIQg3+66gxDXJKefuVgpBWyozPBW8nPI=; b=o3K+Q70dRYXJYzCFwWch5KEqXsgFigIsL/80tqUUNOhIJIXdqALdqbal6IffdnMY5v ufqbh2VCxOLKNDRlhMSOuTJJhXx357jjGaVZFDAhiO4/rtADmrL2ZYEiwa/62/YCULTl xT3fZTKjFsMyk6CmtUPVW+61CM70Tm/H5/5pmIMrMLib1NO/UlmlItycUgk6rNSocgf5 mbDhcQZKBCylkX3NH0pCA909rLP9qt7sqIOWpzT8wFoaYdY0IdK13uj3ohcDUjibfa8o hW5ki+sx2XSOijXUBNi6SMkGI3V/7kZEHxI6Kh+Rlx1pgghL444plYya/WzvYIBfb9jo YmGg== 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=xnUaejTO+RHAIQg3+66gxDXJKefuVgpBWyozPBW8nPI=; b=S/t8GhtfmIvqdNCx/qDi9fCYP2CK7n3MTjD1h7LYLVE7YtaObhNd5pbFjIg8YPAr7H B1wA05Vj2p8ywcSpSu3epjNhVPwk9ZW6Bi/HEdq3yWhjeddKl2cR43bzbm+5Va1f7VI5 jJhbownhRgnRPG4/fJjY+zm5hpgG1rT6GO8FJRaBfxVXc7Cm77gaMeJrogFtVWgfvPwK Flrexwnx5+y4el5NrPLTTt7zn3X3ePx2EcCow7blI7P3BPhQgTehv+mdKkWA8zVQAwny x6SvR6jtXem0vdFuYOa8S0Teu5nbApex2Voa7HudUpI9yCr8U2CO24uZWHRQxgcYiruY Bg9Q== X-Gm-Message-State: AJcUukcjroPjHdeKNM9rui9KTt12nvNx2KGO5YWej9L9TN0rFZLLxww8 3Y8H6c7kHpxNiQ4oAZL4rhw= X-Received: by 2002:a63:2b01:: with SMTP id r1mr15297416pgr.432.1547257668154; Fri, 11 Jan 2019 17:47:48 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a3:ffc5:36e2:bccb:ba63:9e84]) by smtp.gmail.com with ESMTPSA id 4sm130950762pfq.10.2019.01.11.17.47.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Jan 2019 17:47:47 -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, William Breathitt Gray , Andy Shevchenko Subject: [PATCH v7 2/8] lib/test_bitmap.c: Add for_each_set_clump8 test cases Date: Sat, 12 Jan 2019 10:48:22 +0900 Message-Id: <7672ec8b5801519cf4b459926b13bd37370bc581.1547257386.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.20.1 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: Andy Shevchenko Cc: Andrew Morton Cc: Rasmus Villemoes 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.20.1