bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] tests: omit MEMCHR etc as no longer needed


From: Paul Eggert
Subject: [PATCH] tests: omit MEMCHR etc as no longer needed
Date: Wed, 20 Nov 2024 17:22:27 -0800

* tests/test-memchr.c (MEMCHR):
* tests/test-memchr2.c (MEMCHR2):
* tests/test-memrchr.c (MEMRCHR):
* tests/test-rawmemchr.c (RAWMEMCHR):
Remove these macros, as the code never adds to their results.
All uses replaced by original functions.

* tests/test-memchr.c (lib_memchr, volatile_memchr, memchr)
---
 ChangeLog              | 11 +++++++++-
 tests/test-memchr.c    | 38 ++++++++++++++++------------------
 tests/test-memchr2.c   | 46 +++++++++++++++++++-----------------------
 tests/test-memrchr.c   | 28 +++++++++++--------------
 tests/test-rawmemchr.c | 34 ++++++++++++++-----------------
 5 files changed, 75 insertions(+), 82 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index df1e60997c..e03ab61ceb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2024-11-20  Paul Eggert  <eggert@cs.ucla.edu>
 
+       tests: omit MEMCHR etc as no longer needed
+       * tests/test-memchr.c (MEMCHR):
+       * tests/test-memchr2.c (MEMCHR2):
+       * tests/test-memrchr.c (MEMRCHR):
+       * tests/test-rawmemchr.c (RAWMEMCHR):
+       Remove these macros, as the code never adds to their results.
+       All uses replaced by original functions.
+
        tests: dissuade unwanted clang optimization
        Pacify Apple clang 14.0.0 (clang-1400.0.29.202) for
        arm64-apple-darwin21.6.0 on test-memset_explicit.c,
@@ -9,7 +17,8 @@
        Do other tests consistently.
        * tests/test-bsearch.c (lib_bsearch, volatile_bsearch, bsearch):
        * tests/test-memccpy.c (lib_memccpy, volatile_memccpy, memccpy):
-       * tests/test-memchr.c (lib_memchr, volatile_memchr, memchr):
+       * tests/test-memchr.c (lib_memchr, volatile_memchr, memchr)
+
        * tests/test-memcmp.c (lib_memcmp, volatile_memcmp, memcmp):
        * tests/test-memcpy.c (lib_memcpy, volatile_memcpy, memcpy):
        * tests/test-memmove.c (lib_memmove, volatile_memmove, memmove):
diff --git a/tests/test-memchr.c b/tests/test-memchr.c
index 1ab0f65e3c..eff97accc9 100644
--- a/tests/test-memchr.c
+++ b/tests/test-memchr.c
@@ -38,10 +38,6 @@ static void *(*volatile volatile_memchr) (void const *, int, 
size_t)
 #undef memchr
 #define memchr volatile_memchr
 
-/* Calculating void * + int is not portable, so this wrapper converts
-   to char * to make the tests easier to write.  */
-#define MEMCHR (char *) memchr
-
 int
 main (void)
 {
@@ -57,26 +53,26 @@ main (void)
   input[n - 1] = 'a';
 
   /* Basic behavior tests.  */
-  ASSERT (MEMCHR (input, 'a', n) == input);
+  ASSERT (memchr (input, 'a', n) == input);
 
-  ASSERT (MEMCHR (input, 'a', 0) == NULL);
+  ASSERT (memchr (input, 'a', 0) == NULL);
 
   {
     void *page_boundary = zerosize_ptr ();
     if (page_boundary)
-      ASSERT (MEMCHR (page_boundary, 'a', 0) == NULL);
+      ASSERT (memchr (page_boundary, 'a', 0) == NULL);
   }
 
-  ASSERT (MEMCHR (input, 'b', n) == input + 1);
-  ASSERT (MEMCHR (input, 'c', n) == input + 2);
-  ASSERT (MEMCHR (input, 'd', n) == input + 1026);
+  ASSERT (memchr (input, 'b', n) == input + 1);
+  ASSERT (memchr (input, 'c', n) == input + 2);
+  ASSERT (memchr (input, 'd', n) == input + 1026);
 
-  ASSERT (MEMCHR (input + 1, 'a', n - 1) == input + n - 1);
-  ASSERT (MEMCHR (input + 1, 'e', n - 1) == input + n - 2);
-  ASSERT (MEMCHR (input + 1, 0x789abc00 | 'e', n - 1) == input + n - 2);
+  ASSERT (memchr (input + 1, 'a', n - 1) == input + n - 1);
+  ASSERT (memchr (input + 1, 'e', n - 1) == input + n - 2);
+  ASSERT (memchr (input + 1, 0x789abc00 | 'e', n - 1) == input + n - 2);
 
-  ASSERT (MEMCHR (input, 'f', n) == NULL);
-  ASSERT (MEMCHR (input, '\0', n) == NULL);
+  ASSERT (memchr (input, 'f', n) == NULL);
+  ASSERT (memchr (input, '\0', n) == NULL);
 
   /* Check that a very long haystack is handled quickly if the byte is
      found near the beginning.  */
@@ -84,7 +80,7 @@ main (void)
     size_t repeat = 10000;
     for (; repeat > 0; repeat--)
       {
-        ASSERT (MEMCHR (input, 'c', n) == input + 2);
+        ASSERT (memchr (input, 'c', n) == input + 2);
       }
   }
 
