Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1688849pxk; Fri, 2 Oct 2020 16:51:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZ8cwwaHEX4rNda3YeZQLP7xVzn4gjQRAdalxEykYIl3PvZSDtjW6tX3at15vWygiX2n4p X-Received: by 2002:a17:906:4f8d:: with SMTP id o13mr4460082eju.20.1601682686679; Fri, 02 Oct 2020 16:51:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601682686; cv=none; d=google.com; s=arc-20160816; b=zBEhjkmuMnoWAOz3ieWcf2Cy2n5XFPPtE2nGcMJNs5pFiwwd7NbxBoixr3qVJn4QzT cFh1FJijD7zhIe2/zajz2RfBNqdeNuAwTj6HurREq4UShbslLzMVEgPYDvxYxTtUFwUo bS08lwpaDSFdn/lK2vd0v1vT97dqramdz7JBeWoCVHZUwLU7+JZp8fgswXG2wVIYpMyU AJL1n3kF1pPQQyigIRwWxx2VUQeDU5WV9zBgptOSI9i6DOoIjwiX7J5HmRiwJrDEP+5H C9RYTEw5C2vWt367leqW8m85QW0rWyrD5VFPs1ZPlsXvUwoJT6TxfX2jjOvlzoaQkH8q b8Tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=ciW+8DSoLurx/lK45N+pUdMaER8HwkWRc6xsxgU8NiE=; b=sotIVYvoIHi5qyz6zkDih8k+IeHEZoakJP7JIJw+e6S+2M8iX7Y+Y9F95p1eYCn1VE rRdXlPqGVzfZd9sGW8GNnm8CqL/e0HJoshCX/6L6fVc/6DnPd8Md84So/V5yEv3S65Oa +KS9ssdijJa/CbNFEvh2Tcejlwyj1+CHNFu5Q6olNCX7UAFj7g8av9a8zVaUVfblX3jz ebXDtrDcTHnsD22Zjfj6b87Av9cqhCYcn8X0F1I65WK6EACf/kml5hvLcDxqw7EDH4UG PJrBQPy9OYu9wKjopYVCpO5Qtq2i/otQ6JOjpQPVdbe6aS63NXpedfZi3xc8eSuNb9mB Z90A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VQh2avvG; 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 g15si2141919edp.579.2020.10.02.16.51.04; Fri, 02 Oct 2020 16:51:26 -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=VQh2avvG; 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 S1725767AbgJBXuG (ORCPT + 99 others); Fri, 2 Oct 2020 19:50:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725283AbgJBXuG (ORCPT ); Fri, 2 Oct 2020 19:50:06 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBD8BC0613D0 for ; Fri, 2 Oct 2020 16:50:05 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id d6so2445683pfn.9 for ; Fri, 02 Oct 2020 16:50:05 -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=ciW+8DSoLurx/lK45N+pUdMaER8HwkWRc6xsxgU8NiE=; b=VQh2avvGPhLu+k3zmCn7PKLkvc7LdlltVWJAM76G3y/7zNNd3i2KtDUSjoGzaLoarA ur5tigGJ1VbqVon9Hlz3bYhwJToiJ0WeHFxWVVjJlHn85Y4lTrYUxlRqIkaI1gO7LgIN GAeYtd7g8SRkUeunplEYkk0nLsE4fScxR34yIglZ8Xk6Ahc0WdmIgg0ZXXvGi36z7P0C r1fqIpp7yGkVTw0JzAPaTlH8E/EX+sajzuZRJrd2qgL1M9lDXK++BU5Bu0vqkyMWn47s ieNovTToOBuVjccKrjwMlMuqf3nwYVgN5zVi8ifE4X6bfA1yVGnoqQERgoLpinm82nGl ZNlA== 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=ciW+8DSoLurx/lK45N+pUdMaER8HwkWRc6xsxgU8NiE=; b=MUf5A4TcRfMBBnlEkSReje04WBtkaZJYbVZPCECe0P/EbU41kSOGLN4NwFMUSoywTp AsgYzWFywF24/g8uK0AuMwriCWvVy//Lbefzl+1Ltp0ciq+fGQKXQmsQOPVVG4XfbT9x OUrs/T5DjpMp0GU+qz8jYGVJwDiLmJ7/ry0SokOnLXN3X0ToBePDvKP/pd6x4+gmMvck b0PumrYs1o/1+RXHDPnMV77kuSEUYkiCu3BQNfdpKaaX/37medHYGyu/gxssEhuS8jOi HVNMlpEQJcyCYzHWptUGscOrZjAz0LpE2bjftID+BJL/87BXEWuX1k97SpcwLFQOTtFM nIbg== X-Gm-Message-State: AOAM5313j0z8SgNPGJLPhIOIyveqgr1j+cghvgeST1gEiq2/pu9mf7+z SN2u6yVBtlqDCKL94X5lpEY= X-Received: by 2002:a62:ee10:0:b029:142:2501:3972 with SMTP id e16-20020a62ee100000b029014225013972mr5018305pfi.55.1601682605342; Fri, 02 Oct 2020 16:50:05 -0700 (PDT) Received: from syed.domain.name ([103.201.127.75]) by smtp.gmail.com with ESMTPSA id h11sm2779119pgi.10.2020.10.02.16.50.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Oct 2020 16:50:04 -0700 (PDT) Date: Sat, 3 Oct 2020 05:19:50 +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 v10 2/4] lib/test_bitmap.c: Add for_each_set_clump test cases Message-ID: <953bf1fe2ced6e268a83faefe18786d769a62705.1601679791.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) 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 v10: - No change. Changes in v9: - No change. Changes in v8: - [Patch 2/4]: Minor change: Use '__initdata' for correct section mismatch in 'clump_test_data' array. 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 df903c53952b..cb2cf3858f93 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -155,6 +155,37 @@ 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 +203,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 +609,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 +642,95 @@ 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; +}; + +static struct clump_test_data_params clump_test_data[] __initdata = + { {{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 @@ -680,6 +823,7 @@ static void __init selftest(void) test_bitmap_parselist_user(); test_mem_optimisations(); test_for_each_set_clump8(); + test_for_each_set_clump(); test_bitmap_cut(); } -- 2.26.2