Skip to content

Commit

Permalink
Merge pull request #16427 from fjmolinas/pr_test_malloc_refactor
Browse files Browse the repository at this point in the history
tests/malloc: refactor test
  • Loading branch information
kaspar030 committed May 4, 2021
2 parents efbd867 + 2d690ee commit c49162c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions tests/malloc/main.c
Expand Up @@ -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);
Expand All @@ -100,6 +103,8 @@ static void free_memory(struct node *head)

total -= sizeof(struct node);
}

printf("Free count: %"PRIu32"\n", freed);
}

int main(void)
Expand Down
9 changes: 6 additions & 3 deletions tests/malloc/tests/01-run.py
Expand Up @@ -12,6 +12,7 @@
# 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):
Expand All @@ -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]")


Expand Down

0 comments on commit c49162c

Please sign in to comment.