mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #6737 from smlng/tests/msg_avail
tests: enhance msg_avail
This commit is contained in:
commit
45e959804a
@ -1,6 +1,9 @@
|
||||
APPLICATION = thread_msg_avail
|
||||
APPLICATION = msg_avail
|
||||
include ../Makefile.tests_common
|
||||
|
||||
DISABLE_MODULE += auto_init
|
||||
|
||||
test:
|
||||
tests/01-run.py
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Nick van IJzendoorn <nijzendoorn@engineering-spirit.nl>
|
||||
* 2017 HAW Hamburg
|
||||
*
|
||||
* 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
|
||||
@ -14,6 +15,7 @@
|
||||
* @brief Thread test application
|
||||
*
|
||||
* @author Nick van IJzendoorn <nijzendoorn@engineering-spirit.nl>
|
||||
* @author Sebastian Meiling <s@mlng.net>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
@ -21,7 +23,7 @@
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "thread.h"
|
||||
#include "log.h"
|
||||
#include "msg.h"
|
||||
|
||||
#define MSG_QUEUE_LENGTH (8)
|
||||
@ -34,28 +36,27 @@ int main(void)
|
||||
|
||||
msg_init_queue(msg_queue, MSG_QUEUE_LENGTH);
|
||||
|
||||
puts("[START]");
|
||||
/* add message to own queue */
|
||||
for (int idx = 0; idx < MSG_QUEUE_LENGTH; ++idx) {
|
||||
msges[idx].sender_pid = thread_getpid();
|
||||
msges[idx].type = idx;
|
||||
|
||||
msg_send_to_self(msges + idx);
|
||||
|
||||
printf("Add message %d\n", idx);
|
||||
|
||||
while (msg_avail() != (idx) + 1)
|
||||
; /* spin forever if we don't have the result we expect */
|
||||
LOG_INFO("+ add msg: %d\n", idx);
|
||||
if (msg_avail() != (idx) + 1) {
|
||||
puts("[FAILED]");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* receive available messages in queue */
|
||||
for (int idx = msg_avail(); idx > 0; --idx) {
|
||||
msg_t msg;
|
||||
msg_receive(&msg);
|
||||
|
||||
printf("Receive message: %d\n", (MSG_QUEUE_LENGTH - idx));
|
||||
|
||||
while (msg.type != (MSG_QUEUE_LENGTH - idx) || msg_avail() != idx - 1)
|
||||
; /* spin forever if we don't have the result we expect */
|
||||
LOG_INFO("- got msg: %d\n", (MSG_QUEUE_LENGTH - idx));
|
||||
if (msg.type != (MSG_QUEUE_LENGTH - idx) || msg_avail() != idx - 1) {
|
||||
puts("[FAILED]");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
puts("TEST PASSED\n");
|
||||
puts("[SUCCESS]");
|
||||
return 0;
|
||||
}
|
20
tests/msg_avail/tests/01-run.py
Executable file
20
tests/msg_avail/tests/01-run.py
Executable file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
# 2017 Sebastian Meiling <s@mlng.net>
|
||||
#
|
||||
# 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_exact(u"[SUCCESS]")
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(testrunner.run(testfunc))
|
Loading…
Reference in New Issue
Block a user