Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp1104118ybb; Thu, 28 Mar 2019 20:04:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqxBVXNyd0W1vcvsDyaYq1c9/78ClgbK75j9peu+oGwuQqnSu22DEDSWnjDz990VRPWyWUp4 X-Received: by 2002:aa7:920b:: with SMTP id 11mr43284685pfo.3.1553828682859; Thu, 28 Mar 2019 20:04:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553828682; cv=none; d=google.com; s=arc-20160816; b=gadCLH7/Aw1kAGhruhpRTr8QykYVs3hPcIpKUfrjYomY1idhtO56cc7zlIbLdXYYP5 frf3aeFkkGsXW+caZ+RE2+ePX+O8ymrNz/Hi1vpWgZ2C9H2GQn0fYUlKXUpZVnl1Uegn HD8NmL7F7ysffYqFoG5eYkYfl1NFEAHTl7bLhyu90W3ybr6q7U0u9kmyCjsXK7i310k0 oOOjiKDnfaSr6yDIh1SuZ0hGF+2qyN5N0cYj2rIS+JuGWzBOWs3hXeJmz2NpsZWlb3/w qFPRRD/Q+YHb7JVE/VtrgBEJgjAoFvy5tUMmZpKYHNq65+wYPSYA5Jvz0VJxJif2/SWw lVCg== 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=voPjJIpaEIENDSX5D22rQL6GtMzeJ5e93HyvmN9lrck=; b=0s17Tzoz1AIxh5U5IwELxrieJSwFFviYRcGVtV/6mKzxv9PFDEAt9Adn3XD92sl9MS TGxU6DioeHebFlZzdFrYXtUG+KEFHRw7dah18uDHeM+Ox0adRdD4n1lTEkzf/2vWtLYe RjJZwQVlrrHJwresoiVXhWkl43PyxvnL7Zp1SbulXbH+FklV2FswnBVBau8amG/r7DrP mMOmfP6kTTFsFLh+nHdGA2dps87oCgkCKFhQ/uRsAUK8tAsrpQUDvNNHF5U105EGHLES 1/lWgVz7PyzLlsqJ9CxqdZvMvKtZ4s6ZwiZ+g13HhQktAI/YPsZ/BATry2Mw44PMe4Wp 59dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FKXQdVCG; 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 e14si727295pff.76.2019.03.28.20.04.27; Thu, 28 Mar 2019 20:04:42 -0700 (PDT) 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=FKXQdVCG; 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 S1728682AbfC2DDe (ORCPT + 99 others); Thu, 28 Mar 2019 23:03:34 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:35513 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727654AbfC2DDd (ORCPT ); Thu, 28 Mar 2019 23:03:33 -0400 Received: by mail-pf1-f193.google.com with SMTP id t21so339916pfe.2; Thu, 28 Mar 2019 20:03:32 -0700 (PDT) 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=voPjJIpaEIENDSX5D22rQL6GtMzeJ5e93HyvmN9lrck=; b=FKXQdVCGLKfyuSoq4WzfGFf4LnXnRbm0ysr/SlvDiJyZe/Nl+D36Hsae0YbkCkVsG3 m+9YesA8P/RUSsulN03LU0TzwVR8DoHNzGdpZ7HeJQYI5BUq7oSquF358f5TCKkYOHbo kUcboC8hcGiYM0Tg8HPWzdNnKys/fe1ds6Gjx4E6xrSmaSjSPjogHO0qonhz/y2gLCzU aqbHrb84iDCR/J/KaGCB2XdwxCUYuZ6pQkTgRYg42WKAMjCsWYUYvwzudFaMdMk+SkGb p22u+GluQzBr1BlnhEdSd/miGBihzcejoD03z8sIiEbz6ZN0UjBmPubm+4q507GEvvVi jo2w== 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=voPjJIpaEIENDSX5D22rQL6GtMzeJ5e93HyvmN9lrck=; b=Na3BoWisGYd+fbDwKIkpUBgkadwjzZaachV9ROErOijhtqKLxT+ilvAbvwpXgOtI7c 7Gd/vLJEn10VsWT8Ky9QbWxWrlUxsnWcdfWK38lwPvI8FtAHkJcDAjwnK7fuyvhS2ndG K/MhZw74LGx9nNB1lR+bqY4jwuYdICqLaoauP0aiigMONT02I+zqwde/bia+lbS/51+w nH/8/zc8h5M1y6lWB4R8Q5mlyYqICVtzcC7YQu1hopcfEMqUGGLJ1ReDZyYEpEjlQlkp 8CrLLrQFSFbNuaIY8oUyGZ0BdUos1Is3d+IuLYVbF0Rs5P9g2NX4HCBJ6hpal2Uyrry9 GQ0A== X-Gm-Message-State: APjAAAU67K8DwO8JkreX6iqK0cdWzDJpM4uCcZeIJFKCeC328FDkB05k te8mjbuMzY2my3QPto6WMT4= X-Received: by 2002:a65:62c5:: with SMTP id m5mr42772448pgv.77.1553828612557; Thu, 28 Mar 2019 20:03:32 -0700 (PDT) Received: from localhost.localdomain ([2001:268:c0a5:ba2:c70:4af9:86e2:2]) by smtp.gmail.com with ESMTPSA id u14sm694291pfm.66.2019.03.28.20.03.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Mar 2019 20:03:32 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org, bgolaszewski@baylibre.com 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, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, geert@linux-m68k.org, preid@electromag.com.au, lukas@wunner.de, William Breathitt Gray , Andy Shevchenko Subject: [PATCH v14 02/11] lib/test_bitmap.c: Add for_each_set_clump8 test cases Date: Fri, 29 Mar 2019 12:04:29 +0900 Message-Id: <824581738681f13901653cee31c430a0e53d7b9f.1553828158.git.vilhelm.gray@gmail.com> 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: Rasmus Villemoes Acked-by: Andrew Morton 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..8d1f268069c1 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 */ + 0x38, /* 3 bits set across 4-bit boundary */ + 0x38, /* 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, 9, 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