Mercurial > ecos
annotate packages/language/c/libc/current/tests/string/memcpy2.c @ 64:c38311975d4f ecos-sw-2000-01-28
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
| author | jlarmour |
|---|---|
| date | Fri, 28 Jan 2000 04:59:39 +0000 |
| parents | 443894e2e912 |
| children | bf00f99aec69 |
| rev | line source |
|---|---|
| 0 | 1 //================================================================= |
| 2 // | |
| 3 // memcpy2.c | |
| 4 // | |
| 5 // Testcase for C library memcpy() | |
| 6 // | |
| 7 //================================================================= | |
| 8 //####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
9 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
10 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
11 // The contents of this file are subject to the Red Hat eCos Public License |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
13 // compliance with the License. You may obtain a copy of the License at |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
14 // http://sourceware.cygnus.com/ecos |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
15 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
16 // Software distributed under the License is distributed on an |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
18 // License for the specific language governing rights and limitations under |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
19 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
20 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
21 // The Original Code is eCos - Embedded Configurable Operating System, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
22 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
24 // The Initial Developer of the Original Code is Red Hat. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
25 // Portions created by Red Hat are |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
27 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
28 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
29 // |
| 0 | 30 //####COPYRIGHTEND#### |
| 31 //================================================================= | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 2 | 34 // Author(s): ctarpy, jlarmour |
| 35 // Contributors: jlarmour | |
| 0 | 36 // Date: 1998/6/3 |
| 37 // Description: Contains testcode for C library memcpy() function | |
| 38 // | |
| 39 // | |
| 40 //####DESCRIPTIONEND#### | |
| 41 | |
| 42 // Declarations for test system: | |
| 43 // | |
| 44 // TESTCASE_TYPE=CYG_TEST_MODULE | |
| 45 // COMPOUND_TESTCASE | |
| 46 | |
| 47 | |
| 48 // CONFIGURATION | |
| 49 | |
| 50 #include <pkgconf/libc.h> // Configuration header | |
| 51 | |
| 52 // INCLUDES | |
| 53 | |
| 54 #include <string.h> | |
| 55 #include <cyg/infra/testcase.h> | |
| 56 #include <sys/cstartup.h> // C library initialisation | |
| 57 | |
| 58 // CONSTANTS | |
| 59 | |
| 60 #define NUM_ROBUSTNESS_RUNS 300 | |
| 61 | |
| 62 // FUNCTIONS | |
| 63 | |
| 64 | |
| 65 externC void | |
| 66 cyg_package_start( void ) | |
| 67 { | |
| 68 #ifdef CYGPKG_LIBC | |
| 69 cyg_iso_c_start(); | |
| 70 #else | |
| 71 (void)main(0, NULL); | |
| 72 #endif | |
| 73 } // cyg_package_start() | |
| 74 | |
| 75 | |
| 76 | |
| 77 // Functions to avoid having to use libc strings | |
| 78 | |
| 79 #ifdef CYGPKG_LIBC | |
| 80 static int my_strlen(const char *s) | |
| 81 { | |
| 82 const char *ptr; | |
| 83 | |
| 84 ptr = s; | |
| 85 for ( ptr=s ; *ptr != '\0' ; ptr++ ) | |
| 86 ; | |
| 87 | |
| 88 return (int)(ptr-s); | |
| 89 } // my_strlen() | |
| 90 | |
| 91 | |
| 92 static int my_strcmp(const char *s1, const char *s2) | |
| 93 { | |
| 94 for ( ; *s1 == *s2 ; s1++,s2++ ) | |
| 95 { | |
| 96 if ( *s1 == '\0' ) | |
| 97 break; | |
| 98 } // for | |
| 99 | |
| 100 return (*s1 - *s2); | |
| 101 } // my_strcmp() | |
| 102 | |
| 103 | |
| 104 static char *my_strcpy(char *s1, const char *s2) | |
| 105 { | |
| 106 while (*s2 != '\0') { | |
| 107 *(s1++) = *(s2++); | |
| 108 } | |
| 109 *s1 = '\0'; | |
| 110 | |
| 111 return s1; | |
| 112 } // my_strcpy() | |
| 113 #endif // ifdef CYGPKG_LIBC | |
| 114 | |
| 115 | |
| 116 int main( int argc, char *argv[] ) | |
| 117 { | |
| 118 #ifdef CYGPKG_LIBC | |
| 119 char x[300]; | |
| 120 char y[300]; | |
| 121 void *ret, *ptr1, *ptr2; | |
| 122 char *c_ret; | |
| 123 int ctr; | |
| 124 int fail; | |
| 125 #endif | |
| 126 | |
| 127 CYG_TEST_INIT(); | |
| 128 | |
| 129 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library " | |
| 130 "memcpy() function"); | |
| 131 CYG_TEST_INFO("This testcase tests robustness, and may take some time"); | |
| 132 | |
| 133 | |
| 134 #ifdef CYGPKG_LIBC | |
| 135 | |
| 136 fail = 0; | |
| 137 for (ctr = 0; ctr < NUM_ROBUSTNESS_RUNS; ctr++) { | |
| 138 my_strcpy(x, "in the land of Mordor"); | |
| 139 my_strcpy(y, " "); | |
| 140 ptr1 = x; | |
| 141 ptr2 = y; | |
| 142 ret = memcpy(ptr2, ptr1, my_strlen(x) + 1); | |
| 143 c_ret = ret; | |
| 144 if ((my_strcmp(y, x) != 0) || (my_strcmp(c_ret, x)!=0)) { | |
| 145 fail = 1; | |
| 146 break; | |
| 147 } | |
| 148 } | |
| 149 | |
| 150 CYG_TEST_PASS_FAIL( (fail == 0), "Robustness test"); | |
| 151 | |
| 152 #else // ifndef CYGPKG_LIBC | |
| 2 | 153 CYG_TEST_NA("Testing is not applicable to this configuration"); |
| 0 | 154 #endif // ifndef CYGPKG_LIBC |
| 155 | |
| 156 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library " | |
| 157 "memcpy() function"); | |
| 158 } // main() | |
| 159 | |
| 160 | |
| 161 // EOF memcpy2.c |
