-
Notifications
You must be signed in to change notification settings - Fork 2.1k
tests/xtimer_usleep_short: add expected runtime #9037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9af59b4
6550535
c4e543c
dfcf9e9
cb23ea4
6a4b963
fd6a9c6
ec11938
bfe9884
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <michel.rottleuthner@haw-hamburg.de> | ||
| * @author Josua Arndt <jarndt@ias.rwth-aachen.de> | ||
| * @} | ||
| */ | ||
| #include <stdio.h> | ||
|
|
@@ -22,18 +24,56 @@ | |
| #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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any suggestions on how to fix this? Increase the sleep? |
||
| printf("This test will call xtimer_usleep for values from %d down to %d\n", | ||
| TEST_USLEEP_MAX, TEST_USLEEP_MIN); | ||
| 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", | ||
| 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 usecs...\n", i); | ||
|
|
||
| uint32_t start = xtimer_now_usec(); | ||
| xtimer_usleep(i); | ||
| uint32_t slept = xtimer_now_usec() - start; | ||
|
|
||
| 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 { | ||
| 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; | ||
| } | ||
|
|
||
| puts("[SUCCESS]"); | ||
| printf("Slept for %" PRIu32 " us expected %" PRIu32 " us.\n", | ||
| sleeping_time, test_time); | ||
|
|
||
| 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; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The margin may not be enough as mentioned in #8990.
I need to do the xtimer_configure to check if it helps getting in the margin.