Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp83856ybs; Sat, 23 May 2020 22:08:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPdN0k4pElCdfb7ioc6U+jDCGY1iUfL60v4X+D9roTtrgDYWLW7Pgd620oFkqJktyVloir X-Received: by 2002:a05:6402:719:: with SMTP id w25mr4475895edx.179.1590296892505; Sat, 23 May 2020 22:08:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590296892; cv=none; d=google.com; s=arc-20160816; b=zunu8PdghnyzRbpHatVaKU0vmn7GtWpDk9aSBPGvwl5QCTfDFZFFMU9KSdv1LMac0I KzL8vNNxpici3ZxGiZKayQf+EGP8hONIBySKVkrY1DaCyDujT9ucnBgYLyyTkhXbYZek a+LkeXI9sC8JM1aCtq6zptNZBVr9jEzI0TyaLYLWnJjSGAYw2lvxBaFFoqWXIb/+HK/t tEyl7C400OiDST6++oRdzhZub1VTadQwUDnbnYW4FlFCaQqYjtP7kwarcpbG5q0ZeGGb j9I+YiVixQuB7mtlK4H5he66JeJb+D14Mbk0t1YNJhP6rR2TApwKuapT+sCF/yiPEuuE 3iNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=SG/Bv/Aw0zdk8jUii+TXQLtSrOOylEZqrhUbfPceguE=; b=ji1HixTzOtaI/PL5NZrmBXzSZ21I1/b8jLP2kSqN53yok1l6bG+aBCFsBlSfQeHfBA aOJrB12NytJw9O2s+3KLoAZ/C9NsJnC2ltEWoC7y52I7Z0O0AtQqv0qYPEnoU5ASa9iz Dd0AF6XpmTnkSkFSC1UP4Fp9Sg8f2PPBjgeptvK/g9ka52wBK+7dmJdAh6EuOs+nWLv5 XPoLvpfbvnAs34Lzn1ljVzVv8xy+3lyMPqAXPTRdF+NtRqRnoK9fvC8ElTBzEPcj2zIr g3mVUFSgzJuwsomOoqbsRVRCrMzLwIMilnF001X8QjLWu/R7Y5c9GERbzphQZ3+f/dRn kJbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uflyzSAj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id o23si6844991eds.570.2020.05.23.22.07.19; Sat, 23 May 2020 22:08:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uflyzSAj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726477AbgEXFEc (ORCPT + 99 others); Sun, 24 May 2020 01:04:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725805AbgEXFEb (ORCPT ); Sun, 24 May 2020 01:04:31 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9D63C061A0E for ; Sat, 23 May 2020 22:04:31 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id e11so6257464pfn.3 for ; Sat, 23 May 2020 22:04:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=SG/Bv/Aw0zdk8jUii+TXQLtSrOOylEZqrhUbfPceguE=; b=uflyzSAj6KZ1yqMnHH+y/k/pfZIDvebfpVCwijaHELUKDpmNbpIb/rsWSbstSM1csE PJx/qXnvGGIr90IFCMCXsJUaynjNYVYtjRkqfERSsQ46GbTItZBG6L5LALBmS/gMye4S oC9JDN0BcR6oA3/rxeAN4QDX5PPGlxZJtKViCn43TLZBouC8nfIGeLvpccIOL67tidwp ksbYawY3/vFMV2N5tcJjecOy+IzN/bXZnx0G4lGiT7HlOV4C+fsPHyelDbmalnsUTu00 Hj0ge018ex9UUYygZxCQFfpl7xKcHdTLWdJf400uFLd/ha8XA+R0zROVCJRo4/f6ryBc VMkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=SG/Bv/Aw0zdk8jUii+TXQLtSrOOylEZqrhUbfPceguE=; b=QV38jiueOL9t1oWQ2D2nfDbnGCToQMAZNivgr1wC8BHCrdOLmwg8amQXx9N3EhGmiu 39JYWu+2ZmX/XmyoBtRYuJMc8m7d1JanLI65iYm7rg9zgXF35E7imuYgO9FfBBq0x4Bu +5T0rUUEJACVvpL3RI6MKmPZLfj/2w9JAP4H5FTkQX7WQJJxFPcNwuNbM5Ay/pN0sExG NAFzk0uMRmeSeEBXs7ME3SgGh1s8IuHa/2kVP2LsYSPFWRpmlyKM2NH29SB4xfajpmZX mhjHO7JN5csdfOsl+yBjzrgQS4RnedKyW6QxR2KRWL4k7HckHB3bAOG+wiofROfcgsPI Or0Q== X-Gm-Message-State: AOAM533sBWN3a2FhscIIhzvgDXRZ2tsxO4XRMeEv2dth52j0TH6sHjgd id2A+iPBf40SPea1FSiZrHI= X-Received: by 2002:a62:b503:: with SMTP id y3mr11492679pfe.3.1590296671299; Sat, 23 May 2020 22:04:31 -0700 (PDT) Received: from syed ([106.223.122.111]) by smtp.gmail.com with ESMTPSA id w12sm8841110pjb.11.2020.05.23.22.04.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 23 May 2020 22:04:30 -0700 (PDT) Date: Sun, 24 May 2020 10:34:14 +0530 From: Syed Nayyar Waris To: linus.walleij@linaro.org, akpm@linux-foundation.org Cc: andriy.shevchenko@linux.intel.com, vilhelm.gray@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH v7 2/4] lib/test_bitmap.c: Add for_each_set_clump test cases Message-ID: <042eddd4b87f0db3588a79d829afe6b23fa8365c.1590017578.git.syednwaris@gmail.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The introduction of the generic for_each_set_clump macro need test cases to verify the implementation. This patch adds test cases for scenarios in which clump sizes are 8 bits, 24 bits, 30 bits and 6 bits. The cases contain situations where clump is getting split at the word boundary and also when zeroes are present in the start and middle of bitmap. Signed-off-by: Syed Nayyar Waris Reviewed-by: Andy Shevchenko Signed-off-by: William Breathitt Gray --- Changes in v7: - Minor changes: Use macro 'DECLARE_BITMAP()' and split 'struct' definition and test data. Changes in v6: - Make 'for loop' inside 'test_for_each_set_clump' more succinct. Changes in v5: - No change. Changes in v4: - Use 'for' loop in test function of 'for_each_set_clump'. Changes in v3: - No Change. Changes in v2: - Unify different tests for 'for_each_set_clump'. Pass test data as function parameters. - Remove unnecessary bitmap_zero calls. lib/test_bitmap.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index 6b13150667f5..31b3cd920c93 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -155,6 +155,38 @@ static bool __init __check_eq_clump8(const char *srcfile, unsigned int line, return true; } +static bool __init __check_eq_clump(const char *srcfile, unsigned int line, + const unsigned int offset, + const unsigned int size, + const unsigned long *const clump_exp, + const unsigned long *const clump, + const unsigned long clump_size) +{ + 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 / clump_size]; + 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; \ @@ -172,6 +204,7 @@ static bool __init __check_eq_clump8(const char *srcfile, unsigned int line, #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__) +#define expect_eq_clump(...) __expect_eq(clump, ##__VA_ARGS__) static void __init test_zero_clear(void) { @@ -577,6 +610,28 @@ static void noinline __init test_mem_optimisations(void) } } +static const unsigned long clump_bitmap_data[] __initconst = { + 0x38000201, + 0x05ff0f38, + 0xeffedcba, + 0xbbbbabcd, + 0x000000aa, + 0x000000aa, + 0x00ff0000, + 0xaaaaaa00, + 0xff000000, + 0x00aa0000, + 0x00000000, + 0x00000000, + 0x00000000, + 0x0f000000, + 0x00ff0000, + 0xaaaaaa00, + 0xff000000, + 0x00aa0000, + 0x00000ac0, +}; + static const unsigned char clump_exp[] __initconst = { 0x01, /* 1 bit set */ 0x02, /* non-edge 1 bit set */ @@ -588,6 +643,94 @@ static const unsigned char clump_exp[] __initconst = { 0x05, /* non-adjacent 2 bits set */ }; +static const unsigned long clump_exp1[] __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 const unsigned long clump_exp2[] __initconst = { + 0xfedcba, /* 24 bits */ + 0xabcdef, + 0xaabbbb, /* Clump split between 2 words */ + 0x000000, /* zeroes in between */ + 0x0000aa, + 0x000000, + 0x0000ff, + 0xaaaaaa, + 0x000000, + 0x0000ff, +}; + +static const unsigned long clump_exp3[] __initconst = { + 0x00000000, /* starting with 0s*/ + 0x00000000, /* All 0s */ + 0x00000000, + 0x00000000, + 0x3f00000f, /* Non zero set */ + 0x2aa80003, + 0x00000aaa, + 0x00003fc0, +}; + +static const unsigned long clump_exp4[] __initconst = { + 0x00, + 0x2b, +}; + +struct clump_test_data_params { + DECLARE_BITMAP(data, 256); + unsigned long count; + unsigned long offset; + unsigned long limit; + unsigned long clump_size; + unsigned long const *exp; +}; + +struct clump_test_data_params clump_test_data[] = { {{0}, 2, 0, 64, 8, clump_exp1}, + {{0}, 8, 2, 240, 24, clump_exp2}, + {{0}, 8, 10, 240, 30, clump_exp3}, + {{0}, 1, 18, 18, 6, clump_exp4} }; + +static void __init prepare_test_data(unsigned int index) +{ + int i; + unsigned long width = 0; + + for(i = 0; i < clump_test_data[index].count; i++) + { + bitmap_set_value(clump_test_data[index].data, + clump_bitmap_data[(clump_test_data[index].offset)++], width, 32); + width += 32; + } +} + +static void __init execute_for_each_set_clump_test(unsigned int index) +{ + unsigned long start, clump; + + for_each_set_clump(start, clump, clump_test_data[index].data, + clump_test_data[index].limit, + clump_test_data[index].clump_size) + expect_eq_clump(start, clump_test_data[index].limit, clump_test_data[index].exp, + &clump, clump_test_data[index].clump_size); +} + +static void __init test_for_each_set_clump(void) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(clump_test_data); i++) { + prepare_test_data(i); + execute_for_each_set_clump_test(i); + } +} + static void __init test_for_each_set_clump8(void) { #define CLUMP_EXP_NUMBITS 64 @@ -623,6 +766,7 @@ static void __init selftest(void) test_bitmap_parselist_user(); test_mem_optimisations(); test_for_each_set_clump8(); + test_for_each_set_clump(); } KSTM_MODULE_LOADERS(test_bitmap); -- 2.26.2