1 /* Copyright (C) 2002 Free Software Foundation.
3 Test strcmp with various combinations of pointer alignments and lengths to
4 make sure any optimizations in the library are correct.
6 Written by Michael Meissner, March 9, 2002. */
12 #define MAX_OFFSET (sizeof (long long))
16 #define MAX_TEST (8 * sizeof (long long))
20 #define MAX_EXTRA (sizeof (long long))
23 #define MAX_LENGTH (MAX_OFFSET + MAX_TEST + MAX_EXTRA + 2)
26 unsigned char buf
[MAX_LENGTH
];
32 test (const unsigned char *s1
, const unsigned char *s2
, int expected
)
34 int value
= strcmp ((char *) s1
, (char *) s2
);
36 if (expected
< 0 && value
>= 0)
38 else if (expected
== 0 && value
!= 0)
40 else if (expected
> 0 && value
<= 0)
46 size_t off1
, off2
, len
, i
;
47 unsigned char *buf1
, *buf2
;
48 unsigned char *mod1
, *mod2
;
49 unsigned char *p1
, *p2
;
51 for (off1
= 0; off1
< MAX_OFFSET
; off1
++)
52 for (off2
= 0; off2
< MAX_OFFSET
; off2
++)
53 for (len
= 0; len
< MAX_TEST
; len
++)
56 for (i
= 0; i
< off1
; i
++)
60 for (i
= 0; i
< len
; i
++)
64 for (i
= 0; i
< MAX_EXTRA
+2; i
++)
68 for (i
= 0; i
< off2
; i
++)
72 for (i
= 0; i
< len
; i
++)
76 for (i
= 0; i
< MAX_EXTRA
+2; i
++)
86 test (buf1
, buf2
, +1);
91 test (buf1
, buf2
, -1);
97 test (buf1
, buf2
, -1);
103 test (buf1
, buf2
, +1);
107 mod2
[0] = (unsigned char)'\251';
109 test (buf1
, buf2
, -1);
111 mod1
[0] = (unsigned char)'\251';
115 test (buf1
, buf2
, +1);
117 mod1
[0] = (unsigned char)'\251';
119 mod2
[0] = (unsigned char)'\252';
121 test (buf1
, buf2
, -1);
123 mod1
[0] = (unsigned char)'\252';
125 mod2
[0] = (unsigned char)'\251';
127 test (buf1
, buf2
, +1);