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