Mercurial > ecos
annotate packages/language/c/libc/current/tests/stdlib/malloc3.c @ 66:bf00f99aec69 ecos-sw-2000-02-02
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
| author | jlarmour |
|---|---|
| date | Wed, 02 Feb 2000 19:57:02 +0000 |
| parents | c38311975d4f |
| children |
| rev | line source |
|---|---|
| 0 | 1 //================================================================= |
| 2 // | |
| 3 // malloc3.c | |
| 4 // | |
| 5 // Testcase for C library malloc(), calloc() and free() | |
| 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 |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
12 // Version 1.1 (the "License"); you may not use this file except in |
|
64
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 |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
14 // http://www.redhat.com/ |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
15 // |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
64
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): jlarmour |
| 35 // Contributors: jlarmour | |
| 0 | 36 // Date: 1998/6/3 |
| 37 // Description: Contains testcode for C library malloc(), calloc() and | |
| 38 // free() functions | |
| 39 // | |
| 40 // | |
| 41 //####DESCRIPTIONEND#### | |
| 42 | |
| 43 // Declarations for test system: | |
| 44 // | |
| 45 // TESTCASE_TYPE=CYG_TEST_MODULE | |
| 46 | |
| 47 | |
| 48 // INCLUDES | |
| 49 | |
| 2 | 50 #include <pkgconf/system.h> // Overall system configuration |
| 51 #include <pkgconf/libc.h> // config header for C library so we can know | |
| 52 // size of malloc pool | |
| 53 #ifdef CYGPKG_KERNEL | |
| 54 # include <pkgconf/kernel.h> // CYGSEM_KERNEL_MEMORY_COALESCE | |
| 55 #endif | |
| 0 | 56 #include <stdlib.h> |
| 57 #include <cyg/infra/testcase.h> | |
| 58 #include <sys/cstartup.h> // C library initialisation | |
| 59 | |
| 60 | |
| 61 // FUNCTIONS | |
| 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 | |
| 2 | 74 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_MALLOC) && \ |
| 75 defined(CYGSEM_KERNEL_MEMORY_COALESCE) | |
| 0 | 76 static int |
| 77 fill_with_data( char *buf, int size ) | |
| 78 { | |
| 79 int i; | |
| 80 | |
| 81 for (i=0; i < size; i++) | |
| 82 buf[i] = 'f'; | |
| 83 | |
| 84 for (i=0; i < size; i++) | |
| 85 if (buf[i] != 'f') { | |
| 86 CYG_TEST_FAIL( "data written to buffer does not compare " | |
| 87 "correctly! #1" ); | |
| 88 return 0; | |
| 89 } // if | |
| 90 | |
| 91 | |
| 92 for (i=0; i < size; i++) | |
| 93 buf[i] = 'z'; | |
| 94 | |
| 95 for (i=0; i < size; i++) | |
| 96 if (buf[i] != 'z') { | |
| 97 CYG_TEST_FAIL( "data written to buffer does not compare " | |
| 98 "correctly! #2" ); | |
| 99 return 0; | |
| 100 } // if | |
| 101 | |
| 102 return 1; | |
| 103 } // fill_with_data() | |
| 104 | |
| 2 | 105 #endif // if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_MALLOC) && |
| 106 // defined(CYGSEM_KERNEL_MEMORY_COALESCE) | |
| 107 | |
| 0 | 108 |
| 109 int | |
| 110 main( int argc, char *argv[] ) | |
| 111 { | |
| 2 | 112 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_MALLOC) && \ |
| 113 defined(CYGSEM_KERNEL_MEMORY_COALESCE) | |
| 114 | |
| 0 | 115 char *str; |
| 116 int size = CYGNUM_LIBC_MALLOC_MEMPOOL_SIZE/2; | |
| 117 #endif | |
| 118 | |
| 119 CYG_TEST_INIT(); | |
| 120 | |
| 121 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library " | |
| 122 "malloc() and free() functions"); | |
| 123 CYG_TEST_INFO("This checks allocation and freeing of large regions"); | |
| 124 | |
| 2 | 125 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_MALLOC) && \ |
| 126 defined(CYGSEM_KERNEL_MEMORY_COALESCE) | |
| 0 | 127 |
| 128 // Don't allocate all the memory at once - leave room for any structures | |
| 129 // used to manage the memory | |
| 130 str = (char *)malloc( size ); | |
| 131 CYG_TEST_PASS_FAIL( str != NULL, "allocation 1"); | |
| 132 CYG_TEST_PASS_FAIL( fill_with_data( str, size ), "allocation 1 usability"); | |
| 133 free( str ); | |
| 134 | |
| 135 | |
| 136 str = (char *)malloc( size ); | |
| 137 CYG_TEST_PASS_FAIL( str != NULL, "allocation 2"); | |
| 138 CYG_TEST_PASS_FAIL( fill_with_data( str, size ), "allocation 2 usability"); | |
| 139 free( str ); | |
| 140 | |
| 141 str = (char *)malloc( size ); | |
| 142 CYG_TEST_PASS_FAIL( str != NULL, "allocation 3"); | |
| 143 CYG_TEST_PASS_FAIL( fill_with_data( str, size ), "allocation 3 usability"); | |
| 144 free( str ); | |
| 145 | |
| 146 str = (char *)malloc( size ); | |
| 147 CYG_TEST_PASS_FAIL( str != NULL, "allocation 4"); | |
| 148 CYG_TEST_PASS_FAIL( fill_with_data( str, size ), "allocation 4 usability"); | |
| 149 free( str ); | |
| 150 | |
| 151 str = (char *)malloc( size ); | |
| 152 CYG_TEST_PASS_FAIL( str != NULL, "allocation 5"); | |
| 153 CYG_TEST_PASS_FAIL( fill_with_data( str, size ), "allocation 5 usability"); | |
| 154 free( str ); | |
| 155 | |
| 156 str = (char *)malloc( size ); | |
| 157 CYG_TEST_PASS_FAIL( str != NULL, "allocation 6"); | |
| 158 CYG_TEST_PASS_FAIL( fill_with_data( str, size ), "allocation 6 usability"); | |
| 159 free( str ); | |
| 160 | |
| 161 str = (char *)malloc( size ); | |
| 162 CYG_TEST_PASS_FAIL( str != NULL, "allocation 7"); | |
| 163 CYG_TEST_PASS_FAIL( fill_with_data( str, size ), "allocation 7 usability"); | |
| 164 free( str ); | |
| 165 | |
| 166 str = (char *)malloc( size ); | |
| 167 CYG_TEST_PASS_FAIL( str != NULL, "allocation 8"); | |
| 168 CYG_TEST_PASS_FAIL( fill_with_data( str, size ), "allocation 8 usability"); | |
| 169 free( str ); | |
| 170 | |
| 171 str = (char *)malloc( size ); | |
| 172 CYG_TEST_PASS_FAIL( str != NULL, "allocation 9"); | |
| 173 CYG_TEST_PASS_FAIL( fill_with_data( str, size ), "allocation 9 usability"); | |
| 174 free( str ); | |
| 175 | |
| 176 str = (char *)malloc( size ); | |
| 177 CYG_TEST_PASS_FAIL( str != NULL, "allocation 10"); | |
| 178 CYG_TEST_PASS_FAIL( fill_with_data( str, size ),"allocation 10 usability"); | |
| 179 free( str ); | |
| 180 | |
| 181 | |
| 182 #else | |
| 2 | 183 CYG_TEST_NA("Testing is not applicable to this configuration"); |
| 184 #endif // if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_MALLOC) && | |
| 185 // defined(CYGSEM_KERNEL_MEMORY_COALESCE) | |
| 186 | |
| 0 | 187 |
| 188 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library " | |
| 189 "malloc() and free() functions"); | |
| 190 } // main() | |
| 191 | |
| 192 // EOF malloc3.c |
