From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dog.birch.relay.mailchannels.net (dog.birch.relay.mailchannels.net [23.83.209.48]) by sourceware.org (Postfix) with ESMTPS id 80930395443A for ; Thu, 19 May 2022 15:40:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 80930395443A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id F0B14213D1; Thu, 19 May 2022 15:40:18 +0000 (UTC) Received: from pdx1-sub0-mail-a307.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 314CC218F8; Thu, 19 May 2022 15:40:18 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1652974818; a=rsa-sha256; cv=none; b=G1UIP0lK6+rpAJAqjecZTYfJce0/Elx/YXNdYHKWhhblf5bc9+NnyKJei3EoBbNaZrhI6E lClmXhm1wGLf03M8x5EFXY+cfOge+MkSmgMsSXatpJYkM0xS5YKRMGDu+yV1/T6uK32oFV SrGyWU/g55icOfbVsS6NRtVmgb+IMCRIoILpIXn5YPbkR4/I4Z92U4rmZ/4PhO6b5fG9/P E4tdOY4hguiMvqIovWpFB4nwjicdnWqP7T1A2J+svbBg3jPLBKyikuRTx7IkRTqMQApPFn fcRiHqUADNExVgRl/DY6kdbB7sViUrUavnw/d8BOzo//BbV2+P88rlvqmPZvKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1652974818; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/Pr5qL9bh/w6GNPn7U8eedJGhVojAg99K5iGAwzt8Vk=; b=QKPrm1t0ZXha/LYD+J9pz2NtM2FPWmGvQRUSWZuBDVnXxWUinbaDCZC1riTxEY8wjy/dWr P4TjxtU5P/UT+q7lV4T9eKjRaxKL/BM/8wPJHFWecxUH0i8V33Se0sCkehHVmwxExHwoFn hdD8Gqfk1cQ7OWVOyFVDT1ou5F6u5BstjPDQ4orsUBNgp64bFNECGrg8ACN+c6sUgHbNvw N43s0UK8Ad3jT4lTRB7il8lj1UBsTWd8B2E6CD5eJm37Kzf0BOlvENKPaqhJJDnziP22fC dL7sOHP+3HAYE7JI6R5vvL6zYpB5mrQ2xYCCITldb+3FrjU61LXtAumSumiSJA== ARC-Authentication-Results: i=1; rspamd-6fcfc4d76-ffqgq; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Abaft-Industry: 00e5c1d15c413f57_1652974818452_3587572065 X-MC-Loop-Signature: 1652974818452:1247216125 X-MC-Ingress-Time: 1652974818452 Received: from pdx1-sub0-mail-a307.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.96.96.15 (trex/6.7.1); Thu, 19 May 2022 15:40:18 +0000 Received: from [192.168.1.174] (unknown [1.186.223.88]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a307.dreamhost.com (Postfix) with ESMTPSA id 4L3vFF0XbCz3B; Thu, 19 May 2022 08:40:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1652974817; bh=/Pr5qL9bh/w6GNPn7U8eedJGhVojAg99K5iGAwzt8Vk=; h=Date:Subject:From:To:Content-Type:Content-Transfer-Encoding; b=owZOHOHHVvEXr8Xq4Q8QUq7Ka/yQIHnTsbXs1zJJXlhQNj6Y4hsP+LoJrRmY0YxaN QbXnuEjziAmMlJbeSirLOhYAtc8YIqnKxI2VeOVRKuFlmDi5V40kXlITdfLwt85RnU y/8vuncLJDoWrp38WEe4moBAd0EPV41ecU9cjqWtniJfM+3RmVtl++RqCjWeUJaZUM 6BmR5wrBTXk7OepzTiFyqIrKUMGfv0WIr9TCtTf/reffTneHj4ZwuOi1FtUN6ZRgNU 3K+SF1Q0qfv3O8WoO8KcoENfOJA6f0oQGsmhI7fmb+gopBW26uj718Sp2TEccnThGJ dnO9C3+wu9I9g== Message-ID: <844b5851-38ca-3785-4f3a-5d219ea62d2d@gotplt.org> Date: Thu, 19 May 2022 21:10:12 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH v10 3/6] nss: Add tests for the nss_hash in nss_hash.h Content-Language: en-US From: Siddhesh Poyarekar To: Noah Goldstein , libc-alpha@sourceware.org References: <20220414041231.926415-1-goldstein.w.n@gmail.com> <20220518172635.291119-1-goldstein.w.n@gmail.com> <20220518172635.291119-3-goldstein.w.n@gmail.com> <22a2afdb-a68c-f30c-e080-093e29c04d25@gotplt.org> In-Reply-To: <22a2afdb-a68c-f30c-e080-093e29c04d25@gotplt.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3035.5 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 May 2022 15:40:23 -0000 On 19/05/2022 20:39, Siddhesh Poyarekar wrote: > On 18/05/2022 22:56, Noah Goldstein via Libc-alpha wrote: >> If we want to further optimize the function tests are needed. >> --- >>   nss/Makefile          |  1 + >>   nss/nss_hash.c        | 16 +++++++++ >>   nss/simple-nss-hash.h | 42 +++++++++++++++++++++++ >>   nss/tst-nss-hash.c    | 80 +++++++++++++++++++++++++++++++++++++++++++ >>   4 files changed, 139 insertions(+) >>   create mode 100644 nss/simple-nss-hash.h >>   create mode 100644 nss/tst-nss-hash.c > > LGTM. > > Reviewed-by: Siddhesh Poyarekar > >> >> diff --git a/nss/Makefile b/nss/Makefile >> index d8b06b44fb..a978e3927a 100644 >> --- a/nss/Makefile >> +++ b/nss/Makefile >> @@ -62,6 +62,7 @@ tests := \ >>     test-digits-dots \ >>     test-netdb \ >>     tst-nss-getpwent \ >> +  tst-nss-hash \ >>     tst-nss-test1 \ >>     tst-nss-test2 \ >>     tst-nss-test4 \ >> diff --git a/nss/nss_hash.c b/nss/nss_hash.c >> index 27a348ea9b..f9e17d068a 100644 >> --- a/nss/nss_hash.c >> +++ b/nss/nss_hash.c >> @@ -75,4 +75,20 @@ __nss_hash (const void *keyarg, size_t len) >>     return h; >>   } >> +/* For testing/benchmarking purposes. */ >> +static uint32_t >> +__simple_nss_hash (const void *keyarg, size_t len) >> +{ >> +  const unsigned char *key; >> +  size_t i; >> +  uint32_t h = 0; >> +  key = keyarg; >> + >> +  for (i = 0; i < len; ++i) >> +    h = *key++ + 65599 * h; >> + >> +  return h; >> +} >> + >> + It just struck me (while reviewing 5/6) that this is duplicated in simple-nss-hash.h below. Shouldn't it be one or the other? I know it's "fixed" in 5/6 but it would be nice to restructure things so that the tree builds at this point of the patchset too. >>   libc_hidden_def (__nss_hash) >> diff --git a/nss/simple-nss-hash.h b/nss/simple-nss-hash.h >> new file mode 100644 >> index 0000000000..47708972e7 >> --- /dev/null >> +++ b/nss/simple-nss-hash.h >> @@ -0,0 +1,42 @@ >> +/* __simple_nss_hash for testing nss_hash function >> +   Copyright (C) 2022 Free Software Foundation, Inc. >> +   This file is part of the GNU C Library. >> + >> +   The GNU C Library is free software; you can redistribute it and/or >> +   modify it under the terms of the GNU Lesser General Public >> +   License as published by the Free Software Foundation; either >> +   version 2.1 of the License, or (at your option) any later version. >> + >> +   The GNU C Library is distributed in the hope that it will be useful, >> +   but WITHOUT ANY WARRANTY; without even the implied warranty of >> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU >> +   Lesser General Public License for more details. >> + >> +   You should have received a copy of the GNU Lesser General Public >> +   License along with the GNU C Library; if not, see >> +   .  */ >> + >> +#ifndef _SIMPLE_NSS_HASH_H >> +#define _SIMPLE_NSS_HASH_H 1 >> + >> +#include >> + >> +/* For testing/benchmarking purposes.  Real implementation in >> +   nss/nss_hash.c.  */ >> +static uint32_t >> +__attribute__ ((unused)) >> +__simple_nss_hash (const void *keyarg, size_t len) >> +{ >> +  const unsigned char *key; >> +  size_t i; >> +  uint32_t h = 0; >> +  key = keyarg; >> + >> +  for (i = 0; i < len; ++i) >> +    h = *key++ + 65599 * h; >> + >> +  return h; >> +} >> + >> + >> +#endif /* simple-nss-hash.h */ >> diff --git a/nss/tst-nss-hash.c b/nss/tst-nss-hash.c >> new file mode 100644 >> index 0000000000..5ec1f9b0c5 >> --- /dev/null >> +++ b/nss/tst-nss-hash.c >> @@ -0,0 +1,80 @@ >> +/* Test __nss_hash >> +   Copyright (C) 2022 Free Software Foundation, Inc. >> +   This file is part of the GNU C Library. >> + >> +   The GNU C Library is free software; you can redistribute it and/or >> +   modify it under the terms of the GNU Lesser General Public >> +   License as published by the Free Software Foundation; either >> +   version 2.1 of the License, or (at your option) any later version. >> + >> +   The GNU C Library is distributed in the hope that it will be useful, >> +   but WITHOUT ANY WARRANTY; without even the implied warranty of >> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU >> +   Lesser General Public License for more details. >> + >> +   You should have received a copy of the GNU Lesser General Public >> +   License along with the GNU C Library; if not, see >> +   .  */ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +uint32_t __nss_hash (const void *__key, size_t __length); >> + >> +static int >> +do_fill_tests (size_t len, int fill) >> +{ >> +  uint32_t expec, res; >> +  char buf[len]; >> +  memset (buf, fill, len); >> + >> +  expec = __simple_nss_hash (buf, len); >> +  res = __nss_hash (buf, len); >> +  if (expec != res) >> +    FAIL_EXIT1 ("FAIL: fill(%d) (%zu), %x != %x\n", fill, len, expec, >> res); >> + >> +  return 0; >> +} >> + >> +static int >> +do_rand_tests (size_t len) >> +{ >> +  uint32_t expec, res; >> +  size_t i; >> +  char buf[len]; >> +  for (i = 0; i < len; ++i) >> +    buf[i] = random (); >> + >> +  expec = __simple_nss_hash (buf, len); >> +  res = __nss_hash (buf, len); >> +  if (expec != res) >> +    FAIL_EXIT1 ("FAIL: random (%zu), %x != %x\n", len, expec, res); >> + >> +  return 0; >> +} >> + >> +static int >> +do_test (void) >> +{ >> +  size_t i, j; >> +  for (i = 0; i < 100; ++i) >> +    { >> +      for (j = 0; j < 8192; ++j) >> +    { >> +      if (do_rand_tests (i)) >> +        return 1; >> + >> +      if (do_fill_tests (i, -1) || do_fill_tests (i, 1) >> +          || do_fill_tests (i, 0x80) || do_fill_tests (i, 0x88)) >> +        return 1; >> +    } >> +    } >> +  return 0; >> +} >> + >> +#include >