Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4784310imu; Tue, 18 Dec 2018 23:37:27 -0800 (PST) X-Google-Smtp-Source: AFSGD/XB09uMFkqPQO6IPnd/EzVLd8g+DZeNjnYVgbZUmnj4yH7oTajcwVL5GQ/DreP6yPT8aaR/ X-Received: by 2002:a63:5320:: with SMTP id h32mr18510577pgb.414.1545205047035; Tue, 18 Dec 2018 23:37:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545205047; cv=none; d=google.com; s=arc-20160816; b=WGLHzm3SCLOWZ5Okpd+oGR9QpFeU1oGbn8K4T8t4gGzepokbI6nTa/BUhK5ZK7NoT3 9LCv0aAL6m/A98bw/AWBZh7tMqIy05mzQMP3ZglqF4X1wd7FkOhOFYKXUHWkYRWCbwqk qHNNIr2IgKg/2uAKa//6USD49P3hNVbisKjIKaBnEjZeZ4uu74J7ylcJFRTFEhpTihe+ BqY5+2fkrDmSgVzWaE0BfFtalmAp5/+mnk5crmK9GhctRMsoShEaXVi4us+crFK4VFqH YPf6sr9hJUJkFSnhwHpEqXX8AccVT4AJVzFIDD/vt9IWFqmOHa9f9vNBrpJ4/A9oxOKq FYyg== 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=jp1S9dqvmwPSJcVmS+r3haS3QGDtEpCJPpnDh3YyXIapYbJmBYV49qw1k0GgpIhIMj WfFIAgYmXEYKeG6M0c9m0Elh2M1OrDvIblpucUhj2M6HEvN+R34k3n7H1lgElrNwZAcj pvLl2M0CCVx/a9V2NHTFcdakpu5DXuQ7jAE9HRu8OsFbbb8uJ47tPEk+sPlRrG93wyQ0 jfe/JDV5vXpKasBfrhRPjJzHDA/m/o8/v5C64FonpQ6m65UadxvlCJQsdcrxC1+t7GzN s7JZUeV7e9EuTc68da+eHmfe0XRHMzvTJmSOHfbFfxroX7dg0Iw3MIZevBE/U/YXKLoD nA5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FLrEwq39; 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 187si4301783pfz.249.2018.12.18.23.37.10; Tue, 18 Dec 2018 23:37:26 -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=FLrEwq39; 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 S1727831AbeLSGA2 (ORCPT + 99 others); Wed, 19 Dec 2018 01:00:28 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:42997 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726920AbeLSGA1 (ORCPT ); Wed, 19 Dec 2018 01:00:27 -0500 Received: by mail-pg1-f196.google.com with SMTP id d72so8957610pga.9; Tue, 18 Dec 2018 22:00:27 -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=FLrEwq39Dtedo1lXWu9vPxPrs8VKabP7hU3XdGRj1wdQrfW8ERYTnWU00o1IL+LXoA YYkuIwg6K6s72ZxcaQoJhwl+Ta0rHybTa7GCCw1LoNN96+ClZWjd/Unj4FdPwv+DPEUU F1ZOJxqzLu8MJOezGWG8rEze1xOYsjwPBS2NFe+boRsA5m4sfLF3OAyrSMKFiwMKn1LU 6R+uRpEXHs+aE9lalbm78bpGct+1ujgG0cXgWEAkGeoPyQ4X/n+sxoYxzemOB5R7cAOn 4s3Cahua2bDvMcz8P91qK4PsaLqVtHTSDRBizLr44yYg5dqBRDw5WUwxE3Ayv3FOiNUg YB7w== 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=mTK2WczdkClzVrVxp/4dvDkuL0NjTAsL+EeWRL0PWD/C8gYewBp2Z9IGOSFFcdtIcv 4nVcgsnUt+KLzqZIbKtITMFhFPlumT2HiR76dMfiUvKY/iXQTglOpjFAquu5S7bACLIA 6mUdHd08WyuGMY+7Z4OkNFRMxJ8IHtb5W4om+nzFIHOm2w+z4Qn15W3Rjq+9INqkjW3p mZabPMo0GAlIvUoukWfI+Pyc/z05qm6OHBf5z0fIN8QPJ6X3yig46i04BX8nC4mghrwd xsxnV47YjrdDR4u0oQ27CNOAEYjemhluYPKBlAKndiuKn/x500Rf/MPBiXwfG7C7UO6I aBCg== X-Gm-Message-State: AA+aEWb3SY6a4tVKiNiG2ICyXUymLSefuaj1gc/UAnu5uohJF+Ejpcfh ZfMZ+Boa2Xdf66AMaYYfwOE= X-Received: by 2002:a63:e5c:: with SMTP id 28mr5404940pgo.369.1545199226912; Tue, 18 Dec 2018 22:00:26 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a2:eb51:6018:45d4:55a2:e94b]) by smtp.gmail.com with ESMTPSA id y71sm35592141pfi.123.2018.12.18.22.00.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Dec 2018 22:00:26 -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 v6 2/8] lib/test_bitmap.c: Add for_each_set_clump8 test cases Date: Wed, 19 Dec 2018 15:00:55 +0900 Message-Id: <53bc13df75e9a26ef9fc7ba764c3536b4fc51433.1545198260.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