mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #6736 from smlng/tests/xtimer_msg_receive_timeout
tests: enhance xtimer_msg_receive_timeout
This commit is contained in:
commit
9d286240be
9
tests/xtimer_msg_receive_timeout/README.md
Normal file
9
tests/xtimer_msg_receive_timeout/README.md
Normal file
@ -0,0 +1,9 @@
|
||||
# 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.
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 INRIA
|
||||
* 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
|
||||
@ -13,13 +14,8 @@
|
||||
* @file
|
||||
* @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 Sebastian Meiling <s@mlng.net>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
@ -30,27 +26,27 @@
|
||||
#include "xtimer.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)
|
||||
{
|
||||
msg_t m, tmsg;
|
||||
xtimer_t t;
|
||||
int64_t offset = -1000;
|
||||
tmsg.type = 44;
|
||||
t.target = 0;
|
||||
t.long_target = 0;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int64_t offset = -(TEST_PERIOD/10);
|
||||
tmsg.type = 42;
|
||||
puts("[START]");
|
||||
for (unsigned i = 0; i < TEST_COUNT; i++) {
|
||||
xtimer_set_msg(&t, TEST_PERIOD + offset, &tmsg, sched_active_pid);
|
||||
if (xtimer_msg_receive_timeout(&m, TEST_PERIOD) < 0) {
|
||||
puts("Timeout!");
|
||||
}
|
||||
else {
|
||||
printf("Message received: %" PRIu16 "\n", m.type);
|
||||
printf("Message: %" PRIu16 "\n", m.type);
|
||||
}
|
||||
offset = (offset < 0) ? 1000 : -1000;
|
||||
xtimer_remove(&t);
|
||||
/* flip sign */
|
||||
offset *= (-1);
|
||||
}
|
||||
puts("[SUCCESS]");
|
||||
return 0;
|
||||
}
|
||||
|
@ -13,9 +13,11 @@ sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
|
||||
import testrunner
|
||||
|
||||
def testfunc(child):
|
||||
child.expect("[START]")
|
||||
for i in range(5):
|
||||
child.expect("Message received: 44")
|
||||
child.expect("Message: 42")
|
||||
child.expect("Timeout!")
|
||||
child.expect("[SUCCESS]")
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(testrunner.run(testfunc))
|
||||
|
Loading…
Reference in New Issue
Block a user