URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
Compare Revisions
- This comparison shows the changes necessary to convert path
/openrisc/tags/gnu-src/newlib-1.18.0/newlib-1.18.0-or32-1.0rc1/newlib/testsuite/newlib.string
- from Rev 207 to Rev 345
- ↔ Reverse comparison
Rev 207 → Rev 345
/string.exp
0,0 → 1,12
# Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. |
# |
# Permission to use, copy, modify, and distribute this software |
# is freely granted, provided that this notice is preserved. |
# |
|
load_lib passfail.exp |
|
set exclude_list { |
} |
|
newlib_pass_fail_all -x $exclude_list |
/memmove1.c
0,0 → 1,184
/* A minor test-program for memmove. |
Copyright (C) 2005 Axis Communications. |
All rights reserved. |
|
Redistribution and use in source and binary forms, with or without |
modification, are permitted provided that the following conditions |
are met: |
|
1. Redistributions of source code must retain the above copyright |
notice, this list of conditions and the following disclaimer. |
|
2. Neither the name of Axis Communications nor the names of its |
contributors may be used to endorse or promote products derived |
from this software without specific prior written permission. |
|
THIS SOFTWARE IS PROVIDED BY AXIS COMMUNICATIONS AND ITS CONTRIBUTORS |
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AXIS |
COMMUNICATIONS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
POSSIBILITY OF SUCH DAMAGE. */ |
|
/* Test moves of 0..MAX bytes; overlapping-src-higher, |
overlapping-src-lower and non-overlapping. The overlap varies with |
1..N where N is the size moved. This means an order of MAX**2 |
iterations. The size of an octet may seem appropriate for MAX and |
makes an upper limit for simple testing. For the CRIS simulator, |
making this 256 added 90s to the test-run (2GHz P4) while 64 (4s) was |
enough to spot the bugs that had crept in, hence the number chosen. */ |
#define MAX 64 |
|
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
|
#define TOO_MANY_ERRORS 11 |
int errors = 0; |
|
#define DEBUGP \ |
if (errors == TOO_MANY_ERRORS) \ |
printf ("Further errors omitted\n"); \ |
else if (errors < TOO_MANY_ERRORS) \ |
printf |
|
/* A safe target-independent memmove. */ |
|
void |
mymemmove (unsigned char *dest, unsigned char *src, size_t n) |
{ |
size_t i; |
|
if ((src <= dest && src + n <= dest) |
|| src >= dest) |
while (n-- > 0) |
*dest++ = *src++; |
else |
{ |
dest += n; |
src += n; |
while (n-- > 0) |
*--dest = *--src; |
} |
} |
|
/* It's either the noinline attribute or forcing the test framework to |
pass -fno-builtin-memmove. */ |
void |
xmemmove (unsigned char *dest, unsigned char *src, size_t n) |
__attribute__ ((__noinline__)); |
|
void |
xmemmove (unsigned char *dest, unsigned char *src, size_t n) |
{ |
void *retp; |
retp = memmove (dest, src, n); |
|
if (retp != dest) |
{ |
errors++; |
DEBUGP ("memmove of n bytes returned %p instead of dest=%p\n", |
retp, dest); |
} |
} |
|
|
/* Fill the array with something we can associate with a position, but |
not exactly the same as the position index. */ |
|
void |
fill (unsigned char dest[MAX*3]) |
{ |
size_t i; |
for (i = 0; i < MAX*3; i++) |
dest[i] = (10 + i) % MAX; |
} |
|
int |
main (void) |
{ |
size_t i; |
int errors = 0; |
|
/* Leave some room before and after the area tested, so we can detect |
overwrites of up to N bytes, N being the amount tested. If you |
want to test using valgrind, make these malloced instead. */ |
unsigned char from_test[MAX*3]; |
unsigned char to_test[MAX*3]; |
unsigned char from_known[MAX*3]; |
unsigned char to_known[MAX*3]; |
|
/* Non-overlap. */ |
for (i = 0; i < MAX; i++) |
{ |
/* Do the memmove first before setting the known array, so we know |
it didn't change any of the known array. */ |
fill (from_test); |
fill (to_test); |
xmemmove (to_test + MAX, 1 + from_test + MAX, i); |
|
fill (from_known); |
fill (to_known); |
mymemmove (to_known + MAX, 1 + from_known + MAX, i); |
|
if (memcmp (to_known, to_test, sizeof (to_known)) != 0) |
{ |
errors++; |
DEBUGP ("memmove failed non-overlap test for %d bytes\n", i); |
} |
} |
|
/* Overlap-from-before. */ |
for (i = 0; i < MAX; i++) |
{ |
size_t j; |
for (j = 0; j < i; j++) |
{ |
fill (to_test); |
xmemmove (to_test + MAX * 2 - i, to_test + MAX * 2 - i - j, i); |
|
fill (to_known); |
mymemmove (to_known + MAX * 2 - i, to_known + MAX * 2 - i - j, i); |
|
if (memcmp (to_known, to_test, sizeof (to_known)) != 0) |
{ |
errors++; |
DEBUGP ("memmove failed for %d bytes," |
" with src %d bytes before dest\n", |
i, j); |
} |
} |
} |
|
/* Overlap-from-after. */ |
for (i = 0; i < MAX; i++) |
{ |
size_t j; |
for (j = 0; j < i; j++) |
{ |
fill (to_test); |
xmemmove (to_test + MAX, to_test + MAX + j, i); |
|
fill (to_known); |
mymemmove (to_known + MAX, to_known + MAX + j, i); |
|
if (memcmp (to_known, to_test, sizeof (to_known)) != 0) |
{ |
errors++; |
DEBUGP ("memmove failed when moving %d bytes," |
" with src %d bytes after dest\n", |
i, j); |
} |
} |
} |
|
if (errors != 0) |
abort (); |
exit (0); |
} |
memmove1.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: tstring.c
===================================================================
--- tstring.c (nonexistent)
+++ tstring.c (revision 345)
@@ -0,0 +1,353 @@
+/*
+ * Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software
+ * is freely granted, provided that this notice is preserved.
+ */
+
+#include
+#include
+#include
+
+#ifndef MAX_1
+#ifdef __SPU__
+#define MAX_1 11000
+#else
+#define MAX_1 33000
+#endif
+#endif
+
+#define MAX_2 (2 * MAX_1 + MAX_1 / 10)
+
+void eprintf (int line, char *result, char *expected, int size)
+{
+ if (size != 0)
+ printf ("Failure at line %d, result is <%.*s>, should be <%s> of size %d\n",
+ line, size, result, expected, size);
+ else
+ printf ("Failure at line %d, result is <%s>, should be <%s>\n",
+ line, result, expected);
+}
+
+void mycopy (char *target, char *source, int size)
+{
+ int i;
+
+ for (i = 0; i < size; ++i)
+ {
+ target[i] = source[i];
+ }
+}
+
+void myset (char *target, char ch, int size)
+{
+ int i;
+
+ for (i = 0; i < size; ++i)
+ {
+ target[i] = ch;
+ }
+}
+
+int main()
+{
+ char target[MAX_1] = "A";
+ char first_char;
+ char second_char;
+ char array[] = "abcdefghijklmnopqrstuvwxz";
+ char array2[] = "0123456789!@#$%^&*(";
+ char buffer2[MAX_1];
+ char buffer3[MAX_1];
+ char buffer4[MAX_1];
+ char buffer5[MAX_2];
+ char buffer6[MAX_2];
+ char buffer7[MAX_2];
+ char expected[MAX_1];
+ char *tmp1, *tmp2, *tmp3, *tmp4, *tmp5, *tmp6, *tmp7;
+ int i, j, k, x, z, align_test_iterations;
+
+ int test_failed = 0;
+
+ tmp1 = target;
+ tmp2 = buffer2;
+ tmp3 = buffer3;
+ tmp4 = buffer4;
+ tmp5 = buffer5;
+ tmp6 = buffer6;
+ tmp7 = buffer7;
+
+ tmp2[0] = 'Z';
+ tmp2[1] = '\0';
+
+ if (memset (target, 'X', 0) != target ||
+ memcpy (target, "Y", 0) != target ||
+ memmove (target, "K", 0) != target ||
+ strncpy (tmp2, "4", 0) != tmp2 ||
+ strncat (tmp2, "123", 0) != tmp2 ||
+ strcat (target, "") != target)
+ {
+ eprintf (__LINE__, target, "A", 0);
+ test_failed = 1;
+ }
+
+ if (strcmp (target, "A") || strlen(target) != 1 || memchr (target, 'A', 0) != NULL
+ || memcmp (target, "J", 0) || strncmp (target, "A", 1) || strncmp (target, "J", 0) ||
+ tmp2[0] != 'Z' || tmp2[1] != '\0')
+ {
+ eprintf (__LINE__, target, "A", 0);
+ test_failed = 1;
+ }
+
+ tmp2[2] = 'A';
+ if (strcpy (target, "") != target ||
+ strncpy (tmp2, "", 4) != tmp2 ||
+ strcat (target, "") != target)
+ {
+ eprintf (__LINE__, target, "", 0);
+ test_failed = 1;
+ }
+
+ if (target[0] != '\0' || strncmp (target, "", 1) ||
+ memcmp (tmp2, "\0\0\0\0", 4))
+ {
+ eprintf (__LINE__, target, "", 0);
+ test_failed = 1;
+ }
+
+ tmp2[2] = 'A';
+ if (strncat (tmp2, "1", 3) != tmp2 ||
+ memcmp (tmp2, "1\0A", 3))
+ {
+ eprintf (__LINE__, tmp2, "1\0A", 3);
+ test_failed = 1;
+ }
+
+ if (strcpy (tmp3, target) != tmp3 ||
+ strcat (tmp3, "X") != tmp3 ||
+ strncpy (tmp2, "X", 2) != tmp2 ||
+ memset (target, tmp2[0], 1) != target)
+ {
+ eprintf (__LINE__, target, "X", 0);
+ test_failed = 1;
+ }
+
+ if (strcmp (target, "X") || strlen (target) != 1 ||
+ memchr (target, 'X', 2) != target ||
+ strchr (target, 'X') != target ||
+ memchr (target, 'Y', 2) != NULL ||
+ strchr (target, 'Y') != NULL ||
+ strcmp (tmp3, target) ||
+ strncmp (tmp3, target, 2) ||
+ memcmp (target, "K", 0) ||
+ strncmp (target, tmp3, 3))
+ {
+ eprintf (__LINE__, target, "X", 0);
+ test_failed = 1;
+ }
+
+ if (strcpy (tmp3, "Y") != tmp3 ||
+ strcat (tmp3, "Y") != tmp3 ||
+ memset (target, 'Y', 2) != target)
+ {
+ eprintf (__LINE__, target, "Y", 0);
+ test_failed = 1;
+ }
+
+ target[2] = '\0';
+ if (memcmp (target, "YY", 2) || strcmp (target, "YY") ||
+ strlen (target) != 2 || memchr (target, 'Y', 2) != target ||
+ strcmp (tmp3, target) ||
+ strncmp (target, tmp3, 3) ||
+ strncmp (target, tmp3, 4) ||
+ strncmp (target, tmp3, 2) ||
+ strchr (target, 'Y') != target)
+ {
+ eprintf (__LINE__, target, "YY", 2);
+ test_failed = 1;
+ }
+
+ strcpy (target, "WW");
+ if (memcmp (target, "WW", 2) || strcmp (target, "WW") ||
+ strlen (target) != 2 || memchr (target, 'W', 2) != target ||
+ strchr (target, 'W') != target)
+ {
+ eprintf (__LINE__, target, "WW", 2);
+ test_failed = 1;
+ }
+
+ if (strncpy (target, "XX", 16) != target ||
+ memcmp (target, "XX\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16))
+ {
+ eprintf (__LINE__, target, "XX\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16);
+ test_failed = 1;
+ }
+
+ if (strcpy (tmp3, "ZZ") != tmp3 ||
+ strcat (tmp3, "Z") != tmp3 ||
+ memcpy (tmp4, "Z", 2) != tmp4 ||
+ strcat (tmp4, "ZZ") != tmp4 ||
+ memset (target, 'Z', 3) != target)
+ {
+ eprintf (__LINE__, target, "ZZZ", 3);
+ test_failed = 1;
+ }
+
+ target[3] = '\0';
+ tmp5[0] = '\0';
+ strncat (tmp5, "123", 2);
+ if (memcmp (target, "ZZZ", 3) || strcmp (target, "ZZZ") ||
+ strcmp (tmp3, target) || strcmp (tmp4, target) ||
+ strncmp (target, "ZZZ", 4) || strncmp (target, "ZZY", 3) <= 0 ||
+ strncmp ("ZZY", target, 4) >= 0 ||
+ memcmp (tmp5, "12", 3) ||
+ strlen (target) != 3)
+ {
+ eprintf (__LINE__, target, "ZZZ", 3);
+ test_failed = 1;
+ }
+
+ target[2] = 'K';
+ if (memcmp (target, "ZZZ", 2) || strcmp (target, "ZZZ") >= 0 ||
+ memcmp (target, "ZZZ", 3) >= 0 || strlen (target) != 3 ||
+ memchr (target, 'K', 3) != target + 2 ||
+ strncmp (target, "ZZZ", 2) || strncmp (target, "ZZZ", 4) >= 0 ||
+ strchr (target, 'K') != target + 2)
+ {
+ eprintf (__LINE__, target, "ZZK", 3);
+ test_failed = 1;
+ }
+
+ strcpy (target, "AAA");
+ if (memcmp (target, "AAA", 3) || strcmp (target, "AAA") ||
+ strncmp (target, "AAA", 3) ||
+ strlen (target) != 3)
+ {
+ eprintf (__LINE__, target, "AAA", 3);
+ test_failed = 1;
+ }
+
+ j = 5;
+ while (j < MAX_1)
+ {
+ for (i = j-1; i <= j+1; ++i)
+ {
+ /* don't bother checking unaligned data in the larger
+ sizes since it will waste time without performing additional testing */
+ if (i <= 16 * sizeof(long))
+ {
+ align_test_iterations = 2*sizeof(long);
+ if (i <= 2 * sizeof(long) + 1)
+ z = 2;
+ else
+ z = 2 * sizeof(long);
+ }
+ else
+ {
+ align_test_iterations = 1;
+ }
+
+ for (x = 0; x < align_test_iterations; ++x)
+ {
+ tmp1 = target + x;
+ tmp2 = buffer2 + x;
+ tmp3 = buffer3 + x;
+ tmp4 = buffer4 + x;
+ tmp5 = buffer5 + x;
+ tmp6 = buffer6 + x;
+
+ first_char = array[i % (sizeof(array) - 1)];
+ second_char = array2[i % (sizeof(array2) - 1)];
+ memset (tmp1, first_char, i);
+ mycopy (tmp2, tmp1, i);
+ myset (tmp2 + z, second_char, i - z - 1);
+ if (memcpy (tmp1 + z, tmp2 + z, i - z - 1) != tmp1 + z)
+ {
+ printf ("error at line %d\n", __LINE__);
+ test_failed = 1;
+ }
+
+ tmp1[i] = '\0';
+ tmp2[i] = '\0';
+ if (strcpy (expected, tmp2) != expected)
+ {
+ printf ("error at line %d\n", __LINE__);
+ test_failed = 1;
+ }
+ tmp2[i-z] = first_char + 1;
+ if (memmove (tmp2 + z + 1, tmp2 + z, i - z - 1) != tmp2 + z + 1 ||
+ memset (tmp3, first_char, i) != tmp3)
+ {
+ printf ("error at line %d\n", __LINE__);
+ test_failed = 1;
+ }
+
+ myset (tmp4, first_char, i);
+ tmp5[0] = '\0';
+ if (strncpy (tmp5, tmp1, i+1) != tmp5 ||
+ strcat (tmp5, tmp1) != tmp5)
+ {
+ printf ("error at line %d\n", __LINE__);
+ test_failed = 1;
+ }
+ mycopy (tmp6, tmp1, i);
+ mycopy (tmp6 + i, tmp1, i + 1);
+
+ tmp7[2*i+z] = second_char;
+ strcpy (tmp7, tmp1);
+
+ strchr (tmp1, second_char);
+
+ if (memcmp (tmp1, expected, i) || strcmp (tmp1, expected) ||
+ strncmp (tmp1, expected, i) ||
+ strncmp (tmp1, expected, i+1) ||
+ strcmp (tmp1, tmp2) >= 0 || memcmp (tmp1, tmp2, i) >= 0 ||
+ strncmp (tmp1, tmp2, i+1) >= 0 ||
+ strlen (tmp1) != i || memchr (tmp1, first_char, i) != tmp1 ||
+ strchr (tmp1, first_char) != tmp1 ||
+ memchr (tmp1, second_char, i) != tmp1 + z ||
+ strchr (tmp1, second_char) != tmp1 + z ||
+ strcmp (tmp5, tmp6) ||
+ strncat (tmp7, tmp1, i+2) != tmp7 ||
+ strcmp (tmp7, tmp6) ||
+ tmp7[2*i+z] != second_char)
+ {
+ eprintf (__LINE__, tmp1, expected, 0);
+ printf ("x is %d\n",x);
+ printf ("i is %d\n", i);
+ printf ("tmp1 is <%p>\n", tmp1);
+ printf ("tmp5 is <%p> <%s>\n", tmp5, tmp5);
+ printf ("tmp6 is <%p> <%s>\n", tmp6, tmp6);
+ test_failed = 1;
+ }
+
+ for (k = 1; k <= align_test_iterations && k <= i; ++k)
+ {
+ if (memcmp (tmp3, tmp4, i - k + 1) != 0 ||
+ strncmp (tmp3, tmp4, i - k + 1) != 0)
+ {
+ printf ("Failure at line %d, comparing %.*s with %.*s\n",
+ __LINE__, i, tmp3, i, tmp4);
+ test_failed = 1;
+ }
+ tmp4[i-k] = first_char + 1;
+ if (memcmp (tmp3, tmp4, i) >= 0 ||
+ strncmp (tmp3, tmp4, i) >= 0 ||
+ memcmp (tmp4, tmp3, i) <= 0 ||
+ strncmp (tmp4, tmp3, i) <= 0)
+ {
+ printf ("Failure at line %d, comparing %.*s with %.*s\n",
+ __LINE__, i, tmp3, i, tmp4);
+ test_failed = 1;
+ }
+ tmp4[i-k] = first_char;
+ }
+ }
+ }
+ j = ((2 * j) >> 2) << 2;
+ }
+
+ if (test_failed)
+ abort();
+ else
+ exit(0);
+}
tstring.c
Property changes :
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property