Skip to content

Commit 56154c0

Browse files
author
Deepika
committed
Update the test case to check multiple bank heap regions
1 parent 1576fb0 commit 56154c0

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

TESTS/mbedmicro-rtos-mbed/heap_and_stack/main.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ extern uint32_t mbed_heap_size;
4848
extern uint32_t mbed_stack_isr_start;
4949
extern uint32_t mbed_stack_isr_size;
5050

51+
#if defined(TOOLCHAIN_GCC_ARM) && defined(MBED_SPLIT_HEAP)
52+
extern uint32_t __mbed_sbrk_start_0;
53+
extern uint32_t __mbed_krbs_start_0;
54+
unsigned char *mbed_heap_start_0 = (unsigned char *) &__mbed_sbrk_start_0;;
55+
uint32_t mbed_heap_size_0 = (uint32_t) &__mbed_krbs_start_0 - (uint32_t) &__mbed_sbrk_start_0;
56+
#endif
5157

5258
struct linked_list {
5359
linked_list *next;
@@ -121,7 +127,11 @@ static void allocate_and_fill_heap(linked_list *&head)
121127
break;
122128
}
123129
bool result = rangeinrange((uint32_t) temp, sizeof(linked_list), mbed_heap_start, mbed_heap_size);
124-
130+
#if defined(TOOLCHAIN_GCC_ARM) && defined(MBED_SPLIT_HEAP)
131+
if (false == result) {
132+
result = rangeinrange((uint32_t) temp, sizeof(linked_list), (uint32_t)mbed_heap_start_0, mbed_heap_size_0);
133+
}
134+
#endif
125135
TEST_ASSERT_TRUE_MESSAGE(result, "Memory allocation out of range");
126136

127137
// Init
@@ -169,7 +179,11 @@ void test_heap_in_range(void)
169179
TEST_ASSERT_NOT_NULL(initial_heap);
170180

171181
bool result = inrange((uint32_t) initial_heap, mbed_heap_start, mbed_heap_size);
172-
182+
#if defined(TOOLCHAIN_GCC_ARM) && defined(MBED_SPLIT_HEAP)
183+
if (false == result) {
184+
result = inrange((uint32_t) initial_heap, (uint32_t)mbed_heap_start_0, mbed_heap_size_0);
185+
}
186+
#endif
173187
TEST_ASSERT_TRUE_MESSAGE(result, "Heap in wrong location");
174188
free(initial_heap);
175189
}

TESTS/mbedmicro-rtos-mbed/malloc/main.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,44 @@ void test_multithread_allocation(void)
107107
TEST_ASSERT_FALSE(thread_alloc_failure);
108108
}
109109

110+
/** Test for multiple heap alloc and free calls */
111+
#define ALLOC_ARRAY_SIZE 100
112+
#define ALLOC_LOOP 20
113+
#define SIZE_INCREMENTS 1023
114+
#define SIZE_MODULO 31
115+
116+
void test_alloc_and_free(void)
117+
{
118+
void *array[ALLOC_ARRAY_SIZE];
119+
void *data = NULL;
120+
long total_allocated = 0;
121+
int count = 0;
122+
int size = SIZE_INCREMENTS;
123+
int loop = ALLOC_LOOP;
124+
while (loop) {
125+
data = malloc(size);
126+
if (NULL != data) {
127+
array[count++] = data;
128+
memset((void *)data, 0xdeadbeef, size);
129+
total_allocated += size;
130+
size += SIZE_INCREMENTS;
131+
if (size > 10000) {
132+
size %= SIZE_MODULO;
133+
}
134+
} else {
135+
for (int i = 0; i < count; i++) {
136+
free(array[i]);
137+
array[i] = NULL;
138+
}
139+
loop--;
140+
printf("Total size dynamically allocated: %luB\n", total_allocated);
141+
total_allocated = 0;
142+
count = 0;
143+
continue;
144+
}
145+
}
146+
}
147+
110148
/** Test for large heap allocation
111149
112150
Given a heap of size mbed_heap_size
@@ -167,7 +205,8 @@ Case cases[] = {
167205
Case("Test 0 size allocation", test_zero_allocation),
168206
Case("Test NULL pointer free", test_null_free),
169207
Case("Test multithreaded allocations", test_multithread_allocation),
170-
Case("Test large allocation", test_big_allocation)
208+
Case("Test large allocation", test_big_allocation),
209+
Case("Test multiple alloc and free calls", test_alloc_and_free)
171210
};
172211

173212
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)

0 commit comments

Comments
 (0)