mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #15168 from JulianHolzwarth/pr/software/test/IPC/change
core/msg.c: fixed msg_queue_print()
This commit is contained in:
commit
e142001221
20
core/msg.c
20
core/msg.c
@ -460,23 +460,27 @@ void msg_init_queue(msg_t *array, int num)
|
||||
void msg_queue_print(void)
|
||||
{
|
||||
unsigned state = irq_disable();
|
||||
|
||||
thread_t *thread = thread_get_active();
|
||||
|
||||
int msg_counter = msg_avail();
|
||||
|
||||
if (msg_counter <= -1) {
|
||||
/* no msg queue */
|
||||
printf("No message queue\n");
|
||||
return;
|
||||
}
|
||||
cib_t *msg_queue = &thread->msg_queue;
|
||||
msg_t *msg_array = thread->msg_array;
|
||||
unsigned int i = msg_queue->read_count & msg_queue->mask;
|
||||
int first_msg = cib_peek(msg_queue);
|
||||
|
||||
printf("Message queue of thread %" PRIkernel_pid "\n", thread->pid);
|
||||
printf(" size: %u (avail: %u)\n", msg_queue->mask + 1,
|
||||
cib_avail(msg_queue));
|
||||
printf(" size: %u (avail: %d)\n", msg_queue->mask + 1, msg_counter);
|
||||
|
||||
for (; i != (msg_queue->write_count & msg_queue->mask);
|
||||
i = (i + 1) & msg_queue->mask) {
|
||||
msg_t *m = &msg_array[i];
|
||||
for (int i = 0; i < msg_counter; i++) {
|
||||
msg_t *m = &msg_array[(first_msg + i) & msg_queue->mask];
|
||||
printf(" * %u: sender: %" PRIkernel_pid ", type: 0x%04" PRIu16
|
||||
", content: %" PRIu32 " (%p)\n", i, m->sender_pid, m->type,
|
||||
m->content.value, m->content.ptr);
|
||||
}
|
||||
|
||||
irq_restore(state);
|
||||
}
|
||||
|
3
tests/msg_queue_print/Makefile
Normal file
3
tests/msg_queue_print/Makefile
Normal file
@ -0,0 +1,3 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
47
tests/msg_queue_print/main.c
Normal file
47
tests/msg_queue_print/main.c
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Freie Universität Berlin,
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup tests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief testing msg_queue_print
|
||||
*
|
||||
*
|
||||
* @author Julian Holzwarth <julian.holzwarth@fu-berlin.de>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "msg.h"
|
||||
|
||||
#define QUEUE_SIZE 8
|
||||
|
||||
msg_t msg_queue[QUEUE_SIZE];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
msg_t messages[QUEUE_SIZE];
|
||||
|
||||
msg_queue_print();
|
||||
msg_init_queue(msg_queue, QUEUE_SIZE);
|
||||
msg_queue_print();
|
||||
|
||||
for (int i = 0; i < QUEUE_SIZE; i++) {
|
||||
messages[i].type = i;
|
||||
messages[i].content.value = i;
|
||||
msg_send_to_self(&messages[i]);
|
||||
}
|
||||
|
||||
msg_queue_print();
|
||||
printf("DONE");
|
||||
return 0;
|
||||
}
|
33
tests/msg_queue_print/tests/01-run.py
Executable file
33
tests/msg_queue_print/tests/01-run.py
Executable file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2021 Freie Universität Berlin,
|
||||
#
|
||||
# This file is subject to the terms and conditions of the GNU Lesser
|
||||
# General Public License v2.1. See the file LICENSE in the top level
|
||||
# directory for more details.
|
||||
|
||||
# @author Julian Holzwarth <julian.holzwarth@fu-berlin.de>
|
||||
|
||||
import sys
|
||||
from testrunner import run
|
||||
|
||||
|
||||
def testfunc(child):
|
||||
child.expect("No message queue")
|
||||
child.expect("Message queue of thread 2")
|
||||
child.expect_exact('size: 8 (avail: 0)')
|
||||
child.expect("Message queue of thread 2")
|
||||
child.expect_exact('size: 8 (avail: 8)')
|
||||
child.expect_exact('type: 0x0000, content: 0 ((nil))')
|
||||
child.expect_exact('type: 0x0001, content: 1 (0x1)')
|
||||
child.expect_exact('type: 0x0002, content: 2 (0x2)')
|
||||
child.expect_exact('type: 0x0003, content: 3 (0x3)')
|
||||
child.expect_exact('type: 0x0004, content: 4 (0x4)')
|
||||
child.expect_exact('type: 0x0005, content: 5 (0x5)')
|
||||
child.expect_exact('type: 0x0006, content: 6 (0x6)')
|
||||
child.expect_exact('type: 0x0007, content: 7 (0x7)')
|
||||
child.expect_exact('DONE')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(run(testfunc))
|
Loading…
Reference in New Issue
Block a user