From 22c7a6496399900271128fb799f3ae7b181124c6 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 25 Jun 2013 12:22:23 +0200 Subject: psxtests/psxkey02: Simplify This avoids problems with debugging enabled. --- testsuites/psxtests/psxkey02/init.c | 93 ++++++++----------------------- testsuites/psxtests/psxkey02/psxkey02.scn | 1 - 2 files changed, 23 insertions(+), 71 deletions(-) diff --git a/testsuites/psxtests/psxkey02/init.c b/testsuites/psxtests/psxkey02/init.c index 943dedc85c..6055dac828 100644 --- a/testsuites/psxtests/psxkey02/init.c +++ b/testsuites/psxtests/psxkey02/init.c @@ -13,6 +13,7 @@ #include #include +#include #include "tmacros.h" #include "pmacros.h" @@ -24,103 +25,55 @@ void *POSIX_Init( ) { pthread_key_t key; - int sc; - bool sb; - Heap_Information_block start; - Heap_Information_block info; - size_t to_alloc; + int eno; + bool ok; + uintptr_t to_alloc; void *alloced; + rtems_resource_snapshot snapshot; + void *greedy; puts( "\n\n*** TEST KEY 02 ***" ); - puts( "Init - rtems_workspace_get_information - OK" ); - sb = rtems_workspace_get_information( &start ); - rtems_test_assert( sb ); - - #if 0 - printf( "Init - workspace free = %d\n", start.Free.largest ); - printf( "Init - workspace free blocks = %d\n", start.Free.number ); - #endif - rtems_test_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 task - */ - sb = rtems_workspace_get_information( &info ); - rtems_test_assert( sb ); - rtems_test_assert( info.Free.largest == start.Free.largest ); - rtems_test_assert( info.Free.number == start.Free.number ); + greedy = rtems_workspace_greedy_allocate_all_except_largest( &to_alloc ); + rtems_resource_snapshot_take( &snapshot ); puts( "Init - pthread_key_create - ENOMEM" ); - while (1) { + while ( to_alloc > 8 ) { + ok = rtems_workspace_allocate( to_alloc, &alloced ); + rtems_test_assert( ok ); - sb = rtems_workspace_allocate( to_alloc, &alloced ); - rtems_test_assert( sb ); + eno = pthread_key_create( &key, NULL ); - sc = pthread_key_create( &key, NULL ); - - /* free the memory we snagged, then check the status */ rtems_workspace_free( alloced ); - if ( !sc ) + if ( eno == 0 ) break; - if ( sc != ENOMEM ) { - printf( "key create returned %s\n", strerror(sc) ); - rtems_test_exit(0); - } + rtems_test_assert( eno == ENOMEM ); /* * 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 - rtems_test_assert( sb ); - rtems_test_assert( info.Free.largest == start.Free.largest ); - rtems_test_assert( info.Free.number == start.Free.number ); + ok = rtems_resource_snapshot_check( &snapshot ); + rtems_test_assert( ok ); to_alloc -= 8; - if ( to_alloc == 0 ) - break; } - if ( sc ) - rtems_test_exit(0); + rtems_test_assert( eno == 0 ); /* * Verify heap is still in same shape after we free the task */ puts( "Init - pthread_key_delete - OK" ); - sc = pthread_key_delete( key ); - rtems_test_assert( sc == 0 ); + eno = pthread_key_delete( key ); + rtems_test_assert( eno == 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 - rtems_test_assert( sb ); - rtems_test_assert( info.Free.largest == start.Free.largest ); - rtems_test_assert( info.Free.number == start.Free.number ); + ok = rtems_resource_snapshot_check( &snapshot ); + rtems_test_assert( ok ); + + rtems_workspace_greedy_free( greedy ); puts( "*** END OF TEST KEY 02 ***" ); rtems_test_exit(0); diff --git a/testsuites/psxtests/psxkey02/psxkey02.scn b/testsuites/psxtests/psxkey02/psxkey02.scn index 58786d7dfd..fbc3342a23 100644 --- a/testsuites/psxtests/psxkey02/psxkey02.scn +++ b/testsuites/psxtests/psxkey02/psxkey02.scn @@ -1,5 +1,4 @@ *** TEST KEY 02 *** -Init - rtems_workspace_get_information - OK Init - pthread_key_create - ENOMEM Init - pthread_key_delete - OK Init - verify workspace has same memory -- cgit v1.2.3