From patchwork Fri Oct 22 05:49:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 46523 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9263D3857408 for ; Fri, 22 Oct 2021 05:52:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9263D3857408 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1634881977; bh=3cCb8Vs63u+sIbpkktzFujjNi3hf5X21l6AgVIwrwOc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=jSFvQXBZI9z/YI1G16+04+kKUmGLvoxnLT+tOPvEwlOjzvnzvGgVNUIuZmoikDRx1 YcNZPwyf1QdLJAJ4Picq0lz8PEdMxKazbGXKKJ5nMjcfs52jpL5I0RDeSgFoVmIO4M ZAMySjHl7O8W4r0RWC7QWF4RALAuE1Qnjy4tYHas= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by sourceware.org (Postfix) with ESMTPS id 40CAF3857813 for ; Fri, 22 Oct 2021 05:51:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 40CAF3857813 Received: by mail-io1-xd33.google.com with SMTP id y67so3879507iof.10 for ; Thu, 21 Oct 2021 22:51:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3cCb8Vs63u+sIbpkktzFujjNi3hf5X21l6AgVIwrwOc=; b=CVT1NmNk60oJY5b0R5R+6Q62jh21MkvyplLm6083PpOacaKH6K++l4uv7p2Weo7Jbc tAsvHHzoQWW3S+55F3Fs2TqoN99UOgnGzuSHUO1/FiNMvnEDzZMTs73th/2f97E9LiEA QHcwC5ilu8sv4OZbz6u5jUaz06oSTo5NMdFpBodYIWwtDlHTm4Zl4wBeDiamMvXq1OdG bhGylK76xJS0q39qOmEa8nGnHSNY40GZ2hWpmXevWHvf/WBOpHzacnWTaDpcyphjOSiv gSe/X/q+DOLL3sxI2nwU6X/d4Ujaq/GQ0v6K0tdOAQyfr2VaTUAksN8GHJxiS1/U1FQO 2pfw== X-Gm-Message-State: AOAM531B3AiXAkYAHSlBz9uQO5SL6VEpvJrbZ4pCqlAoCZOfArD2F4T5 UH5jLhsmc7ZSwYPOZTAIQqSgWVLNMgU= X-Google-Smtp-Source: ABdhPJzH3Iufi/zsWN39W/w79Wx/LQ61YJoP6AlaHi+tlS6Tx5XWe/FASeRMT1bZlZlOEZvtYJ0mVQ== X-Received: by 2002:a05:6602:2b8f:: with SMTP id r15mr7389698iov.93.1634881867513; Thu, 21 Oct 2021 22:51:07 -0700 (PDT) Received: from localhost.localdomain (node-17-161.flex.volo.net. [76.191.17.161]) by smtp.googlemail.com with ESMTPSA id m188sm3532574ioa.27.2021.10.21.22.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 22:51:07 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v9 3/3] String: Add tests for __memcmpeq Date: Fri, 22 Oct 2021 00:49:50 -0500 Message-Id: <20211022054949.895120-3-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210927203827.2852935-1-goldstein.w.n@gmail.com> References: <20210927203827.2852935-1-goldstein.w.n@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-Patchwork-Original-From: Noah Goldstein via Libc-alpha From: Noah Goldstein Reply-To: Noah Goldstein Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" No bug. This commit adds tests for the new function __memcmpeq. The new tests use the existing tests in 'test-memcmp.c' but relax the result requirement to only check for zero or non-zero returns. All string tests include test-memcmpeq are passing. Reviewed-by: H.J. Lu --- string/Makefile | 4 ++-- string/test-memcmp.c | 32 +++++++++++++++++++++----------- string/test-memcmpeq.c | 21 +++++++++++++++++++++ 3 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 string/test-memcmpeq.c diff --git a/string/Makefile b/string/Makefile index f0fce2a0b8..40d6fac133 100644 --- a/string/Makefile +++ b/string/Makefile @@ -48,8 +48,8 @@ routines := strcat strchr strcmp strcoll strcpy strcspn \ sigdescr_np sigabbrev_np strerrorname_np \ strerrordesc_np -strop-tests := memchr memcmp memcpy memmove mempcpy memset memccpy \ - stpcpy stpncpy strcat strchr strcmp strcpy strcspn \ +strop-tests := memchr memcmp memcpy memcmpeq memmove mempcpy memset \ + memccpy stpcpy stpncpy strcat strchr strcmp strcpy strcspn \ strlen strncmp strncpy strpbrk strrchr strspn memmem \ strstr strcasestr strnlen strcasecmp strncasecmp \ strncat rawmemchr strchrnul bcopy bzero memrchr \ diff --git a/string/test-memcmp.c b/string/test-memcmp.c index 6ddbc05d2f..70529137ae 100644 --- a/string/test-memcmp.c +++ b/string/test-memcmp.c @@ -17,11 +17,14 @@ . */ #define TEST_MAIN -#ifdef WIDE +#ifdef TEST_MEMCMPEQ +# define TEST_NAME "__memcmpeq" +#elif defined WIDE # define TEST_NAME "wmemcmp" #else # define TEST_NAME "memcmp" #endif + #include "test-string.h" #ifdef WIDE # include @@ -35,6 +38,7 @@ # define CHARBYTES 4 # define CHAR__MIN WCHAR_MIN # define CHAR__MAX WCHAR_MAX + int simple_wmemcmp (const wchar_t *s1, const wchar_t *s2, size_t n) { @@ -48,10 +52,14 @@ simple_wmemcmp (const wchar_t *s1, const wchar_t *s2, size_t n) } #else # include - -# define MEMCMP memcmp +# ifdef TEST_MEMCMPEQ +# define MEMCMP __memcmpeq +# define SIMPLE_MEMCMP simple_memcmpeq +# else +# define MEMCMP memcmp +# define SIMPLE_MEMCMP simple_memcmp +# endif # define MEMCPY memcpy -# define SIMPLE_MEMCMP simple_memcmp # define CHAR char # define MAX_CHAR 255 # define UCHAR unsigned char @@ -60,7 +68,7 @@ simple_wmemcmp (const wchar_t *s1, const wchar_t *s2, size_t n) # define CHAR__MAX CHAR_MAX int -simple_memcmp (const char *s1, const char *s2, size_t n) +SIMPLE_MEMCMP (const char *s1, const char *s2, size_t n) { int ret = 0; @@ -69,6 +77,12 @@ simple_memcmp (const char *s1, const char *s2, size_t n) } #endif +#ifndef BAD_RESULT +# define BAD_RESULT(result, expec) \ + (((result) == 0 && (expec)) || ((result) < 0 && (expec) >= 0) || \ + ((result) > 0 && (expec) <= 0)) +# endif + typedef int (*proto_t) (const CHAR *, const CHAR *, size_t); IMPL (SIMPLE_MEMCMP, 0) @@ -79,9 +93,7 @@ check_result (impl_t *impl, const CHAR *s1, const CHAR *s2, size_t len, int exp_result) { int result = CALL (impl, s1, s2, len); - if ((exp_result == 0 && result != 0) - || (exp_result < 0 && result >= 0) - || (exp_result > 0 && result <= 0)) + if (BAD_RESULT(result, exp_result)) { error (0, 0, "Wrong result in function %s %d %d", impl->name, result, exp_result); @@ -186,9 +198,7 @@ do_random_tests (void) { r = CALL (impl, (CHAR *) p1 + align1, (const CHAR *) p2 + align2, len); - if ((r == 0 && result) - || (r < 0 && result >= 0) - || (r > 0 && result <= 0)) + if (BAD_RESULT(r, result)) { error (0, 0, "Iteration %zd - wrong result in function %s (%zd, %zd, %zd, %zd) %ld != %d, p1 %p p2 %p", n, impl->name, align1 * CHARBYTES & 63, align2 * CHARBYTES & 63, len, pos, r, result, p1, p2); diff --git a/string/test-memcmpeq.c b/string/test-memcmpeq.c new file mode 100644 index 0000000000..8889117868 --- /dev/null +++ b/string/test-memcmpeq.c @@ -0,0 +1,21 @@ +/* Test and measure __memcmpeq functions. + Copyright (C) 2012-2021 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 + . */ + +#define BAD_RESULT(result, expec) ((!(result)) != (!(expec))) +#define TEST_MEMCMPEQ 1 +#include "test-memcmp.c"