Mercurial > ecos
comparison packages/language/c/libc/current/tests/stdlib/malloc3.c @ 2:443894e2e912 ecos-v1_2_1-release
Block commit of eCos version 1.2.1
| author | jlarmour |
|---|---|
| date | Tue, 11 May 1999 12:24:34 +0000 |
| parents | 3111d98ba7b3 |
| children | c38311975d4f |
comparison
equal
deleted
inserted
replaced
| 1:72f549f0d891 | 2:443894e2e912 |
|---|---|
| 20 // | 20 // |
| 21 // The Original Code is eCos - Embedded Cygnus Operating System, released | 21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
| 22 // September 30, 1998. | 22 // September 30, 1998. |
| 23 // | 23 // |
| 24 // The Initial Developer of the Original Code is Cygnus. Portions created | 24 // The Initial Developer of the Original Code is Cygnus. Portions created |
| 25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. | 25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
| 26 // ------------------------------------------- | 26 // ------------------------------------------- |
| 27 // | 27 // |
| 28 //####COPYRIGHTEND#### | 28 //####COPYRIGHTEND#### |
| 29 //================================================================= | 29 //================================================================= |
| 30 //#####DESCRIPTIONBEGIN#### | 30 //#####DESCRIPTIONBEGIN#### |
| 31 // | 31 // |
| 32 // Author(s): jlarmour@cygnus.co.uk | 32 // Author(s): jlarmour |
| 33 // Contributors: jlarmour@cygnus.co.uk | 33 // Contributors: jlarmour |
| 34 // Date: 1998/6/3 | 34 // Date: 1998/6/3 |
| 35 // Description: Contains testcode for C library malloc(), calloc() and | 35 // Description: Contains testcode for C library malloc(), calloc() and |
| 36 // free() functions | 36 // free() functions |
| 37 // | 37 // |
| 38 // | 38 // |
| 43 // TESTCASE_TYPE=CYG_TEST_MODULE | 43 // TESTCASE_TYPE=CYG_TEST_MODULE |
| 44 | 44 |
| 45 | 45 |
| 46 // INCLUDES | 46 // INCLUDES |
| 47 | 47 |
| 48 #include <pkgconf/libc.h> // config header for C library so we can know size | 48 #include <pkgconf/system.h> // Overall system configuration |
| 49 // of malloc pool | 49 #include <pkgconf/libc.h> // config header for C library so we can know |
| 50 // size of malloc pool | |
| 51 #ifdef CYGPKG_KERNEL | |
| 52 # include <pkgconf/kernel.h> // CYGSEM_KERNEL_MEMORY_COALESCE | |
| 53 #endif | |
| 50 #include <stdlib.h> | 54 #include <stdlib.h> |
| 51 #include <cyg/infra/testcase.h> | 55 #include <cyg/infra/testcase.h> |
| 52 #include <sys/cstartup.h> // C library initialisation | 56 #include <sys/cstartup.h> // C library initialisation |
| 53 | 57 |
| 54 | 58 |
| 63 (void)main(0, NULL); | 67 (void)main(0, NULL); |
| 64 #endif | 68 #endif |
| 65 } // cyg_package_start() | 69 } // cyg_package_start() |
| 66 | 70 |
| 67 | 71 |
| 68 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_MALLOC) | 72 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_MALLOC) && \ |
| 73 defined(CYGSEM_KERNEL_MEMORY_COALESCE) | |
| 69 static int | 74 static int |
| 70 fill_with_data( char *buf, int size ) | 75 fill_with_data( char *buf, int size ) |
| 71 { | 76 { |
| 72 int i; | 77 int i; |
| 73 | 78 |
| 93 } // if | 98 } // if |
| 94 | 99 |
| 95 return 1; | 100 return 1; |
| 96 } // fill_with_data() | 101 } // fill_with_data() |
| 97 | 102 |
| 98 #endif // if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_MALLOC) | 103 #endif // if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_MALLOC) && |
| 104 // defined(CYGSEM_KERNEL_MEMORY_COALESCE) | |
| 105 | |
| 99 | 106 |
| 100 int | 107 int |
| 101 main( int argc, char *argv[] ) | 108 main( int argc, char *argv[] ) |
| 102 { | 109 { |
| 103 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_MALLOC) | 110 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_MALLOC) && \ |
| 111 defined(CYGSEM_KERNEL_MEMORY_COALESCE) | |
| 112 | |
| 104 char *str; | 113 char *str; |
| 105 int size = CYGNUM_LIBC_MALLOC_MEMPOOL_SIZE/2; | 114 int size = CYGNUM_LIBC_MALLOC_MEMPOOL_SIZE/2; |
| 106 #endif | 115 #endif |
| 107 | 116 |
| 108 CYG_TEST_INIT(); | 117 CYG_TEST_INIT(); |
| 109 | 118 |
| 110 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library " | 119 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library " |
| 111 "malloc() and free() functions"); | 120 "malloc() and free() functions"); |
| 112 CYG_TEST_INFO("This checks allocation and freeing of large regions"); | 121 CYG_TEST_INFO("This checks allocation and freeing of large regions"); |
| 113 | 122 |
| 114 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_MALLOC) | 123 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_MALLOC) && \ |
| 124 defined(CYGSEM_KERNEL_MEMORY_COALESCE) | |
| 115 | 125 |
| 116 // Don't allocate all the memory at once - leave room for any structures | 126 // Don't allocate all the memory at once - leave room for any structures |
| 117 // used to manage the memory | 127 // used to manage the memory |
| 118 str = (char *)malloc( size ); | 128 str = (char *)malloc( size ); |
| 119 CYG_TEST_PASS_FAIL( str != NULL, "allocation 1"); | 129 CYG_TEST_PASS_FAIL( str != NULL, "allocation 1"); |
| 166 CYG_TEST_PASS_FAIL( fill_with_data( str, size ),"allocation 10 usability"); | 176 CYG_TEST_PASS_FAIL( fill_with_data( str, size ),"allocation 10 usability"); |
| 167 free( str ); | 177 free( str ); |
| 168 | 178 |
| 169 | 179 |
| 170 #else | 180 #else |
| 171 CYG_TEST_PASS("Testing is not applicable to this configuration"); | 181 CYG_TEST_NA("Testing is not applicable to this configuration"); |
| 172 #endif // if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_MALLOC) | 182 #endif // if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_MALLOC) && |
| 183 // defined(CYGSEM_KERNEL_MEMORY_COALESCE) | |
| 184 | |
| 173 | 185 |
| 174 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library " | 186 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library " |
| 175 "malloc() and free() functions"); | 187 "malloc() and free() functions"); |
| 176 } // main() | 188 } // main() |
| 177 | 189 |