@@ -97,7 +93,7 @@ main (void)
           input[i + j] = j;
         for (j = 0; j < 256; j++)
           {
-            ASSERT (MEMCHR (input + i, j, 256) == input + i + j);
+            ASSERT (memchr (input + i, j, 256) == input + i + j);
           }
       }
   }
@@ -120,8 +116,8 @@ main (void)
           {
             char *mem = page_boundary - n;
             memset (mem, 'X', n);
-            ASSERT (MEMCHR (mem, 'U', n) == NULL);
-            ASSERT (MEMCHR (mem, 0, n) == NULL);
+            ASSERT (memchr (mem, 'U', n) == NULL);
+            ASSERT (memchr (mem, 0, n) == NULL);
 
             {
               size_t i;
@@ -131,10 +127,10 @@ main (void)
                 {
                   mem[i] = 'U';
                   for (k = i + 1; k < n + limit; k++)
-                    ASSERT (MEMCHR (mem, 'U', k) == mem + i);
+                    ASSERT (memchr (mem, 'U', k) == mem + i);
                   mem[i] = 0;
                   for (k = i + 1; k < n + limit; k++)
-                    ASSERT (MEMCHR (mem, 0, k) == mem + i);
+                    ASSERT (memchr (mem, 0, k) == mem + i);
                   mem[i] = 'X';
                 }
             }
diff --git a/tests/test-memchr2.c b/tests/test-memchr2.c
index bffc4b1dcd..92128b06e7 100644
--- a/tests/test-memchr2.c
+++ b/tests/test-memchr2.c
@@ -25,10 +25,6 @@
 #include "zerosize-ptr.h"
 #include "macros.h"
 
-/* Calculating void * + int is not portable, so this wrapper converts
-   to char * to make the tests easier to write.  */
-#define MEMCHR2 (char *) memchr2
-
 int
 main (void)
 {
@@ -44,29 +40,29 @@ main (void)
   input[n - 1] = 'a';
 
   /* Basic behavior tests.  */
-  ASSERT (MEMCHR2 (input, 'a', 'b', n) == input);
-  ASSERT (MEMCHR2 (input, 'b', 'a', n) == input);
+  ASSERT (memchr2 (input, 'a', 'b', n) == input);
+  ASSERT (memchr2 (input, 'b', 'a', n) == input);
 
-  ASSERT (MEMCHR2 (input, 'a', 'b', 0) == NULL);
+  ASSERT (memchr2 (input, 'a', 'b', 0) == NULL);
   void *page_boundary = zerosize_ptr ();
   if (page_boundary)
-    ASSERT (MEMCHR2 (page_boundary, 'a', 'b', 0) == NULL);
+    ASSERT (memchr2 (page_boundary, 'a', 'b', 0) == NULL);
 
-  ASSERT (MEMCHR2 (input, 'b', 'd', n) == input + 1);
-  ASSERT (MEMCHR2 (input + 2, 'b', 'd', n - 2) == input + 1026);
+  ASSERT (memchr2 (input, 'b', 'd', n) == input + 1);
+  ASSERT (memchr2 (input + 2, 'b', 'd', n - 2) == input + 1026);
 
-  ASSERT (MEMCHR2 (input, 'd', 'e', n) == input + 1026);
-  ASSERT (MEMCHR2 (input, 'e', 'd', n) == input + 1026);
+  ASSERT (memchr2 (input, 'd', 'e', n) == input + 1026);
+  ASSERT (memchr2 (input, 'e', 'd', n) == input + 1026);
 
-  ASSERT (MEMCHR2 (input + 1, 'a', 'e', n - 1) == input + n - 2);
-  ASSERT (MEMCHR2 (input + 1, 'e', 'a', n - 1) == input + n - 2);
+  ASSERT (memchr2 (input + 1, 'a', 'e', n - 1) == input + n - 2);
+  ASSERT (memchr2 (input + 1, 'e', 'a', n - 1) == input + n - 2);
 
-  ASSERT (MEMCHR2 (input, 'f', 'g', n) == NULL);
-  ASSERT (MEMCHR2 (input, 'f', '\0', n) == NULL);
+  ASSERT (memchr2 (input, 'f', 'g', n) == NULL);
+  ASSERT (memchr2 (input, 'f', '\0', n) == NULL);
 
-  ASSERT (MEMCHR2 (input, 'a', 'a', n) == input);
-  ASSERT (MEMCHR2 (input + 1, 'a', 'a', n - 1) == input + n - 1);
-  ASSERT (MEMCHR2 (input, 'f', 'f', n) == NULL);
+  ASSERT (memchr2 (input, 'a', 'a', n) == input);
+  ASSERT (memchr2 (input + 1, 'a', 'a', n - 1) == input + n - 1);
+  ASSERT (memchr2 (input, 'f', 'f', n) == NULL);
 
   /* Check that a very long haystack is handled quickly if one of the
      two bytes is found near the beginning.  */
@@ -74,10 +70,10 @@ main (void)
     size_t repeat = 10000;
     for (; repeat > 0; repeat--)
       {
-        ASSERT (MEMCHR2 (input, 'c', 'e', n) == input + 2);
-        ASSERT (MEMCHR2 (input, 'e', 'c', n) == input + 2);
-        ASSERT (MEMCHR2 (input, 'c', '\0', n) == input + 2);
-        ASSERT (MEMCHR2 (input, '\0', 'c', n) == input + 2);
+        ASSERT (memchr2 (input, 'c', 'e', n) == input + 2);
+        ASSERT (memchr2 (input, 'e', 'c', n) == input + 2);
+        ASSERT (memchr2 (input, 'c', '\0', n) == input + 2);
+        ASSERT (memchr2 (input, '\0', 'c', n) == input + 2);
       }
   }
 
@@ -90,8 +86,8 @@ main (void)
           input[i + j] = j;
         for (j = 0; j < 256; j++)
           {
-            ASSERT (MEMCHR2 (input + i, j, 0xff, 256) == input + i + j);
-            ASSERT (MEMCHR2 (input + i, 0xff, j, 256) == input + i + j);
+            ASSERT (memchr2 (input + i, j, 0xff, 256) == input + i + j);
+            ASSERT (memchr2 (input + i, 0xff, j, 256) == input + i + j);
           }
       }
   }
