From 8812745b020e77af33680b790270a03341ddf20f Mon Sep 17 00:00:00 2001 From: Lotte Steenbrink Date: Wed, 12 Feb 2014 15:58:05 +0000 Subject: [PATCH] added two test cases for issue #100 test_thread_msg_block_w_queue: demonstrates the behaviour described in issue #100 and that it is solved by PR #569 test_thread_msg_block_wo_queue: demonstrates behaviour similar to the above but without a messge queue. This works with the current master, but breaks with PR #569 --- tests/test_thread_msg_block_w_queue/Makefile | 9 +++ tests/test_thread_msg_block_w_queue/main.c | 65 +++++++++++++++++++ tests/test_thread_msg_block_wo_queue/Makefile | 9 +++ tests/test_thread_msg_block_wo_queue/main.c | 62 ++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 tests/test_thread_msg_block_w_queue/Makefile create mode 100644 tests/test_thread_msg_block_w_queue/main.c create mode 100644 tests/test_thread_msg_block_wo_queue/Makefile create mode 100644 tests/test_thread_msg_block_wo_queue/main.c diff --git a/tests/test_thread_msg_block_w_queue/Makefile b/tests/test_thread_msg_block_w_queue/Makefile new file mode 100644 index 0000000000..2c6cecfcce --- /dev/null +++ b/tests/test_thread_msg_block_w_queue/Makefile @@ -0,0 +1,9 @@ +# name of your project +export PROJECT = test_thread_msg_block_w_queue + +export BOARD ?= native + +# the absolute path of the RIOT-base dir +export RIOTBASE =$(CURDIR)/../.. + +include $(RIOTBASE)/Makefile.include diff --git a/tests/test_thread_msg_block_w_queue/main.c b/tests/test_thread_msg_block_w_queue/main.c new file mode 100644 index 0000000000..e4b0edbfc2 --- /dev/null +++ b/tests/test_thread_msg_block_w_queue/main.c @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2014 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License. See the file LICENSE in the top level directory for more + * details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Thread test application + * + * @author Christian Mehlis + * @author Lotte Steenbrink + * + * @} + */ + +#include +#include + +#include "thread.h" +#include "msg.h" + +char t1_stack[KERNEL_CONF_STACKSIZE_PRINTF]; + +uint16_t p1, p_main; + +void thread1(void) +{ + printf("THREAD %u start\n", p1); + + msg_t msg, reply; + memset(&msg, 1, sizeof(msg_t)); + + /* step 1: send asynchonously */ + msg_send(&msg, p_main, 0); + + /* step 2: send message, turning its status into STATUS_REPLY_BLOCKED */ + msg_send_receive(&msg, &reply, p_main); + printf("received: %u, %u \n", reply.sender_pid, reply.type); + printf("pointer: %s\n", reply.content.ptr); + + printf("THREAD %u SHOULD BE BLOCKING :(\n", p1); +} + +int main(void) +{ + msg_t msg; + p_main = thread_pid; + + msg_t msg_q[1]; + msg_init_queue(msg_q, 1); + + p1 = thread_create(t1_stack, KERNEL_CONF_STACKSIZE_PRINTF, PRIORITY_MAIN - 1, + CREATE_WOUT_YIELD | CREATE_STACKTEST, thread1, "nr1"); + + /* step 3: receive a msg */ + msg_receive(&msg); + + printf("MAIN THREAD %u ALIVE!\n", p_main); +} diff --git a/tests/test_thread_msg_block_wo_queue/Makefile b/tests/test_thread_msg_block_wo_queue/Makefile new file mode 100644 index 0000000000..0ff66bfdd3 --- /dev/null +++ b/tests/test_thread_msg_block_wo_queue/Makefile @@ -0,0 +1,9 @@ +# name of your project +export PROJECT = test_thread_msg_block_wo_queue + +export BOARD ?= native + +# the absolute path of the RIOT-base dir +export RIOTBASE =$(CURDIR)/../.. + +include $(RIOTBASE)/Makefile.include diff --git a/tests/test_thread_msg_block_wo_queue/main.c b/tests/test_thread_msg_block_wo_queue/main.c new file mode 100644 index 0000000000..ca9470b191 --- /dev/null +++ b/tests/test_thread_msg_block_wo_queue/main.c @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2014 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License. See the file LICENSE in the top level directory for more + * details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Thread test application + * + * @author Christian Mehlis + * @author Lotte Steenbrink + * + * @} + */ + +#include +#include + +#include "thread.h" +#include "msg.h" + +char t1_stack[KERNEL_CONF_STACKSIZE_PRINTF]; + +uint16_t p1, p_main; + +void thread1(void) +{ + printf("THREAD %u start\n", p1); + + msg_t msg, reply; + memset(&msg, 1, sizeof(msg_t)); + + /* step 1: send asynchonously */ + msg_send(&msg, p_main, 0); + + /* step 2: send message, turning its status into STATUS_REPLY_BLOCKED */ + msg_send_receive(&msg, &reply, p_main); + printf("received: %u, %u \n", reply.sender_pid, reply.type); + printf("pointer: %s\n", reply.content.ptr); + + printf("THREAD %u SHOULD BE BLOCKING :(\n", p1); +} + +int main(void) +{ + msg_t msg; + p_main = thread_pid; + + p1 = thread_create(t1_stack, KERNEL_CONF_STACKSIZE_PRINTF, PRIORITY_MAIN - 1, + CREATE_WOUT_YIELD | CREATE_STACKTEST, thread1, "nr1"); + + /* step 3: receive a msg */ + msg_receive(&msg); + + printf("MAIN THREAD %u ALIVE!\n", p_main); +}