diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2009-08-05 20:58:17 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2009-08-05 20:58:17 +0000 |
commit | abc4af35f87e8e0122d3b26fef9ed830694c4156 (patch) | |
tree | 0283d44c1c228c963f423e9c817ca5a009acb4a7 /testsuites/sptests/sp64/init.c | |
parent | 2009-08-05 Joel Sherrill <joel.sherrill@oarcorp.com> (diff) | |
download | rtems-abc4af35f87e8e0122d3b26fef9ed830694c4156.tar.bz2 |
2009-08-05 Joel Sherrill <joel.sherrill@OARcorp.com>
* Makefile.am, configure.ac, sp63/init.c: Add new test for exercising
when we are unable to allocate the memory needed for an object
extend. Make sure all is handled properly.
* sp64/.cvsignore, sp64/Makefile.am, sp64/init.c, sp64/sp64.doc,
sp64/sp64.scn: New files.
Diffstat (limited to 'testsuites/sptests/sp64/init.c')
-rw-r--r-- | testsuites/sptests/sp64/init.c | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/testsuites/sptests/sp64/init.c b/testsuites/sptests/sp64/init.c new file mode 100644 index 0000000000..b435e827fd --- /dev/null +++ b/testsuites/sptests/sp64/init.c @@ -0,0 +1,167 @@ +/* + * COPYRIGHT (c) 1989-2009. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#include "tmacros.h" + +uint32_t Area1[50]; +uint32_t Area2[50]; + +rtems_task Init( + rtems_task_argument ignored +) +{ + rtems_id region1; + rtems_id region2; + rtems_status_code sc; + bool sb; + Heap_Information_block start; + Heap_Information_block info; + size_t to_alloc; + void *alloced; + + puts( "\n\n*** TEST 64 ***" ); + + puts( "Allocate one region -- so second auto extends" ); + sc = rtems_region_create( + rtems_build_name( 'R', 'N', '1', ' ' ), + Area1, + sizeof(Area1), + 8, + RTEMS_DEFAULT_ATTRIBUTES, + ®ion1 + ); + directive_failed( sc, "rtems_region_create of RN1" ); + + puts( "Init - rtems_workspace_get_information - OK" ); + sb = rtems_workspace_get_information( &start ); + assert( sb ); + + #if 0 + printf( "Init - workspace free = %d\n", start.Free.largest ); + printf( "Init - workspace free blocks = %d\n", start.Free.number ); + #endif + assert( start.Free.number == 1 ); + to_alloc = start.Free.largest; + + /* find the largest we can actually allocate */ + while ( 1 ) { + sb = rtems_workspace_allocate( to_alloc, &alloced ); + if ( sb ) + break; + to_alloc -= 4; + } + + rtems_workspace_free( alloced ); + + #if 0 + printf( "Init - start with to_alloc of = %d\n", to_alloc ); + #endif + + /* + * Verify heap is still in same shape if we couldn't allocate a region + */ + sb = rtems_workspace_get_information( &info ); + assert( sb ); + assert( info.Free.largest == start.Free.largest ); + assert( info.Free.number == start.Free.number ); + + puts( "Init - rtems_region_create - auto-extend - RTEMS_UNSATISFIED" ); + while (1) { + + sb = rtems_workspace_allocate( to_alloc, &alloced ); + assert( sb ); + + sc = rtems_region_create( + rtems_build_name( 'R', 'N', '2', ' ' ), + Area2, + sizeof(Area2), + 8, + RTEMS_DEFAULT_ATTRIBUTES, + ®ion2 + ); + + /* free the memory we snagged, then check the status */ + rtems_workspace_free( alloced ); + + if ( sc == RTEMS_SUCCESSFUL ) + break; + + if ( sc != RTEMS_TOO_MANY ) { + printf( "region create returned %d or %s\n", sc, rtems_status_text(sc) ); + rtems_test_exit(0); + } + +/* + * Extending the object structure can fail after it has extended one + * part of the object management information but not another. Chris + * needs to think about this. XXX TBD + */ +#if 0 + /* + * Verify heap is still in same shape if we couldn't allocate a task + */ + sb = rtems_workspace_get_information( &info ); + #if 0 + printf( "Init - workspace free/blocks = %d/%d\n", + info.Free.largest, info.Free.number ); + #endif + assert( sb ); + assert( info.Free.largest == start.Free.largest ); + assert( info.Free.number == start.Free.number ); +#endif + + to_alloc -= 8; + if ( to_alloc == 0 ) + break; + } + + if ( sc ) + rtems_test_exit(0); + + /* another Chris thinking case .. will this shrink back to exactly + * the same? TBD XXX + */ +#if 0 + /* + * Verify heap is still in same shape after we free the region + */ + puts( "Init - rtems_region_delete - OK" ); + sc = rtems_region_delete( region2 ); + assert( sc == 0 ); + + puts( "Init - verify workspace has same memory" ); + sb = rtems_workspace_get_information( &info ); + #if 0 + printf( "Init - workspace free/blocks = %d/%d\n", + info.Free.largest, info.Free.number ); + #endif + assert( sb ); + assert( info.Free.largest == start.Free.largest ); + assert( info.Free.number == start.Free.number ); +#endif + + puts( "*** END OF TEST 63 ***" ); + rtems_test_exit(0); +} + +/* configuration information */ + +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER + +#define CONFIGURE_MAXIMUM_TASKS 2 +#define CONFIGURE_MAXIMUM_REGIONS rtems_resource_unlimited(1) +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE + +#define CONFIGURE_INIT +#include <rtems/confdefs.h> + +/* global variables */ |