diff --git a/tests/test-memrchr.c b/tests/test-memrchr.c
index 836ed6f25d..279413c7a9 100644
--- a/tests/test-memrchr.c
+++ b/tests/test-memrchr.c
@@ -32,10 +32,6 @@ SIGNATURE_CHECK (memrchr, void *, (void const *, int, 
size_t));
 # pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
 #endif
 
-/* Calculating void * + int is not portable, so this wrapper converts
-   to char * to make the tests easier to write.  */
-#define MEMRCHR (char *) memrchr
-
 int
 main (void)
 {
@@ -51,22 +47,22 @@ main (void)
   input[0] = 'a';
 
   /* Basic behavior tests.  */
-  ASSERT (MEMRCHR (input, 'a', n) == input + n - 1);
+  ASSERT (memrchr (input, 'a', n) == input + n - 1);
 
-  ASSERT (MEMRCHR (input, 'a', 0) == NULL);
+  ASSERT (memrchr (input, 'a', 0) == NULL);
   void *page_boundary = zerosize_ptr ();
   if (page_boundary)
-    ASSERT (MEMRCHR (page_boundary, 'a', 0) == NULL);
+    ASSERT (memrchr (page_boundary, 'a', 0) == NULL);
 
-  ASSERT (MEMRCHR (input, 'b', n) == input + n - 2);
-  ASSERT (MEMRCHR (input, 'c', n) == input + n - 3);
-  ASSERT (MEMRCHR (input, 'd', n) == input + n - 1027);
+  ASSERT (memrchr (input, 'b', n) == input + n - 2);
+  ASSERT (memrchr (input, 'c', n) == input + n - 3);
+  ASSERT (memrchr (input, 'd', n) == input + n - 1027);
 
-  ASSERT (MEMRCHR (input, 'a', n - 1) == input);
-  ASSERT (MEMRCHR (input, 'e', n - 1) == input + 1);
+  ASSERT (memrchr (input, 'a', n - 1) == input);
+  ASSERT (memrchr (input, 'e', n - 1) == input + 1);
 
-  ASSERT (MEMRCHR (input, 'f', n) == NULL);
-  ASSERT (MEMRCHR (input, '\0', n) == NULL);
+  ASSERT (memrchr (input, 'f', n) == NULL);
+  ASSERT (memrchr (input, '\0', n) == NULL);
 
   /* Check that a very long haystack is handled quickly if the byte is
      found near the end.  */
@@ -74,7 +70,7 @@ main (void)
     size_t repeat = 10000;
     for (; repeat > 0; repeat--)
       {
-        ASSERT (MEMRCHR (input, 'c', n) == input + n - 3);
+        ASSERT (memrchr (input, 'c', n) == input + n - 3);
       }
   }
 
