Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3440307pxb; Sun, 26 Sep 2021 15:37:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnE0bLSMMFgUvT+t/mbCiJ9jr7SV7UgN5PwsWDibt4idUznFUZrQr9+zg68GJyTX5NjtRU X-Received: by 2002:a63:2b4b:: with SMTP id r72mr13752475pgr.57.1632695852049; Sun, 26 Sep 2021 15:37:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632695852; cv=none; d=google.com; s=arc-20160816; b=pDC++gA/FaqgoMvSIA1UQA/+r7J14WsTMSLpNC4yrJzCaoBZjIFRH02bCjoG/hUBKd jEctRYOxb5CvNWlx1oP3zRyO3HNdoaPN93UeTfyO9xr/WhIp4/KyeiDM13OlDVDm/0IO JdGq5jkophdOJsF4u8/v87TtexH+lV41aTztzlz5BT3GvUpRkHYihtg6uNnbAYQLmuAz FsuoFnvvITT4RJ7wlZzqrhYE4moV90kJ5aX/EGTWhUv+DeAHKUwOWy5iHZ8vC6e9RMhF rDgMx7Nb6QTyM3eSH/4/s/C13cTFCqfqwNfK2W2+jsxTWNly7M8Stm3HLsMBFlXmaxib 7jWg== 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=keB75pA8tqWnwI9BXtLybyOviHEmwePg0jqXukti5H0=; b=eb7z2WG0LsPUkyd2lorU4KfQPaqQJDwpeoUtD5nu31LLooFXMDclml9bk1CkI6F6e8 k09rW3pJpJkSVj9nFiss9sqMbNYScWAOo/ewlND/sbiVyBY3xFmJhYgN/zqYPv4oM85/ geegkR/GMcrvGS2nzRI2gogrBxx+aCNMhvcspnvmm6OU6KV7HYDKUGDbEE72PQZE6Mnh BHZk0Sa/pSZMKKNEAmFNGBT5Cw8KJGuinpZok99XkxHnbh7d29wIYm4Q/kX4rFrfFJ3h yUheF1GBavJ8AK9gYPwRC89dO3vX8aC5nCIPUx/KDGubQtibPL/Y5smQChHwf0W7qh8z NPiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@usp.br header.s=usp-google header.b=YkNS0cUG; 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=QUARANTINE sp=NONE dis=NONE) header.from=usp.br Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f22si17999622pgv.464.2021.09.26.15.37.19; Sun, 26 Sep 2021 15:37:32 -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=@usp.br header.s=usp-google header.b=YkNS0cUG; 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=QUARANTINE sp=NONE dis=NONE) header.from=usp.br Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230525AbhIZWfR (ORCPT + 99 others); Sun, 26 Sep 2021 18:35:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231124AbhIZWfQ (ORCPT ); Sun, 26 Sep 2021 18:35:16 -0400 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38266C061604 for ; Sun, 26 Sep 2021 15:33:39 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id q81so31099044qke.5 for ; Sun, 26 Sep 2021 15:33:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp.br; s=usp-google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=keB75pA8tqWnwI9BXtLybyOviHEmwePg0jqXukti5H0=; b=YkNS0cUGVRMRN4pM13cbUzfkfYkN+S5ChWWvDx9U9VzL0puW6p85QqS4nMvhw2K9/8 GD+38B2lvKd1u/X6Q6dr7pa2IXt9/a+LvIJK/dkb37GdQh5x48/3wiUeIldiBC7J2m7S W1S60u65asCW5aSIBjt8koryzI21oZ7k+ppRnT/GRz9E1E9BpIo0T1ciUO82M4OwVRdO YVwauef4oPuZ1SFOOVKvK/OlwPx4ZKkv0BA7i9AKXQxEgijpUYCPZR6tRNK8FVhEz5HE nxX8LvQGVzkF0lBcIJ+aIqXUQT7pU149pCCNQ3yqBOofuujtF0VFxNl56SjyEKfr42cB k6Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=keB75pA8tqWnwI9BXtLybyOviHEmwePg0jqXukti5H0=; b=ZQzNBH3xj10LO+Q30NfknCeDC4/r0oXuEtkwCyO5uk9eumbfl0iaf1MbjhI4IsbR15 ndddkXPKf9ODlaS1N3JnG6vwso5/TRl7VTolgvgiJDsnf6PtVzv05E5RHrODwpb4GeTT NZHtLxul6LLrhADScpWtp/tpcsxjvZpMKDTQERkxZtYv9IT1ielyhjrihb6+kAXKXTl7 X82IKW0QdBdGh/DiveW6bmMwbxrEnDiaqaGP0H3kZ/TtXa4w72kdGdBHMJJFNtfQUjpp l7T7MfLgytG9FzJXPpwh8Pp1PJ1b+homxt23dv6HZPsEnH8YLPFo89vhQX6ouvxdiU5V wgNQ== X-Gm-Message-State: AOAM531AvTfZZEMRm3fbaH6mm2T0odJku5UDBT3WL58+ogUz56HGvJz7 Ysraw18ye5SknjfHRMp0whNgFw== X-Received: by 2002:a37:716:: with SMTP id 22mr20662271qkh.99.1632695618422; Sun, 26 Sep 2021 15:33:38 -0700 (PDT) Received: from aehse.localdomain ([2804:d41:bd1c:9100:f2e1:f671:7a83:1eb8]) by smtp.gmail.com with ESMTPSA id x6sm7244151qts.79.2021.09.26.15.33.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Sep 2021 15:33:38 -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, Isabella Basso Subject: [PATCH v2 3/5] test_hash.c: split test_hash_init Date: Sun, 26 Sep 2021 19:33:20 -0300 Message-Id: <20210926223322.848641-4-isabellabdoamaral@usp.br> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210926223322.848641-1-isabellabdoamaral@usp.br> References: <20210926223322.848641-1-isabellabdoamaral@usp.br> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Changes since v1: - As suggested by David Gow: 1. Rename arch-specific test functions. 2. Remove spare whitespace changes. - As suggested by Marco Elver: 1. Add struct for carrying test variables. Tested-by: David Gow Signed-off-by: Isabella Basso --- 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 08fe63776c4f..db9dd18b4e8b 100644 --- a/lib/test_hash.c +++ b/lib/test_hash.c @@ -153,11 +153,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; @@ -187,7 +215,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; @@ -195,12 +222,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); @@ -232,6 +253,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 @@ -247,10 +275,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.0