1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tests: added test for xtimer_msg_receive_timeout

This commit is contained in:
Oleg Hahm 2015-11-14 20:33:39 +01:00
parent 0ddd6ec15e
commit 24ce427a3a
3 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,7 @@
APPLICATION = xtimer_msg_receive_timeout
include ../Makefile.tests_common
FEATURES_REQUIRED += periph_timer
USEMODULE += xtimer
include $(RIOTBASE)/Makefile.include

View File

@ -0,0 +1,44 @@
/*
* Copyright (C) 2015 INRIA
*
* 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.
*/
/**
* @ingroup tests
* @{
*
* @file
* @brief test application for xtimer_msg_receive_timeout()
*
* @author Oliver Hahm <oliver.hahm@inria.fr>
*
* @}
*/
#include "thread.h"
#include "msg.h"
#include "xtimer.h"
#include "timex.h"
int main(void)
{
msg_t m, tmsg;
xtimer_t t;
int64_t offset = -1000;
tmsg.type = 44;
for (int i = 0; i < 10; i++) {
xtimer_set_msg(&t, SEC_IN_USEC + offset, &tmsg, sched_active_pid);
if (xtimer_msg_receive_timeout(&m, SEC_IN_USEC) < 0) {
puts("Timeout!");
}
else {
printf("Message received: %" PRIu16 "\n", m.type);
}
offset = (offset < 0) ? 1000 : -1000;
}
return 0;
}

View File

@ -0,0 +1,39 @@
#!/usr/bin/env python
# Copyright (C) 2015 INRIA
#
# 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, signal, sys
from pexpect import TIMEOUT, EOF
if sys.version_info[0] == 2:
from pexpect import spawn
else:
from pexpect import spawnu as spawn
DEFAULT_TIMEOUT = 2
def main():
p = None
try:
p = spawn("make term", timeout=DEFAULT_TIMEOUT)
p.logfile = sys.stdout
for i in range(10):
p.expect("Message received: 44")
p.expect("Timeout")
except TIMEOUT as exc:
print(exc)
return 1
finally:
if p and not p.terminate():
print("SUCCESS")
os.killpg(p.pid, signal.SIGKILL)
return 0
if __name__ == "__main__":
sys.exit(main())