From patchwork Thu Aug 26 01:26:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Isabella B do Amaral X-Patchwork-Id: 12458733 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 972BCC432BE for ; Thu, 26 Aug 2021 01:26:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 77E0C60FE7 for ; Thu, 26 Aug 2021 01:26:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236055AbhHZB11 (ORCPT ); Wed, 25 Aug 2021 21:27:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236654AbhHZB10 (ORCPT ); Wed, 25 Aug 2021 21:27:26 -0400 Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2EFFC061757 for ; Wed, 25 Aug 2021 18:26:39 -0700 (PDT) Received: by mail-qk1-x72d.google.com with SMTP id y144so1633015qkb.6 for ; Wed, 25 Aug 2021 18:26: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=2RDPNDoVhpC2D8PS/iTn00/DSRKBuu8x3HruL1SBfjE=; b=jRvHoeR/shoYNO7xRWlI+t8hIou6HrapcCtwwbc1lSSeEu67RhBZapTBJ81wNEhja+ Lw5A+dDRgKLDZSrCINUcByak6nEBEdQUVkuyu2KqAZA/MP5f/8B0+eRsNlI7X9SUJpXH hohPqHarST5l2hMM4K0h9dNaTRRhBGkyBFplNBv6NbOABJ2lKURtGMrvDPo3qQF+FS+y xKukq7FuKp8/DiQ+nrdak0UHpo67AZOWW8dbcQjbEQ4ZFdDYdLQYAq7pvNWal/xCm54L mm5xx4E5lYV7UZ93y9mSqzxsnvicLjN38+f4IG2RP9tDy0HzxgLtBOChEpFjp1ByJdx8 Z+Hw== 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:mime-version:content-transfer-encoding; bh=2RDPNDoVhpC2D8PS/iTn00/DSRKBuu8x3HruL1SBfjE=; b=Ff8HWGAzPaiHw5kF/dbHxwXFu2pCi2tEzXpIL/D/Bz4qD5i6vqF0JBrAF5OqC6DEkK 4YrU77CqmGcxdVUffddLWg76hdkpDnPmGKVJjeFIDBtqU5GzRQIH2xNfbw6ALP3DJjzS 8yGb6qkLL6l79D2e+kSvHE7yQPQx4VYpagzXYaP5khhxInxmcL0pNkn17RIQjOi8kdYo Kz1qSy/UlJbujSKtvKLFaimTmmnTSiRBzK5capGaCZoX6QajeQXuAc7mbSVR6ONYRYyz YOWsVp6puJK0c+/BO8spvVK2DKfsszy0RaLzl5qO/5Q2KlZLEinaNdODtYh46Y3PFwJX OVdg== X-Gm-Message-State: AOAM530HUq5LqOP7ESzRu2aoxl44FxGFBrbc/fUi0P+YoWiNfIILlzXJ /aZUP1xei3iZCh7ZVkw/vHSxFVUxoqFbgLDP X-Google-Smtp-Source: ABdhPJwxv7Mi2+cX2h1K/u8wARE/mAZlTiRGK+681jGMY9EGTqS3PjqyeQYt64cryNKcFdEk1MCVpA== X-Received: by 2002:a37:81c2:: with SMTP id c185mr1456849qkd.446.1629941198911; Wed, 25 Aug 2021 18:26:38 -0700 (PDT) Received: from aehse.localdomain (177-209-76-11.user3p.veloxzone.com.br. [177.209.76.11]) by smtp.gmail.com with ESMTPSA id p123sm1375053qke.94.2021.08.25.18.26.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Aug 2021 18:26:38 -0700 (PDT) From: Isabella Basso To: linux@sciencehorizons.net, 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 1/6] hash.h: remove unused define directive Date: Wed, 25 Aug 2021 22:26:21 -0300 Message-Id: <20210826012626.1163705-2-isabellabdoamaral@usp.br> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210826012626.1163705-1-isabellabdoamaral@usp.br> References: <20210826012626.1163705-1-isabellabdoamaral@usp.br> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org The HAVE_ARCH_HASH_32 (single underscore) define hasn't been used for any known supported architectures that have their own hash function implementation (i.e. m68k, Microblaze, H8/300, pa-risc) since George's patch [1], which introduced it. The supported 32-bit architectures from the list above have only been making use of the (more general) HAVE_ARCH__HASH_32 define, which only lacks the right shift operator, that wasn't targeted for optimizations so far. [1] https://lore.kernel.org/lkml/20160525073311.5600.qmail@ns.sciencehorizons.net/ Co-developed-by: Augusto Durães Camargo Signed-off-by: Augusto Durães Camargo Co-developed-by: Enzo Ferreira Signed-off-by: Enzo Ferreira Signed-off-by: Isabella Basso --- include/linux/hash.h | 5 +---- lib/test_hash.c | 24 +----------------------- tools/include/linux/hash.h | 5 +---- 3 files changed, 3 insertions(+), 31 deletions(-) diff --git a/include/linux/hash.h b/include/linux/hash.h index ad6fa21d977b..38edaa08f862 100644 --- a/include/linux/hash.h +++ b/include/linux/hash.h @@ -62,10 +62,7 @@ static inline u32 __hash_32_generic(u32 val) return val * GOLDEN_RATIO_32; } -#ifndef HAVE_ARCH_HASH_32 -#define hash_32 hash_32_generic -#endif -static inline u32 hash_32_generic(u32 val, unsigned int bits) +static inline u32 hash_32(u32 val, unsigned int bits) { /* High bits are more random, so use them. */ return __hash_32(val) >> (32 - bits); diff --git a/lib/test_hash.c b/lib/test_hash.c index 0ee40b4a56dd..d4b0cfdb0377 100644 --- a/lib/test_hash.c +++ b/lib/test_hash.c @@ -94,22 +94,7 @@ test_int_hash(unsigned long long h64, u32 hash_or[2][33]) pr_err("hash_32(%#x, %d) = %#x > %#x", h0, k, h1, m); return false; } -#ifdef HAVE_ARCH_HASH_32 - h2 = hash_32_generic(h0, k); -#if HAVE_ARCH_HASH_32 == 1 - if (h1 != h2) { - pr_err("hash_32(%#x, %d) = %#x != hash_32_generic() " - " = %#x", h0, k, h1, h2); - return false; - } -#else - if (h2 > m) { - pr_err("hash_32_generic(%#x, %d) = %#x > %#x", - h0, k, h1, m); - return false; - } -#endif -#endif + /* Test hash_64 */ hash_or[1][k] |= h1 = hash_64(h64, k); if (h1 > m) { @@ -227,13 +212,6 @@ test_hash_init(void) #else pr_info("__hash_32() has no arch implementation to test."); #endif -#ifdef HAVE_ARCH_HASH_32 -#if HAVE_ARCH_HASH_32 != 1 - pr_info("hash_32() is arch-specific; not compared to generic."); -#endif -#else - pr_info("hash_32() has no arch implementation to test."); -#endif #ifdef HAVE_ARCH_HASH_64 #if HAVE_ARCH_HASH_64 != 1 pr_info("hash_64() is arch-specific; not compared to generic."); diff --git a/tools/include/linux/hash.h b/tools/include/linux/hash.h index ad6fa21d977b..38edaa08f862 100644 --- a/tools/include/linux/hash.h +++ b/tools/include/linux/hash.h @@ -62,10 +62,7 @@ static inline u32 __hash_32_generic(u32 val) return val * GOLDEN_RATIO_32; } -#ifndef HAVE_ARCH_HASH_32 -#define hash_32 hash_32_generic -#endif -static inline u32 hash_32_generic(u32 val, unsigned int bits) +static inline u32 hash_32(u32 val, unsigned int bits) { /* High bits are more random, so use them. */ return __hash_32(val) >> (32 - bits); From patchwork Thu Aug 26 01:26:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isabella B do Amaral X-Patchwork-Id: 12458735 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 914CEC432BE for ; Thu, 26 Aug 2021 01:26:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 75CE7610A1 for ; Thu, 26 Aug 2021 01:26:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236880AbhHZB1a (ORCPT ); Wed, 25 Aug 2021 21:27:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236644AbhHZB13 (ORCPT ); Wed, 25 Aug 2021 21:27:29 -0400 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42FACC0613C1 for ; Wed, 25 Aug 2021 18:26:43 -0700 (PDT) Received: by mail-qk1-x732.google.com with SMTP id c10so1579457qko.11 for ; Wed, 25 Aug 2021 18:26:43 -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=hDuUPantBA5RaLY4chr+boj+alaUK90TOLcT8GmDFog=; b=xUDBsaZhosklBFsDMllxdJ1Q26GXuAW0BjjO05dH7OLOQ+RGuXZZ/EVLO8aUiDtRPr aaKGrjzokz6zBfJzWr8GXkX0ztaQwn51TQ5o6Tkx/D6xCmsfOgvHYlIXAm5tGQbbD52u 7dfBn3OOgA0Q8AYGaoy25OSC5YELbHCTXr1DBnseakkBcWFL4A9Is9PaUBMbLePupTlQ Au8uNHPI3pVZJzCeqwlF8MUXRrdDxwMIOJkYdYW0Nm12YOg+w8G8kOyy6u8O0NNKd5Bn K2lyZpXmBpYYyMSjcNlCzNh/bo4AgubB+gqcXl44q1MzPNHYBbqJAZer1E/f8V2gi13q hM9w== 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:mime-version:content-transfer-encoding; bh=hDuUPantBA5RaLY4chr+boj+alaUK90TOLcT8GmDFog=; b=UU8hAk9sLNkJP9T9CURdLa0ii/0rXYS7pqllPWtpe1QRx9mKfP5quAwtGO4DXcvSMO pvc34YLhxDupbZB7kK6Nxlxt4aYCPQ/xio8Ix13vTLHcbckGMXH1dwJjXhXBxdFjGmSl hGYgzuB0d/0qKO9DPyG6Vze93g4MkjEm26TAMdO8qaajxug/y3j240YLGNS9+BdT5xwt jydSn0vNPDjkqjXDxIEh0A3RQAXskCRXXiputlgEtlhV7/InqWXq/MgG5IUkPaiTV3wE mCA3sKmYBnp1Xwnyo1/KotL0MpzP0bDcbLWGSyRpT09jOBVGgbvj2NZqLN5XEoIAbrud MMsQ== X-Gm-Message-State: AOAM530CkgSm+HB9wEgsgM5JCkhieqT/LtKf8qtmYAGz6GehrOtpW2GM TyPDao3nOFg55yhpLgIBowBYfw== X-Google-Smtp-Source: ABdhPJwqTbJbzCjOHPPOzcZvtSF1x/eVVApq71pKqGyGJ+LPxko/qgdrJcm3zVtAoKzhv0rWSdr3Zw== X-Received: by 2002:a37:2f47:: with SMTP id v68mr1485643qkh.190.1629941202408; Wed, 25 Aug 2021 18:26:42 -0700 (PDT) Received: from aehse.localdomain (177-209-76-11.user3p.veloxzone.com.br. [177.209.76.11]) by smtp.gmail.com with ESMTPSA id p123sm1375053qke.94.2021.08.25.18.26.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Aug 2021 18:26:42 -0700 (PDT) From: Isabella Basso To: linux@sciencehorizons.net, 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 2/6] test_hash.c: move common definitions to top of file Date: Wed, 25 Aug 2021 22:26:22 -0300 Message-Id: <20210826012626.1163705-3-isabellabdoamaral@usp.br> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210826012626.1163705-1-isabellabdoamaral@usp.br> References: <20210826012626.1163705-1-isabellabdoamaral@usp.br> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Keep function signatures minimal by making common definitions static. This does not change any behavior. Signed-off-by: Isabella Basso --- lib/test_hash.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/test_hash.c b/lib/test_hash.c index d4b0cfdb0377..8bcc645a7294 100644 --- a/lib/test_hash.c +++ b/lib/test_hash.c @@ -23,6 +23,11 @@ #include #include +#define SIZE 256 /* Run time is cubic in SIZE */ + +static u32 string_or; /* stores or-ed string output */ +static u32 hash_or[2][33] = { { 0, } }; /* stores or-ed hash output */ + /* 32-bit XORSHIFT generator. Seed must not be zero. */ static u32 __init __attribute_const__ xorshift(u32 seed) @@ -66,7 +71,7 @@ fill_buf(char *buf, size_t len, u32 seed) * recompile and re-test the module without rebooting. */ static bool __init -test_int_hash(unsigned long long h64, u32 hash_or[2][33]) +test_int_hash(unsigned long long h64) { int k; u32 h0 = (u32)h64, h1, h2; @@ -123,17 +128,15 @@ test_int_hash(unsigned long long h64, u32 hash_or[2][33]) return true; } -#define SIZE 256 /* Run time is cubic in SIZE */ - static int __init test_hash_init(void) { char buf[SIZE+1]; - u32 string_or = 0, hash_or[2][33] = { { 0, } }; unsigned tests = 0; unsigned long long h64 = 0; int i, j; + string_or = 0; fill_buf(buf, SIZE, 1); /* Test every possible non-empty substring in the buffer. */ @@ -161,7 +164,7 @@ test_hash_init(void) string_or |= h0; h64 = h64 << 32 | h0; /* For use with hash_64 */ - if (!test_int_hash(h64, hash_or)) + if (!test_int_hash(h64)) return -EINVAL; tests++; } /* i */ From patchwork Thu Aug 26 01:26:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isabella B do Amaral X-Patchwork-Id: 12458737 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 093C7C43214 for ; Thu, 26 Aug 2021 01:26:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D80B861073 for ; Thu, 26 Aug 2021 01:26:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236988AbhHZB1d (ORCPT ); Wed, 25 Aug 2021 21:27:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236929AbhHZB1d (ORCPT ); Wed, 25 Aug 2021 21:27:33 -0400 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE8C7C061757 for ; Wed, 25 Aug 2021 18:26:46 -0700 (PDT) Received: by mail-qt1-x831.google.com with SMTP id d2so1159450qto.6 for ; Wed, 25 Aug 2021 18:26:46 -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=IxYlFUnO2M/nJ6H1WkLFPoOltR5Vzxqh9iu0B7vvtZA=; b=woMw9BiquP1EK/cXNQYpXU0Mb1189T6DikI6OOQ84d8epoIXxt3B4ke5WIKCN5jaEZ WnCMAF5N/O7vihOw6ZIwk8UrX2XTEFxLRczUCm6jq5STkkCM8dl5BoQ2kBah4flBqJ5L n+KH+o7lAaDVf3zEfplHAdSPVmtegiOpoLThI7y7G0U+GQ82O1ewFWSvvPskwMuNEMXO p/sc0e8bXsKDI4HBPuqwz7Tpa9L77ACtMIDHuJ/4r9QVy7hoMfHC2vwj8n5wTJ9JBfu6 r4eeYDNkfZJz51IQxtFSIxAMh/vfzasczh22JC4yQ3wqgc6tSI6AqFYD4WWxXsHOyr4a eGnw== 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:mime-version:content-transfer-encoding; bh=IxYlFUnO2M/nJ6H1WkLFPoOltR5Vzxqh9iu0B7vvtZA=; b=mo2lyT8RnZ1HMuj+x2dQ/VSwOvHDq795s68ND7Pg5vAYiwXD2xggx2AOxhCFyWSj/z WxyuhC9P2XjzgJA8asAKIaZNn8NWUV9bfsT7V1fozjUT/LAQ0sOll6UJZ0kRuZGk5ZbY aUdlJN9ADPorkuYKyOpEJrG59sqOj7z7RoRRroUCnh7208+JdpTZESKl0YQ+Re1d/MEr D+Wi/OpxUzt50b6lfEsMhz1EWnSdAyGGqHl9yRIeBhBOV0rvGuzsOw4kyPeknWo1d9+f jASeGaL21UxVg4hA7RpFD+6Y5xfoltCVr6w7rN9xMKpvErHXte1jGN3gFe9+C/tCITyj 5J1g== X-Gm-Message-State: AOAM531tbsigYPV3EH8+52kWoShFD5+9fB+YzJPenAaN8Dd7fAnIzTQR q7deTD6Wt8XnG0fEqHlOOL3rXw== X-Google-Smtp-Source: ABdhPJyrBem87bGdjjuLn/kOSVNJnDmrCcbf/Ep2216b7ltoapwkVqmAXevAJ4qlxanFD5lmQnP2Rg== X-Received: by 2002:ac8:4cca:: with SMTP id l10mr1117500qtv.70.1629941205855; Wed, 25 Aug 2021 18:26:45 -0700 (PDT) Received: from aehse.localdomain (177-209-76-11.user3p.veloxzone.com.br. [177.209.76.11]) by smtp.gmail.com with ESMTPSA id p123sm1375053qke.94.2021.08.25.18.26.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Aug 2021 18:26:45 -0700 (PDT) From: Isabella Basso To: linux@sciencehorizons.net, 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 3/6] test_hash.c: split test_int_hash into arch-specific functions Date: Wed, 25 Aug 2021 22:26:23 -0300 Message-Id: <20210826012626.1163705-4-isabellabdoamaral@usp.br> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210826012626.1163705-1-isabellabdoamaral@usp.br> References: <20210826012626.1163705-1-isabellabdoamaral@usp.br> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Split the The test_int_hash function to keep its mainloop separate from arch-specific chunks, which are only compiled as needed. This aims at improving readability. Signed-off-by: Isabella Basso --- lib/test_hash.c | 84 +++++++++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 30 deletions(-) diff --git a/lib/test_hash.c b/lib/test_hash.c index 8bcc645a7294..ed75c768c231 100644 --- a/lib/test_hash.c +++ b/lib/test_hash.c @@ -61,6 +61,45 @@ fill_buf(char *buf, size_t len, u32 seed) } } +#ifdef HAVE_ARCH__HASH_32 +static bool __init +test_int_hash32(u32 *h0, u32 *h1, u32 *h2) +{ + hash_or[1][0] |= *h2 = __hash_32_generic(h0); +#if HAVE_ARCH__HASH_32 == 1 + if (*h1 != *h2) { + pr_err("__hash_32(%#x) = %#x != __hash_32_generic() = %#x", + *h0, *h1, *h2); + return false; + } +#endif + return true; +} +#endif + +#ifdef HAVE_ARCH_HASH_64 +static bool __init +test_int_hash64(unsigned long long h64, u32 *h0, u32 *h1, u32 *h2, u32 const *m, int k) +{ + *h2 = hash_64_generic(*h64, *k); +#if HAVE_ARCH_HASH_64 == 1 + if (*h1 != *h2) { + pr_err("hash_64(%#llx, %d) = %#x != hash_64_generic() = %#x", + *h64, *k, *h1, *h2); + return false; + } +#else + if (*h2 > *m) { + pr_err("hash_64_generic(%#llx, %d) = %#x > %#x", + *h64, *k, *h1, *m); + return false; + } +#endif + return true; + +} +#endif + /* * Test the various integer hash functions. h64 (or its low-order bits) * is the integer to hash. hash_or accumulates the OR of the hash values, @@ -74,19 +113,17 @@ static bool __init test_int_hash(unsigned long long h64) { int k; - u32 h0 = (u32)h64, h1, h2; + u32 h0 = (u32)h64, h1; + +#if defined HAVE_ARCH__HASH_32 || defined HAVE_ARCH_HASH_64 + u32 h2; +#endif /* Test __hash32 */ hash_or[0][0] |= h1 = __hash_32(h0); #ifdef HAVE_ARCH__HASH_32 - hash_or[1][0] |= h2 = __hash_32_generic(h0); -#if HAVE_ARCH__HASH_32 == 1 - if (h1 != h2) { - pr_err("__hash_32(%#x) = %#x != __hash_32_generic() = %#x", - h0, h1, h2); + if (!test_int_hash32(&h0, &h1, &h2)) return false; - } -#endif #endif /* Test k = 1..32 bits */ @@ -107,24 +144,11 @@ test_int_hash(unsigned long long h64) return false; } #ifdef HAVE_ARCH_HASH_64 - h2 = hash_64_generic(h64, k); -#if HAVE_ARCH_HASH_64 == 1 - if (h1 != h2) { - pr_err("hash_64(%#llx, %d) = %#x != hash_64_generic() " - "= %#x", h64, k, h1, h2); + if (!test_int_hash64(&h64, &h0, &h1, &h2, &m, &k)) return false; - } -#else - if (h2 > m) { - pr_err("hash_64_generic(%#llx, %d) = %#x > %#x", - h64, k, h1, m); - return false; - } -#endif #endif } - (void)h2; /* Suppress unused variable warning */ return true; } @@ -150,15 +174,15 @@ test_hash_init(void) /* Check that hashlen_string gets the length right */ if (hashlen_len(hashlen) != j-i) { pr_err("hashlen_string(%d..%d) returned length" - " %u, expected %d", - i, j, hashlen_len(hashlen), j-i); + " %u, expected %d", + i, j, hashlen_len(hashlen), j-i); return -EINVAL; } /* Check that the hashes match */ if (hashlen_hash(hashlen) != h0) { pr_err("hashlen_string(%d..%d) = %08x != " - "full_name_hash() = %08x", - i, j, hashlen_hash(hashlen), h0); + "full_name_hash() = %08x", + i, j, hashlen_hash(hashlen), h0); return -EINVAL; } @@ -178,14 +202,14 @@ test_hash_init(void) } if (~hash_or[0][0]) { pr_err("OR of all __hash_32 results = %#x != %#x", - hash_or[0][0], -1u); + hash_or[0][0], -1u); return -EINVAL; } #ifdef HAVE_ARCH__HASH_32 #if HAVE_ARCH__HASH_32 != 1 /* Test is pointless if results match */ if (~hash_or[1][0]) { pr_err("OR of all __hash_32_generic results = %#x != %#x", - hash_or[1][0], -1u); + hash_or[1][0], -1u); return -EINVAL; } #endif @@ -197,12 +221,12 @@ test_hash_init(void) if (hash_or[0][i] != m) { pr_err("OR of all hash_32(%d) results = %#x " - "(%#x expected)", i, hash_or[0][i], m); + "(%#x expected)", i, hash_or[0][i], m); return -EINVAL; } if (hash_or[1][i] != m) { pr_err("OR of all hash_64(%d) results = %#x " - "(%#x expected)", i, hash_or[1][i], m); + "(%#x expected)", i, hash_or[1][i], m); return -EINVAL; } } From patchwork Thu Aug 26 01:26:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isabella B do Amaral X-Patchwork-Id: 12458739 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66064C4320E for ; Thu, 26 Aug 2021 01:26:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 50843610A1 for ; Thu, 26 Aug 2021 01:26:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236934AbhHZB1h (ORCPT ); Wed, 25 Aug 2021 21:27:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237144AbhHZB1g (ORCPT ); Wed, 25 Aug 2021 21:27:36 -0400 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16CC8C0613C1 for ; Wed, 25 Aug 2021 18:26:50 -0700 (PDT) Received: by mail-qk1-x735.google.com with SMTP id a10so1568647qka.12 for ; Wed, 25 Aug 2021 18:26:50 -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=wCMESC09DMuVqDRtZN4Rgv4o7FUGs82VSyG8NO9Wyd0=; b=oW/3pp7SXxrXxk6tUWU3MF4PNh3HbPXN91MBLf7YHqTMilELcJW0AbYgnEdo4F2SH/ XE9ypcl1J0kboAKZY7bXhA/7uLF2G4bds+7skpmZvzAOhPgiZ4nAN91DH5EY6HlJ5qGD fpvgP46peWZYDbQ1sRRY8ZQzVnJq8lnnI2vR8OoBZ5hqmujBBIKkdnJs3msabIc1mCNu Byhp/RDdaiXn3eyfmnaTU13C9QPCPDPDm5EYpGcs6eXDxq9V0nUei4DsNbKLDC9e++en rgSA7fm44/frDY1ufPeIXAnqEXV0HYl2FjpPY/nIU07B3whnqz8k8Z1dmMi82JO1BPrM Ttjg== 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:mime-version:content-transfer-encoding; bh=wCMESC09DMuVqDRtZN4Rgv4o7FUGs82VSyG8NO9Wyd0=; b=IVNO3DG9BTuOhSAIwPuXK6jkMtDcGUf0E88Xph3rtCxO734vHurt0oKNJ1vJ+ena2q aG/23YwOK95TG7C8cpR2yo5dYp7cjl40jr1JH8I1LEXofwdYqNH7CfrBO26yVqrMb2a3 hmaSSv0qFAz70gsiDjk4eo+XjHo2BeRIGPO+WtxnC5eKYISPaCb04DEz0dmTa8DhrR+T o/9Z7y/hyCQBkrp8Krl4cgsL9J/hXfhm1fQKhjVuSqV6mkcspCYqQtFhD9a72uuRhocH I9eqToUAlsyduiqrLQS4RKihiu+b4O3hLWKnEJRykJlr+A3oQgOXvQfvP3xnujG0tX2+ vlOA== X-Gm-Message-State: AOAM531yyRXhj1bDlmGpS5UmftN1Igsu78hf9PMH3tHXL+qPhyvR9hZ4 i/HoX0UEKf5FGmhbIZfd7/nTmg== X-Google-Smtp-Source: ABdhPJwMvwKJejA2bQALADkWTdAgTTn5mx5zJKHWPnllMw0ezDOfMmEvx1neARFfMH/DzSToOZoxuA== X-Received: by 2002:a37:db0a:: with SMTP id e10mr1466514qki.259.1629941209278; Wed, 25 Aug 2021 18:26:49 -0700 (PDT) Received: from aehse.localdomain (177-209-76-11.user3p.veloxzone.com.br. [177.209.76.11]) by smtp.gmail.com with ESMTPSA id p123sm1375053qke.94.2021.08.25.18.26.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Aug 2021 18:26:48 -0700 (PDT) From: Isabella Basso To: linux@sciencehorizons.net, 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 4/6] test_hash.c: split test_hash_init Date: Wed, 25 Aug 2021 22:26:24 -0300 Message-Id: <20210826012626.1163705-5-isabellabdoamaral@usp.br> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210826012626.1163705-1-isabellabdoamaral@usp.br> References: <20210826012626.1163705-1-isabellabdoamaral@usp.br> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@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. Signed-off-by: Isabella Basso --- lib/test_hash.c | 65 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 11 deletions(-) diff --git a/lib/test_hash.c b/lib/test_hash.c index ed75c768c231..c168823b0963 100644 --- a/lib/test_hash.c +++ b/lib/test_hash.c @@ -152,8 +152,37 @@ test_int_hash(unsigned long long h64) return true; } -static int __init -test_hash_init(void) +static int __init test_string_or(void) +{ + char buf[SIZE+1]; + int i, j; + u32 h0; + + string_or = 0; + 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++) { + 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]; unsigned tests = 0; @@ -186,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)) return -EINVAL; @@ -194,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); @@ -231,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 @@ -246,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) From patchwork Thu Aug 26 01:26:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isabella B do Amaral X-Patchwork-Id: 12458741 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4ED15C432BE for ; Thu, 26 Aug 2021 01:26:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3681460FE7 for ; Thu, 26 Aug 2021 01:26:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237306AbhHZB1l (ORCPT ); Wed, 25 Aug 2021 21:27:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237177AbhHZB1j (ORCPT ); Wed, 25 Aug 2021 21:27:39 -0400 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81E66C0613C1 for ; Wed, 25 Aug 2021 18:26:53 -0700 (PDT) Received: by mail-qk1-x730.google.com with SMTP id t190so1618713qke.7 for ; Wed, 25 Aug 2021 18:26:53 -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=BggQHky/pXzcE7QiPL5k7sg98dxSxMdww6ldwaEmBp0=; b=QYwdlB6TuvVHIuEIo3d5yH6CEF8VK3DovhMjsqFmowpcsebJsFZrYUE9Qjo+ro84+e 3STTCnrcyVs5gAXLLArT6woMh7WmW6fAk93Kfvv/ztAkqse76GWaF8T7XonkHjmxTzwc b17pvPQgIivZGYT6E6/3h0iar2sv1gf+hEDSpwt8YL8C9w3q56DXpUdPgf5qce5YdTVs ekfZ1CtCmcJnw31dB3NOkaKtTagdyfcUlAO+d8GXuUJucUPEk+UkPLcixqLQOIA1QrA5 Ky8yntLCI3npiZiC/fT8Hphn5OF96ScGzSiFpgi6PGJSZrGoxDPdskt6s80DuRknd6qX FdaA== 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:mime-version:content-transfer-encoding; bh=BggQHky/pXzcE7QiPL5k7sg98dxSxMdww6ldwaEmBp0=; b=peZIUqN+UfJwVtcdloLf3MzpsSZ0Rt0J+My84kob6+CcxZ1FIu0n3cokf3VqrNBb74 DXhAG1xC3C8nl0+MYLzCbI1Xi1An8OMPYy6m5XTEe48B/fdafis5btaBYYGl4oDFwo75 Fbre1Iweis644A56RJiRm/PppHIgYCXLYMaEjqskhmQOnu44jez2BNO6E0kpKFTrjIMd FLLFtwKTbiixQYfAfpAmfR0bUj5kvdnhO3AimLviQaKdEKj4bhfUPW1V+gxByuG2ZQz2 uDJWd+4LXmQuw7kbIXPrsPajFO5Swnhppt4VKndF2ENV/8nfCs5/0bAOkFbtl4xA/ZYj LyyA== X-Gm-Message-State: AOAM533ezfPy0buQXW6CeOAyyUTczKz6W07Nyzk04UjYD2qOcjXprqCc hRO74rKmWiNz0rLi6vDFohvtDQ== X-Google-Smtp-Source: ABdhPJxvxpmP8WmwImn9XK+xFbumd3Wt4ZiDhUg321z4BDq7FLla6lPBXnL8Uvp6FFbA14cpd8Fntg== X-Received: by 2002:a05:620a:21dc:: with SMTP id h28mr1494397qka.198.1629941212717; Wed, 25 Aug 2021 18:26:52 -0700 (PDT) Received: from aehse.localdomain (177-209-76-11.user3p.veloxzone.com.br. [177.209.76.11]) by smtp.gmail.com with ESMTPSA id p123sm1375053qke.94.2021.08.25.18.26.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Aug 2021 18:26:52 -0700 (PDT) From: Isabella Basso To: linux@sciencehorizons.net, 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 5/6] lib/Kconfig.debug: properly split hash test kernel entries Date: Wed, 25 Aug 2021 22:26:25 -0300 Message-Id: <20210826012626.1163705-6-isabellabdoamaral@usp.br> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210826012626.1163705-1-isabellabdoamaral@usp.br> References: <20210826012626.1163705-1-isabellabdoamaral@usp.br> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Split TEST_HASH so that each entry only has one file. Note that there's no stringhash test file, but actually tests are performed in lib/test_hash.c. Signed-off-by: Isabella Basso --- lib/Kconfig.debug | 14 +++++++++++--- lib/Makefile | 3 ++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 5ddd575159fb..5e5894d98c50 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2224,9 +2224,17 @@ config TEST_RHASHTABLE config TEST_HASH tristate "Perform selftest on hash functions" help - Enable this option to test the kernel's integer (), - string (), and siphash () - hash functions on boot (or module load). + Enable this option to test the kernel's integer (), and + string () hash functions on boot (or module load). + + This is intended to help people writing architecture-specific + optimized versions. If unsure, say N. + +config TEST_SIPHASH + tristate "Perform selftest on siphash functions" + help + Enable this option to test the kernel's siphash () hash + functions on boot (or module load). This is intended to help people writing architecture-specific optimized versions. If unsure, say N. diff --git a/lib/Makefile b/lib/Makefile index 5efd1b435a37..c2e81d0eb31c 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -61,7 +61,8 @@ obj-$(CONFIG_TEST_FIRMWARE) += test_firmware.o obj-$(CONFIG_TEST_BITOPS) += test_bitops.o CFLAGS_test_bitops.o += -Werror obj-$(CONFIG_TEST_SYSCTL) += test_sysctl.o -obj-$(CONFIG_TEST_HASH) += test_hash.o test_siphash.o +obj-$(CONFIG_TEST_SIPHASH) += test_siphash.o +obj-$(CONFIG_TEST_HASH) += test_hash.o obj-$(CONFIG_TEST_IDA) += test_ida.o obj-$(CONFIG_KASAN_KUNIT_TEST) += test_kasan.o CFLAGS_test_kasan.o += -fno-builtin From patchwork Thu Aug 26 01:26:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Isabella B do Amaral X-Patchwork-Id: 12458743 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3ECF9C432BE for ; Thu, 26 Aug 2021 01:26:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2768861073 for ; Thu, 26 Aug 2021 01:26:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237332AbhHZB1o (ORCPT ); Wed, 25 Aug 2021 21:27:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237348AbhHZB1n (ORCPT ); Wed, 25 Aug 2021 21:27:43 -0400 Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15AE8C0613C1 for ; Wed, 25 Aug 2021 18:26:57 -0700 (PDT) Received: by mail-qk1-x72a.google.com with SMTP id a66so1677638qkc.1 for ; Wed, 25 Aug 2021 18:26:57 -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=PbE2qfFBe6GYsESxfnvqNdhyVyD92IjDvn8DjhZslDM=; b=D79nZV86emSiTJ4o+M2dkx+eEA0XD/Q4el8sDyGUdTPC/AYBSKRZWQSVOrQuhVm9Kk +pu8ApPjWVFYJhGwi+iSaLQTyXcaAMgMlG3ODp7hkLQ7hmha5ZNhiYnnAaV4a670oz4v 8JSVQq/9UjrOM3prRLCbOuQeuULrypHL3z4ViKjxVdTtZtuiqSWZklUQ3tFtvgtDGc/U OLNqUqqj5kRFekXMBUIZmcdLdzbQPsHT+VOQyDUWEu62ChSX2QypMO2AdXvJgiG3GmRi TWrCOVeDLWT/IvEBj2ZjXPyRIzLOjpL9HisPqMyBsmIW07Q2G58M6ZeVJ8bzGcjsbCgO HTzw== 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:mime-version:content-transfer-encoding; bh=PbE2qfFBe6GYsESxfnvqNdhyVyD92IjDvn8DjhZslDM=; b=Rfl+zVf+bEQ7KvhI1M8tGHMdbUpVAKNjyvOPpjZLtUKM7aIOplykFi5y6SSiH3uTvK m4RxwJ0pxzCZwCwE0m46BJmxSrihp+0kVEC93ymg8tETCSFsunstO80zTIThcL9g7u9k MTXMw2DpsipB/fyWw1h6MUYF1mCU5I6oCyLEtiuEJQqw/kswVF4Ws/KMyPlZ7dDkorjd 7LD9THuqhabaKPwvEDj41B3Ahq2K62gQWxqX22EspKVUpWccjWtJ/0AxuQTebxfNoUvq zWdUx6LIUIWED+WjPdvJTAB0fdMDrW8SwUw4CfoNzjGfhQJTQ0txSTVMJAB+8DJxc52m v/LA== X-Gm-Message-State: AOAM53326GO0SHb/+Jeiclarbs4PqAP5xfKdae/tDH73GobIPQNLMm/5 TDOtWmR6wQqMpYBpWAJjgULu8Q== X-Google-Smtp-Source: ABdhPJz9oQRN3zhWVZyBfF+URj1GACWGeD105/MZy1aeE23hmNqVSavp+ikwVZXUzpRQowcUiF8PbQ== X-Received: by 2002:a05:620a:2549:: with SMTP id s9mr1455470qko.256.1629941216216; Wed, 25 Aug 2021 18:26:56 -0700 (PDT) Received: from aehse.localdomain (177-209-76-11.user3p.veloxzone.com.br. [177.209.76.11]) by smtp.gmail.com with ESMTPSA id p123sm1375053qke.94.2021.08.25.18.26.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Aug 2021 18:26:55 -0700 (PDT) From: Isabella Basso To: linux@sciencehorizons.net, 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 6/6] test_hash.c: refactor into kunit Date: Wed, 25 Aug 2021 22:26:26 -0300 Message-Id: <20210826012626.1163705-7-isabellabdoamaral@usp.br> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210826012626.1163705-1-isabellabdoamaral@usp.br> References: <20210826012626.1163705-1-isabellabdoamaral@usp.br> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Use KUnit framework to make tests more easily integrable with CIs. Even though these tests are not yet properly written as unit tests this change should help in debugging. Also drop module support and remove kernel messages (i.e. through pr_info) as KUnit handles all debugging output. Co-developed-by: Augusto Durães Camargo Signed-off-by: Augusto Durães Camargo Co-developed-by: Enzo Ferreira Signed-off-by: Enzo Ferreira Signed-off-by: Isabella Basso Tested-by: David Gow Reported-by: kernel test robot Reported-by: kernel test robot --- lib/Kconfig.debug | 28 ++++--- lib/Makefile | 2 +- lib/test_hash.c | 197 ++++++++++++++-------------------------------- 3 files changed, 79 insertions(+), 148 deletions(-) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 5e5894d98c50..adefb03a7e16 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2221,15 +2221,6 @@ config TEST_RHASHTABLE If unsure, say N. -config TEST_HASH - tristate "Perform selftest on hash functions" - help - Enable this option to test the kernel's integer (), and - string () hash functions on boot (or module load). - - This is intended to help people writing architecture-specific - optimized versions. If unsure, say N. - config TEST_SIPHASH tristate "Perform selftest on siphash functions" help @@ -2378,6 +2369,25 @@ config BITFIELD_KUNIT If unsure, say N. +config HASH_KUNIT_TEST + tristate "KUnit Test for integer hash functions" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS + help + Enable this option to test the kernel's string (), and + integer () hash functions on boot. + + KUnit tests run during boot and output the results to the debug log + in TAP format (https://testanything.org/). Only useful for kernel devs + running the KUnit test harness, and not intended for inclusion into a + production build. + + For more information on KUnit and unit tests in general please refer + to the KUnit documentation in Documentation/dev-tools/kunit/. + + This is intended to help people writing architecture-specific + optimized versions. If unsure, say N. + config RESOURCE_KUNIT_TEST tristate "KUnit test for resource API" depends on KUNIT diff --git a/lib/Makefile b/lib/Makefile index c2e81d0eb31c..0bc336d9d036 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -62,7 +62,7 @@ obj-$(CONFIG_TEST_BITOPS) += test_bitops.o CFLAGS_test_bitops.o += -Werror obj-$(CONFIG_TEST_SYSCTL) += test_sysctl.o obj-$(CONFIG_TEST_SIPHASH) += test_siphash.o -obj-$(CONFIG_TEST_HASH) += test_hash.o +obj-$(CONFIG_HASH_KUNIT_TEST) += test_hash.o obj-$(CONFIG_TEST_IDA) += test_ida.o obj-$(CONFIG_KASAN_KUNIT_TEST) += test_kasan.o CFLAGS_test_kasan.o += -fno-builtin diff --git a/lib/test_hash.c b/lib/test_hash.c index c168823b0963..84590bbf47dc 100644 --- a/lib/test_hash.c +++ b/lib/test_hash.c @@ -14,14 +14,10 @@ * and hash_64(). */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt "\n" - -#include #include -#include #include #include -#include +#include #define SIZE 256 /* Run time is cubic in SIZE */ @@ -29,7 +25,7 @@ static u32 string_or; /* stores or-ed string output */ static u32 hash_or[2][33] = { { 0, } }; /* stores or-ed hash output */ /* 32-bit XORSHIFT generator. Seed must not be zero. */ -static u32 __init __attribute_const__ +static u32 __attribute_const__ xorshift(u32 seed) { seed ^= seed << 13; @@ -39,7 +35,7 @@ xorshift(u32 seed) } /* Given a non-zero x, returns a non-zero byte. */ -static u8 __init __attribute_const__ +static u8 __attribute_const__ mod255(u32 x) { x = (x & 0xffff) + (x >> 16); /* 1 <= x <= 0x1fffe */ @@ -50,8 +46,7 @@ mod255(u32 x) } /* Fill the buffer with non-zero bytes. */ -static void __init -fill_buf(char *buf, size_t len, u32 seed) +static void fill_buf(char *buf, size_t len, u32 seed) { size_t i; @@ -62,41 +57,31 @@ fill_buf(char *buf, size_t len, u32 seed) } #ifdef HAVE_ARCH__HASH_32 -static bool __init -test_int_hash32(u32 *h0, u32 *h1, u32 *h2) +static bool test_int_hash32(struct kunit *test, u32 *h0, u32 *h1, u32 *h2) { hash_or[1][0] |= *h2 = __hash_32_generic(h0); #if HAVE_ARCH__HASH_32 == 1 - if (*h1 != *h2) { - pr_err("__hash_32(%#x) = %#x != __hash_32_generic() = %#x", - *h0, *h1, *h2); - return false; - } + KUNIT_ASSERT_EQ_MSG(test, *h1, *h2, + "__hash_32(%#x) = %#x != __hash_32_generic() = %#x", + *h0, *h1, *h2); #endif - return true; } #endif #ifdef HAVE_ARCH_HASH_64 -static bool __init -test_int_hash64(unsigned long long h64, u32 *h0, u32 *h1, u32 *h2, u32 const *m, int k) +static bool test_int_hash64(struct kunit *test, unsigned long long h64, u32 *h0, u32 *h1, + u32 *h2, u32 const *m, int k) { *h2 = hash_64_generic(*h64, *k); #if HAVE_ARCH_HASH_64 == 1 - if (*h1 != *h2) { - pr_err("hash_64(%#llx, %d) = %#x != hash_64_generic() = %#x", - *h64, *k, *h1, *h2); - return false; - } + KUNIT_ASSERT_EQ_MSG(test, *h1, *h2, + "hash_64(%#llx, %d) = %#x != hash_64_generic() = %#x", + *h64, *k, *h1, *h2); #else - if (*h2 > *m) { - pr_err("hash_64_generic(%#llx, %d) = %#x > %#x", - *h64, *k, *h1, *m); - return false; - } + KUNIT_ASSERT_LE_MSG(test, *h1, *h2, + "hash_64_generic(%#llx, %d) = %#x > %#x", + *h64, *k, *h1, *m); #endif - return true; - } #endif @@ -109,8 +94,7 @@ test_int_hash64(unsigned long long h64, u32 *h0, u32 *h1, u32 *h2, u32 const *m, * inline, the code being tested is actually in the module, and you can * recompile and re-test the module without rebooting. */ -static bool __init -test_int_hash(unsigned long long h64) +static void test_int_hash(struct kunit *test, unsigned long long h64) { int k; u32 h0 = (u32)h64, h1; @@ -122,7 +106,7 @@ test_int_hash(unsigned long long h64) /* Test __hash32 */ hash_or[0][0] |= h1 = __hash_32(h0); #ifdef HAVE_ARCH__HASH_32 - if (!test_int_hash32(&h0, &h1, &h2)) + if (!test_int_hash32(test, &h0, &h1, &h2)) return false; #endif @@ -132,27 +116,22 @@ test_int_hash(unsigned long long h64) /* Test hash_32 */ hash_or[0][k] |= h1 = hash_32(h0, k); - if (h1 > m) { - pr_err("hash_32(%#x, %d) = %#x > %#x", h0, k, h1, m); - return false; - } + KUNIT_ASSERT_LE_MSG(test, h1, m, + "hash_32(%#x, %d) = %#x > %#x", + h0, k, h1, m); /* Test hash_64 */ hash_or[1][k] |= h1 = hash_64(h64, k); - if (h1 > m) { - pr_err("hash_64(%#llx, %d) = %#x > %#x", h64, k, h1, m); - return false; - } + KUNIT_ASSERT_LE_MSG(test, h1, m, + "hash_64(%#llx, %d) = %#x > %#x", + h64, k, h1, m); #ifdef HAVE_ARCH_HASH_64 - if (!test_int_hash64(&h64, &h0, &h1, &h2, &m, &k)) - return false; + test_int_hash64(test, &h64, &h0, &h1, &h2, &m, &k); #endif } - - return true; } -static int __init test_string_or(void) +static void test_string_or(struct kunit *test) { char buf[SIZE+1]; int i, j; @@ -173,19 +152,14 @@ static int __init test_string_or(void) } /* 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; + KUNIT_ASSERT_FALSE_MSG(test, ~string_or, + "OR of all string hash results = %#x != %#x", + string_or, -1u); } -static int __init test_hash_or(void) +static void test_hash_or(struct kunit *test) { char buf[SIZE+1]; - unsigned tests = 0; unsigned long long h64 = 0; int i, j; @@ -201,39 +175,27 @@ static int __init test_hash_or(void) u32 h0 = full_name_hash(buf+i, buf+i, j-i); /* Check that hashlen_string gets the length right */ - if (hashlen_len(hashlen) != j-i) { - pr_err("hashlen_string(%d..%d) returned length" - " %u, expected %d", - i, j, hashlen_len(hashlen), j-i); - return -EINVAL; - } + KUNIT_ASSERT_EQ_MSG(test, hashlen_len(hashlen), j-i, + "hashlen_string(%d..%d) returned length %u, expected %d", + i, j, hashlen_len(hashlen), j-i); /* Check that the hashes match */ - if (hashlen_hash(hashlen) != h0) { - pr_err("hashlen_string(%d..%d) = %08x != " - "full_name_hash() = %08x", - i, j, hashlen_hash(hashlen), h0); - return -EINVAL; - } + KUNIT_ASSERT_EQ_MSG(test, hashlen_hash(hashlen), h0, + "hashlen_string(%d..%d) = %08x != full_name_hash() = %08x", + i, j, hashlen_hash(hashlen), h0); h64 = h64 << 32 | h0; /* For use with hash_64 */ - if (!test_int_hash(h64)) - return -EINVAL; - tests++; + test_int_hash(test, h64); } /* i */ } /* j */ - if (~hash_or[0][0]) { - pr_err("OR of all __hash_32 results = %#x != %#x", - hash_or[0][0], -1u); - return -EINVAL; - } + KUNIT_ASSERT_FALSE_MSG(test, ~hash_or[0][0], + "OR of all __hash_32 results = %#x != %#x", + hash_or[0][0], -1u); #ifdef HAVE_ARCH__HASH_32 #if HAVE_ARCH__HASH_32 != 1 /* Test is pointless if results match */ - if (~hash_or[1][0]) { - pr_err("OR of all __hash_32_generic results = %#x != %#x", - hash_or[1][0], -1u); - return -EINVAL; - } + KUNIT_ASSERT_FALSE_MSG(test, ~hash_or[1][0], + "OR of all __hash_32_generic results = %#x != %#x", + hash_or[1][0], -1u); #endif #endif @@ -241,65 +203,24 @@ static int __init test_hash_or(void) for (i = 1; i <= 32; i++) { u32 const m = ((u32)2 << (i-1)) - 1; /* Low i bits set */ - if (hash_or[0][i] != m) { - pr_err("OR of all hash_32(%d) results = %#x " - "(%#x expected)", i, hash_or[0][i], m); - return -EINVAL; - } - if (hash_or[1][i] != m) { - pr_err("OR of all hash_64(%d) results = %#x " - "(%#x expected)", i, hash_or[1][i], m); - return -EINVAL; - } + KUNIT_ASSERT_EQ_MSG(test, hash_or[0][i], m, + "OR of all hash_32(%d) results = %#x (%#x expected)", + i, hash_or[0][i], m); + KUNIT_ASSERT_EQ_MSG(test, hash_or[1][i], m, + "OR of all hash_64(%d) results = %#x (%#x expected)", + i, hash_or[1][i], m); } - - 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 - pr_info("__hash_32() is arch-specific; not compared to generic."); -#endif -#else - pr_info("__hash_32() has no arch implementation to test."); -#endif -#ifdef HAVE_ARCH_HASH_64 -#if HAVE_ARCH_HASH_64 != 1 - pr_info("hash_64() is arch-specific; not compared to generic."); -#endif -#else - pr_info("hash_64() has no arch implementation to test."); -#endif -} - -static int __init -test_hash_init(void) -{ - int ret; - - 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) -{ -} +static struct kunit_case hash_test_cases[] = { + KUNIT_CASE(test_string_or), + KUNIT_CASE(test_hash_or), + {} +}; -module_init(test_hash_init); /* Does everything */ -module_exit(test_hash_exit); /* Does nothing */ +static struct kunit_suite hash_test_suite = { + .name = "hash_tests", + .test_cases = hash_test_cases, +}; -MODULE_LICENSE("GPL"); +kunit_test_suite(hash_test_suite);