From: Noah Goldstein <goldstein.w.n@gmail.com>
To: libc-alpha@sourceware.org
Subject: [PATCH v14 3/4] String: Add tests for __memcmpeq
Date: Sat, 23 Oct 2021 18:24:03 -0500 [thread overview]
Message-ID: <20211023232404.622433-3-goldstein.w.n@gmail.com> (raw)
In-Reply-To: <20211023232404.622433-1-goldstein.w.n@gmail.com>
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.
---
string/Makefile | 4 ++--
string/test-memcmp.c | 34 ++++++++++++++++++++++------------
string/test-memcmpeq.c | 21 +++++++++++++++++++++
3 files changed, 45 insertions(+), 14 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..fdf148102c 100644
--- a/string/test-memcmp.c
+++ b/string/test-memcmp.c
@@ -17,11 +17,14 @@
<https://www.gnu.org/licenses/>. */
#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 <inttypes.h>
@@ -35,8 +38,9 @@
# 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)
+SIMPLE_MEMCMP (const wchar_t *s1, const wchar_t *s2, size_t n)
{
int ret = 0;
/* Warning!
@@ -48,10 +52,14 @@ simple_wmemcmp (const wchar_t *s1, const wchar_t *s2, size_t n)
}
#else
# include <limits.h>
-
-# 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
+ <https://www.gnu.org/licenses/>. */
+
+#define BAD_RESULT(result, expec) ((!(result)) != (!(expec)))
+#define TEST_MEMCMPEQ 1
+#include "test-memcmp.c"
--
2.25.1
next prev parent reply other threads:[~2021-10-23 23:24 UTC|newest]
Thread overview: 106+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-27 20:38 [PATCH v1] String: Add support for __memcmpeq() ABI on all targets Noah Goldstein
2021-09-27 20:43 ` Joseph Myers
2021-09-27 21:06 ` Noah Goldstein
2021-09-27 21:06 ` [PATCH v2] " Noah Goldstein
2021-09-27 21:52 ` Joseph Myers
2021-09-28 1:24 ` Noah Goldstein
2021-09-28 1:24 ` [PATCH v3] " Noah Goldstein
2021-09-28 8:15 ` Andreas Schwab
2021-09-28 16:47 ` Noah Goldstein
2021-09-28 8:40 ` Florian Weimer
2021-09-28 16:47 ` Noah Goldstein
2021-09-28 16:51 ` Florian Weimer
2021-09-28 16:46 ` [PATCH v4] " Noah Goldstein
2021-09-28 16:50 ` [PATCH v5] " Noah Goldstein
2021-09-28 16:53 ` [PATCH v6] " Noah Goldstein
2021-09-29 8:36 ` Florian Weimer
2021-09-29 15:17 ` Noah Goldstein
2021-09-29 8:52 ` Andreas Schwab
2021-09-29 9:18 ` Florian Weimer
2021-09-29 9:31 ` Andreas Schwab
2021-09-29 9:44 ` Florian Weimer
2021-09-28 16:57 ` [PATCH v1] " Noah Goldstein
2021-09-29 15:17 ` [PATCH v7] " Noah Goldstein
2021-09-30 19:31 ` Noah Goldstein
2021-10-11 2:33 ` Noah Goldstein
2021-10-18 14:47 ` Noah Goldstein
2021-10-21 19:28 ` H.J. Lu
2021-10-21 19:58 ` Noah Goldstein
2021-10-21 20:00 ` H.J. Lu
2021-10-21 21:04 ` Noah Goldstein
2021-10-21 20:02 ` Adhemerval Zanella
2021-10-21 20:23 ` Noah Goldstein
2021-10-21 20:26 ` Adhemerval Zanella
2021-10-21 19:33 ` Adhemerval Zanella
2021-10-21 20:01 ` Noah Goldstein
2021-10-21 20:06 ` Adhemerval Zanella
2021-10-21 21:18 ` Florian Weimer
2021-10-21 20:07 ` H.J. Lu
2021-10-21 20:11 ` Noah Goldstein
2021-10-21 22:38 ` [PATCH v8 1/3] " Noah Goldstein
2021-10-21 22:38 ` [PATCH v8 2/3] String: Add hidden defs for __memcmpeq() to enable internal usage Noah Goldstein
2021-10-21 22:52 ` H.J. Lu
2021-10-21 23:08 ` Joseph Myers
2021-10-21 23:10 ` H.J. Lu
2021-10-21 23:14 ` Joseph Myers
2021-10-21 23:39 ` Noah Goldstein
2021-10-21 23:45 ` Noah Goldstein
2021-10-22 0:19 ` Joseph Myers
2021-10-22 0:40 ` H.J. Lu
2021-10-25 16:41 ` Joseph Myers
2021-10-22 0:18 ` Joseph Myers
2021-10-21 22:38 ` [PATCH v8 3/3] String: Add tests for __memcmpeq Noah Goldstein
2021-10-21 22:57 ` H.J. Lu
2021-10-21 23:47 ` Noah Goldstein
2021-10-22 0:41 ` H.J. Lu
2021-10-22 1:01 ` Noah Goldstein
2021-10-21 22:50 ` [PATCH v8 1/3] String: Add support for __memcmpeq() ABI on all targets H.J. Lu
2021-10-21 23:42 ` Noah Goldstein
2021-10-22 2:38 ` H.J. Lu
2021-10-22 4:04 ` Noah Goldstein
2021-10-22 5:49 ` [PATCH v9 " Noah Goldstein
2021-10-22 12:38 ` H.J. Lu
2021-10-22 16:07 ` Noah Goldstein
2021-10-22 17:19 ` Noah Goldstein
2021-10-22 17:40 ` Noah Goldstein
2021-10-22 17:44 ` H.J. Lu
2021-10-22 18:09 ` Noah Goldstein
2021-10-22 18:33 ` H.J. Lu
2021-10-22 5:49 ` [PATCH v9 2/3] String: Add hidden defs for __memcmpeq() to enable internal usage Noah Goldstein
2021-10-22 12:44 ` H.J. Lu
2021-10-22 5:49 ` [PATCH v9 3/3] String: Add tests for __memcmpeq Noah Goldstein
2021-10-22 12:42 ` H.J. Lu
2021-10-22 16:06 ` [PATCH v10 1/4] String: Add support for __memcmpeq() ABI on all targets Noah Goldstein
2021-10-22 16:06 ` [PATCH v10 2/4] String: Add hidden defs for __memcmpeq() to enable internal usage Noah Goldstein
2021-10-22 16:06 ` [PATCH v10 3/4] String: Add tests for __memcmpeq Noah Goldstein
2021-10-22 16:06 ` [PATCH v10 4/4] NEWS: Add item " Noah Goldstein
2021-10-22 16:12 ` H.J. Lu
2021-10-22 16:12 ` [PATCH v10 1/4] String: Add support for __memcmpeq() ABI on all targets H.J. Lu
2021-10-22 16:18 ` Noah Goldstein
2021-10-22 18:37 ` [PATCH v11 " Noah Goldstein
2021-10-22 18:37 ` [PATCH v11 2/4] String: Add hidden defs for __memcmpeq() to enable internal usage Noah Goldstein
2021-10-22 18:37 ` [PATCH v11 3/4] String: Add tests for __memcmpeq Noah Goldstein
2021-10-22 18:37 ` [PATCH v11 4/4] NEWS: Add item " Noah Goldstein
2021-10-22 19:46 ` [PATCH v12 1/4] String: Add support for __memcmpeq() ABI on all targets Noah Goldstein
2021-10-22 19:46 ` [PATCH v12 2/4] String: Add hidden defs for __memcmpeq() to enable internal usage Noah Goldstein
2021-10-22 19:46 ` [PATCH v12 3/4] String: Add tests for __memcmpeq Noah Goldstein
2021-10-22 19:46 ` [PATCH v12 4/4] NEWS: Add item " Noah Goldstein
2021-10-22 20:28 ` [PATCH v12 1/4] String: Add support for __memcmpeq() ABI on all targets H.J. Lu
2021-10-22 20:33 ` Noah Goldstein
2021-10-22 20:45 ` H.J. Lu
2021-10-22 21:24 ` Noah Goldstein
2021-10-22 21:23 ` [PATCH v13 " Noah Goldstein
2021-10-22 21:23 ` [PATCH v13 2/4] String: Add hidden defs for __memcmpeq() to enable internal usage Noah Goldstein
2021-10-22 21:23 ` [PATCH v13 3/4] String: Add tests for __memcmpeq Noah Goldstein
2021-10-22 21:23 ` [PATCH v13 4/4] NEWS: Add item " Noah Goldstein
2021-10-23 23:23 ` [PATCH v13 1/4] String: Add support for __memcmpeq() ABI on all targets Noah Goldstein
2021-10-23 23:24 ` [PATCH v14 " Noah Goldstein
2021-10-23 23:24 ` [PATCH v14 2/4] String: Add hidden defs for __memcmpeq() to enable internal usage Noah Goldstein
2021-10-26 18:56 ` H.J. Lu
2021-10-23 23:24 ` Noah Goldstein [this message]
2021-10-26 18:57 ` [PATCH v14 3/4] String: Add tests for __memcmpeq H.J. Lu
2021-10-23 23:24 ` [PATCH v14 4/4] NEWS: Add item " Noah Goldstein
2021-10-26 18:58 ` H.J. Lu
2021-10-25 2:45 ` [PATCH v14 1/4] String: Add support for __memcmpeq() ABI on all targets Noah Goldstein
2021-10-26 18:55 ` H.J. Lu
2021-10-26 22:29 ` Noah Goldstein
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211023232404.622433-3-goldstein.w.n@gmail.com \
--to=goldstein.w.n@gmail.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).