Skip to content

Commit

Permalink
thread_msg_block_wo_queue: add README & pexpect script, extend comments
Browse files Browse the repository at this point in the history
Fixes #6680
  • Loading branch information
Lotterleben committed Mar 7, 2017
1 parent b0649e6 commit f2fa8bd
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 13 deletions.
5 changes: 5 additions & 0 deletions tests/thread_msg_block_wo_queue/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ BOARD_INSUFFICIENT_MEMORY := nucleo32-f031
DISABLE_MODULE += auto_init

include $(RIOTBASE)/Makefile.include

test:
# `testrunner` calls `make term` recursively, results in duplicated `TERMFLAGS`.
# So clears `TERMFLAGS` before run.
TERMFLAGS= tests/01-run.py
24 changes: 24 additions & 0 deletions tests/thread_msg_block_wo_queue/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Background
==========
Tests for the same situation as `thread_msg_block_w_queue`, but without an initialized message queue for the main thread:

This test application checks for the behavior reported in https://github.com/RIOT-OS/RIOT/issues/100:

Usually, when a thread (here `sender_thread`) sends a message to another thread (here the `main` thread) whose message queue already holds a message, the message of `sender_thread` is copied into `main`'s message queue and `sender_thread` is set to `STATUS_PENDING`. However, this should *not* happen if `sender_thread` is currently in `STATUS_REPLY_BLOCKED` mode, since it is in the middle of a different, blocking send.

In the aforementioned issue, it was reported that this undesired behavior was happening. It has been fixed since, and this test ensures that it doesn't re-occur again.

Expected result
===============
The output should look as follows:

```
sender_thread start
main thread alive
```

If you see
```
ERROR: sender_thread should be blocking
```
something went wrong.
27 changes: 14 additions & 13 deletions tests/thread_msg_block_wo_queue/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,42 +27,43 @@

char t1_stack[THREAD_STACKSIZE_MAIN];

kernel_pid_t p1 = KERNEL_PID_UNDEF, p_main = KERNEL_PID_UNDEF;
kernel_pid_t p_send = KERNEL_PID_UNDEF, p_recv = KERNEL_PID_UNDEF;

void *thread1(void *arg)
{
(void) arg;

printf("THREAD %u start\n", p1);
printf("sender_thread start\n");

msg_t msg, reply;
memset(&msg, 1, sizeof(msg_t));

/* step 1: send asynchonously */
msg_try_send(&msg, p_main);
/* step 1: send non-blocking to fill up the msg_queue of p_recv */
msg_try_send(&msg, p_recv);

/* step 2: send message, turning its status into STATUS_REPLY_BLOCKED */
msg_send_receive(&msg, &reply, p_main);
printf("received: %" PRIkernel_pid ", %u \n", reply.sender_pid, reply.type);
printf("pointer: %s\n", (char *)reply.content.ptr);
/* step 2: send message. This puts sender_thread into msg_waiters and turns its
status into STATUS_REPLY_BLOCKED. It should block forever, since the
second message is never read by p_recv. */
msg_send_receive(&msg, &reply, p_recv);

printf("THREAD %" PRIkernel_pid " SHOULD BE BLOCKING :(\n", p1);
/* If this is printed, sender_thread did *not* block as expected. */
printf("ERROR: sender_thread should be blocking\n");

return NULL;
}

int main(void)
{
msg_t msg;
p_main = sched_active_pid;
p_recv = sched_active_pid;

p1 = thread_create(t1_stack, sizeof(t1_stack), THREAD_PRIORITY_MAIN - 1,
p_send = thread_create(t1_stack, sizeof(t1_stack), THREAD_PRIORITY_MAIN - 1,
THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST,
thread1, NULL, "nr1");

/* step 3: receive a msg */
/* step 3: receive first msg from sender_thread*/
msg_receive(&msg);

printf("MAIN THREAD %" PRIkernel_pid " ALIVE!\n", p_main);
printf("main thread alive\n");
return 0;
}
20 changes: 20 additions & 0 deletions tests/thread_msg_block_wo_queue/tests/01-run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3

# Copyright (C) 2017 Lotte Steenbrink <lotte.steenbrink@fu-berlin.de>
#
# 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.

import os
import sys

sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
import testrunner

def testfunc(child):
child.expect('sender_thread start\r\n')
child.expect('main thread alive\r\n')

if __name__ == "__main__":
sys.exit(testrunner.run(testfunc))

0 comments on commit f2fa8bd

Please sign in to comment.