From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from black.elm.relay.mailchannels.net (black.elm.relay.mailchannels.net [23.83.212.19]) by sourceware.org (Postfix) with ESMTPS id 80FC3394BE17 for ; Thu, 19 May 2022 15:09:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 80FC3394BE17 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 165A1C1068; Thu, 19 May 2022 15:09:13 +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 6C299C1FF3; Thu, 19 May 2022 15:09:12 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1652972952; a=rsa-sha256; cv=none; b=nLL+OO6iB8KoOb48/rQZICO0KX2BCyYAX4gV0xLfCe2m+3JyWcilkLwE7ZFFge/wCHAfTY 1rHlGY64oHB2zZR/rauurk1aQLp5mR/qV97csEMVDr6HRWQyNblygoNJbf23NfL9lPajPM GXzguxiEwAJkKwendEoiEfp6/fTyRsVFzw3RnERuUDPZnWOOntDOEOypQ1YaLaQK2FO9b3 rA7sGjoF4slAb5oD87X8ltoA4e9ElHLLMOkf6fj2r1lXWp0ps+2CH5C9qO3DDvxaCYJyqz 5MDaZ2icylJmTuZlK/WW3761jzq3v1R3WRtQHAkVOPTSRpWB3J841A3zSIvR3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1652972952; 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=scpdxHlvxIiYCK0RTBQLF9sXb92HoeLaZxg50iGs6E4=; b=iC5vlNA+gJ+ul8NQu3fLN3aUYIsE4c3MrJQgoF6mkdV1o4QpCX19MoF4X1oOkP6v/DyHnH UXuOjn3k9gCjIssYfYF3292oXnHoR5UHpjUMxfLvcMBU7s8VYt+Vz7iy8Xw+XIPFXOz8DD LgYexRKLFb6jWQZMfq+62lr1V3CqTQi2hFgwC+GqQwdHkNoBJswaAXPIN/8OOrxz1Bbrsz OBQSaiLEYcADQUqVMzN9CeEryEinxgHkF5F+gFvsxeJGSqC66dIhDjGalFmwdgS8073o2o LqKsMr6cAEeOQJWFK42y4tgQan3+gXCqD89jQKKc5CpAUK7fG3pDNQRHYIfZnQ== ARC-Authentication-Results: i=1; rspamd-554c8f6c56-6m84f; 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-Average-Ski: 5158a801024dea0f_1652972952708_1201845738 X-MC-Loop-Signature: 1652972952708:2418843788 X-MC-Ingress-Time: 1652972952707 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.101.255.183 (trex/6.7.1); Thu, 19 May 2022 15:09:12 +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)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a307.dreamhost.com (Postfix) with ESMTPSA id 4L3tYM09SfzlP; Thu, 19 May 2022 08:09:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1652972952; bh=scpdxHlvxIiYCK0RTBQLF9sXb92HoeLaZxg50iGs6E4=; h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding; b=ptgqYWOwAP8isbZpG2p+LjAfZ5kmViozh7RAPUF7WDkNcL1Ta2TnjCNBdAqyOynLz bJ6leIAKWKOVSDxe2/+olRHG1n9B3y0KzmUJLunLpthA7LMnjbA7Wec035aRaPuSEG TsITle8tpToTGew84fL8HcpywyQJ8b115qNscyYkFj5zLph2BKq201WOnmHZ2LxexW JwAhRDF1sf5wF1ufjltoOqSeZ9FDyIph/9x8Mkaan7OLFQF3d4P0LOPIRC4XXJnJ0S D3pcGdGera2pp+GehptZ2pYgWZRNtJOF22Hn+kHjMG9AhYyaNx5lT2mum7xjN1oW+6 f5Z0B4cUXDUPA== Message-ID: <22a2afdb-a68c-f30c-e080-093e29c04d25@gotplt.org> Date: Thu, 19 May 2022 20:39:06 +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 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> From: Siddhesh Poyarekar In-Reply-To: <20220518172635.291119-3-goldstein.w.n@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3037.0 required=5.0 tests=BAYES_00, 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:09:17 -0000 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; > +} > + > + > 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