From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from antelope.ash.relay.mailchannels.net (antelope.ash.relay.mailchannels.net [23.83.222.4]) by sourceware.org (Postfix) with ESMTPS id A4DD8394CC32 for ; Thu, 19 May 2022 14:49:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A4DD8394CC32 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 08D96C22A2; Thu, 19 May 2022 14:49:08 +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 3B890C0F8B; Thu, 19 May 2022 14:49:07 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1652971747; a=rsa-sha256; cv=none; b=+A0AeU1yA9FrIVYFtUTmyVnraAsKmHsMNbu8EtJfLHm1LuZ0k++dfG0hLqu8vDFzKyfmVa OFLzFlnqjfuDP6oIu2rk4a9xNA6K0+5RHzPhPl4epsHM4c7Z5AiA+egetVL6xbEi4EY1Am CICta7SKEPq5x6rN5GrmFvHp9Fa3XX1Qcwk1mmFfJck/Da6piP2DqI6cHdYEcxNFTRQTa+ mlp6DfJDS9x/R0ldZeq7lsxT5VAeOyRG9NEAlfn31liz90w5289XG9SVNby3KEvD24ChZg TPXfz/5yjsc1Vrho96rDskxpXKlAmYoE1D/0TnUbjtJFu3eVxnhKXrHa58y/lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1652971747; 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=dxHQ4r/TTEZAmFd0zSzNFTmnc7BtSWpnY2NUvxCJilw=; b=psOKHep7M1EFLH9wyc2+iKtqBgcJDHbnCMkYxYlouqrrubnHrsHxy8MkPLHhyC3grWGrws UeopA2bYo42uy5VwyJJk++pL0CGxNGmkphR32vemxHzYk+Apdf8TZjua7RZA3QcK/2BNOn n2D4WTIKAPmI+Nh2sjRLv9zmd8mT2WpfzG25tBHx/cle0+q3MdyvgQNRao2LkmxE9Gu8kW TukSrjr1LXROaBNQzYJGov1HkVPrr2GGt76ySzOyBwSsS5Kh8MXvEY5KeLsJc1aUtziFQ+ EWFPyJeRDtB5X6QOim6boq8z2nNWF4QapqQCHIf+nO3sbMdbItKEka8b6CBgtQ== ARC-Authentication-Results: i=1; rspamd-554c8f6c56-nskrg; 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-Coil-Chief: 57cbda464fcac96f_1652971747768_223374573 X-MC-Loop-Signature: 1652971747768:4007321448 X-MC-Ingress-Time: 1652971747768 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.116.106.119 (trex/6.7.1); Thu, 19 May 2022 14:49:07 +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 4L3t696P3LzlP; Thu, 19 May 2022 07:49:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1652971747; bh=dxHQ4r/TTEZAmFd0zSzNFTmnc7BtSWpnY2NUvxCJilw=; h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding; b=II4qEU06DJXqzEEr9XJ+LtmaWfbPveteEpb2aA/N9zYvR8ePhnDkxxPShsLoygqvY zQfXvthNH/rcPleKtyHxe+FonWReu/vFsL6Y/4z4X2H8Y2I1oxXcHgiWgbnSTn4ThN qljkKu1hQeerBw6eUcNV5wttGh3p0m+PXfar18WSegjTKBYidjk8d1LxiCpYotx+JH 1hU0Ue9uAU6yLvVEGuznr7UZ6ukU/9nVXCzp1LHM0ncFyjGbuoVX2GmPlHE/UoKxez uSxYnZ/e6SUwI05Lzg0yRKn48XyfclYmY6ROCchnYmnD+s/sTLT/bjkze1QGu7Puwx ZM7+9c8Qfwf0Q== Message-ID: <0e3ad8d7-e062-0382-bc7e-12756b3c93ff@gotplt.org> Date: Thu, 19 May 2022 20:19:01 +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 2/6] elf: Add tests for the dl hash funcs (_dl_new_hash and _dl_elf_hash) 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-2-goldstein.w.n@gmail.com> From: Siddhesh Poyarekar In-Reply-To: <20220518172635.291119-2-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 14:49:14 -0000 On 18/05/2022 22:56, Noah Goldstein via Libc-alpha wrote: > If we want to further optimize the functions tests are needed. > --- > elf/Makefile | 1 + > elf/simple-dl-hash.h | 42 ++++++++++++++++ > elf/tst-dl-hash.c | 115 +++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 158 insertions(+) > create mode 100644 elf/simple-dl-hash.h > create mode 100644 elf/tst-dl-hash.c LGTM. Reviewed-by: Siddhesh Poyarekar > > diff --git a/elf/Makefile b/elf/Makefile > index ce3345ed92..adf1bcf6ce 100644 > --- a/elf/Makefile > +++ b/elf/Makefile > @@ -312,6 +312,7 @@ tests := \ > tst-array4 \ > tst-array5 \ > tst-auxv \ > + tst-dl-hash \ > tst-leaks1 \ > tst-stringtable \ > tst-tls9 \ > diff --git a/elf/simple-dl-hash.h b/elf/simple-dl-hash.h > new file mode 100644 > index 0000000000..53702b3c55 > --- /dev/null > +++ b/elf/simple-dl-hash.h > @@ -0,0 +1,42 @@ > +/* __simple_dl_elf_hash for testing true elf symbol lookup. > + 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_DL_ELF_HASH_H > +#define _SIMPLE_DL_ELF_HASH_H 1 > + > +#include > + > +/* For testing/benchmarking purposes. Real implementation in > + sysdeps/generic/dl-hash.h. */ > +static uint32_t > +__attribute__ ((unused)) > +__simple_dl_elf_hash (const char *name_arg) > +{ > + unsigned long int hash = 0; > + for (unsigned char c = *name_arg; c != '\0'; c = *(++name_arg)) > + { > + unsigned long int hi; > + hash = (hash << 4) + c; > + hi = hash & 0xf0000000; > + hash ^= hi >> 24; > + hash &= 0x0fffffff; > + } > + return hash; > +} > + > +#endif /* simple-dl-hash.h */ > diff --git a/elf/tst-dl-hash.c b/elf/tst-dl-hash.c > new file mode 100644 > index 0000000000..8697eb73a0 > --- /dev/null > +++ b/elf/tst-dl-hash.c > @@ -0,0 +1,115 @@ > +/* Test dl-hash functions. > + 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 > +#include > + > +typedef unsigned int (*hash_f) (const char *); > + > + > + > +static int > +do_fill_test (size_t len, int fill, const char *name, hash_f testf, > + hash_f expecf) > +{ > + uint32_t expec, res; > + char buf[len + 1]; > + memset (buf, fill, len); > + buf[len] = '\0'; > + > + expec = expecf (buf); > + res = testf (buf); > + if (expec != res) > + FAIL_EXIT1 ("FAIL: fill(%d) %s(%zu), %x != %x\n", fill, name, len, expec, > + res); > + > + return 0; > +} > + > +static int > +do_fill_tests (size_t len, int fill) > +{ > + if (do_fill_test (len, fill, "dl_new_hash", &_dl_new_hash, > + &__simple_dl_new_hash)) > + return 1; > + > + return do_fill_test (len, fill, "dl_elf_hash", &_dl_elf_hash, > + &__simple_dl_elf_hash); > +} > + > +static int > +do_rand_test (size_t len, const char *name, hash_f testf, hash_f expecf) > +{ > + uint32_t expec, res; > + size_t i; > + char buf[len + 1]; > + char v; > + for (i = 0; i < len; ++i) > + { > + v = random (); > + if (v == 0) > + v = 1; > + > + buf[i] = v; > + } > + buf[len] = '\0'; > + > + expec = expecf (buf); > + res = testf (buf); > + if (expec != res) > + FAIL_EXIT1 ("FAIL: random %s(%zu), %x != %x\n", name, len, expec, res); > + > + return 0; > +} > + > +static int > +do_rand_tests (size_t len) > +{ > + if (do_rand_test (len, "dl_new_hash", &_dl_new_hash, &__simple_dl_new_hash)) > + return 1; > + > + return do_rand_test (len, "dl_elf_hash", &_dl_elf_hash, &__simple_dl_elf_hash); > +} > + > +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