Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2066118pxb; Thu, 28 Oct 2021 15:33:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPPf4fQG5xis5/g2oj1UI9gxgx5zoBfkdn/lf3JYnGY/lFNy7uX8A6H/hkHexK7NOacxpq X-Received: by 2002:a17:902:bd01:b0:141:6232:6f89 with SMTP id p1-20020a170902bd0100b0014162326f89mr6449116pls.12.1635460398236; Thu, 28 Oct 2021 15:33:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635460398; cv=none; d=google.com; s=arc-20160816; b=E/xNQzrokhaoALSfotIl4osSBbDgtGMfRyEcleSsmCO4OXXpB3A9FXQHFKFC7Gl1Wx WLI0V3hSQ/u2diCC8hpPMs4vF9mTD6VdmLuUw8YIDlC34mP/x3/ecXu0eJJIOxf+7XAG 4DmQ0v5for9W9eP2wfa4+GfQkL8DeXxsreznUgP0Q6m/aIeTtbqf9LGU+YhNdloTb9S0 lw4LFceEtqiC1Qbnt19faghPSXjN3uf1TZnowqscouNR03KN5Tmv2pqYD7KsSMmAWm+P 1f1KA6zvqH8NEM8QlSF1S0SxQKLOlH1TmhawRwVjDo4oAO0c7G73GTbMK5y2NQ5sih+r Yd0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NRR7zcgDP9T0eENqcwQC1cjsjVkxSFpRTMuZszq/FwE=; b=jHUMIKHLXaKOP4g4tyBoDFQna65zDVNlD2FSOBux8j9RMmbanxGZA0uy1HLyRaUjKR w1XEawBrWJaa9GXkqYs5H2OBuykKvZvS/7z1x6qesR8utnauXM7uOgOBy9AD0ZyohOzB kZg3j/fHe9fYdugKLx32WX7lGkf5M8apVrM1bUWj3ovdImSlwOr+nw1Bfqyhr7znq4zv Yis77Cuii38spGX94BDz1AX8WFpGHPYNtHf5uroeFshykk+BPe8El7WFBZW/6MR/Abad PQNYxu8zA35B+bmerjGxe5aNSHg7Hx1cvRa0I76RfPklDVM7064hJ67kC7LUHNqACd/u 2ifA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@riseup.net header.s=squak header.b=YIfX07so; 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=NONE dis=NONE) header.from=riseup.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z22si5181993plo.230.2021.10.28.15.33.04; Thu, 28 Oct 2021 15:33:18 -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=@riseup.net header.s=squak header.b=YIfX07so; 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=NONE dis=NONE) header.from=riseup.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231442AbhJ1Wed (ORCPT + 99 others); Thu, 28 Oct 2021 18:34:33 -0400 Received: from mx1.riseup.net ([198.252.153.129]:55034 "EHLO mx1.riseup.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231298AbhJ1Wec (ORCPT ); Thu, 28 Oct 2021 18:34:32 -0400 Received: from fews1.riseup.net (fews1-pn.riseup.net [10.0.1.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail.riseup.net", Issuer "R3" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4HgKry0gw5zF2qM; Thu, 28 Oct 2021 15:25:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1635459954; bh=1jvLTlqGRu0TJnki2C8LiadfnqaSajWb0fYooId00EA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YIfX07socbns0LVFCjSfMo6A77IVxaXeMXqknPi/qUTNZYibFT4YT8rH7ZEZA1cg8 IHYKISketkNNhrUZXT9l7pEGX9+Bi7eteMhXMW94caLnNBmIWn2Dt4/FbT8r4rtZ/C dN6hSqnex3pyaPYJjZwD+TBNGAB0kBVnORAiAY2w= X-Riseup-User-ID: A94EC2BC6246647A26E5BC4558F50C76D4C007D1060112DAB446E745C22724EA Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews1.riseup.net (Postfix) with ESMTPSA id 4HgKrt11XWz5vvd; Thu, 28 Oct 2021 15:25:49 -0700 (PDT) From: Isabella Basso To: geert@linux-m68k.org Cc: ferreiraenzoa@gmail.com, augusto.duraes33@gmail.com, brendanhiggins@google.com, dlatypov@google.com, davidgow@google.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, ~lkcamp/patches@lists.sr.ht, rodrigosiqueiramelo@gmail.com, akpm@linux-foundation.org, skhan@linuxfoundation.org, Isabella Basso , Isabella Basso Subject: [PATCH v3 3/5] test_hash.c: split test_hash_init Date: Thu, 28 Oct 2021 19:25:31 -0300 Message-Id: <20211028222533.432641-4-isabbasso@riseup.net> In-Reply-To: <20211028222533.432641-1-isabbasso@riseup.net> References: <20211028222533.432641-1-isabbasso@riseup.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Isabella Basso 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. Reviewed-by: David Gow Tested-by: David Gow Signed-off-by: Isabella Basso --- Changes since v1: - As suggested by David Gow: 1. Rename arch-specific test functions. 2. Remove spare whitespace changes. lib/test_hash.c | 66 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 12 deletions(-) diff --git a/lib/test_hash.c b/lib/test_hash.c index 2b4fe4976cc4..032849a48da7 100644 --- a/lib/test_hash.c +++ b/lib/test_hash.c @@ -158,11 +158,39 @@ test_int_hash(unsigned long long h64, u32 hash_or[2][33]) #define SIZE 256 /* Run time is cubic in SIZE */ -static int __init -test_hash_init(void) +static int __init test_string_or(void) { char buf[SIZE+1]; - u32 string_or = 0, hash_or[2][33] = { { 0, } }; + u32 string_or = 0; + int i, j; + + fill_buf(buf, SIZE, 1); + + /* Test every possible non-empty substring in the buffer. */ + for (j = SIZE; j > 0; --j) { + buf[j] = '\0'; + + for (i = 0; i <= j; i++) { + u32 h0 = full_name_hash(buf+i, buf+i, j-i); + + string_or |= 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 = %#x != %#x", + string_or, -1u); + return -EINVAL; + } + + return 0; +} + +static int __init test_hash_or(void) +{ + char buf[SIZE+1]; + u32 hash_or[2][33] = { { 0, } }; unsigned tests = 0; unsigned long long h64 = 0; int i, j; @@ -192,7 +220,6 @@ test_hash_init(void) return -EINVAL; } - string_or |= h0; h64 = 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 */ - /* The OR of all the hash values should cover all the bits */ - if (~string_or) { - pr_err("OR of all string hash results = %#x != %#x", - string_or, -1u); - return -EINVAL; - } if (~hash_or[0][0]) { pr_err("OR of all __hash_32 results = %#x != %#x", hash_or[0][0], -1u); @@ -237,6 +258,13 @@ test_hash_init(void) } } + 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 != 1 @@ -252,10 +280,24 @@ test_hash_init(void) #else pr_info("hash_64() has no arch implementation to test."); #endif +} - pr_notice("%u tests passed.", tests); +static int __init +test_hash_init(void) +{ + int ret; - return 0; + ret = test_string_or(); + if (ret < 0) + return ret; + + ret = test_hash_or(); + if (ret < 0) + return ret; + + notice_skipped_tests(); + + return ret; } static void __exit test_hash_exit(void) -- 2.33.1