7 #define ITERATIONS 10000
9 int test_memcmp(const void *s1
, const void *s2
, size_t n
);
11 /* test all offsets and lengths */
12 static void test_one(char *s1
, char *s2
)
14 unsigned long offset
, size
;
16 for (offset
= 0; offset
< SIZE
; offset
++) {
17 for (size
= 0; size
< (SIZE
-offset
); size
++) {
21 y
= memcmp(s1
+offset
, s2
+offset
, size
);
22 x
= test_memcmp(s1
+offset
, s2
+offset
, size
);
24 if (((x
^ y
) < 0) && /* Trick to compare sign */
25 ((x
| y
) != 0)) { /* check for zero */
26 printf("memcmp returned %d, should have returned %d (offset %ld size %ld)\n", x
, y
, offset
, size
);
28 for (i
= offset
; i
< offset
+size
; i
++)
29 printf("%02x ", s1
[i
]);
32 for (i
= offset
; i
< offset
+size
; i
++)
33 printf("%02x ", s2
[i
]);
41 static int testcase(void)
47 s1
= memalign(128, SIZE
);
53 s2
= memalign(128, SIZE
);
61 for (i
= 0; i
< ITERATIONS
; i
++) {
65 for (j
= 0; j
< SIZE
; j
++)
71 change
= random() % SIZE
;
72 s2
[change
] = random() & 0xff;
79 for (i
= 0; i
< ITERATIONS
; i
++) {
83 for (j
= 0; j
< SIZE
; j
++)
88 /* change multiple bytes, 1/8 of total */
89 for (j
= 0; j
< SIZE
/ 8; j
++) {
90 change
= random() % SIZE
;
91 s2
[change
] = random() & 0xff;
102 return test_harness(testcase
, "memcmp");