2 strcmp-1.c from the execute part of the gcc torture tests.
7 /* Copyright (C) 2002 Free Software Foundation.
9 Test strcmp with various combinations of pointer alignments and lengths to
10 make sure any optimizations in the library are correct.
12 Written by Michael Meissner, March 9, 2002. */
18 #define MAX_OFFSET (sizeof (long long))
22 #define MAX_TEST (2 * sizeof (long long)) /* Was (8 * sizeof (long long)) in GCC, reduced to speed up regression testing */
26 #define MAX_EXTRA (sizeof (long long))
29 #define MAX_LENGTH (MAX_OFFSET + MAX_TEST + MAX_EXTRA + 2)
31 #if !(defined(__SDCC_mcs51) && defined(__SDCC_MODEL_SMALL)) && !defined(__SDCC_pdk14) // Lack of memory
33 unsigned char buf
[MAX_LENGTH
];
35 #if 0 // TODO: Enable when SDCC suports long double!
42 test (const unsigned char *s1
, const unsigned char *s2
, int expected
)
44 int value
= strcmp ((char *) s1
, (char *) s2
);
46 if (expected
< 0 && value
>= 0)
48 else if (expected
== 0 && value
!= 0)
50 else if (expected
> 0 && value
<= 0)
55 testTortureExecute (void)
57 #if !(defined(__SDCC_mcs51) && defined(__SDCC_MODEL_SMALL)) && !defined(__SDCC_pdk14) // Lack of memory
58 size_t off1
, off2
, len
, i
;
59 unsigned char *buf1
, *buf2
;
60 unsigned char *mod1
, *mod2
;
61 unsigned char *p1
, *p2
;
63 for (off1
= 0; off1
< MAX_OFFSET
; off1
++)
64 for (off2
= 0; off2
< MAX_OFFSET
; off2
++)
65 for (len
= 0; len
< MAX_TEST
; len
++)
68 for (i
= 0; i
< off1
; i
++)
72 for (i
= 0; i
< len
; i
++)
76 for (i
= 0; i
< MAX_EXTRA
+2; i
++)
80 for (i
= 0; i
< off2
; i
++)
84 for (i
= 0; i
< len
; i
++)
88 for (i
= 0; i
< MAX_EXTRA
+2; i
++)
98 test (buf1
, buf2
, +1);
103 test (buf1
, buf2
, -1);
109 test (buf1
, buf2
, -1);
115 test (buf1
, buf2
, +1);
119 mod2
[0] = (unsigned char)'\251';
121 test (buf1
, buf2
, -1);
123 mod1
[0] = (unsigned char)'\251';
127 test (buf1
, buf2
, +1);
129 mod1
[0] = (unsigned char)'\251';
131 mod2
[0] = (unsigned char)'\252';
133 test (buf1
, buf2
, -1);
135 mod1
[0] = (unsigned char)'\252';
137 mod2
[0] = (unsigned char)'\251';
139 test (buf1
, buf2
, +1);