1 //=================================================================
5 // Testcase for C library malloc(), calloc() and free()
7 //=================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //=================================================================
41 //#####DESCRIPTIONBEGIN####
43 // Author(s): jlarmour
46 // Description: Contains testcode for C library malloc(), calloc() and
50 //####DESCRIPTIONEND####
54 #include <pkgconf/system.h> // Overall system configuration
55 #include <pkgconf/memalloc.h> // config header
56 #ifdef CYGPKG_ISOINFRA
57 # include <pkgconf/isoinfra.h>
60 #include <cyg/infra/testcase.h>
62 #if !defined(CYGPKG_ISOINFRA)
63 # define NA_MSG "Requires isoinfra package"
64 #elif !CYGINT_ISO_MAIN_STARTUP
65 # define NA_MSG "Requires main() to be called"
66 #elif !CYGINT_ISO_MALLOC
67 # define NA_MSG "Requires malloc"
68 #elif !CYGINT_ISO_MALLINFO
69 # define NA_MSG "Requires mallinfo"
77 CYG_TEST_NA( NA_MSG );
78 CYG_TEST_FINISH("Done");
85 cyg_memalloc_maxalloc( void );
88 fill_with_data( char *buf, int size )
92 for (i=0; i < size; i++)
95 for (i=0; i < size; i++)
97 CYG_TEST_FAIL( "data written to buffer does not compare "
103 for (i=0; i < size; i++)
106 for (i=0; i < size; i++)
108 CYG_TEST_FAIL( "data written to buffer does not compare "
114 } // fill_with_data()
117 main( int argc, char *argv[] )
125 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
126 "malloc() and free() functions");
127 CYG_TEST_INFO("This checks allocation and freeing of large regions");
129 poolmax = mallinfo().maxfree;
131 if ( poolmax <= 0 ) {
132 CYG_TEST_FAIL_FINISH( "Can't determine allocation size to use" );
137 // Don't allocate all the memory at once - leave room for any structures
138 // used to manage the memory
139 str = (char *)malloc( size );
140 CYG_TEST_PASS_FAIL( str != NULL, "allocation 1");
141 CYG_TEST_PASS_FAIL( fill_with_data( str, size ), "allocation 1 usability");
145 str = (char *)malloc( size );
146 CYG_TEST_PASS_FAIL( str != NULL, "allocation 2");
147 CYG_TEST_PASS_FAIL( fill_with_data( str, size ), "allocation 2 usability");
150 str = (char *)malloc( size );
151 CYG_TEST_PASS_FAIL( str != NULL, "allocation 3");
152 CYG_TEST_PASS_FAIL( fill_with_data( str, size ), "allocation 3 usability");
155 str = (char *)malloc( size );
156 CYG_TEST_PASS_FAIL( str != NULL, "allocation 4");
157 CYG_TEST_PASS_FAIL( fill_with_data( str, size ), "allocation 4 usability");
160 str = (char *)malloc( size );
161 CYG_TEST_PASS_FAIL( str != NULL, "allocation 5");
162 CYG_TEST_PASS_FAIL( fill_with_data( str, size ), "allocation 5 usability");
165 str = (char *)malloc( size );
166 CYG_TEST_PASS_FAIL( str != NULL, "allocation 6");
167 CYG_TEST_PASS_FAIL( fill_with_data( str, size ), "allocation 6 usability");
170 str = (char *)malloc( size );
171 CYG_TEST_PASS_FAIL( str != NULL, "allocation 7");
172 CYG_TEST_PASS_FAIL( fill_with_data( str, size ), "allocation 7 usability");
175 str = (char *)malloc( size );
176 CYG_TEST_PASS_FAIL( str != NULL, "allocation 8");
177 CYG_TEST_PASS_FAIL( fill_with_data( str, size ), "allocation 8 usability");
180 str = (char *)malloc( size );
181 CYG_TEST_PASS_FAIL( str != NULL, "allocation 9");
182 CYG_TEST_PASS_FAIL( fill_with_data( str, size ), "allocation 9 usability");
185 str = (char *)malloc( size );
186 CYG_TEST_PASS_FAIL( str != NULL, "allocation 10");
187 CYG_TEST_PASS_FAIL( fill_with_data( str, size ),"allocation 10 usability");
190 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
191 "malloc() and free() functions");
196 #endif // ifndef NA_MSG