tests/malloc: refactor test

Matching on every free leads to flimsy test results where all memory
is freed but one line fails to be matched by pexpect, instead, match
the final count.
This commit is contained in:
Francisco Molina 2021-05-03 10:30:31 +02:00
parent d806aa42c6
commit 2d690ee05a
No known key found for this signature in database
GPG Key ID: 3E94EAC3DBDEEDA8
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]")