mirror of https://github.com/ARMmbed/mbed-os.git
Update the test case to check multiple bank heap regions
parent
1576fb0aaa
commit
56154c096d
|
@ -48,6 +48,12 @@ extern uint32_t mbed_heap_size;
|
|||
extern uint32_t mbed_stack_isr_start;
|
||||
extern uint32_t mbed_stack_isr_size;
|
||||
|
||||
#if defined(TOOLCHAIN_GCC_ARM) && defined(MBED_SPLIT_HEAP)
|
||||
extern uint32_t __mbed_sbrk_start_0;
|
||||
extern uint32_t __mbed_krbs_start_0;
|
||||
unsigned char *mbed_heap_start_0 = (unsigned char *) &__mbed_sbrk_start_0;;
|
||||
uint32_t mbed_heap_size_0 = (uint32_t) &__mbed_krbs_start_0 - (uint32_t) &__mbed_sbrk_start_0;
|
||||
#endif
|
||||
|
||||
struct linked_list {
|
||||
linked_list *next;
|
||||
|
@ -121,7 +127,11 @@ static void allocate_and_fill_heap(linked_list *&head)
|
|||
break;
|
||||
}
|
||||
bool result = rangeinrange((uint32_t) temp, sizeof(linked_list), mbed_heap_start, mbed_heap_size);
|
||||
|
||||
#if defined(TOOLCHAIN_GCC_ARM) && defined(MBED_SPLIT_HEAP)
|
||||
if (false == result) {
|
||||
result = rangeinrange((uint32_t) temp, sizeof(linked_list), (uint32_t)mbed_heap_start_0, mbed_heap_size_0);
|
||||
}
|
||||
#endif
|
||||
TEST_ASSERT_TRUE_MESSAGE(result, "Memory allocation out of range");
|
||||
|
||||
// Init
|
||||
|
@ -169,7 +179,11 @@ void test_heap_in_range(void)
|
|||
TEST_ASSERT_NOT_NULL(initial_heap);
|
||||
|
||||
bool result = inrange((uint32_t) initial_heap, mbed_heap_start, mbed_heap_size);
|
||||
|
||||
#if defined(TOOLCHAIN_GCC_ARM) && defined(MBED_SPLIT_HEAP)
|
||||
if (false == result) {
|
||||
result = inrange((uint32_t) initial_heap, (uint32_t)mbed_heap_start_0, mbed_heap_size_0);
|
||||
}
|
||||
#endif
|
||||
TEST_ASSERT_TRUE_MESSAGE(result, "Heap in wrong location");
|
||||
free(initial_heap);
|
||||
}
|
||||
|
|
|
@ -107,6 +107,44 @@ void test_multithread_allocation(void)
|
|||
TEST_ASSERT_FALSE(thread_alloc_failure);
|
||||
}
|
||||
|
||||
/** Test for multiple heap alloc and free calls */
|
||||
#define ALLOC_ARRAY_SIZE 100
|
||||
#define ALLOC_LOOP 20
|
||||
#define SIZE_INCREMENTS 1023
|
||||
#define SIZE_MODULO 31
|
||||
|
||||
void test_alloc_and_free(void)
|
||||
{
|
||||
void *array[ALLOC_ARRAY_SIZE];
|
||||
void *data = NULL;
|
||||
long total_allocated = 0;
|
||||
int count = 0;
|
||||
int size = SIZE_INCREMENTS;
|
||||
int loop = ALLOC_LOOP;
|
||||
while (loop) {
|
||||
data = malloc(size);
|
||||
if (NULL != data) {
|
||||
array[count++] = data;
|
||||
memset((void *)data, 0xdeadbeef, size);
|
||||
total_allocated += size;
|
||||
size += SIZE_INCREMENTS;
|
||||
if (size > 10000) {
|
||||
size %= SIZE_MODULO;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < count; i++) {
|
||||
free(array[i]);
|
||||
array[i] = NULL;
|
||||
}
|
||||
loop--;
|
||||
printf("Total size dynamically allocated: %luB\n", total_allocated);
|
||||
total_allocated = 0;
|
||||
count = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Test for large heap allocation
|
||||
|
||||
Given a heap of size mbed_heap_size
|
||||
|
@ -167,7 +205,8 @@ Case cases[] = {
|
|||
Case("Test 0 size allocation", test_zero_allocation),
|
||||
Case("Test NULL pointer free", test_null_free),
|
||||
Case("Test multithreaded allocations", test_multithread_allocation),
|
||||
Case("Test large allocation", test_big_allocation)
|
||||
Case("Test large allocation", test_big_allocation),
|
||||
Case("Test multiple alloc and free calls", test_alloc_and_free)
|
||||
};
|
||||
|
||||
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
|
||||
|
|
Loading…
Reference in New Issue