]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - string/test-string.h
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / string / test-string.h
index 896b713e17009bb59dacb1644e317856138c5457..d8bd45b00b2e7ffc35a82b53a45094ba0fee9083 100644 (file)
@@ -1,5 +1,5 @@
 /* Test and measure string and memory functions.
-   Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1999-2015 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Jakub Jelinek <jakub@redhat.com>, 1999.
 
    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, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/cdefs.h>
 
 typedef struct
 {
   const char *name;
   void (*fn) (void);
-  int test;
+  long test;
 } impl_t;
 extern impl_t __start_impls[], __stop_impls[];
 
 #define IMPL(name, test) \
-  impl_t tst_ ## name                          \
-  __attribute__ ((section ("impls")))          \
-    = { #name, (void (*) (void))name, test };
+  impl_t tst_ ## name                                                  \
+  __attribute__ ((section ("impls"), aligned (sizeof (void *))))       \
+       = { __STRING (name), (void (*) (void))name, test };
 
 #ifdef TEST_MAIN
 
@@ -43,13 +44,15 @@ extern impl_t __start_impls[], __stop_impls[];
 #include <stdlib.h>
 #include <string.h>
 #include <sys/mman.h>
+#include <sys/param.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <error.h>
 #include <errno.h>
 #include <time.h>
+#include <ifunc-impl-list.h>
 #define GL(x) _##x
-#include <hp-timing.h>
+#define GLRO(x) _##x
 
 
 # define TEST_FUNCTION test_main ()
@@ -63,8 +66,6 @@ int ret, do_srandom;
 unsigned int seed;
 size_t page_size;
 
-hp_timing_t _dl_hp_timing_overhead;
-
 # ifndef ITERATIONS
 size_t iterations = 100000;
 #  define ITERATIONS_OPTIONS \
@@ -103,33 +104,81 @@ size_t iterations = 100000;
 #define CALL(impl, ...)        \
   (* (proto_t) (impl)->fn) (__VA_ARGS__)
 
-#define FOR_EACH_IMPL(impl, notall) \
+#ifdef TEST_NAME
+/* Increase size of FUNC_LIST if assert is triggered at run-time.  */
+static struct libc_ifunc_impl func_list[32];
+static int func_count;
+static int impl_count = -1;
+static impl_t *impl_array;
+
+# define FOR_EACH_IMPL(impl, notall) \
+  impl_t *impl;                                                                \
+  int count;                                                           \
+  if (impl_count == -1)                                                        \
+    {                                                                  \
+      impl_count = 0;                                                  \
+      if (func_count != 0)                                             \
+       {                                                               \
+         int f;                                                        \
+         impl_t *skip = NULL, *a;                                      \
+         for (impl = __start_impls; impl < __stop_impls; ++impl)       \
+           if (strcmp (impl->name, TEST_NAME) == 0)                    \
+             skip = impl;                                              \
+           else                                                        \
+             impl_count++;                                             \
+         a = impl_array = malloc ((impl_count + func_count) *          \
+                                  sizeof (impl_t));                    \
+         for (impl = __start_impls; impl < __stop_impls; ++impl)       \
+           if (impl != skip)                                           \
+             *a++ = *impl;                                             \
+         for (f = 0; f < func_count; f++)                              \
+           if (func_list[f].usable)                                    \
+             {                                                         \
+               a->name = func_list[f].name;                            \
+               a->fn = func_list[f].fn;                                \
+               a->test = 1;                                            \
+               a++;                                                    \
+             }                                                         \
+         impl_count = a - impl_array;                                  \
+       }                                                               \
+      else                                                             \
+        {                                                              \
+         impl_count = __stop_impls - __start_impls;                    \
+         impl_array = __start_impls;                                   \
+        }                                                              \
+    }                                                                  \
+  impl = impl_array;                                                   \
+  for (count = 0; count < impl_count; ++count, ++impl)                 \
+    if (!notall || impl->test)
+#else
+# define FOR_EACH_IMPL(impl, notall) \
   for (impl_t *impl = __start_impls; impl < __stop_impls; ++impl)      \
     if (!notall || impl->test)
+#endif
 
-#define HP_TIMING_BEST(best_time, start, end)  \
-  do                                                                   \
-    {                                                                  \
-      hp_timing_t tmptime;                                             \
-      HP_TIMING_DIFF (tmptime, start + _dl_hp_timing_overhead, end);   \
-      if (best_time > tmptime)                                         \
-       best_time = tmptime;                                            \
-    }                                                                  \
-  while (0)
+#ifndef BUF1PAGES
+# define BUF1PAGES 1
+#endif
 
 static void
 test_init (void)
 {
+#ifdef TEST_NAME
+  func_count = __libc_ifunc_impl_list (TEST_NAME, func_list,
+                                      (sizeof func_list
+                                       / sizeof func_list[0]));
+#endif
+
   page_size = 2 * getpagesize ();
 #ifdef MIN_PAGE_SIZE
   if (page_size < MIN_PAGE_SIZE)
     page_size = MIN_PAGE_SIZE;
 #endif
-  buf1 = mmap (0, 2 * page_size, PROT_READ | PROT_WRITE,
+  buf1 = mmap (0, (BUF1PAGES + 1) * page_size, PROT_READ | PROT_WRITE,
               MAP_PRIVATE | MAP_ANON, -1, 0);
   if (buf1 == MAP_FAILED)
     error (EXIT_FAILURE, errno, "mmap failed");
-  if (mprotect (buf1 + page_size, page_size, PROT_NONE))
+  if (mprotect (buf1 + BUF1PAGES * page_size, page_size, PROT_NONE))
     error (EXIT_FAILURE, errno, "mprotect failed");
   buf2 = mmap (0, 2 * page_size, PROT_READ | PROT_WRITE,
               MAP_PRIVATE | MAP_ANON, -1, 0);
@@ -137,12 +186,14 @@ test_init (void)
     error (EXIT_FAILURE, errno, "mmap failed");
   if (mprotect (buf2 + page_size, page_size, PROT_NONE))
     error (EXIT_FAILURE, errno, "mprotect failed");
-  HP_TIMING_DIFF_INIT ();
   if (do_srandom)
     {
       printf ("Setting seed to 0x%x\n", seed);
       srandom (seed);
     }
+
+  memset (buf1, 0xa5, BUF1PAGES * page_size);
+  memset (buf2, 0x5a, page_size);
 }
 
 #endif