1 /* Test and measure string and memory functions.
2 Copyright (C) 1999, 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Written by Jakub Jelinek <jakub@redhat.com>, 1999.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 extern impl_t __start_impls
[], __stop_impls
[];
29 #define IMPL(name, test) \
31 __attribute__ ((section ("impls"), aligned (sizeof (void *)))) \
32 = { #name, (void (*) (void))name, test };
40 #undef __USE_STRING_INLINES
52 #include <hp-timing.h>
55 # define TEST_FUNCTION test_main ()
56 # define TIMEOUT (4 * 60)
57 # define OPT_ITERATIONS 10000
58 # define OPT_RANDOM 10001
59 # define OPT_SEED 10002
61 unsigned char *buf1
, *buf2
;
66 hp_timing_t _dl_hp_timing_overhead
;
69 size_t iterations
= 100000;
70 # define ITERATIONS_OPTIONS \
71 { "iterations", required_argument, NULL, OPT_ITERATIONS },
72 # define ITERATIONS_PROCESS \
73 case OPT_ITERATIONS: \
74 iterations = strtoul (optarg, NULL, 0); \
76 # define ITERATIONS iterations
78 # define ITERATIONS_OPTIONS
79 # define ITERATIONS_PROCESS
82 # define CMDLINE_OPTIONS ITERATIONS_OPTIONS \
83 { "random", no_argument, NULL, OPT_RANDOM }, \
84 { "seed", required_argument, NULL, OPT_SEED },
85 # define CMDLINE_PROCESS ITERATIONS_PROCESS \
88 int fdr = open ("/dev/urandom", O_RDONLY); \
90 if (fdr < 0 || read (fdr, &seed, sizeof(seed)) != sizeof (seed)) \
99 seed = strtoul (optarg, NULL, 0); \
103 #define CALL(impl, ...) \
104 (* (proto_t) (impl)->fn) (__VA_ARGS__)
106 #define FOR_EACH_IMPL(impl, notall) \
107 for (impl_t *impl = __start_impls; impl < __stop_impls; ++impl) \
108 if (!notall || impl->test)
110 #define HP_TIMING_BEST(best_time, start, end) \
113 hp_timing_t tmptime; \
114 HP_TIMING_DIFF (tmptime, start + _dl_hp_timing_overhead, end); \
115 if (best_time > tmptime) \
116 best_time = tmptime; \
123 page_size
= 2 * getpagesize ();
125 if (page_size
< MIN_PAGE_SIZE
)
126 page_size
= MIN_PAGE_SIZE
;
128 buf1
= mmap (0, 2 * page_size
, PROT_READ
| PROT_WRITE
,
129 MAP_PRIVATE
| MAP_ANON
, -1, 0);
130 if (buf1
== MAP_FAILED
)
131 error (EXIT_FAILURE
, errno
, "mmap failed");
132 if (mprotect (buf1
+ page_size
, page_size
, PROT_NONE
))
133 error (EXIT_FAILURE
, errno
, "mprotect failed");
134 buf2
= mmap (0, 2 * page_size
, PROT_READ
| PROT_WRITE
,
135 MAP_PRIVATE
| MAP_ANON
, -1, 0);
136 if (buf2
== MAP_FAILED
)
137 error (EXIT_FAILURE
, errno
, "mmap failed");
138 if (mprotect (buf2
+ page_size
, page_size
, PROT_NONE
))
139 error (EXIT_FAILURE
, errno
, "mprotect failed");
140 HP_TIMING_DIFF_INIT ();
143 printf ("Setting seed to 0x%x\n", seed
);
147 memset (buf1
, 0xa5, page_size
);
148 memset (buf2
, 0x5a, page_size
);