LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Isabella B do Amaral <isabellabdoamaral@usp.br>
To: David Gow <davidgow@google.com>
Cc: "Geert Uytterhoeven" <geert@linux-m68k.org>,
	"Enzo Ferreira" <ferreiraenzoa@gmail.com>,
	"Augusto Durães Camargo" <augusto.duraes33@gmail.com>,
	"Brendan Higgins" <brendanhiggins@google.com>,
	"Daniel Latypov" <dlatypov@google.com>,
	"open list:KERNEL SELFTEST FRAMEWORK"
	<linux-kselftest@vger.kernel.org>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"KUnit Development" <kunit-dev@googlegroups.com>,
	~lkcamp/patches@lists.sr.ht, rodrigosiqueiramelo@gmail.com
Subject: Re: [PATCH 3/6] test_hash.c: split test_int_hash into arch-specific functions
Date: Sun, 5 Sep 2021 19:53:56 -0300	[thread overview]
Message-ID: <CAAniXFQBZUFrRV6c_g9L_yqFMYyvz4DDyof5cOtPc8kWMR+jiw@mail.gmail.com> (raw)
In-Reply-To: <CABVgOSkhN-DPYnhuTG1hGU-2aP0MEaKjz+0=Sr_VNKUhpgz79g@mail.gmail.com>

Hi, David,

On Thu, Aug 26, 2021 at 1:21 AM David Gow <davidgow@google.com> wrote:
>
> On Thu, Aug 26, 2021 at 9:26 AM Isabella Basso <isabellabdoamaral@usp.br> wrote:
> >
> > 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 <isabellabdoamaral@usp.br>
> > ---
>
> I like this, but have a note below. It _may_ be worth combining some
> of these test refactoring patches with the KUnit port patch:
> definitely a matter of taste rather than something I think is
> necessary, but I personally think they're related enough they could go
> together if you wanted.

I'm not really comfortable with such big diffs, to be honest, but I'll keep
this in mind!

> >  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)
>
> I'm unsure about this name. Having test_int_hash32() test only
> __hash_32(), where test_int_hash64() tests hash_64() feels a little
> bit inconsistent. Maybe this is somewhere we should have the extra
> underscore like in HAVE_ARCH__HASH_32.
>
> I get that because the architecture-specific hash_32() is removed
> earlier, there's no need for an extra function to test how that
> compares against a generic function, so there's no conflict here, but
> it did confuse me briefly.

I see your point. This actually hadn't occurred to me. Now I'm thinking
test_int__hash_32() (and, by extension, test_int_hash_64()) should make for a
clearer naming convention.

> The other option is, as mentioned in the earlier patch, to keep the
> architecture-specific hash_32() (and _maybe_ get rid of __hash_32()
> entirely), in which case this name would be perfect for testing that.
>
> > +{
> > +       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);
>
> These whitespace changes probably aren't necessary.

Oops, that's my bad. Really unintended changes, thanks for the heads up!

> >                                 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);
>
> These whitespace changes probably aren't necessary.
>
> >                                 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);
>
> This whitespace change probably isn't necessary.
>
> >                 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);
>
> You get the idea...
>
> >                 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;
> >                 }
> >         }
> > --
> > 2.33.0

Thanks,
--
Isabella Basso

  reply	other threads:[~2021-09-05 22:54 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-26  1:26 [PATCH 0/6] test_hash.c: refactor into KUnit Isabella Basso
2021-08-26  1:26 ` [PATCH 1/6] hash.h: remove unused define directive Isabella Basso
2021-08-26  4:01   ` David Gow
2021-09-05 22:31     ` Isabella B do Amaral
2021-08-26  1:26 ` [PATCH 2/6] test_hash.c: move common definitions to top of file Isabella Basso
2021-08-26 14:36   ` Marco Elver
2021-09-05 22:40     ` Isabella B do Amaral
2021-08-26  1:26 ` [PATCH 3/6] test_hash.c: split test_int_hash into arch-specific functions Isabella Basso
2021-08-26  4:21   ` David Gow
2021-09-05 22:53     ` Isabella B do Amaral [this message]
2021-08-26  1:26 ` [PATCH 4/6] test_hash.c: split test_hash_init Isabella Basso
2021-08-26  1:26 ` [PATCH 5/6] lib/Kconfig.debug: properly split hash test kernel entries Isabella Basso
2021-08-26  1:26 ` [PATCH 6/6] test_hash.c: refactor into kunit Isabella Basso
2021-08-26  4:26   ` David Gow
2021-09-05 23:32     ` Isabella B do Amaral
2021-08-26  6:00   ` kernel test robot
2021-08-26 10:10   ` kernel test robot
2021-08-26  1:36 ` [PATCH 0/6] test_hash.c: refactor into KUnit Daniel Latypov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAAniXFQBZUFrRV6c_g9L_yqFMYyvz4DDyof5cOtPc8kWMR+jiw@mail.gmail.com \
    --to=isabellabdoamaral@usp.br \
    --cc=augusto.duraes33@gmail.com \
    --cc=brendanhiggins@google.com \
    --cc=davidgow@google.com \
    --cc=dlatypov@google.com \
    --cc=ferreiraenzoa@gmail.com \
    --cc=geert@linux-m68k.org \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=rodrigosiqueiramelo@gmail.com \
    --cc=~lkcamp/patches@lists.sr.ht \
    --subject='Re: [PATCH 3/6] test_hash.c: split test_int_hash into arch-specific functions' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).