From f2a7fa028164da6ee2cf00e4e2920d6c774baac0 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Thu, 31 Jan 2008 16:06:21 +0000 Subject: 2008-01-31 Joel Sherrill * malloctest/init.c: Add new test cases per Sergei. Make some of the stranger cases operate directly on a freshly initialized heap. This should make them more reproducible. --- testsuites/libtests/ChangeLog | 6 ++++ testsuites/libtests/malloctest/init.c | 58 +++++++++++++++++++++++------------ 2 files changed, 44 insertions(+), 20 deletions(-) (limited to 'testsuites/libtests') diff --git a/testsuites/libtests/ChangeLog b/testsuites/libtests/ChangeLog index 1202f81e01..8461cda030 100644 --- a/testsuites/libtests/ChangeLog +++ b/testsuites/libtests/ChangeLog @@ -1,3 +1,9 @@ +2008-01-31 Joel Sherrill + + * malloctest/init.c: Add new test cases per Sergei. Make some of the + stranger cases operate directly on a freshly initialized heap. This + should make them more reproducible. + 2008-01-29 Joel Sherrill * malloctest/init.c: Add more tests per suggestions from Sergei diff --git a/testsuites/libtests/malloctest/init.c b/testsuites/libtests/malloctest/init.c index bf341e8572..409e7c2a3e 100644 --- a/testsuites/libtests/malloctest/init.c +++ b/testsuites/libtests/malloctest/init.c @@ -11,7 +11,7 @@ * * Output parameters: NONE * - * COPYRIGHT (c) 1989-2007. + * COPYRIGHT (c) 1989-2008. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -97,6 +97,21 @@ void test_realloc(void) * Realloc with a bad pointer to force a point */ p4 = realloc( test_realloc, 32 ); +} + +#define TEST_HEAP_SIZE 1024 +uint8_t TestHeapMemory[TEST_HEAP_SIZE]; +Heap_Control TestHeap; + +void test_heap_init() +{ + _Heap_Initialize( &TestHeap, TestHeapMemory, TEST_HEAP_SIZE, 0 ); +} +void test_heap_cases_1() +{ + void *p1, *p2, *p3, *p4; + uint32_t u1, u2; + Heap_Resize_status rsc; /* * Another odd case. What we are trying to do from Sergei @@ -104,26 +119,28 @@ void test_realloc(void) * 32-bit CPU when CPU_ALIGNMENT = 4 (most targets have 8) with the * code like this: */ - p1 = malloc(12); - p2 = malloc(32); - p3 = malloc(32); - free(p2); - sc = rtems_memalign(&p2, 8, 28); - free(p1); - free(p2); - free(p3); - - /* - * Odd case in resizing a block. Again test case outline per Sergei - */ - p1 = malloc(32); - p2 = malloc(8); - p3 = malloc(32); - free(p2); - p4 = realloc(p1, 42); - free(p3); - free(p4); + test_heap_init(); + p1 = _Heap_Allocate( &TestHeap, 12 ); + p2 = _Heap_Allocate( &TestHeap, 32 ); + p3 = _Heap_Allocate( &TestHeap, 32 ); + _Heap_Free( &TestHeap, p2 ); + p2 = _Heap_Allocate_aligned( &TestHeap, 8, 28 ); + _Heap_Free( &TestHeap, p1 ); + _Heap_Free( &TestHeap, p2 ); + _Heap_Free( &TestHeap, p3 ); + /* + * Odd case in resizing a block. Again test case outline per Sergei + */ + test_heap_init(); + p1 = _Heap_Allocate( &TestHeap, 32 ); + p2 = _Heap_Allocate( &TestHeap, 8 ); + p3 = _Heap_Allocate( &TestHeap, 32 ); + _Heap_Free( &TestHeap, p2 ); + rsc = _Heap_Resize_block( &TestHeap, p1, 41, &u1, &u2 ); + /* XXX what should we expect */ + _Heap_Free( &TestHeap, p3 ); + _Heap_Free( &TestHeap, p4 ); } /* @@ -175,6 +192,7 @@ rtems_task Init( directive_failed( status, "rtems_clock_set" ); test_realloc(); + test_heap_cases_1(); test_posix_memalign(); -- cgit v1.2.3