From 2390ea87d80c0949c547aa44c7520fee8eeaf3b2 Mon Sep 17 00:00:00 2001 From: MichelRottleuthner Date: Tue, 11 Jul 2017 10:37:34 +0200 Subject: [PATCH] tests: add small values test for xtimer_usleep --- tests/xtimer_usleep_short/Makefile | 8 +++++ tests/xtimer_usleep_short/main.c | 39 +++++++++++++++++++++++ tests/xtimer_usleep_short/tests/01-run.py | 34 ++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 tests/xtimer_usleep_short/Makefile create mode 100644 tests/xtimer_usleep_short/main.c create mode 100755 tests/xtimer_usleep_short/tests/01-run.py diff --git a/tests/xtimer_usleep_short/Makefile b/tests/xtimer_usleep_short/Makefile new file mode 100644 index 0000000000..c148cf4119 --- /dev/null +++ b/tests/xtimer_usleep_short/Makefile @@ -0,0 +1,8 @@ +include ../Makefile.tests_common + +USEMODULE += xtimer + +include $(RIOTBASE)/Makefile.include + +test: + ./tests/01-run.py diff --git a/tests/xtimer_usleep_short/main.c b/tests/xtimer_usleep_short/main.c new file mode 100644 index 0000000000..5cfd849a1f --- /dev/null +++ b/tests/xtimer_usleep_short/main.c @@ -0,0 +1,39 @@ +/* + * Copyright (C) 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 + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief xtimer_usleep_short test application + * + * @author Michel Rottleuthner + * @} + */ +#include +#include "xtimer.h" + +#define TEST_USLEEP_MIN (0) +#define TEST_USLEEP_MAX (500) + +int main(void) +{ + xtimer_sleep(3); + printf("This test will call xtimer_usleep for values from %d down to %d\n", + TEST_USLEEP_MAX, TEST_USLEEP_MIN); + + for (int i = TEST_USLEEP_MAX; i >= TEST_USLEEP_MIN; i--) { + printf("going to sleep %d usecs...\n", i); + xtimer_usleep(i); + } + + puts("Test end."); + + return 0; +} diff --git a/tests/xtimer_usleep_short/tests/01-run.py b/tests/xtimer_usleep_short/tests/01-run.py new file mode 100755 index 0000000000..a831099893 --- /dev/null +++ b/tests/xtimer_usleep_short/tests/01-run.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +# Copyright (C) 2017 Michel Rottleuthner +# +# 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 +import pexpect + +sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner')) +import testrunner + +def testfunc(child): + + child.expect(u"This test will call xtimer_usleep for values from \\d+ down to \\d+\r\n") + + i = 500 + + while (i >= 0): + try: + child.expect(u"going to sleep \\d+ usecs...\r\n", timeout=3) + except pexpect.TIMEOUT: + print("xtimer stuck when trying to sleep %d usecs" % (i+1)); + print("[FAILED]") + break; + i = i -1 + + child.expect(u"Test end.", timeout=3) + +if __name__ == "__main__": + sys.exit(testrunner.run(testfunc))