summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2013-05-03 17:28:48 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2013-05-03 17:30:53 +0200
commit85387db5aaa0496016b2609e1f62200a8904b249 (patch)
treeedadcfffa9e617a4826703af7976da7dacf231ef
parentSUPPORT: Fix phone number (diff)
downloadrtems-85387db5aaa0496016b2609e1f62200a8904b249.tar.bz2
libtests/malloc04: Adjust for new sbrk() support
-rw-r--r--testsuites/libtests/malloc04/init.c115
-rw-r--r--testsuites/libtests/malloc04/malloc04.doc3
-rw-r--r--testsuites/libtests/malloc04/malloc04.scn15
3 files changed, 84 insertions, 49 deletions
diff --git a/testsuites/libtests/malloc04/init.c b/testsuites/libtests/malloc04/init.c
index 00355dabd4..89cbab327f 100644
--- a/testsuites/libtests/malloc04/init.c
+++ b/testsuites/libtests/malloc04/init.c
@@ -40,7 +40,7 @@ void *rtems_heap_null_extend(
}
#endif
-char Malloc_Heap[ 128 ] CPU_STRUCTURE_ALIGNMENT;
+char Malloc_Heap[ 256 ] CPU_STRUCTURE_ALIGNMENT;
int sbrk_count;
Heap_Control TempHeap;
@@ -52,31 +52,25 @@ void * sbrk(ptrdiff_t incr)
printf( "sbrk(%td)\n", incr );
if ( sbrk_count == -1 ) {
- p = (void *) (NULL - 2);
- } else if ( offset + incr < sizeof(Malloc_Heap) ) {
- p = &Malloc_Heap[ offset ];
- offset += incr;
- } else {
- if ( sbrk_count == 0 )
- p = (void *) rtems_task_create;
- sbrk_count++;
+ p = (void *) -2;
+ sbrk_count = 0;
+ } else if ( offset + incr <= sizeof(Malloc_Heap) ) {
+ p = &Malloc_Heap[ offset ];
+ offset += incr;
}
- sbrk_count++;
+ ++sbrk_count;
+
return p;
}
-void *p1, *p2, *p3, *p4;
-
rtems_task Init(
rtems_task_argument argument
)
{
Heap_Control *real_heap;
Heap_Area area;
-
- sbrk_count = 0;
- offset = 0;
+ void *p;
puts( "\n\n*** TEST MALLOC 04 ***" );
@@ -84,42 +78,83 @@ rtems_task Init(
real_heap = malloc_get_heap_pointer();
malloc_set_heap_pointer( &TempHeap );
- rtems_heap_set_sbrk_amount( 64 );
+ rtems_heap_set_sbrk_amount( 0 );
+
+ puts( "No sbrk() amount" );
- puts( "Initialize heap with some memory" );
- offset = 64;
sbrk_count = 0;
+ offset = 64;
area.begin = &Malloc_Heap [0];
- area.size = 64;
+ area.size = offset;
RTEMS_Malloc_Initialize( &area, 1, NULL );
- p1 = malloc(64);
- p2 = malloc(64);
- p3 = malloc(48);
- p4 = malloc(48);
-
- puts( "Initialize heap with some memory - return address out of heap" );
- area.begin = &Malloc_Heap [1];
- area.size = 64;
+
+ errno = 0;
+ p = malloc(64);
+ rtems_test_assert( p == NULL );
+ rtems_test_assert( errno == ENOMEM );
+ rtems_test_assert( sbrk_count == 0 );
+
+ rtems_heap_set_sbrk_amount( 64 );
+
+ puts( "Misaligned extend" );
+
+ sbrk_count = 0;
+ offset = 64;
+ area.begin = &Malloc_Heap [0];
+ area.size = offset;
RTEMS_Malloc_Initialize( &area, 1, NULL );
+
+ p = malloc(1);
+ rtems_test_assert( p != NULL );
+ rtems_test_assert( sbrk_count == 0 );
+
+ p = malloc(65);
+ rtems_test_assert( p != NULL );
+ rtems_test_assert( sbrk_count == 1 );
+
+ puts( "Not enough sbrk() space" );
+
+ sbrk_count = 0;
offset = 64;
- sbrk_count = -1;
- p1 = malloc( 127 );
- rtems_test_assert( p1 == (void *) NULL );
+ area.begin = &Malloc_Heap [0];
+ area.size = offset;
+ RTEMS_Malloc_Initialize( &area, 1, NULL );
+
+ errno = 0;
+ p = malloc( sizeof( Malloc_Heap ) );
+ rtems_test_assert( p == NULL );
rtems_test_assert( errno == ENOMEM );
-
+ rtems_test_assert( sbrk_count == 1 );
+
+ puts( "Valid heap extend" );
+ sbrk_count = 0;
+ offset = 64;
area.begin = &Malloc_Heap [0];
- area.size = 64;
+ area.size = offset;
RTEMS_Malloc_Initialize( &area, 1, NULL );
- puts( "Initialize heap with some unaligned memory" );
- offset = 65;
- sbrk_count = 0;
- area.begin = &Malloc_Heap [1];
- area.size = 64;
+
+ p = malloc(32);
+ rtems_test_assert( p != NULL );
+ rtems_test_assert( sbrk_count == 0 );
+
+ p = malloc(32);
+ rtems_test_assert( p != NULL );
+ rtems_test_assert( sbrk_count == 1 );
+
+ puts( "Invalid heap extend" );
+
+ sbrk_count = -1;
+ offset = 64;
+ area.begin = &Malloc_Heap [0];
+ area.size = offset;
RTEMS_Malloc_Initialize( &area, 1, NULL );
- p1 = malloc(64);
- p2 = malloc(64);
- p3 = malloc(48);
+
+ errno = 0;
+ p = malloc( 64 );
+ rtems_test_assert( p == NULL );
+ rtems_test_assert( errno == ENOMEM );
+ rtems_test_assert( sbrk_count == 2 );
/* Restore information on real heap */
malloc_set_heap_pointer( real_heap );
diff --git a/testsuites/libtests/malloc04/malloc04.doc b/testsuites/libtests/malloc04/malloc04.doc
index 2e18042529..5f27bdf9c0 100644
--- a/testsuites/libtests/malloc04/malloc04.doc
+++ b/testsuites/libtests/malloc04/malloc04.doc
@@ -16,4 +16,5 @@ directives:
concepts:
-+ Exercise all non-fatal paths in the sbrk() support in the malloc family.
++ Exercise all paths in rtems_heap_extend_via_sbrk() function of the sbrk()
+ support in the malloc family.
diff --git a/testsuites/libtests/malloc04/malloc04.scn b/testsuites/libtests/malloc04/malloc04.scn
index f6169933b5..afe644afba 100644
--- a/testsuites/libtests/malloc04/malloc04.scn
+++ b/testsuites/libtests/malloc04/malloc04.scn
@@ -1,13 +1,12 @@
*** TEST MALLOC 04 ***
-Initialize heap with some memory
-sbrk(128)
+No sbrk() amount
+Misaligned extend
sbrk(128)
+Not enough sbrk() space
+sbrk(256)
+Valid heap extend
sbrk(64)
-Initialize heap with some memory - return address out of heap
-sbrk(128)
-sbrk(-128)
-Initialize heap with some unaligned memory
-sbrk(128)
-sbrk(128)
+Invalid heap extend
sbrk(64)
+sbrk(-64)
*** END OF TEST MALLOC 04 ***