From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from purple.birch.relay.mailchannels.net (purple.birch.relay.mailchannels.net [23.83.209.150]) by sourceware.org (Postfix) with ESMTPS id 988F6385782C for ; Tue, 17 May 2022 04:32:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 988F6385782C 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 3AB49121370; Tue, 17 May 2022 04:32:14 +0000 (UTC) Received: from pdx1-sub0-mail-a304.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id D3EF2121351; Tue, 17 May 2022 04:32:13 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1652761933; a=rsa-sha256; cv=none; b=0tHxyey80O9UhTlh1kMPm3BsSTRjX5V6RFMr/JFub7jf2wpH3Zbvscjq1XS3xBatSTl1Mf OAhQRYptg+eEMJjsWcyxsn6TsOLZ9wpMlB9WZTdWS+dIBpShg2A1VmLR8qBiHvRWSJibrT YaWpAGZ/fT0/u4tP+SkbSts6bTrlTDoyy+kUkXbef+RiI/oBXKKQkLphjUa5h+ZPXwhCIX XzR8+1JDreKpcmGEPY/lfMToj56+17ivk3UWkRFQSNAwQWjAS9yIz58OSmpiiAyVvj5jQ8 y483n5Vo2WHWXaN4C17i/n+E0sQG3JID/gudyZMY799qrJNONjt4WNWXsQr1kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1652761933; 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=HHGxikuPiwnPkFrF1amsV7q+RaeTqbblkSRuVaMGD0Y=; b=5DYqji65FltQhlKLkIx869eQPodFkeLB0HaAwyJ2unZWBW3d7nt893XV+PoJs3VS20GFkw wWx5wj7FulOvwmXANOfTvIMc7nudNo61xxUQHvAxEZR4ihUeUf3VUigTjRC55n3yswItm7 anZdhBNavM1BZAjyicH6OxomYtcqPWXlqMKvKGc+KOhYtZ0SB07nAmaHAsDG+2h0BGDNaK yxykfvWJ0ak4TS2VP0EP0a8tWR14xm6+IX0gLcAMiTkVP5mk4aTjVcedkvvPny9n73UB+C V8tvGilaHlnqW7nLdPW6058iYQY5E8k2vqCVJxNtzD7b8CZrnHFoZIBd0szqpA== ARC-Authentication-Results: i=1; rspamd-6fcfc4d76-9x94h; 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-Power-Power: 15b2fad50f27fd0d_1652761934097_2959965857 X-MC-Loop-Signature: 1652761934097:4127262144 X-MC-Ingress-Time: 1652761934097 Received: from pdx1-sub0-mail-a304.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); Tue, 17 May 2022 04:32:14 +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-a304.dreamhost.com (Postfix) with ESMTPSA id 4L2NWJ4ZqWz1K6; Mon, 16 May 2022 21:32:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1652761933; bh=HHGxikuPiwnPkFrF1amsV7q+RaeTqbblkSRuVaMGD0Y=; h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding; b=LhYV366DsIid+SLfmyyEVt5P9VkC4eC+M85w89HA570mmHEP9L6a8M636kNCG3ynA CW7aagy0GdzmW0oeGl0qYZ2y5h84kWVjKuFgmI3QAkEXujKFLvR0yv/dgm9DEEtm+u Hbayddhz8FW8PagiMaLqvWzDS4JpOETYYNoR+SlAuRNHq9HRbiVhgEbRC8Oj++1Wr7 emUaE5WlpZIdY/zuXVJv9BGvBKf/YQX9zNjI6xpc9Q9kn1q1OxzJA+t2a6T2fgcCTM ASyRijzmx8PjgTmo4QospKuv7Ip6ahCp5QYHMd4lrO+y9g9Ja8uzqiwUPW3yWP43Sm yFnQ093+3t87g== Message-ID: Date: Tue, 17 May 2022 10:02:07 +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 v9 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> <20220516203004.38687-1-goldstein.w.n@gmail.com> <20220516203004.38687-3-goldstein.w.n@gmail.com> From: Siddhesh Poyarekar In-Reply-To: <20220516203004.38687-3-goldstein.w.n@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3036.8 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: Tue, 17 May 2022 04:32:18 -0000 On 17/05/2022 02:00, Noah Goldstein via Libc-alpha wrote: > If we want to further optimize the function tests are needed. > --- > nss/Makefile | 1 + > nss/tst-nss-hash.c | 105 +++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 106 insertions(+) > create mode 100644 nss/tst-nss-hash.c > > 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/tst-nss-hash.c b/nss/tst-nss-hash.c > new file mode 100644 > index 0000000000..6bb2ce06ab > --- /dev/null > +++ b/nss/tst-nss-hash.c > @@ -0,0 +1,105 @@ > +/* Test __nss_hash > + Copyright (C) 2017-2022 Free Software Foundation, Inc. New file, so only 2022? > + 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 > + > +uint32_t __nss_hash (const void *__key, size_t __length); > + > +/* Simplist implementation of __nss_hash. */ > +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; > +} Same as dl-hash, it may make sense to maintain this in elf/nss-hash.c: #ifdef __nss_hash /* Describe the reference macro */ static uint32_t __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; } #else static uint32_t __nss_hash (const void *keyarg, size_t len) { ... the current implementation... } #endif It can then be included like so: #define __nss_hash simple_nss_hash #include "nss_hash.c" > + > +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) > + { Redundant paranthesis. > + 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) > + { Redundant paranthesis. > + buf[i] = random (); > + } > + > + expec = simple_nss_hash (buf, len); > + res = __nss_hash (buf, len); > + if (expec != res) > + { > + printf ("FAIL: random (%zu), %x != %x\n", len, expec, res); > + return 1; > + } > + > + 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)) > + { Redundant paranthesis. > + return 1; > + } > + if (do_fill_tests (i, -1) || do_fill_tests (i, 1) > + || do_fill_tests (i, 0x80) || do_fill_tests (i, 0x88)) > + { Redundant paranthesis. > + return 1; > + } > + } > + } > + return 0; > +} > + > +#include