Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1895943pxb; Sat, 2 Oct 2021 00:30:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFwK+y8+jjjtC51siON67KUZOAT8ObnADoOHMzQP/U4nLNnnSorCFusx4y6Q2ryNpcowC3 X-Received: by 2002:a17:906:70c5:: with SMTP id g5mr2800097ejk.63.1633159828508; Sat, 02 Oct 2021 00:30:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633159828; cv=none; d=google.com; s=arc-20160816; b=fjuJkVAIsXQnEmtvG7U3olKhiHxUYTfQRYip94jgm3+yY81/xArLKTx0OmNxBmMJyC lRXFpZ6GbDwcitymS/GnYes7jbcnt6M5kF4m8IOhxBOPYugs+SHfa11vbkeRn4J1IXNj H/nQyo+zze2YO4VH1+NIPOK8g0maNHtTJM8nGhArN39VV5IMaMKj5RYWUcKL2p4tojpd 5MTrcC3O02sPzteIQhKTKVmZ5bKpY5IBH5JnUZtMMPqS+KwWAs9e08SqWjQLHcBAm2YR wqcjKA/oAU+07LPwFx5E6DnId1CFPRoR8yPkDxJRLQ8UoXhLXvvCun++GVTylbzsuOAT doWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=T1Ud3yDO/mU6TccdcskPnDQTaXDLehnkBGI7d6s35xM=; b=zzpqmo2EEPUZ6KSq9CV7NobwGuZ5q5ZmnJALh/oSZyD7nx8GLtQbpFD7wp/F8kurIi 7wpRihw55Hp0c39QMWLXU1MWFRNShtcAl07kJHbeHTjoLcMrk7mHScSqwmDkEsdK3LkH 8VUih7DoO+fOSaZ0CSxa8cuPbzl0DsbGFqsKxUsrvdPjMbIb5F744KKifYytN/RQHPzp ZRUo/dpfSwZVxTAIY0RB0j5EUNa7f2RiwozXNxidb9NdLURWhHQHGTJgLl2qpleKMqZ7 DVJkXAQuSzPaJdMP1+ERoGDCbazeVzcPC9lRcf/1MtprduR4obhcWg3U+0Xty3RB3mJX Ms3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=B0EcOkKc; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y2si9832228ejr.90.2021.10.02.00.30.04; Sat, 02 Oct 2021 00:30:28 -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=@google.com header.s=20210112 header.b=B0EcOkKc; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232536AbhJBHW3 (ORCPT + 99 others); Sat, 2 Oct 2021 03:22:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232505AbhJBHWZ (ORCPT ); Sat, 2 Oct 2021 03:22:25 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91265C061775 for ; Sat, 2 Oct 2021 00:20:39 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id l18-20020a05600c4f1200b002f8cf606262so13016547wmq.1 for ; Sat, 02 Oct 2021 00:20:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=T1Ud3yDO/mU6TccdcskPnDQTaXDLehnkBGI7d6s35xM=; b=B0EcOkKcH3oEQb7zcg9ToBGl49Rxgm9YBwkA6a4QdbCQqnY+1hJkg5bV+35BR1Fc8M lf13Nv7bgPZWZOpYZMa9ytM+a1/VhHOMZBaU8CZBBOYsRxFxQdWCM0SIr3n1zHnh42gm zYKYo8xQGDzPmR+wJLwPMjH7hPL9JyYuOvPYx6P3LR0xMub7nCaGFZqaCZPLr49bO+tP 8u40ttpjkXTtTZKDFgQQLFaJB8Qrh2Y/I5uFxeSvomknEV2BH385POo9XNfzxTkCKdqx DqUakPPOmGw995gSbqgCzGzMVctudL8OVyZZJVNh0pSi1aoYYWV1TDfjFB/13pEow5Y7 lGJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=T1Ud3yDO/mU6TccdcskPnDQTaXDLehnkBGI7d6s35xM=; b=lUWcsuTSkJMdGDlJQ5Zw8Sq2AH7DLFCegbWu6LiwCorBJgtG5BTY3Ogxt+u0E+k2rg uhu3gBN4J0SJ6bAS9myEJMo6k6QokuMiY7QBlyYyBd9LnkqiDlCYi6GaNCb4b2tM9f9c lxWvDnPMkWoB4eKRkeqLfaKLOx8QOCgajVv6uD/UcCsIroI4nnoTu7c2ldCPYYMZ3nKL v5P96gmEFm9cn0fi+7mSfgaXFgYDMXiWVeB9FtVTlO1BwHp+0kZmB1tZKR2vk3XU7L8Y EMhKO0K5aCAKAMkW4D+38iGFLH890oVnY1+L/F1iNeMNs9vMMLVFEMJCIH2SddMx27ks Z+Ug== X-Gm-Message-State: AOAM532Lsg5Mt0TrwOF8ORx3+tbbCofvgMxEvjEfxZQ4fVW1I8mvcwdF RiWdjAna7ie6mNNPeY9nup1DopGwJNfOr3BwOXcncQ== X-Received: by 2002:a05:600c:4eca:: with SMTP id g10mr8303412wmq.16.1633159238067; Sat, 02 Oct 2021 00:20:38 -0700 (PDT) MIME-Version: 1.0 References: <20210926223322.848641-1-isabellabdoamaral@usp.br> <20210926223322.848641-4-isabellabdoamaral@usp.br> In-Reply-To: <20210926223322.848641-4-isabellabdoamaral@usp.br> From: David Gow Date: Sat, 2 Oct 2021 15:20:27 +0800 Message-ID: Subject: Re: [PATCH v2 3/5] test_hash.c: split test_hash_init To: Isabella Basso Cc: Geert Uytterhoeven , ferreiraenzoa@gmail.com, augusto.duraes33@gmail.com, Brendan Higgins , Daniel Latypov , "open list:KERNEL SELFTEST FRAMEWORK" , Linux Kernel Mailing List , KUnit Development , ~lkcamp/patches@lists.sr.ht, rodrigosiqueiramelo@gmail.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 27, 2021 at 6:33 AM Isabella Basso wrote: > > 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. Nit: Move the changelog to after the "---" (and the correct patch). > > Tested-by: David Gow > Signed-off-by: Isabella Basso > --- This seems good to me, though I admit this is the part I'm probably least knowledgeable about. I'm pretty sure there has to be a more straightforward way to test some of these hash functions, but it's probably better to keep this as-is rather than doing anything too drastic in the middle of the port to KUnit. The biggest downside here is that we now double the number of calls to fill_buffer() and full_name_hash(), so the test is likely to be a bit slower. It still runs fast enough (at least with the default SIZE of 256) that it's not noticeable to me, though, so I don't think it's a problem. Apart from Marco's comment about the changelog in the commit message is fixed, this is: Reviewed-by: David Gow Cheers, -- David > 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 >