From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from beige.elm.relay.mailchannels.net (beige.elm.relay.mailchannels.net [23.83.212.16]) by sourceware.org (Postfix) with ESMTPS id AB810383E6A5 for ; Mon, 23 May 2022 07:43:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AB810383E6A5 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 76CA8121F40; Mon, 23 May 2022 07:42:59 +0000 (UTC) Received: from pdx1-sub0-mail-a305.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 0E7CF1211BE; Mon, 23 May 2022 07:42:59 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1653291779; a=rsa-sha256; cv=none; b=qQyRrh3a7OCUYsiuoV274N1tK1cfwUKaofmpwJ2c0NeT+hyZ+LOSFEW782WR6NJml4o7uH gYJ2jFKgR9Up7J8HavWgS61xX5iJVEykn07kybS1M9zIehrYjb9poF30IUHfIesqhcrGUA EPcsUGX4xgyWkDg4iGXjPEE08GFvysvuviqm07U8OSfgGQ/5cyOxK9woGzJh35hupBqagh ONbf0BoyHX48EZkqQfzWnau3IomeD3/JIePendPOvwQ0l2jCDlzFgSzmVtgUYZjjRopj+O e4Hwl7radqzbYZ0G6/V5AUzmkYSDLxb6Etsjn7d7GgXiRVor99OWJoRiZhPVyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1653291779; 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=S1AAv11+TULH4WxPp374PeCxI70Rywta2/TtKsggYUY=; b=4lDeeYESOyggRDUEruVBvsixtbuyAvnZ8NjuJSXJozVEu5t+4lpjMtfjwIT6mi5/ZwfMkx /CED77Rzbp+kfG1q9aHZfj1bcVF62fF8xTDJVLt8+V6SbLUt6vks9MZlQj4uBK7iA0IJQv dUX4zjTHnbVB2iN3bNChNTCtXvzJ+NNIUUIOHp9O+ESX7S98DwJ5cY1NWi26FXVYl8iwsP IBniORx/CI9Sc34M0DOFLqSvtMKXZClfTj3R0tU4mNgzGW8SqIAeTHUPNQJiCQn6Dx5HsY MpF0YdF0Hz4b+XCFmT3Zy2ZyqvmCwo1+KxWFbmK870onFZxkUjVPYPt8HEZXUg== ARC-Authentication-Results: i=1; rspamd-54dc6fd65d-mxj97; 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-Squirrel-Cellar: 7056ab4630d6439a_1653291779275_90510782 X-MC-Loop-Signature: 1653291779275:3147821608 X-MC-Ingress-Time: 1653291779275 Received: from pdx1-sub0-mail-a305.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.120.38.156 (trex/6.7.1); Mon, 23 May 2022 07:42:59 +0000 Received: from [100.96.149.178] (unknown [49.248.235.144]) (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-a305.dreamhost.com (Postfix) with ESMTPSA id 4L68Sd6TPyz24; Mon, 23 May 2022 00:42:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1653291778; bh=S1AAv11+TULH4WxPp374PeCxI70Rywta2/TtKsggYUY=; h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding; b=dm4rPaeWbg59eLQNzeTyvxlOxaecNeYHOlSG1JJJEuJpjFiUmU0ng2ToYi4C7hoXS 35bNqRA0HuJ2zqa+nB0ZS9ntP0nWSSjIceErIrRYqFpBZPysPyj9zqRtGjDS5dXbkh XNZFLXorlZwTOL0dneKiBdL35CN2C/NHJmMrV78Llci6+nSbQ0AL1VQVU4a0F2neQO ZHnwPLCVt1G6xhyiuGSnU8G76hQv0XLBCk37FY/zLEqt0Im6Krx3XUs8XzQuVZTsn9 BNA1W4Fym0sX42UgB+9eCnzQdJPMaiaeEN3Y4+A0SIuMe7YHzWkBMm21eHVGkewRVv BRuiryK2YXZdw== Message-ID: <7883a558-c5e4-c086-c6a9-aa0b7ab9ce55@gotplt.org> Date: Mon, 23 May 2022 13:12:54 +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 v11 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> <20220519221803.57957-1-goldstein.w.n@gmail.com> <20220519221803.57957-3-goldstein.w.n@gmail.com> From: Siddhesh Poyarekar In-Reply-To: <20220519221803.57957-3-goldstein.w.n@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3039.7 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_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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: Mon, 23 May 2022 07:43:04 -0000 On 20/05/2022 03:48, Noah Goldstein via Libc-alpha wrote: > If we want to further optimize the function tests are needed. > --- > nss/Makefile | 1 + > nss/nss_hash.c | 1 + > nss/simple-nss-hash.h | 42 +++++++++++++++++++++++ > nss/tst-nss-hash.c | 80 +++++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 124 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..3d8e4cf37e 100644 > --- a/nss/nss_hash.c > +++ b/nss/nss_hash.c > @@ -75,4 +75,5 @@ __nss_hash (const void *keyarg, size_t len) > 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