2 strncmp-1.c from the execute part of the gcc torture tests.
7 /* { dg-xfail-if "kernel strncmp does not perform unsigned comparisons" { vxworks_kernel } } */
8 /* Copyright (C) 2002 Free Software Foundation.
10 Test strncmp with various combinations of pointer alignments and lengths to
11 make sure any optimizations in the library are correct.
13 Written by Michael Meissner, March 9, 2002. */
19 #define MAX_OFFSET (sizeof (long long))
23 #define MAX_TEST (2 * sizeof (long long)) /* Was (8 * sizeof (long long)) in GCC, reduced to speed up regression testing */
27 #define MAX_EXTRA (sizeof (long long))
30 #define MAX_LENGTH (MAX_OFFSET + MAX_TEST + MAX_EXTRA)
32 #if !(defined(__SDCC_mcs51) && defined(__SDCC_MODEL_SMALL)) && !defined(__SDCC_pdk14) // Lack of memory
34 unsigned char buf
[MAX_LENGTH
];
36 #if 0 // TODO: enable when SDCC supports long double!
43 test (const unsigned char *s1
, const unsigned char *s2
, size_t len
, int expected
)
45 int value
= strncmp ((char *) s1
, (char *) s2
, len
);
47 if (expected
< 0 && value
>= 0)
49 else if (expected
== 0 && value
!= 0)
51 else if (expected
> 0 && value
<= 0)
56 testTortureExecute (void)
58 #if !(defined(__SDCC_mcs51) && defined(__SDCC_MODEL_SMALL)) && !defined(__SDCC_pdk14) // Lack of memory
59 size_t off1
, off2
, len
, i
;
60 unsigned char *buf1
, *buf2
;
61 unsigned char *mod1
, *mod2
;
62 unsigned char *p1
, *p2
;
64 for (off1
= 0; off1
< MAX_OFFSET
; off1
++)
65 for (off2
= 0; off2
< MAX_OFFSET
; off2
++)
66 for (len
= 0; len
< MAX_TEST
; len
++)
69 for (i
= 0; i
< off1
; i
++)
73 for (i
= 0; i
< len
; i
++)
77 for (i
= 0; i
< MAX_EXTRA
; i
++)
81 for (i
= 0; i
< off2
; i
++)
85 for (i
= 0; i
< len
; i
++)
89 for (i
= 0; i
< MAX_EXTRA
; i
++)
94 test (buf1
, buf2
, MAX_LENGTH
, 0);
95 test (buf1
, buf2
, len
, 0);
100 test (buf1
, buf2
, MAX_LENGTH
, +1);
101 test (buf1
, buf2
, len
, 0);
106 test (buf1
, buf2
, MAX_LENGTH
, -1);
107 test (buf1
, buf2
, len
, 0);
113 test (buf1
, buf2
, MAX_LENGTH
, -1);
114 test (buf1
, buf2
, len
, 0);
120 test (buf1
, buf2
, MAX_LENGTH
, +1);
121 test (buf1
, buf2
, len
, 0);
125 mod2
[0] = (unsigned char)'\251';
127 test (buf1
, buf2
, MAX_LENGTH
, -1);
128 test (buf1
, buf2
, len
, 0);
130 mod1
[0] = (unsigned char)'\251';
134 test (buf1
, buf2
, MAX_LENGTH
, +1);
135 test (buf1
, buf2
, len
, 0);
137 mod1
[0] = (unsigned char)'\251';
139 mod2
[0] = (unsigned char)'\252';
141 test (buf1
, buf2
, MAX_LENGTH
, -1);
142 test (buf1
, buf2
, len
, 0);
144 mod1
[0] = (unsigned char)'\252';
146 mod2
[0] = (unsigned char)'\251';
148 test (buf1
, buf2
, MAX_LENGTH
, +1);
149 test (buf1
, buf2
, len
, 0);