From patchwork Fri Mar 29 03:04:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 10876241 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5EA5D1669 for ; Fri, 29 Mar 2019 03:03:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42C8D290A2 for ; Fri, 29 Mar 2019 03:03:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32CBD290A6; Fri, 29 Mar 2019 03:03:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BE805290A2 for ; Fri, 29 Mar 2019 03:03:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NGjO61jJ+ZtHjMj7PjKydAZFMhP3fiH/iEzwOEbSN9s=; b=qaOYiW+9DlARMc qLqB9+zt/FqYHn36t1W5Zr4DKWYt5vvR1fp9NP+bmA+NcZQVjv2i8OmUMohfG834RiHKTQ5nv3+3C ZTWlF3QGaFtjP/CGtrrCpDjGP5ZbebC9lj1rvY82VGtOT8OVSvl0wOTO8oMTj0bgJzc6H+c0MKzW9 2+V9jMRlXBdZrGUxQkBKUpzMceYa5Bx1lmbH5WeklO46Qg1KOUmvT9jvajPqIfixS40pMmjI8XPZe F7sR9mcCs+2TMO+pHWTS79AorZxXqaZWdypCjXRS25VnaAqJakeMJ/eYl6K+iJkYL+n/VW6hemkLv KxR1Lwig49CH67l1nVFA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h9hnu-000268-W7; Fri, 29 Mar 2019 03:03:39 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h9hnp-00023t-Ax for linux-arm-kernel@lists.infradead.org; Fri, 29 Mar 2019 03:03:37 +0000 Received: by mail-pf1-x441.google.com with SMTP id 9so316205pfj.13 for ; Thu, 28 Mar 2019 20:03:33 -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=dghR0Mc1SqY89YZJ9+i0ufFZ0Kpdpwjarj8nHTDAtfQFCKI9p9kaiscJtQ1nYLuCPs p+7qOocoDp/LXRcMYkcKmS2Kjev9I1LGBx8cEoT7TrwrxgxKTXN7GElc0si/kiX5+blE qV7DBLg5A+bmdcBn7HvnvHLDKBns93iyd9JPyfNA26oqrUxb9y2F5SMfdzlamz3g5CRx 9TAkva6r+U3OIXElFRjF2fU+B96ntXVfPfh9OeGOgKqYQcGZ7KZdlgkpoN64cp85AbVL VgFCICPuyb1Q7KLcRfleIVxrCD9QsbzQXvajIutWPrHLOBT5PVUxtp7Mo3/assw5ESVC w8Ew== X-Gm-Message-State: APjAAAWODZNuTPT08Ppb7NTnnzKtgkDANHlduFq/RDmc1SNjfNf6sdiB iou/aYjox6FIsxU3wcbohV9X8bIJ X-Google-Smtp-Source: APXvYqxi49xuewvzw0oP0dAiDUsaCW96vW9bJkIxv5sajuOg6P5Vno+QImcnedQUp/39MJYKF5+SNA== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190328_200333_474166_F8D6C984 X-CRM114-Status: GOOD ( 14.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, preid@electromag.com.au, yamada.masahiro@socionext.com, linux-pm@vger.kernel.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, William Breathitt Gray , linux-gpio@vger.kernel.org, Andy Shevchenko , lukas@wunner.de, geert@linux-m68k.org, akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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);