Rev 6433 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6433 | siemargl | 1 | /* |
2 | * Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. |
||
3 | * |
||
4 | * Permission to use, copy, modify, and distribute this software |
||
5 | * is freely granted, provided that this notice is preserved. |
||
6 | */ |
||
7 | |||
8 | #include |
||
9 | #include |
||
10 | #include |
||
11 | |||
12 | #ifndef MAX_1 |
||
13 | #ifdef __SPU__ |
||
14 | #define MAX_1 11000 |
||
15 | #else |
||
16 | #define MAX_1 33000 |
||
17 | #endif |
||
18 | #endif |
||
19 | |||
20 | #define MAX_2 (2 * MAX_1 + MAX_1 / 10) |
||
21 | |||
22 | void eprintf (int line, char *result, char *expected, int size) |
||
23 | { |
||
24 | if (size != 0) |
||
25 | printf ("Failure at line %d, result is <%.*s>, should be <%s> of size %d\n", |
||
26 | line, size, result, expected, size); |
||
27 | else |
||
28 | printf ("Failure at line %d, result is <%s>, should be <%s>\n", |
||
29 | line, result, expected); |
||
30 | } |
||
31 | |||
32 | void mycopy (char *target, char *source, int size) |
||
33 | { |
||
34 | int i; |
||
35 | |||
36 | for (i = 0; i < size; ++i) |
||
37 | { |
||
38 | target[i] = source[i]; |
||
39 | } |
||
40 | } |
||
41 | |||
42 | void myset (char *target, char ch, int size) |
||
43 | { |
||
44 | int i; |
||
45 | |||
46 | for (i = 0; i < size; ++i) |
||
47 | { |
||
48 | target[i] = ch; |
||
49 | } |
||
50 | } |
||
51 | |||
52 | int main() |
||
53 | { |
||
54 | char target[MAX_1] = "A"; |
||
55 | char first_char; |
||
56 | char second_char; |
||
57 | char array[] = "abcdefghijklmnopqrstuvwxz"; |
||
58 | char array2[] = "0123456789!@#$%^&*("; |
||
59 | char buffer2[MAX_1]; |
||
60 | char buffer3[MAX_1]; |
||
61 | char buffer4[MAX_1]; |
||
62 | char buffer5[MAX_2]; |
||
63 | char buffer6[MAX_2]; |
||
64 | char buffer7[MAX_2]; |
||
65 | char expected[MAX_1]; |
||
66 | char *tmp1, *tmp2, *tmp3, *tmp4, *tmp5, *tmp6, *tmp7; |
||
67 | int i, j, k, x, z, align_test_iterations; |
||
68 | |||
69 | int test_failed = 0; |
||
70 | |||
71 | tmp1 = target; |
||
72 | tmp2 = buffer2; |
||
73 | tmp3 = buffer3; |
||
74 | tmp4 = buffer4; |
||
75 | tmp5 = buffer5; |
||
76 | tmp6 = buffer6; |
||
77 | tmp7 = buffer7; |
||
78 | |||
79 | tmp2[0] = 'Z'; |
||
80 | tmp2[1] = '\0'; |
||
81 | |||
82 | if (memset (target, 'X', 0) != target || |
||
83 | memcpy (target, "Y", 0) != target || |
||
84 | memmove (target, "K", 0) != target || |
||
85 | strncpy (tmp2, "4", 0) != tmp2 || |
||
86 | strncat (tmp2, "123", 0) != tmp2 || |
||
87 | strcat (target, "") != target) |
||
88 | { |
||
89 | eprintf (__LINE__, target, "A", 0); |
||
90 | test_failed = 1; |
||
91 | } |
||
92 | |||
93 | if (strcmp (target, "A") || strlen(target) != 1 || memchr (target, 'A', 0) != NULL |
||
94 | || memcmp (target, "J", 0) || strncmp (target, "A", 1) || strncmp (target, "J", 0) || |
||
95 | tmp2[0] != 'Z' || tmp2[1] != '\0') |
||
96 | { |
||
97 | eprintf (__LINE__, target, "A", 0); |
||
98 | test_failed = 1; |
||
99 | } |
||
100 | |||
101 | tmp2[2] = 'A'; |
||
102 | if (strcpy (target, "") != target || |
||
103 | strncpy (tmp2, "", 4) != tmp2 || |
||
104 | strcat (target, "") != target) |
||
105 | { |
||
106 | eprintf (__LINE__, target, "", 0); |
||
107 | test_failed = 1; |
||
108 | } |
||
109 | |||
110 | if (target[0] != '\0' || strncmp (target, "", 1) || |
||
111 | memcmp (tmp2, "\0\0\0\0", 4)) |
||
112 | { |
||
113 | eprintf (__LINE__, target, "", 0); |
||
114 | test_failed = 1; |
||
115 | } |
||
116 | |||
117 | tmp2[2] = 'A'; |
||
118 | if (strncat (tmp2, "1", 3) != tmp2 || |
||
119 | memcmp (tmp2, "1\0A", 3)) |
||
120 | { |
||
121 | eprintf (__LINE__, tmp2, "1\0A", 3); |
||
122 | test_failed = 1; |
||
123 | } |
||
124 | |||
125 | if (strcpy (tmp3, target) != tmp3 || |
||
126 | strcat (tmp3, "X") != tmp3 || |
||
127 | strncpy (tmp2, "X", 2) != tmp2 || |
||
128 | memset (target, tmp2[0], 1) != target) |
||
129 | { |
||
130 | eprintf (__LINE__, target, "X", 0); |
||
131 | test_failed = 1; |
||
132 | } |
||
133 | |||
134 | if (strcmp (target, "X") || strlen (target) != 1 || |
||
135 | memchr (target, 'X', 2) != target || |
||
136 | strchr (target, 'X') != target || |
||
137 | memchr (target, 'Y', 2) != NULL || |
||
138 | strchr (target, 'Y') != NULL || |
||
139 | strcmp (tmp3, target) || |
||
140 | strncmp (tmp3, target, 2) || |
||
141 | memcmp (target, "K", 0) || |
||
142 | strncmp (target, tmp3, 3)) |
||
143 | { |
||
144 | eprintf (__LINE__, target, "X", 0); |
||
145 | test_failed = 1; |
||
146 | } |
||
147 | |||
148 | if (strcpy (tmp3, "Y") != tmp3 || |
||
149 | strcat (tmp3, "Y") != tmp3 || |
||
150 | memset (target, 'Y', 2) != target) |
||
151 | { |
||
152 | eprintf (__LINE__, target, "Y", 0); |
||
153 | test_failed = 1; |
||
154 | } |
||
155 | |||
156 | target[2] = '\0'; |
||
157 | if (memcmp (target, "YY", 2) || strcmp (target, "YY") || |
||
158 | strlen (target) != 2 || memchr (target, 'Y', 2) != target || |
||
159 | strcmp (tmp3, target) || |
||
160 | strncmp (target, tmp3, 3) || |
||
161 | strncmp (target, tmp3, 4) || |
||
162 | strncmp (target, tmp3, 2) || |
||
163 | strchr (target, 'Y') != target) |
||
164 | { |
||
165 | eprintf (__LINE__, target, "YY", 2); |
||
166 | test_failed = 1; |
||
167 | } |
||
168 | |||
169 | strcpy (target, "WW"); |
||
170 | if (memcmp (target, "WW", 2) || strcmp (target, "WW") || |
||
171 | strlen (target) != 2 || memchr (target, 'W', 2) != target || |
||
172 | strchr (target, 'W') != target) |
||
173 | { |
||
174 | eprintf (__LINE__, target, "WW", 2); |
||
175 | test_failed = 1; |
||
176 | } |
||
177 | |||
178 | if (strncpy (target, "XX", 16) != target || |
||
179 | memcmp (target, "XX\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16)) |
||
180 | { |
||
181 | eprintf (__LINE__, target, "XX\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16); |
||
182 | test_failed = 1; |
||
183 | } |
||
184 | |||
185 | if (strcpy (tmp3, "ZZ") != tmp3 || |
||
186 | strcat (tmp3, "Z") != tmp3 || |
||
187 | memcpy (tmp4, "Z", 2) != tmp4 || |
||
188 | strcat (tmp4, "ZZ") != tmp4 || |
||
189 | memset (target, 'Z', 3) != target) |
||
190 | { |
||
191 | eprintf (__LINE__, target, "ZZZ", 3); |
||
192 | test_failed = 1; |
||
193 | } |
||
194 | |||
195 | target[3] = '\0'; |
||
196 | tmp5[0] = '\0'; |
||
197 | strncat (tmp5, "123", 2); |
||
198 | if (memcmp (target, "ZZZ", 3) || strcmp (target, "ZZZ") || |
||
199 | strcmp (tmp3, target) || strcmp (tmp4, target) || |
||
200 | strncmp (target, "ZZZ", 4) || strncmp (target, "ZZY", 3) <= 0 || |
||
201 | strncmp ("ZZY", target, 4) >= 0 || |
||
202 | memcmp (tmp5, "12", 3) || |
||
203 | strlen (target) != 3) |
||
204 | { |
||
205 | eprintf (__LINE__, target, "ZZZ", 3); |
||
206 | test_failed = 1; |
||
207 | } |
||
208 | |||
209 | target[2] = 'K'; |
||
210 | if (memcmp (target, "ZZZ", 2) || strcmp (target, "ZZZ") >= 0 || |
||
211 | memcmp (target, "ZZZ", 3) >= 0 || strlen (target) != 3 || |
||
212 | memchr (target, 'K', 3) != target + 2 || |
||
213 | strncmp (target, "ZZZ", 2) || strncmp (target, "ZZZ", 4) >= 0 || |
||
214 | strchr (target, 'K') != target + 2) |
||
215 | { |
||
216 | eprintf (__LINE__, target, "ZZK", 3); |
||
217 | test_failed = 1; |
||
218 | } |
||
219 | |||
220 | strcpy (target, "AAA"); |
||
221 | if (memcmp (target, "AAA", 3) || strcmp (target, "AAA") || |
||
222 | strncmp (target, "AAA", 3) || |
||
223 | strlen (target) != 3) |
||
224 | { |
||
225 | eprintf (__LINE__, target, "AAA", 3); |
||
226 | test_failed = 1; |
||
227 | } |
||
228 | |||
229 | j = 5; |
||
230 | while (j < MAX_1) |
||
231 | { |
||
232 | for (i = j-1; i <= j+1; ++i) |
||
233 | { |
||
234 | /* don't bother checking unaligned data in the larger |
||
235 | sizes since it will waste time without performing additional testing */ |
||
236 | if (i <= 16 * sizeof(long)) |
||
237 | { |
||
238 | align_test_iterations = 2*sizeof(long); |
||
239 | if (i <= 2 * sizeof(long) + 1) |
||
240 | z = 2; |
||
241 | else |
||
242 | z = 2 * sizeof(long); |
||
243 | } |
||
244 | else |
||
245 | { |
||
246 | align_test_iterations = 1; |
||
247 | } |
||
248 | |||
249 | for (x = 0; x < align_test_iterations; ++x) |
||
250 | { |
||
251 | tmp1 = target + x; |
||
252 | tmp2 = buffer2 + x; |
||
253 | tmp3 = buffer3 + x; |
||
254 | tmp4 = buffer4 + x; |
||
255 | tmp5 = buffer5 + x; |
||
256 | tmp6 = buffer6 + x; |
||
257 | |||
258 | first_char = array[i % (sizeof(array) - 1)]; |
||
259 | second_char = array2[i % (sizeof(array2) - 1)]; |
||
260 | memset (tmp1, first_char, i); |
||
261 | mycopy (tmp2, tmp1, i); |
||
262 | myset (tmp2 + z, second_char, i - z - 1); |
||
263 | if (memcpy (tmp1 + z, tmp2 + z, i - z - 1) != tmp1 + z) |
||
264 | { |
||
265 | printf ("error at line %d\n", __LINE__); |
||
266 | test_failed = 1; |
||
267 | } |
||
268 | |||
269 | tmp1[i] = '\0'; |
||
270 | tmp2[i] = '\0'; |
||
271 | if (strcpy (expected, tmp2) != expected) |
||
272 | { |
||
273 | printf ("error at line %d\n", __LINE__); |
||
274 | test_failed = 1; |
||
275 | } |
||
276 | tmp2[i-z] = first_char + 1; |
||
277 | if (memmove (tmp2 + z + 1, tmp2 + z, i - z - 1) != tmp2 + z + 1 || |
||
278 | memset (tmp3, first_char, i) != tmp3) |
||
279 | { |
||
280 | printf ("error at line %d\n", __LINE__); |
||
281 | test_failed = 1; |
||
282 | } |
||
283 | |||
284 | myset (tmp4, first_char, i); |
||
285 | tmp5[0] = '\0'; |
||
286 | if (strncpy (tmp5, tmp1, i+1) != tmp5 || |
||
287 | strcat (tmp5, tmp1) != tmp5) |
||
288 | { |
||
289 | printf ("error at line %d\n", __LINE__); |
||
290 | test_failed = 1; |
||
291 | } |
||
292 | mycopy (tmp6, tmp1, i); |
||
293 | mycopy (tmp6 + i, tmp1, i + 1); |
||
294 | |||
295 | tmp7[2*i+z] = second_char; |
||
296 | strcpy (tmp7, tmp1); |
||
297 | |||
298 | strchr (tmp1, second_char); |
||
299 | |||
300 | if (memcmp (tmp1, expected, i) || strcmp (tmp1, expected) || |
||
301 | strncmp (tmp1, expected, i) || |
||
302 | strncmp (tmp1, expected, i+1) || |
||
303 | strcmp (tmp1, tmp2) >= 0 || memcmp (tmp1, tmp2, i) >= 0 || |
||
304 | strncmp (tmp1, tmp2, i+1) >= 0 || |
||
305 | strlen (tmp1) != i || memchr (tmp1, first_char, i) != tmp1 || |
||
306 | strchr (tmp1, first_char) != tmp1 || |
||
307 | memchr (tmp1, second_char, i) != tmp1 + z || |
||
308 | strchr (tmp1, second_char) != tmp1 + z || |
||
309 | strcmp (tmp5, tmp6) || |
||
310 | strncat (tmp7, tmp1, i+2) != tmp7 || |
||
311 | strcmp (tmp7, tmp6) || |
||
312 | tmp7[2*i+z] != second_char) |
||
313 | { |
||
314 | eprintf (__LINE__, tmp1, expected, 0); |
||
315 | printf ("x is %d\n",x); |
||
316 | printf ("i is %d\n", i); |
||
317 | printf ("tmp1 is <%p>\n", tmp1); |
||
318 | printf ("tmp5 is <%p> <%s>\n", tmp5, tmp5); |
||
319 | printf ("tmp6 is <%p> <%s>\n", tmp6, tmp6); |
||
320 | test_failed = 1; |
||
321 | } |
||
322 | |||
323 | for (k = 1; k <= align_test_iterations && k <= i; ++k) |
||
324 | { |
||
325 | if (memcmp (tmp3, tmp4, i - k + 1) != 0 || |
||
326 | strncmp (tmp3, tmp4, i - k + 1) != 0) |
||
327 | { |
||
328 | printf ("Failure at line %d, comparing %.*s with %.*s\n", |
||
329 | __LINE__, i, tmp3, i, tmp4); |
||
330 | test_failed = 1; |
||
331 | } |
||
332 | tmp4[i-k] = first_char + 1; |
||
333 | if (memcmp (tmp3, tmp4, i) >= 0 || |
||
334 | strncmp (tmp3, tmp4, i) >= 0 || |
||
335 | memcmp (tmp4, tmp3, i) <= 0 || |
||
336 | strncmp (tmp4, tmp3, i) <= 0) |
||
337 | { |
||
338 | printf ("Failure at line %d, comparing %.*s with %.*s\n", |
||
339 | __LINE__, i, tmp3, i, tmp4); |
||
340 | test_failed = 1; |
||
341 | } |
||
342 | tmp4[i-k] = first_char; |
||
343 | } |
||
344 | } |
||
345 | } |
||
346 | j = ((2 * j) >> 2) << 2; |
||
347 | } |
||
348 | |||
6441 | siemargl | 349 | printf("\n %s finished\n", __FILE__); |
6433 | siemargl | 350 | if (test_failed) |
6441 | siemargl | 351 | { |
352 | printf("\n %s FAILED\n", __FILE__); |
||
6433 | siemargl | 353 | abort(); |
6441 | siemargl | 354 | } |
6433 | siemargl | 355 | else |
356 | exit(0); |
||
357 | }><>=>=>=>=>%s>%p>%s>%p>%p>>=>=>=>>=>>>%s>%s>%s>%.*s> |