diff options
Diffstat (limited to 'testsuites/libtests/malloctest/init.c')
-rw-r--r-- | testsuites/libtests/malloctest/init.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/testsuites/libtests/malloctest/init.c b/testsuites/libtests/malloctest/init.c index f7839246c3..2f09f3a582 100644 --- a/testsuites/libtests/malloctest/init.c +++ b/testsuites/libtests/malloctest/init.c @@ -586,6 +586,30 @@ static void test_heap_allocate(void) p1 = test_init_and_alloc( alloc_size, alignment, boundary, NULL ); } +static void test_heap_free(void) +{ + Heap_Control *heap = &TestHeap; + void *p; + Heap_Block *block; + bool ok; + + _Heap_Initialize( heap, &TestHeapMemory[0], sizeof(TestHeapMemory), 0 ); + + p = _Heap_Allocate( heap, 1 ); + rtems_test_assert( p != NULL ); + + block = _Heap_Block_of_alloc_area( (uintptr_t) p, heap->page_size ); + + /* + * This will kick the next block outside of the heap area and the next + * _Heap_Free() will detect this. + */ + block->size_and_flag += sizeof(TestHeapMemory); + + ok = _Heap_Free( heap, p ); + rtems_test_assert( !ok ); +} + static void *test_create_used_block( void ) { uintptr_t const alloc_size = 3 * TEST_DEFAULT_PAGE_SIZE; @@ -1147,6 +1171,29 @@ static void test_posix_memalign(void) } +static void test_greedy_allocate(void) +{ + Heap_Control *heap = &TestHeap; + uintptr_t block_size = 1; + void *p; + + _Heap_Initialize( heap, &TestHeapMemory[0], sizeof(TestHeapMemory), 0 ); + + _Heap_Greedy_allocate( heap, &block_size, 1 ); + + p = _Heap_Allocate( heap, 1 ); + rtems_test_assert( p != NULL ); + + p = _Heap_Allocate( heap, 1 ); + rtems_test_assert( p == NULL ); + + /* The internal allocation fails */ + _Heap_Greedy_allocate( heap, &block_size, 1 ); + + p = _Heap_Allocate( heap, 1 ); + rtems_test_assert( p == NULL ); +} + rtems_task Init( rtems_task_argument argument ) @@ -1184,6 +1231,7 @@ rtems_task Init( test_heap_initialize(); test_heap_block_allocate(); test_heap_allocate(); + test_heap_free(); test_heap_resize_block(); test_realloc(); test_heap_cases_1(); @@ -1194,6 +1242,7 @@ rtems_task Init( test_heap_info(); test_protected_heap_info(); test_rtems_heap_allocate_aligned_with_boundary(); + test_greedy_allocate(); test_posix_memalign(); |