about summary refs log tree commit diff
path: root/string/test-memcmp.c
diff options
context:
space:
mode:
authorNoah Goldstein <goldstein.w.n@gmail.com>2021-10-21 15:07:18 -0500
committerNoah Goldstein <goldstein.w.n@gmail.com>2021-10-26 16:51:29 -0500
commitd9283b71ac1eaba53d9fff504a5272570f8ea01e (patch)
tree9d185da766dc4d5694bb469cc20a9d2ac35a4bd3 /string/test-memcmp.c
parent9894127d202d8c0c821d852658057a03ba3cc3d2 (diff)
downloadglibc-d9283b71ac1eaba53d9fff504a5272570f8ea01e.tar.gz
glibc-d9283b71ac1eaba53d9fff504a5272570f8ea01e.tar.xz
glibc-d9283b71ac1eaba53d9fff504a5272570f8ea01e.zip
String: Add tests for __memcmpeq
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.
Diffstat (limited to 'string/test-memcmp.c')
-rw-r--r--string/test-memcmp.c34
1 files changed, 22 insertions, 12 deletions
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);