1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2026-01-01 01:41:18 +01:00

Merge pull request #16427 from fjmolinas/pr_test_malloc_refactor

tests/malloc: refactor test
This commit is contained in:
Kaspar Schleiser 2021-05-04 10:01:47 +02:00 committed by GitHub
commit c49162cc66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View File

@ -78,10 +78,13 @@ static void free_memory(struct node *head)
{
struct node *old_head;
uint32_t freed = 0;
while (head) {
if (head->ptr) {
if (total > CHUNK_SIZE) {
total -= CHUNK_SIZE;
freed++;
}
printf("Free %"PRIu32" Bytes at 0x%p, total %"PRIu32"\n",
(uint32_t)CHUNK_SIZE, head->ptr, total);
@ -100,6 +103,8 @@ static void free_memory(struct node *head)
total -= sizeof(struct node);
}
printf("Free count: %"PRIu32"\n", freed);
}
int main(void)

View File

@ -12,6 +12,7 @@ from testrunner import run
# For BOARD's with large amount of RAM allocating all chunks takes longer
# than 10s
ALLOCATION_TIMEOUT = 20
FREE_TIMEOUT = ALLOCATION_TIMEOUT
def testfunc(child):
@ -30,9 +31,11 @@ def testfunc(child):
if initial_allocations == 0:
initial_allocations = allocations
assert initial_allocations == allocations
for _ in range(allocations):
child.expect(r"Free {} Bytes at 0x[a-z0-9]+, total [a-z0-9]+\r\n"
.format(chunk_size))
child.expect(r"Free {} Bytes at 0x[a-z0-9]+, total [a-z0-9]+\r\n"
.format(chunk_size))
child.expect(r'Free count: (\d+)\r\n', timeout=FREE_TIMEOUT)
freed = int(child.match.group(1))
assert freed == allocations
child.expect_exact("[SUCCESS]")