@@ -87,7 +83,7 @@ main (void)
           input[i + j] = j;
         for (j = 0; j < 256; j++)
           {
-            ASSERT (MEMRCHR (input + i, j, 256) == input + i + j);
+            ASSERT (memrchr (input + i, j, 256) == input + i + j);
           }
       }
   }
diff --git a/tests/test-rawmemchr.c b/tests/test-rawmemchr.c
index 5374a9be68..e2b8bdf691 100644
--- a/tests/test-rawmemchr.c
+++ b/tests/test-rawmemchr.c
@@ -27,10 +27,6 @@ SIGNATURE_CHECK (rawmemchr, void *, (void const *, int));
 #include "zerosize-ptr.h"
 #include "macros.h"
 
-/* Calculating void * + int is not portable, so this wrapper converts
-   to char * to make the tests easier to write.  */
-#define RAWMEMCHR (char *) rawmemchr
-
 int
 main (void)
 {
@@ -47,16 +43,16 @@ main (void)
   input[n] = '\0';
 
   /* Basic behavior tests.  */
-  ASSERT (RAWMEMCHR (input, 'a') == input);
-  ASSERT (RAWMEMCHR (input, 'b') == input + 1);
-  ASSERT (RAWMEMCHR (input, 'c') == input + 2);
-  ASSERT (RAWMEMCHR (input, 'd') == input + 1026);
+  ASSERT (rawmemchr (input, 'a') == input);
+  ASSERT (rawmemchr (input, 'b') == input + 1);
+  ASSERT (rawmemchr (input, 'c') == input + 2);
+  ASSERT (rawmemchr (input, 'd') == input + 1026);
 
-  ASSERT (RAWMEMCHR (input + 1, 'a') == input + n - 1);
-  ASSERT (RAWMEMCHR (input + 1, 'e') == input + n - 2);
-  ASSERT (RAWMEMCHR (input + 1, 0x789abc00 | 'e') == input + n - 2);
+  ASSERT (rawmemchr (input + 1, 'a') == input + n - 1);
+  ASSERT (rawmemchr (input + 1, 'e') == input + n - 2);
+  ASSERT (rawmemchr (input + 1, 0x789abc00 | 'e') == input + n - 2);
 
-  ASSERT (RAWMEMCHR (input, '\0') == input + n);
+  ASSERT (rawmemchr (input, '\0') == input + n);
 
   /* Alignment tests.  */
   {
@@ -67,7 +63,7 @@ main (void)
           input[i + j] = j;
         for (j = 0; j < 256; j++)
           {
-            ASSERT (RAWMEMCHR (input + i, j) == input + i + j);
+            ASSERT (rawmemchr (input + i, j) == input + i + j);
           }
       }
   }
@@ -82,7 +78,7 @@ main (void)
     memset (page_boundary - 512, '1', 511);
     page_boundary[-1] = '2';
     for (i = 1; i <= 512; i++)
-      ASSERT (RAWMEMCHR (page_boundary - i, (i * 0x01010100) | '2')
+      ASSERT (rawmemchr (page_boundary - i, (i * 0x01010100) | '2')
               == page_boundary - 1);
   }
 
@@ -93,11 +89,11 @@ main (void)
   {
     input = malloc (5);
     memcpy (input, "abcde", 5);
-    ASSERT (RAWMEMCHR (input, 'e') == input + 4);
-    ASSERT (RAWMEMCHR (input + 1, 'e') == input + 4);
-    ASSERT (RAWMEMCHR (input + 2, 'e') == input + 4);
-    ASSERT (RAWMEMCHR (input + 3, 'e') == input + 4);
-    ASSERT (RAWMEMCHR (input + 4, 'e') == input + 4);
+    ASSERT (rawmemchr (input, 'e') == input + 4);
+    ASSERT (rawmemchr (input + 1, 'e') == input + 4);
+    ASSERT (rawmemchr (input + 2, 'e') == input + 4);
+    ASSERT (rawmemchr (input + 3, 'e') == input + 4);
+    ASSERT (rawmemchr (input + 4, 'e') == input + 4);
     free (input);
   }
 
-- 
2.47.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]