Skip to content
Snippets Groups Projects
Commit 44801c4e authored by Sebastian Meiling's avatar Sebastian Meiling
Browse files

tests: enhance xtimer_msg_receive_timeout

    - correct test period from 100ms to 1000ms, to match description
    - moved description to separate README.md
    - changed timer message type from 44 to 42, for nerdiness
    - minor code enhancements
parent fd7f8a52
No related branches found
No related tags found
No related merge requests found
# test application for xtimer_msg_receive_timeout()
This test will sequentially start TEST_COUNT xtimers to send a IPC msg,
alternating with an interval of TEST_PERIOD +/- 10%. Every time a timer
was set, it will wait for a message for at most TEST_PERIOD microseconds.
This should succeed with a message or fail with timeout in an alternating
manner.
Default values are TEST_COUNT = 10, and TEST_PERIOD = 100ms = 100000us.
/* /*
* Copyright (C) 2015 INRIA * Copyright (C) 2015 INRIA
* 2017 HAW Hamburg
* *
* This file is subject to the terms and conditions of the GNU Lesser * 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 * General Public License v2.1. See the file LICENSE in the top level
...@@ -13,13 +14,8 @@ ...@@ -13,13 +14,8 @@
* @file * @file
* @brief test application for xtimer_msg_receive_timeout() * @brief test application for xtimer_msg_receive_timeout()
* *
* This test will start sequentially start 10 xtimers to send a
* IPC msg, alternating with an interval of 900ms and 1100ms
* respectively. Everytime a timer was set, it will wait for a
* message for at most 1000ms. This should succeed and fail in an
* alternating manner.
*
* @author Oliver Hahm <oliver.hahm@inria.fr> * @author Oliver Hahm <oliver.hahm@inria.fr>
* @author Sebastian Meiling <s@mlng.net>
* *
* @} * @}
*/ */
...@@ -30,27 +26,27 @@ ...@@ -30,27 +26,27 @@
#include "xtimer.h" #include "xtimer.h"
#include "timex.h" #include "timex.h"
#define TEST_PERIOD (100000LU) #define TEST_PERIOD (100LU * US_PER_MS) /* 100ms in US */
#define TEST_COUNT (10LU)
int main(void) int main(void)
{ {
msg_t m, tmsg; msg_t m, tmsg;
xtimer_t t; xtimer_t t;
int64_t offset = -1000; int64_t offset = -(TEST_PERIOD/10);
tmsg.type = 44; tmsg.type = 42;
t.target = 0; puts("[START]");
t.long_target = 0; for (unsigned i = 0; i < TEST_COUNT; i++) {
for (int i = 0; i < 10; i++) {
xtimer_set_msg(&t, TEST_PERIOD + offset, &tmsg, sched_active_pid); xtimer_set_msg(&t, TEST_PERIOD + offset, &tmsg, sched_active_pid);
if (xtimer_msg_receive_timeout(&m, TEST_PERIOD) < 0) { if (xtimer_msg_receive_timeout(&m, TEST_PERIOD) < 0) {
puts("Timeout!"); puts("Timeout!");
} }
else { else {
printf("Message received: %" PRIu16 "\n", m.type); printf("Message: %" PRIu16 "\n", m.type);
} }
offset = (offset < 0) ? 1000 : -1000; /* flip sign */
xtimer_remove(&t); offset *= (-1);
} }
puts("[SUCCESS]");
return 0; return 0;
} }
...@@ -13,9 +13,11 @@ sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner')) ...@@ -13,9 +13,11 @@ sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
import testrunner import testrunner
def testfunc(child): def testfunc(child):
child.expect("[START]")
for i in range(5): for i in range(5):
child.expect("Message received: 44") child.expect("Message: 42")
child.expect("Timeout!") child.expect("Timeout!")
child.expect("[SUCCESS]")
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(testrunner.run(testfunc)) sys.exit(testrunner.run(testfunc))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment