Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752059AbdHGWzk (ORCPT ); Mon, 7 Aug 2017 18:55:40 -0400 Received: from mail-sn1nam02on0062.outbound.protection.outlook.com ([104.47.36.62]:52821 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751761AbdHGWzi (ORCPT ); Mon, 7 Aug 2017 18:55:38 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@cavium.com; From: Yury Norov To: Andrew Morton , Noam Camus , Rasmus Villemoes Cc: Matthew Wilcox , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org, Yury Norov Subject: [PATCH 2/2] lib: add test for bitmap_parselist() Date: Tue, 8 Aug 2017 01:54:38 +0300 Message-Id: <20170807225438.16161-2-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170807225438.16161-1-ynorov@caviumnetworks.com> References: <20170807225438.16161-1-ynorov@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [41.141.196.40] X-ClientProxiedBy: DB6PR02CA0004.eurprd02.prod.outlook.com (10.170.218.145) To DM3PR07MB2121.namprd07.prod.outlook.com (10.164.4.139) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 800b077d-5f42-4580-681b-08d4dde76a90 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:DM3PR07MB2121; X-Microsoft-Exchange-Diagnostics: 1;DM3PR07MB2121;3:6p9R1psix1wN6WUtJTHrGRlXq954Uu9QYQ80ZNOa3gbg1olu4iBOGw3zb7G4bEd3AvOsptqJFreAcbrTt+LVljVoF0X0rcVEf+nJq/n2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vSe/Uw3lQ7ubXXnVA76xL/YjxsLHl2mc+gUf6wsvsqRNpEncNBgz6FUAxPBjojwXjZkpPhTAP7YSzMnenmr0d/FZHG5UftA0gTCZyO0MHa+zp/e+LGMRSF6RIn5Ge3yjWGHFbS9oOEEd3Wt1CuOQH1UBXysduPh1HDS0PlS6ydnN2mpP4oFfmcjq0ErHe/qFMuOvzibPUFea9F2fPGkYM50+tHuveuc1Y7kNpc9q9ve0QJEqfJJTqBCGGtyN1H3l3m98vt32yJ4APMZolwkZhXd2pdrKxEuN8oS+afaX3EH5a6LpDrIBCXXoWixjZgCATFXqmaxRuTXxLsAvapZFpbbmwYF+bcDTQ=;4:VRY+TfGIqU26OGgFGk5QF/a8zTtUd4AcGRT89ZpsBnf7DZMj2XSaNQcHzqpU0Rd8L+8pLh1PTLvNDZCv8wXtg4+PnLPpj+VSKiEsduWfMpvEKN3JwAvpvNpAVoJl35cqAy/M6Dd7ggNrq+DXbhtSZq1x5KWONtstQkODA0k3iLPgcQZiImoZGMFsa+4nqcMjrUK5WL0ZzLeRo56/ek4XhBcHuMpfv10ALN1wj9snHh41SLWiDD96GeFNVku0326y X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(100000703101)(100105400095)(6041248)(20161123562025)(20161123560025)(20161123564025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:DM3PR07MB2121;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:DM3PR07MB2121; X-Forefront-PRVS: 0392679D18 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(7370300001)(6009001)(6069001)(39400400002)(39850400002)(39410400002)(39840400002)(39450400003)(189002)(199003)(305945005)(3846002)(8676002)(76506005)(105586002)(478600001)(81166006)(25786009)(106356001)(50226002)(97736004)(5001810100001)(42186005)(38730400002)(5003940100001)(7350300001)(72206003)(81156014)(6486002)(10646004)(66066001)(47776003)(68736007)(101416001)(76176999)(2906002)(5660300001)(50986999)(189998001)(10916006)(2950100002)(42882006)(6116002)(36756003)(8666007)(33646002)(107886003)(7736002)(53936002)(4326008)(6496005)(6666003)(1076002)(54906002)(50466002)(48376002)(3486003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM3PR07MB2121;H:localhost;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM3PR07MB2121;23:7FxcUiLJuhQtU9Ktcda5gxtjwHLJ6bmOAPqnwYivN?= =?us-ascii?Q?5VTFhNHDVI5uTWHSOeIviRdOgf06zy7bQTAj8Nk8by/+hA4ELJiEFqC28FWS?= =?us-ascii?Q?fhXE6u+YYhhMFPrY8gl2RNWI04j+i0doZgigmXWDHxn0Vp40npfwabTQDe/i?= =?us-ascii?Q?FUSy9QC9PqaN0H65GjegX8eU7it6hhHEALmEDUk5PF6VKRwqjFGlV+6UgdvW?= =?us-ascii?Q?kcTLCZODMHvfuhrtRp6LAKDWCmxzoDcfTRxRlVAbytxG1SN0QJLvVw+i2hiM?= =?us-ascii?Q?JommM/iPktS82z+B11AxbpPgeyVr0ubkRzxVmYda7G+8ByvSjyVbMvwAa9rZ?= =?us-ascii?Q?aRtwtm7znVozn4GfULNSlAK8p+L6PY19XLgtVCgp1z1q1fLes3zFD894fgh1?= =?us-ascii?Q?9ImjYHTUidZnam2lDpDv8obsivTzJAvODBz8kNW9t6eJU1QAiYAmWYg0CmWj?= =?us-ascii?Q?s2QrH/8U4AbJ73Vhtm9knlRh7puszMVd8Rpvvi7dbxL3RFY+QPaHvzG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6Lru6A7H6KL3odNNIyMaR1YUPgu+0J+mE7GefZfEWvOHl?= =?us-ascii?Q?6jCTyGjvQ=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;DM3PR07MB2121;6:F/bkjMrKIuLrFgWs5c9BlT3fX+3wQmZgt/ExTu7ARWn5aCQZQQbixCWZ4N1UloeIpfxkL1+hUfTI5R66JyJP2GkkHZPGv5v9I0u9kn3XEoK40BJ2L1aRv9uRYYV3kOikV4EAo6XBZ9mmtuhkVKcihjl3NOgk1dPguWQwMsiRopI5v4EFKRjnudwb/HTMJBxDMOZ/nUi1ODYyXXIjVYZichcu8zZm/SS4sYf/KsmI9o2nHp62TKxv3bjVpJxwqXjJGLhrqLlByLICH2aGjbKf4caYNLtsdSjG14e5ZraW61Uw+fMFA/Ws6ec43htN9ApPEdsyRWeEEBoLMEWXyrTUBg==;5:JzuLP9atL8SGg5XAcdHZZA95RarGGV/Dnez4SOBFnkTI4ariDUizvXWAiiZq4CyUqKr+8GfAQLfKCjkZoM8YXN+UmisuzMCevKNbLv92lvsTA1a8CwUnZiuD+nmozRPGOFIKWWOl5xzqaR8RPASCaA==;24:TwGSoKz9OPDfhxsLF4jgHvkdrpDVu2v3gfptOBzPWWL+9giAwg6uPrScsU7UJnANZp6NzcK9/ZXg2IH/wO2z6rLo0OBb/scRsVMp+a+D5LY=;7:1UzOKp5onYEQkuUUfcOJxQfcsXRycSetYo+IVcLSJZP5jnKVqnMAbive21QlqdG0DNrtJLnmWo6woGzYHmF4zahjwssSihvwcTUaZMqEsv18UWQq5B8zB78iZXajFKwvKF3gQBTqpi+Lz592fXDhSE63VuUgVRInxBgzMNB4r4OwKhwzY6qR9SJgnLn7plqRw5HIVGSmpDpmk7+81VwnG0urytmQo9YBhRTHGxzFyB0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2017 22:55:23.3922 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR07MB2121 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2840 Lines: 100 Do some basic checks for the bitmap_parselist(). Signed-off-by: Yury Norov --- lib/test_bitmap.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c index 2526a2975c51..5b80dd94e4d1 100644 --- a/lib/test_bitmap.c +++ b/lib/test_bitmap.c @@ -165,6 +165,78 @@ static void __init test_zero_fill_copy(void) expect_eq_pbl("128-1023", bmap2, 1024); } +#define PARSE_TIME 0x1 + +struct test_bitmap_parselist{ + const int errno; + const char *in; + const unsigned long *expected; + const int nbits; + const int flags; +}; + +static const unsigned long exp[] = {1, 2, 0x0000ffff, 0xffff0000, 0x55555555, + 0xaaaaaaaa, 0x11111111, 0x22222222, 0xffffffff, + 0xfffffffe, 0x3333333311111111, 0xffffffff77777777}; +static const unsigned long exp2[] = {0x3333333311111111, 0xffffffff77777777}; + +static const struct test_bitmap_parselist parselist_tests[] __initconst = { + {0, "0", &exp[0], 8, 0}, + {0, "1", &exp[1], 8, 0}, + {0, "0-15", &exp[2], 32, 0}, + {0, "16-31", &exp[3], 32, 0}, + {0, "0-31:1/2", &exp[4], 32, 0}, + {0, "1-31:1/2", &exp[5], 32, 0}, + {0, "0-31:1/4", &exp[6], 32, 0}, + {0, "1-31:1/4", &exp[7], 32, 0}, + {0, "0-31:4/4", &exp[8], 32, 0}, + {0, "1-31:4/4", &exp[9], 32, 0}, + {0, "0-31:1/4,32-63:2/4", &exp[10], 64, 0}, + {0, "0-31:3/4,32-63:4/4", &exp[11], 64, 0}, + + {0, "0-31:1/4,32-63:2/4,64-95:3/4,96-127:4/4", exp2, 128, 0}, + + {0, "0-2047:128/256", NULL, 2048, PARSE_TIME}, + + {-EINVAL, "-1", NULL, 8, 0}, + {-EINVAL, "-0", NULL, 8, 0}, + {-EINVAL, "10-1", NULL, 8, 0}, + {-EINVAL, "0-31:10/1", NULL, 8, 0}, +}; + +static void __init test_bitmap_parselist(void) +{ + int i; + int err; + cycles_t cycles; + DECLARE_BITMAP(bmap, 2048); + + for (i = 0; i < ARRAY_SIZE(parselist_tests); i++) { +#define ptest parselist_tests[i] + + cycles = get_cycles(); + err = bitmap_parselist(ptest.in, bmap, ptest.nbits); + cycles = get_cycles() - cycles; + + if (err != ptest.errno) { + pr_err("test %d: input is %s, errno is %d, expected %d\n", + i, ptest.in, err, ptest.errno); + continue; + } + + if (!err && ptest.expected + && !__bitmap_equal(bmap, ptest.expected, ptest.nbits)) { + pr_err("test %d: input is %s, result is 0x%lx, expected 0x%lx\n", + i, ptest.in, bmap[0], *ptest.expected); + continue; + } + + if (ptest.flags & PARSE_TIME) + pr_err("test %d: input is '%s' OK, Time: %lu\n", + i, ptest.in, cycles); + } +} + static void __init test_bitmap_u32_array_conversions(void) { DECLARE_BITMAP(bmap1, 1024); @@ -365,6 +437,7 @@ static int __init test_bitmap_init(void) { test_zero_fill_copy(); test_bitmap_u32_array_conversions(); + test_bitmap_parselist(); test_mem_optimisations(); if (failed_tests == 0) -- 2.11.0