From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E28D3C43387 for ; Mon, 14 Jan 2019 06:19:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A491120660 for ; Mon, 14 Jan 2019 06:19:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QelW8O75" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726613AbfANGTe (ORCPT ); Mon, 14 Jan 2019 01:19:34 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:44502 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726306AbfANGTe (ORCPT ); Mon, 14 Jan 2019 01:19:34 -0500 Received: by mail-pg1-f194.google.com with SMTP id t13so8993616pgr.11; Sun, 13 Jan 2019 22:19:33 -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=QelW8O75LsYONCHxXsJ2mCWOH7VGNzSFmLJA0dpBSH8srvONunSy1wvx+FkXZhNQmN oYhEb1fUkbLLZ0T43rbHRiJs7iNvjuM2a9s6PUFyWKP8RT7tNVOmL0Cx9fn/Yd/y8TLj HaaQXT7P9jHWWeHmif6PfWv24Gg7aFrh/Go9LDWGCJDDkRxL+QDRb3qfZXxDCmGcmkX6 p69q2UjC5mpCXLVZrsEChTwgIKqCjP/kLBsHR0WgnHTtc6WZoqP5cgH/HWmzsuBG+LjX ILFAQOg5859Ode6DhUC3GdiBZP47Tb3/uiPukfdqI6rNtdHFB3BKJ8w7g1sR9gspg9LY 3c+g== 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=R5bkhThiK5oZT5SDNFfK4qAKHGRZN/IxoGb8jdIaAtRBwpy0SmPzQWWnEFlhFLEndK MdiOO2IFsCiMPTp3JyjgLHmEBUxPequ09U+vFm2CwMhWys1dA9/G4yaXvvHkDSo82+Vw 02zmmPzF2CWnz/9MoGS169hhR3tvGcx9p8bmj1CBJu+FpGFrqXpepT90OaZbxY9EAuZP xujVP2DmyW0lv9s2UlgsWzEfLOoe4tWrBJq2W6x0y6HD9AsLdPA1j2v0DoUaOhaCgu7u YVSyegx9P27b7mamyaaX7BXNZnD9BErFi8Te8dOnKj2+pLWn/9SiLQhLm+TTqvwfwAg4 sZ4A== X-Gm-Message-State: AJcUukeHSgy8nTqagXJsy3GBhvJ6RVYNibkvPX6IW/sc+aXA+RJEOBRa INGBXs+oq2W0Wbo8oBTd6d4= X-Google-Smtp-Source: ALg8bN7I13tuqDMCnrFGE1+3QTLtmvoYmHQY8P7vre8hGDeQ1XLgNgzYnlH33uRGrnlO3jE3NTROhg== X-Received: by 2002:a63:7e1a:: with SMTP id z26mr21156568pgc.216.1547446773359; Sun, 13 Jan 2019 22:19:33 -0800 (PST) Received: from localhost.localdomain ([2001:268:c0a3:70f2:4411:7de2:8afe:823b]) by smtp.gmail.com with ESMTPSA id k24sm131234704pfj.13.2019.01.13.22.19.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Jan 2019 22:19:32 -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 v8 2/8] lib/test_bitmap.c: Add for_each_set_clump8 test cases Date: Mon, 14 Jan 2019 15:20:09 +0900 Message-Id: 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