Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp804262imm; Tue, 15 May 2018 09:23:50 -0700 (PDT) X-Google-Smtp-Source: AB8JxZos8hRRuK/S77lwgOxd1yuIwEIfjO9ZuaHf8SeR5/SSZRIFwN/ywL6JL42q5pxX+m4aQR/0 X-Received: by 2002:a65:610d:: with SMTP id z13-v6mr238445pgu.260.1526401430201; Tue, 15 May 2018 09:23:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526401430; cv=none; d=google.com; s=arc-20160816; b=wcQz0080mhGzXm+UUE8zrk5DlQMz2KmqFcknjWBy1GE2fNsk1ozVcpLWbH7Lx0KfXh HpBDn3aUINP0+RFqn6E9XRY3v9Qa2icsicefaffwk4Ymu/fGLKj91srbPachA5p7Rnnv PnzjnOxTold2WH8+xNtj0QAPLlIRFOu0MqXZzdlQ2Hao20+MTPeATStHf84oqUXu6TiO UfpfJF1U4Y2+s+RBthbXF2hj+FaH0A1+m2wh0FX0Ho9AHWgHHhHGkNBoGTPpo8DpPDVQ MEgCggwUbbOMNGQ06PJ6TRHj2nsRqCkL/9uS37u3Br1ElpyUeXtQOII8SQTyxGbz4H02 7xBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=D9uVVPu6I2zJJL9NaoPcbEwomEyazs1KuK61/fOHRF8=; b=ToAPpcTJC7MaTFSG8nN1p30VSzVrp8Tb5IYCWAxCiH4v0BmMMFL66DOVE1dB7IbE6O PrVmhY8h5vB3JQ8efLLdzL8mElWcoe4YB0xjVM45ig2/3hou8NRH/KNtxdYWBzdXnR3Q lY6+DyjxwuDZWgrFQoGanvmkhdT1xC+sWiX1m3vj5fWkZyXjd0E6ts7FcF8g+SrmT0+1 5+waG8gLeiCgNX2NZ8LhZC8qexi9B6to+JbsxHhJMKYntn+pl43Hpwi2STbt/9+mi7hK loCGnNRJNrUi/GZozpgX3+zGgENCPfyIEYeZdZtmjI2Wp58dK/y3SbfoZiJz/7nZ2fQe ZTKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JHgjMudT; 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 k14-v6si299541pgs.418.2018.05.15.09.23.24; Tue, 15 May 2018 09:23:50 -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=JHgjMudT; 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 S1754100AbeEOQWp (ORCPT + 99 others); Tue, 15 May 2018 12:22:45 -0400 Received: from mail-yb0-f194.google.com ([209.85.213.194]:40552 "EHLO mail-yb0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754075AbeEOQWn (ORCPT ); Tue, 15 May 2018 12:22:43 -0400 Received: by mail-yb0-f194.google.com with SMTP id o80-v6so254646ybc.7; Tue, 15 May 2018 09:22:43 -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; bh=D9uVVPu6I2zJJL9NaoPcbEwomEyazs1KuK61/fOHRF8=; b=JHgjMudTerAdNjG/n1x797+YUVG8cR2AAGePX951xRa3NbYvGgc2jM3iIAlcWfRRwR Dg7pO2ldICeWBe7McD8F95g4ntvW3wqYfYurhXIeE5IiGbJRB+ReSEPcLhMq/w0OU8z9 jgK/5cwwQLiAscLHghgF7l9pEZCYlYUGmM/tY/oqmW+BKGK3YHlSGRr0DSQyBGPO1lW9 nnVeki1errLjSWDSXtqck5bE/eZ5OTh8z42nBOgrW8iaKApGEP/J67niFkqplw3fFxn0 V8MncfofhPS8GRyZDhlHt0pOuy8/SHZSUSkWYkwH/MngK3JQnaYh3l7LDxN+9bpB3wDM QGUg== 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; bh=D9uVVPu6I2zJJL9NaoPcbEwomEyazs1KuK61/fOHRF8=; b=tmu3SCSJ7WAAgsgOr+wj1YTpy9Lff8JxsDfuAsEfulxsj1b3swyZ+umBgnl0OftcN1 mVm6Z1QX61Zh7eVebf7qYwxPxfYENxRLHmDDvbOSKl6A5uBJhK10Kiy5Obuwt53tRc+z tZgC3WQnj98/EWGFkYwX7gNkTovfEpLfzHIR8akouvWRAq4zxqBmFbHyQyUWGMFp1SWE WcGO8EA3wW2yyOWwz5igx1fwHcVAAe7pV7GYxcvMUi+B0LVGJLhSzp23pvWrHbgawoKi A27TaxBl3jbiW1jUNyGnufMUTFjR3SVnklZctwgggmdzxylzUnTMmFJNYKiTWxvvNaJF bRSg== X-Gm-Message-State: ALKqPwdGGYrVUBO2qwSfJEHemGB8PQzHE1l8mFMjG4XglD7ZC5AfW1eK hpeZ7AXV0PSXn4tj4bn/ipk= X-Received: by 2002:a25:ae5e:: with SMTP id g30-v6mr8967334ybe.399.1526401362835; Tue, 15 May 2018 09:22:42 -0700 (PDT) Received: from localhost ([72.188.97.40]) by smtp.gmail.com with ESMTPSA id t79-v6sm171612ywg.109.2018.05.15.09.22.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 May 2018 09:22:42 -0700 (PDT) From: William Breathitt Gray To: linus.walleij@linaro.org Cc: linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, William Breathitt Gray , Andy Shevchenko Subject: [PATCH v4 2/8] lib/test_bitmap.c: Add for_each_set_clump test cases Date: Tue, 15 May 2018 12:22:36 -0400 Message-Id: X-Mailer: git-send-email 2.17.0 In-Reply-To: References: 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_clump 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. A 4-bit clump size is chosen in order to verify non-8-bit iteration. Cc: Andy Shevchenko Signed-off-by: William Breathitt Gray --- lib/test_bitmap.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index de16f7869fb1..fd1b9f0d5eda 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -88,6 +88,39 @@ __check_eq_u32_array(const char *srcfile, unsigned int line, return true; } +static bool __init __check_eq_clump(const char *srcfile, unsigned int line, + const size_t clump_index, const size_t size, + const unsigned char *const clump_exp, + const unsigned long *const bits, + const size_t index, + const unsigned int offset) +{ + unsigned long clump; + unsigned long exp; + + if (clump_index >= size) { + pr_warn("[%s:%u] clump index out-of-bounds: expected less than %zu, got %zu\n", + srcfile, line, size, clump_index); + return false; + } + + exp = clump_exp[clump_index]; + if (!exp) { + pr_warn("[%s:%u] clump index for zero clump: expected nonzero clump, got clump index %zu with clump value 0", + srcfile, line, clump_index); + return false; + } + + clump = (bits[index] >> offset) & 0xF; + if (clump != exp) { + pr_warn("[%s:%u] expected 0x%lX, got 0x%lX", + srcfile, line, exp, clump); + return false; + } + + return true; +} + #define __expect_eq(suffix, ...) \ ({ \ int result = 0; \ @@ -104,6 +137,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_clump(...) __expect_eq(clump, ##__VA_ARGS__) static void __init test_zero_clear(void) { @@ -352,6 +386,42 @@ static void noinline __init test_mem_optimisations(void) } } +static const unsigned char clump_exp[] __initconst = { + 0x1, /* 1 bit set */ + 0x2, /* non-edge 1 bit set */ + 0x0, /* zero bits set */ + 0xE, /* 3 bits set */ + 0xE, /* Repeated clump */ + 0xF, /* 4 bits set */ + 0x3, /* 2 bits set */ + 0x5, /* non-adjacent 2 bits set */ +}; + +static void __init test_for_each_set_clump(void) +{ + size_t clump; + size_t index; + unsigned int offset; +#define CLUMP_BITMAP_NUMBITS 32 + DECLARE_BITMAP(bits, CLUMP_BITMAP_NUMBITS); +#define CLUMP_SIZE 4 + const size_t size = DIV_ROUND_UP(CLUMP_BITMAP_NUMBITS, CLUMP_SIZE); + + /* set bitmap to test case */ + bitmap_zero(bits, CLUMP_BITMAP_NUMBITS); + bitmap_set(bits, 0, 1); /* 0x1 */ + bitmap_set(bits, 5, 1); /* 0x2 */ + bitmap_set(bits, 13, 3); /* 0xE */ + bitmap_set(bits, 17, 3); /* 0xE */ + bitmap_set(bits, 20, 4); /* 0xF */ + bitmap_set(bits, 24, 2); /* 0x3 */ + bitmap_set(bits, 28, 1); /* 0x5 - part 1 */ + bitmap_set(bits, 30, 1); /* 0x5 - part 2 */ + + for_each_set_clump(clump, index, offset, bits, size, CLUMP_SIZE) + expect_eq_clump(clump, size, clump_exp, bits, index, offset); +} + static int __init test_bitmap_init(void) { test_zero_clear(); @@ -360,6 +430,7 @@ static int __init test_bitmap_init(void) test_bitmap_arr32(); test_bitmap_parselist(); test_mem_optimisations(); + test_for_each_set_clump(); if (failed_tests == 0) pr_info("all %u tests passed\n", total_tests); -- 2.17.0