From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA941C433FE for ; Thu, 20 Jan 2022 02:09:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E3906B00AF; Wed, 19 Jan 2022 21:09:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7934D6B00B0; Wed, 19 Jan 2022 21:09:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65B3B6B00B1; Wed, 19 Jan 2022 21:09:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0240.hostedemail.com [216.40.44.240]) by kanga.kvack.org (Postfix) with ESMTP id 57F136B00AF for ; Wed, 19 Jan 2022 21:09:13 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1D7B8180FE0ED for ; Thu, 20 Jan 2022 02:09:13 +0000 (UTC) X-FDA: 79049032986.08.37125B4 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf25.hostedemail.com (Postfix) with ESMTP id 8AE7EA0011 for ; Thu, 20 Jan 2022 02:09:12 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5FECCB81B3B; Thu, 20 Jan 2022 02:09:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5208C004E1; Thu, 20 Jan 2022 02:09:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1642644550; bh=oRrx3xONEg6JjQbHh8Xwrg1IDLXtvoRPG+P7LJjOngk=; h=Date:From:To:Subject:In-Reply-To:From; b=fXu+tCjG83PsQImZsgN/Tg2oWNb+18a7rGmVR1ODRgV90DapsH40SbhcghDN5DCvh oCKXT4XUu9DJWopGD2RcLywJTxlO/v79dDlo8FgG7uS5o1dymac/xFP/X3+iMBRPhw Deyl9Bfg7tMrJxNe8HS+e7L0y0VFTi+LjhqlWE50= Date: Wed, 19 Jan 2022 18:09:09 -0800 From: Andrew Morton To: akpm@linux-foundation.org, augusto.duraes33@gmail.com, brendanhiggins@google.com, davidgow@google.com, dlatypov@google.com, ferreiraenzoa@gmail.com, geert@linux-m68k.org, isabbasso@riseup.net, linux-mm@kvack.org, lkp@intel.com, mm-commits@vger.kernel.org, rodrigosiqueiramelo@gmail.com, skhan@linuxfoundation.org, torvalds@linux-foundation.org Subject: [patch 27/55] test_hash.c: split test_hash_init Message-ID: <20220120020909.dUlNR0Vlg%akpm@linux-foundation.org> In-Reply-To: <20220119180714.9e187ce100e4510de3cd9f7d@linux-foundation.org> User-Agent: s-nail v14.8.16 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 8AE7EA0011 X-Stat-Signature: pkrtt8zoisxywd6rx59dmifsgb5o91gi Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=fXu+tCjG; spf=pass (imf25.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspamd-Server: rspam07 X-HE-Tag: 1642644552-577561 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: =46rom: Isabella Basso Subject: test_hash.c: split test_hash_init Split up test_hash_init so that it calls each test more explicitly insofar it is possible without rewriting the entire file. This aims at improving readability. Split tests performed on string_or as they don't interfere with those performed in hash_or. Also separate pr_info calls about skipped tests as they're not part of the tests themselves, but only warn about (un)defined arch-specific hash functions. Link: https://lkml.kernel.org/r/20211208183711.390454-4-isabbasso@riseup.net Reviewed-by: David Gow Tested-by: David Gow Signed-off-by: Isabella Basso Cc: Augusto Dur=C3=A3es Camargo Cc: Brendan Higgins Cc: Daniel Latypov Cc: Enzo Ferreira Cc: Geert Uytterhoeven Cc: kernel test robot Cc: Rodrigo Siqueira Cc: Shuah Khan Signed-off-by: Andrew Morton --- lib/test_hash.c | 66 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 12 deletions(-) --- a/lib/test_hash.c~test_hashc-split-test_hash_init +++ a/lib/test_hash.c @@ -158,11 +158,39 @@ test_int_hash(unsigned long long h64, u3 =20 #define SIZE 256 /* Run time is cubic in SIZE */ =20 -static int __init -test_hash_init(void) +static int __init test_string_or(void) { char buf[SIZE+1]; - u32 string_or =3D 0, hash_or[2][33] =3D { { 0, } }; + u32 string_or =3D 0; + int i, j; + + fill_buf(buf, SIZE, 1); + + /* Test every possible non-empty substring in the buffer. */ + for (j =3D SIZE; j > 0; --j) { + buf[j] =3D '\0'; + + for (i =3D 0; i <=3D j; i++) { + u32 h0 =3D full_name_hash(buf+i, buf+i, j-i); + + string_or |=3D h0; + } /* i */ + } /* j */ + + /* The OR of all the hash values should cover all the bits */ + if (~string_or) { + pr_err("OR of all string hash results =3D %#x !=3D %#x", + string_or, -1u); + return -EINVAL; + } + + return 0; +} + +static int __init test_hash_or(void) +{ + char buf[SIZE+1]; + u32 hash_or[2][33] =3D { { 0, } }; unsigned tests =3D 0; unsigned long long h64 =3D 0; int i, j; @@ -192,7 +220,6 @@ test_hash_init(void) return -EINVAL; } =20 - string_or |=3D h0; h64 =3D h64 << 32 | h0; /* For use with hash_64 */ if (!test_int_hash(h64, hash_or)) return -EINVAL; @@ -200,12 +227,6 @@ test_hash_init(void) } /* i */ } /* j */ =20 - /* The OR of all the hash values should cover all the bits */ - if (~string_or) { - pr_err("OR of all string hash results =3D %#x !=3D %#x", - string_or, -1u); - return -EINVAL; - } if (~hash_or[0][0]) { pr_err("OR of all __hash_32 results =3D %#x !=3D %#x", hash_or[0][0], -1u); @@ -237,6 +258,13 @@ test_hash_init(void) } } =20 + pr_notice("%u tests passed.", tests); + + return 0; +} + +static void __init notice_skipped_tests(void) +{ /* Issue notices about skipped tests. */ #ifdef HAVE_ARCH__HASH_32 #if HAVE_ARCH__HASH_32 !=3D 1 @@ -252,10 +280,24 @@ test_hash_init(void) #else pr_info("hash_64() has no arch implementation to test."); #endif +} =20 - pr_notice("%u tests passed.", tests); +static int __init +test_hash_init(void) +{ + int ret; =20 - return 0; + ret =3D test_string_or(); + if (ret < 0) + return ret; + + ret =3D test_hash_or(); + if (ret < 0) + return ret; + + notice_skipped_tests(); + + return ret; } =20 static void __exit test_hash_exit(void) _