Skip to content

Commit e843514

Browse files
committed
tests/core/msg_queue_print: test for special cases
1 parent 850a827 commit e843514

File tree

3 files changed

+72
-19
lines changed

3 files changed

+72
-19
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
include ../Makefile.core_common
22

3+
CONFIG_MSG_QUEUE_PRINT_MAX ?= 6
4+
5+
CFLAGS += -DCONFIG_MSG_QUEUE_PRINT_MAX=$(CONFIG_MSG_QUEUE_PRINT_MAX)
6+
37
include $(RIOTBASE)/Makefile.include
8+
9+
# Make config available in Python test script via environment variables
10+
export CONFIG_MSG_QUEUE_PRINT_MAX

tests/core/msg_queue_print/main.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
2-
* Copyright (C) 2021 Freie Universität Berlin,
2+
* Copyright (C) 2021 Freie Universität Berlin
3+
* Copyright (C) 2024 TU Dresden
34
*
45
* This file is subject to the terms and conditions of the GNU Lesser
56
* General Public License v2.1. See the file LICENSE in the top level
@@ -15,6 +16,7 @@
1516
*
1617
*
1718
* @author Julian Holzwarth <[email protected]>
19+
* @author Mikolai Gütschow <[email protected]>
1820
*
1921
*/
2022

@@ -29,19 +31,37 @@ msg_t msg_queue[QUEUE_SIZE];
2931

3032
int main(void)
3133
{
32-
msg_t messages[QUEUE_SIZE];
34+
msg_t msg;
3335

3436
msg_queue_print();
3537
msg_init_queue(msg_queue, QUEUE_SIZE);
3638
msg_queue_print();
3739

40+
/* fill message queue */
3841
for (uintptr_t i = 0; i < QUEUE_SIZE; i++) {
39-
messages[i].type = i;
40-
messages[i].content.ptr = (void *) i;
41-
msg_send_to_self(&messages[i]);
42+
msg.type = i;
43+
msg.content.ptr = (void *) i;
44+
msg_send_to_self(&msg);
4245
}
4346

4447
msg_queue_print();
48+
49+
/* drain half of message queue */
50+
for (uintptr_t i = 0; i < QUEUE_SIZE/2; i++) {
51+
msg_receive(&msg);
52+
}
53+
54+
msg_queue_print();
55+
56+
/* fill up message queue again */
57+
for (uintptr_t i = QUEUE_SIZE; i < QUEUE_SIZE + QUEUE_SIZE/2; i++) {
58+
msg.type = i;
59+
msg.content.ptr = (void *) i;
60+
msg_send_to_self(&msg);
61+
}
62+
63+
msg_queue_print();
64+
4565
puts("DONE");
4666
return 0;
4767
}

tests/core/msg_queue_print/tests/01-run.py

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,60 @@
11
#!/usr/bin/env python3
22

3-
# Copyright (C) 2021 Freie Universität Berlin,
3+
# Copyright (C) 2021 Freie Universität Berlin
4+
# Copyright (C) 2024 TU Dresden
45
#
56
# This file is subject to the terms and conditions of the GNU Lesser
67
# General Public License v2.1. See the file LICENSE in the top level
78
# directory for more details.
89

910
# @author Julian Holzwarth <[email protected]>
11+
# @author Mikolai Gütschow <[email protected]>
1012

1113
import os
1214
import sys
1315
from testrunner import run
1416

17+
PRINT_MAX = int(os.getenv('CONFIG_MSG_QUEUE_PRINT_MAX'))
1518

16-
def testfunc(child):
17-
child.expect("No messages or no message queue")
19+
20+
def expect_none(child):
1821
child.expect("No messages or no message queue")
22+
23+
24+
def expect_some(child, size, avail, range_start):
1925
child.expect(r"Message queue of thread \d+\r\n")
20-
child.expect_exact('size: 8 (avail: 8)')
21-
if os.environ.get('BOARD') in ['native', 'native64']:
22-
child.expect_exact('type: 0x0000, content: 0 ((nil))')
26+
child.expect_exact(f'size: {size} (avail: {avail})')
27+
28+
expect_less = avail > PRINT_MAX
29+
30+
if expect_less:
31+
range_end = range_start + PRINT_MAX
2332
else:
24-
child.expect(r'type: 0x0000, content: 0 \((0x)?0+\)')
25-
child.expect_exact('type: 0x0001, content: 1 (0x1)')
26-
child.expect_exact('type: 0x0002, content: 2 (0x2)')
27-
child.expect_exact('type: 0x0003, content: 3 (0x3)')
28-
child.expect_exact('type: 0x0004, content: 4 (0x4)')
29-
child.expect_exact('type: 0x0005, content: 5 (0x5)')
30-
child.expect_exact('type: 0x0006, content: 6 (0x6)')
31-
child.expect_exact('type: 0x0007, content: 7 (0x7)')
33+
range_end = range_start + avail
34+
35+
for counter in range(range_start, range_end):
36+
expect_content(child, counter)
37+
38+
if expect_less:
39+
child.expect('...')
40+
41+
42+
def expect_content(child, counter):
43+
if counter == 0:
44+
if os.environ.get('BOARD') in ['native', 'native64']:
45+
child.expect_exact('type: 0x0000, content: 0 ((nil))')
46+
else:
47+
child.expect(r'type: 0x0000, content: 0 \((0x)?0+\)')
48+
else:
49+
child.expect_exact(f'type: 0x{counter:04x}, content: {counter} (0x{counter:x})')
50+
51+
52+
def testfunc(child):
53+
expect_none(child)
54+
expect_none(child)
55+
expect_some(child, 8, 8, 0)
56+
expect_some(child, 8, 4, 4)
57+
expect_some(child, 8, 8, 4)
3258
child.expect_exact('DONE')
3359

3460

0 commit comments

Comments
 (0)