From 9af59b49b7672c3544f13aa2d9d3b57f6e67815f Mon Sep 17 00:00:00 2001 From: Josarn Date: Fri, 27 Apr 2018 11:58:12 +0200 Subject: [PATCH 1/9] tests/xtimer_usleep_short: add expected runtime --- tests/xtimer_usleep_short/main.c | 8 ++++++++ tests/xtimer_usleep_short/tests/01-run.py | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/tests/xtimer_usleep_short/main.c b/tests/xtimer_usleep_short/main.c index 7493c68a1a52..d806b0de2069 100644 --- a/tests/xtimer_usleep_short/main.c +++ b/tests/xtimer_usleep_short/main.c @@ -22,17 +22,25 @@ #define TEST_USLEEP_MIN (0) #define TEST_USLEEP_MAX (500) +#define TEST_TIME (125250) + 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); + uint32_t start, sleeping_time=0; + for (int i = TEST_USLEEP_MAX; i >= TEST_USLEEP_MIN; i--) { printf("going to sleep %d usecs...\n", i); + start = xtimer_now_usec(); xtimer_usleep(i); + sleeping_time += xtimer_now_usec() - start; } + printf("Slept for %" PRIu32 " expected %" PRIu32"\n", sleeping_time, TEST_TIME); + puts("[SUCCESS]"); return 0; diff --git a/tests/xtimer_usleep_short/tests/01-run.py b/tests/xtimer_usleep_short/tests/01-run.py index d242289512f1..c1e49950f9af 100755 --- a/tests/xtimer_usleep_short/tests/01-run.py +++ b/tests/xtimer_usleep_short/tests/01-run.py @@ -25,6 +25,15 @@ def testfunc(child): break i = i - 1 + child.expect(u"Slept for (\\d+) expected (\\d+)", timeout=3) + runtime = int(child.match.group(1)) + expected = int(child.match.group(2)) + + if runtime < expected*0.9 or runtime > expected*1.1: + print("xtimer slept to long") + print("[FAILED]") + return + child.expect(u"[SUCCESS]", timeout=3) From 6550535188c4b558d2ec5b19854f1db6d23f6020 Mon Sep 17 00:00:00 2001 From: Josarn Date: Fri, 27 Apr 2018 14:18:34 +0200 Subject: [PATCH 2/9] fixup! tests/xtimer_usleep_short: add expected runtime --- tests/xtimer_usleep_short/main.c | 17 +++++++++++++---- tests/xtimer_usleep_short/tests/01-run.py | 10 +--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/tests/xtimer_usleep_short/main.c b/tests/xtimer_usleep_short/main.c index d806b0de2069..4c8089701e27 100644 --- a/tests/xtimer_usleep_short/main.c +++ b/tests/xtimer_usleep_short/main.c @@ -28,9 +28,9 @@ 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); + TEST_USLEEP_MAX, TEST_USLEEP_MIN); - uint32_t start, sleeping_time=0; + uint32_t start, sleeping_time = 0; for (int i = TEST_USLEEP_MAX; i >= TEST_USLEEP_MIN; i--) { printf("going to sleep %d usecs...\n", i); @@ -39,9 +39,18 @@ int main(void) sleeping_time += xtimer_now_usec() - start; } - printf("Slept for %" PRIu32 " expected %" PRIu32"\n", sleeping_time, TEST_TIME); + printf("Slept for %" PRIu32 " expected %" PRIu32 "\n", + sleeping_time, (uint32_t)TEST_TIME); - puts("[SUCCESS]"); + if ((sleeping_time < ((uint32_t)TEST_TIME)*9/10) + || (sleeping_time > ((uint32_t)TEST_TIME) * 11/10)) { + printf("Sleep time is not in 10%% range %" PRIu32 " < %" PRIu32 " < %" PRIu32 "\n", + ((uint32_t)(TEST_TIME)*9/10), ((uint32_t)TEST_TIME), ((uint32_t)(TEST_TIME)*11/10) ); + puts("[FAILED]"); + } + else { + puts("[SUCCESS]"); + } return 0; } diff --git a/tests/xtimer_usleep_short/tests/01-run.py b/tests/xtimer_usleep_short/tests/01-run.py index c1e49950f9af..5ccdcd81ccdd 100755 --- a/tests/xtimer_usleep_short/tests/01-run.py +++ b/tests/xtimer_usleep_short/tests/01-run.py @@ -25,15 +25,7 @@ def testfunc(child): break i = i - 1 - child.expect(u"Slept for (\\d+) expected (\\d+)", timeout=3) - runtime = int(child.match.group(1)) - expected = int(child.match.group(2)) - - if runtime < expected*0.9 or runtime > expected*1.1: - print("xtimer slept to long") - print("[FAILED]") - return - + child.expect(u"Slept for \\d+ expected \\d+") child.expect(u"[SUCCESS]", timeout=3) From c4e543c30f4621754adafcddfe40dc69d394a5f1 Mon Sep 17 00:00:00 2001 From: Josarn Date: Fri, 27 Apr 2018 14:30:00 +0200 Subject: [PATCH 3/9] fixup! fixup! tests/xtimer_usleep_short: add expected runtime --- tests/xtimer_usleep_short/main.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/xtimer_usleep_short/main.c b/tests/xtimer_usleep_short/main.c index 4c8089701e27..15dbc73df5f0 100644 --- a/tests/xtimer_usleep_short/main.c +++ b/tests/xtimer_usleep_short/main.c @@ -22,30 +22,29 @@ #define TEST_USLEEP_MIN (0) #define TEST_USLEEP_MAX (500) -#define TEST_TIME (125250) - 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); - uint32_t start, sleeping_time = 0; + uint32_t start, test_time = 0, sleeping_time = 0; for (int i = TEST_USLEEP_MAX; i >= TEST_USLEEP_MIN; i--) { printf("going to sleep %d usecs...\n", i); start = xtimer_now_usec(); xtimer_usleep(i); sleeping_time += xtimer_now_usec() - start; + test_time += i; } printf("Slept for %" PRIu32 " expected %" PRIu32 "\n", - sleeping_time, (uint32_t)TEST_TIME); + sleeping_time, test_time); - if ((sleeping_time < ((uint32_t)TEST_TIME)*9/10) - || (sleeping_time > ((uint32_t)TEST_TIME) * 11/10)) { + if (sleeping_time < (test_time * 9 / 10) + || sleeping_time > (test_time * 11 / 10)) { printf("Sleep time is not in 10%% range %" PRIu32 " < %" PRIu32 " < %" PRIu32 "\n", - ((uint32_t)(TEST_TIME)*9/10), ((uint32_t)TEST_TIME), ((uint32_t)(TEST_TIME)*11/10) ); + (test_time * 9 / 10), test_time, (test_time * 11 / 10)); puts("[FAILED]"); } else { From dfcf9e997c1fda3323d9882f3d32612039d01eb5 Mon Sep 17 00:00:00 2001 From: Josarn Date: Wed, 9 May 2018 16:51:02 +0200 Subject: [PATCH 4/9] fixup! fixup! fixup! tests/xtimer_usleep_short: add expected runtime --- tests/xtimer_usleep_short/main.c | 18 +++++---------- tests/xtimer_usleep_short/tests/01-run.py | 28 +++++++++++++++++++---- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/tests/xtimer_usleep_short/main.c b/tests/xtimer_usleep_short/main.c index 15dbc73df5f0..98b632507a96 100644 --- a/tests/xtimer_usleep_short/main.c +++ b/tests/xtimer_usleep_short/main.c @@ -28,28 +28,22 @@ int main(void) printf("This test will call xtimer_usleep for values from %d down to %d\n", TEST_USLEEP_MAX, TEST_USLEEP_MIN); - uint32_t start, test_time = 0, sleeping_time = 0; + uint32_t start, slept, test_time = 0, sleeping_time = 0; for (int i = TEST_USLEEP_MAX; i >= TEST_USLEEP_MIN; i--) { - printf("going to sleep %d usecs...\n", i); + printf("going to sleep %d us\n", i); start = xtimer_now_usec(); xtimer_usleep(i); - sleeping_time += xtimer_now_usec() - start; + slept = xtimer_now_usec() - start; + printf("Slept for %" PRIu32 " us\n", slept); + sleeping_time += slept; test_time += i; } printf("Slept for %" PRIu32 " expected %" PRIu32 "\n", sleeping_time, test_time); - if (sleeping_time < (test_time * 9 / 10) - || sleeping_time > (test_time * 11 / 10)) { - printf("Sleep time is not in 10%% range %" PRIu32 " < %" PRIu32 " < %" PRIu32 "\n", - (test_time * 9 / 10), test_time, (test_time * 11 / 10)); - puts("[FAILED]"); - } - else { - puts("[SUCCESS]"); - } + puts("[SUCCESS]"); return 0; } diff --git a/tests/xtimer_usleep_short/tests/01-run.py b/tests/xtimer_usleep_short/tests/01-run.py index 5ccdcd81ccdd..177ae51c0d26 100755 --- a/tests/xtimer_usleep_short/tests/01-run.py +++ b/tests/xtimer_usleep_short/tests/01-run.py @@ -10,22 +10,40 @@ import sys import pexpect +DEVIATION = .1 def testfunc(child): - child.expect(u"This test will call xtimer_usleep for values from \\d+ down to \\d+\r\n") + child.expect(u"This test will call xtimer_usleep for values from (\d+) down to (\d+)") + sleep_max = int(child.match.group(1)) + sleep_min = int(child.match.group(2)) - i = 500 + i = sleep_max - sleep_min while (i >= 0): try: - child.expect(u"going to sleep \\d+ usecs...\r\n", timeout=3) + child.expect(u"going to sleep (\d+) us", timeout=3) + sleep_exp = int(child.match.group(1)) + + child.expect(u"Slept for (\d+) us", timeout=3) + slept = int(child.match.group(1)) + if slept < sleep_exp*(1-DEVIATION) or slept > sleep_exp*(1+DEVIATION): + print("More than %2.0f%% deviation." % (DEVIATION*100)) + except pexpect.TIMEOUT: - print("xtimer stuck when trying to sleep %d usecs" % (i+1)) + print("xtimer stuck when trying to sleep %d us" % (sleep_exp)) print("[FAILED]") break i = i - 1 - child.expect(u"Slept for \\d+ expected \\d+") + child.expect(u"Slept for (\d+) expected (\d+)") + sleep_exp = int(child.match.group(1)) + slept = int(child.match.group(2)) + + if slept < sleep_exp*(1-DEVIATION) or slept > sleep_exp*(1+DEVIATION): + print("All test together had more than %2.0f%% deviation." % (DEVIATION*100)) + print("[FAILED]") + return + child.expect(u"[SUCCESS]", timeout=3) From cb23ea4b33e0a91c2381a82bb2f5f913f0f28cb5 Mon Sep 17 00:00:00 2001 From: Josarn Date: Wed, 16 May 2018 02:37:45 +0200 Subject: [PATCH 5/9] fixup! fixup! fixup! fixup! tests/xtimer_usleep_short: add expected runtime --- tests/xtimer_usleep_short/tests/01-run.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/xtimer_usleep_short/tests/01-run.py b/tests/xtimer_usleep_short/tests/01-run.py index 177ae51c0d26..b749d6cbf3e7 100755 --- a/tests/xtimer_usleep_short/tests/01-run.py +++ b/tests/xtimer_usleep_short/tests/01-run.py @@ -12,6 +12,7 @@ DEVIATION = .1 + def testfunc(child): child.expect(u"This test will call xtimer_usleep for values from (\d+) down to (\d+)") sleep_max = int(child.match.group(1)) From 6a4b96394299977af2dd778d78e2f4ed7989fcb3 Mon Sep 17 00:00:00 2001 From: Josarn Date: Thu, 24 May 2018 10:03:59 +0200 Subject: [PATCH 6/9] fixup! fixup! fixup! fixup! fixup! tests/xtimer_usleep_short: add expected runtime --- tests/xtimer_usleep_short/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/xtimer_usleep_short/main.c b/tests/xtimer_usleep_short/main.c index 98b632507a96..512e545e694f 100644 --- a/tests/xtimer_usleep_short/main.c +++ b/tests/xtimer_usleep_short/main.c @@ -28,13 +28,13 @@ int main(void) printf("This test will call xtimer_usleep for values from %d down to %d\n", TEST_USLEEP_MAX, TEST_USLEEP_MIN); - uint32_t start, slept, test_time = 0, sleeping_time = 0; + uint32_t test_time = 0, sleeping_time = 0; for (int i = TEST_USLEEP_MAX; i >= TEST_USLEEP_MIN; i--) { printf("going to sleep %d us\n", i); - start = xtimer_now_usec(); + uint32_t start = xtimer_now_usec(); xtimer_usleep(i); - slept = xtimer_now_usec() - start; + uint32_t slept = xtimer_now_usec() - start; printf("Slept for %" PRIu32 " us\n", slept); sleeping_time += slept; test_time += i; From fd6a9c615fbc9279eb6247bfae4c2145ad9d3b19 Mon Sep 17 00:00:00 2001 From: Josarn Date: Thu, 24 May 2018 10:53:08 +0200 Subject: [PATCH 7/9] fixup! fixup! fixup! fixup! fixup! fixup! tests/xtimer_usleep_short: add expected runtime --- tests/xtimer_usleep_short/main.c | 36 +++++++++++++++++++---- tests/xtimer_usleep_short/tests/01-run.py | 12 +------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/tests/xtimer_usleep_short/main.c b/tests/xtimer_usleep_short/main.c index 512e545e694f..9b418ec2ec5a 100644 --- a/tests/xtimer_usleep_short/main.c +++ b/tests/xtimer_usleep_short/main.c @@ -22,13 +22,23 @@ #define TEST_USLEEP_MIN (0) #define TEST_USLEEP_MAX (500) +#ifdef BOARD_NATIVE +/* native can sometime take more time to respond as it is not real time */ +#define TEST_XTIMER_USLEEP_SHORT_SLEEP_MARGIN_US (1000) +#else +#define TEST_XTIMER_USLEEP_SHORT_SLEEP_MARGIN_US (20) +#endif /* BOARD_NATIVE */ + 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); - uint32_t test_time = 0, sleeping_time = 0; + printf("Expected delay margin is %d us\n", + TEST_XTIMER_USLEEP_SHORT_SLEEP_MARGIN_US); + + uint32_t test_time = 0, sleeping_time = 0, margin_fault = 0; for (int i = TEST_USLEEP_MAX; i >= TEST_USLEEP_MIN; i--) { printf("going to sleep %d us\n", i); @@ -36,14 +46,30 @@ int main(void) xtimer_usleep(i); uint32_t slept = xtimer_now_usec() - start; printf("Slept for %" PRIu32 " us\n", slept); + + if (slept < (unsigned int)i) { + puts("Timeout to short"); + ++margin_fault; + } + else if (slept > (unsigned int)i + TEST_XTIMER_USLEEP_SHORT_SLEEP_MARGIN_US) { + puts("Timeout longer than expected margin."); + ++margin_fault; + } + sleeping_time += slept; test_time += i; } - printf("Slept for %" PRIu32 " expected %" PRIu32 "\n", + printf("Slept for %" PRIu32 " us expected %" PRIu32 " us\n", sleeping_time, test_time); - puts("[SUCCESS]"); - - return 0; + if (margin_fault != 0) { + printf("Sleep delay margin was not kept for %" PRIu32 " times\n", margin_fault); + puts("[FAILED]"); + return 1; + } + else { + puts("[SUCCESS]"); + return 0; + } } diff --git a/tests/xtimer_usleep_short/tests/01-run.py b/tests/xtimer_usleep_short/tests/01-run.py index b749d6cbf3e7..c5049a1b4dc6 100755 --- a/tests/xtimer_usleep_short/tests/01-run.py +++ b/tests/xtimer_usleep_short/tests/01-run.py @@ -26,9 +26,6 @@ def testfunc(child): sleep_exp = int(child.match.group(1)) child.expect(u"Slept for (\d+) us", timeout=3) - slept = int(child.match.group(1)) - if slept < sleep_exp*(1-DEVIATION) or slept > sleep_exp*(1+DEVIATION): - print("More than %2.0f%% deviation." % (DEVIATION*100)) except pexpect.TIMEOUT: print("xtimer stuck when trying to sleep %d us" % (sleep_exp)) @@ -36,14 +33,7 @@ def testfunc(child): break i = i - 1 - child.expect(u"Slept for (\d+) expected (\d+)") - sleep_exp = int(child.match.group(1)) - slept = int(child.match.group(2)) - - if slept < sleep_exp*(1-DEVIATION) or slept > sleep_exp*(1+DEVIATION): - print("All test together had more than %2.0f%% deviation." % (DEVIATION*100)) - print("[FAILED]") - return + child.expect(u"Slept for (\d+) us expected (\d+) us") child.expect(u"[SUCCESS]", timeout=3) From ec11938fbd7651bf501b0bbd387e39fde70e09ae Mon Sep 17 00:00:00 2001 From: Josarn Date: Tue, 29 May 2018 13:53:08 +0200 Subject: [PATCH 8/9] fixup! fixup! fixup! fixup! fixup! fixup! fixup! tests/xtimer_usleep_short: add expected runtime --- tests/xtimer_usleep_short/tests/01-run.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/xtimer_usleep_short/tests/01-run.py b/tests/xtimer_usleep_short/tests/01-run.py index c5049a1b4dc6..da31566b66d3 100755 --- a/tests/xtimer_usleep_short/tests/01-run.py +++ b/tests/xtimer_usleep_short/tests/01-run.py @@ -10,8 +10,6 @@ import sys import pexpect -DEVIATION = .1 - def testfunc(child): child.expect(u"This test will call xtimer_usleep for values from (\d+) down to (\d+)") From bfe988486d534b9fb13a14c592463798934f4262 Mon Sep 17 00:00:00 2001 From: Josarn Date: Tue, 5 Jun 2018 13:09:40 +0200 Subject: [PATCH 9/9] fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! tests/xtimer_usleep_short: add expected runtime --- tests/xtimer_usleep_short/main.c | 26 +++++++++++-------- tests/xtimer_usleep_short/tests/01-run.py | 31 ++++++++++++----------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/tests/xtimer_usleep_short/main.c b/tests/xtimer_usleep_short/main.c index 9b418ec2ec5a..84fd2da0b562 100644 --- a/tests/xtimer_usleep_short/main.c +++ b/tests/xtimer_usleep_short/main.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2017 HAW-Hamburg + * 2018 Josua Arndt * * 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 xtimer_usleep_short test application * * @author Michel Rottleuthner + * @author Josua Arndt * @} */ #include @@ -32,39 +34,41 @@ int main(void) { xtimer_sleep(3); - printf("This test will call xtimer_usleep for values from %d down to %d\n", + printf("This test will call xtimer_usleep for values from %d us down to %d us.\n", TEST_USLEEP_MAX, TEST_USLEEP_MIN); - printf("Expected delay margin is %d us\n", + printf("Expected delay margin is %d us.\n", TEST_XTIMER_USLEEP_SHORT_SLEEP_MARGIN_US); uint32_t test_time = 0, sleeping_time = 0, margin_fault = 0; for (int i = TEST_USLEEP_MAX; i >= TEST_USLEEP_MIN; i--) { - printf("going to sleep %d us\n", i); + uint32_t start = xtimer_now_usec(); xtimer_usleep(i); uint32_t slept = xtimer_now_usec() - start; - printf("Slept for %" PRIu32 " us\n", slept); - if (slept < (unsigned int)i) { - puts("Timeout to short"); + if (slept < (unsigned int)i || + slept > (unsigned int)i + TEST_XTIMER_USLEEP_SHORT_SLEEP_MARGIN_US) { + printf("ERROR: Slept for %" PRIu32 " us not in range [%d, %d] us.\n", + slept, i, i + TEST_XTIMER_USLEEP_SHORT_SLEEP_MARGIN_US); ++margin_fault; } - else if (slept > (unsigned int)i + TEST_XTIMER_USLEEP_SHORT_SLEEP_MARGIN_US) { - puts("Timeout longer than expected margin."); - ++margin_fault; + else { + printf("OK: Slept for %" PRIu32 " us not in range [%d, %d] us.\n", + slept, i, i + TEST_XTIMER_USLEEP_SHORT_SLEEP_MARGIN_US); } sleeping_time += slept; test_time += i; } - printf("Slept for %" PRIu32 " us expected %" PRIu32 " us\n", + printf("Slept for %" PRIu32 " us expected %" PRIu32 " us.\n", sleeping_time, test_time); if (margin_fault != 0) { - printf("Sleep delay margin was not kept for %" PRIu32 " times\n", margin_fault); + printf("Sleep delay margin was not kept for %" PRIu32 " times.\n", + margin_fault); puts("[FAILED]"); return 1; } diff --git a/tests/xtimer_usleep_short/tests/01-run.py b/tests/xtimer_usleep_short/tests/01-run.py index da31566b66d3..e98375d6fd99 100755 --- a/tests/xtimer_usleep_short/tests/01-run.py +++ b/tests/xtimer_usleep_short/tests/01-run.py @@ -12,29 +12,30 @@ def testfunc(child): - child.expect(u"This test will call xtimer_usleep for values from (\d+) down to (\d+)") + child.expect("This test will call xtimer_usleep for values from (\d+) us down to (\d+) us.") sleep_max = int(child.match.group(1)) sleep_min = int(child.match.group(2)) + delay = sleep_max - sleep_min - i = sleep_max - sleep_min + child.expect("Expected delay margin is (\d+) us.") + sleep_margin = int(child.match.group(1)) - while (i >= 0): + for delay in range(sleep_max, sleep_min, -1): try: - child.expect(u"going to sleep (\d+) us", timeout=3) - sleep_exp = int(child.match.group(1)) - - child.expect(u"Slept for (\d+) us", timeout=3) + child.expect("\w+: Slept for \d+ us not in range \[\d+, \d+\] us.", + timeout=20) except pexpect.TIMEOUT: - print("xtimer stuck when trying to sleep %d us" % (sleep_exp)) + print("xtimer stuck when trying to sleep %d us or failed.".format(delay)) print("[FAILED]") - break - i = i - 1 - - child.expect(u"Slept for (\d+) us expected (\d+) us") - - child.expect(u"[SUCCESS]", timeout=3) - + exit(1) + + child.expect("Slept for \d+ us expected \d+ us.") + child.expect("((Sleep delay margin was not kept for \d+ times.)|(\[SUCCESS\]))") + msg = child.match.group(1) + if msg != "[SUCCESS]" : + child.expect("[FAILED]") + exit(1) if __name__ == "__main__": sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))