tests/xtimer_usleep_short: add expected runtime#9037
tests/xtimer_usleep_short: add expected runtime#9037Josar wants to merge 9 commits intoRIOT-OS:masterfrom
Conversation
aabadie
left a comment
There was a problem hiding this comment.
I have a few comments regarding your changes but the general idea sounds valid.
| runtime = int(child.match.group(1)) | ||
| expected = int(child.match.group(2)) | ||
|
|
||
| if runtime < expected*0.9 or runtime > expected*1.1: |
There was a problem hiding this comment.
This should be tested in the test application not by the pexpect script
tests/xtimer_usleep_short/main.c
Outdated
| 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; |
There was a problem hiding this comment.
put spaces around = operator
tests/xtimer_usleep_short/main.c
Outdated
| #define TEST_USLEEP_MIN (0) | ||
| #define TEST_USLEEP_MAX (500) | ||
|
|
||
| #define TEST_TIME (125250) |
There was a problem hiding this comment.
How did you determine this value ?
There was a problem hiding this comment.
There was a problem hiding this comment.
Then threre's direct relationship with TEST_USLEEP_MAX and TEST_USLEEP_MIN, so I think it's useless.
There was a problem hiding this comment.
I don't understand what you mean, but changed the value to be calculated.
|
This looks more to what I had in mind now. I tested on arduino-zero, microbit and an stm32l4 based board. It only works on the latter, the other ones exceeds the expected test time (even with 20% error tolerance). |
|
I just add some improvements to the xtimer while testing the jiminy board. |
|
There is an example here with a configurable margin instead of doing https://github.com/RIOT-OS/RIOT/blob/master/tests/posix_semaphore/main.c#L241 I need to add other cases because the current |
|
I would make the check in the python test script instead, i.e. just print actual an expected sleep timings and then make any check/verification in the test later on. That makes it more flexible. |
|
Added reports for each sleep, changed the test to be done in python and made the deviation configurable. |
I'm still not in favour of having the time checks done by the python script. The python script is here to verify the output (and in general it checks that |
|
I'm still (and in general) in favour of making any checks and verifications in the python script. Thus let the C test program be simple with limited output which also reduces binary size. I also think its easier to make maths for verification in Python than in C. |
|
As my objective was to highlight the times when the timer delay is too long, thus getting a hint when the timer lags. So i had to change the test to test it in the c code as the Python print does not print sequentially. |
fc751f4 to
d4cc724
Compare
…add expected runtime
d4cc724 to
fd6a9c6
Compare
aabadie
left a comment
There was a problem hiding this comment.
This is much better now. There's an unused variable in the python script (see below).
Didn't test.
| import sys | ||
| import pexpect | ||
|
|
||
| DEVIATION = .1 |
…short: add expected runtime
smlng
left a comment
There was a problem hiding this comment.
having some output on the expected and actual sleep time might be good, but I'm totally against doing any checks within the C code but suggest to put any such evaluation into the python script which can parse the output.
| printf("going to sleep %d us\n", i); | ||
| uint32_t start = xtimer_now_usec(); | ||
| xtimer_usleep(i); | ||
| uint32_t slept = xtimer_now_usec() - start; |
There was a problem hiding this comment.
making two xtimer_now calls is not necessary when saving the last (from previous iteration) and also assuming that all the other calls cost only marginal time compared to the sleep. xtimer_now is rather expensive, anyways.
There was a problem hiding this comment.
The print of "going to sleep %d us\n", if i am not mistaken, needs:
20 * 10 * 1000/9600Buad = 20,8 ms
Then the second print will also need some time.
This test goes from 500ms down to 1ms. So is the time marginal or not?
There was a problem hiding this comment.
I am also in favor of doing two times xtimer_now it helps timing tests correctly, printf takes time.
tests/xtimer_usleep_short/main.c
Outdated
| uint32_t slept = xtimer_now_usec() - start; | ||
| printf("Slept for %" PRIu32 " us\n", slept); | ||
|
|
||
| if (slept < (unsigned int)i) { |
There was a problem hiding this comment.
as already written several times: I'm against making any checks within in the C-code and would rather do this in the (python) test script. We should keep the C test code simple avoiding unnecessary maths operations and also increasing the code size with such addition code and output. Its already the case that many tests don't fit on all boards just because of excessive output.
There was a problem hiding this comment.
Maybe there is a way to get the python script print sequentially?
The idea behind this is to make it obvious if the XTIMER_BACKOFF border or something else causes the error.
Thus the print has to be exactly after the sleep, not 5 sleeps after it.
Adding the slept time is neccessary to get a hint of errors like this #9211
There was a problem hiding this comment.
There are boards that we cannot reboot with make reset so cannot run the automated python tests on them. If the test can alone say it is working I find it better.
All the tests based on embunit are doing asserts on the node and python only checks for [SUCCESS] already.
Also, here they are not math operations, they are simple integer comparison and addition.
tests/xtimer_usleep_short/main.c
Outdated
| uint32_t start = xtimer_now_usec(); | ||
| xtimer_usleep(i); | ||
| uint32_t slept = xtimer_now_usec() - start; | ||
| printf("Slept for %" PRIu32 " us\n", slept); |
There was a problem hiding this comment.
I would prefer a single line for this with also the printed interval.
Now it is actually quite long also
going to sleep 12 us
Slept for 35 us
Timeout longer than expected margin.
Maybe a message like:
ERROR: Slept for 35 us not in range [12, 32] us.
OK: Slept for 15 us in range [12, 32] us.
| i = 500 | ||
| i = sleep_max - sleep_min | ||
|
|
||
| while (i >= 0): |
There was a problem hiding this comment.
for delay in range(sleep_max, sleep_min -1, -1): It is python not C :)
It is time to fix the previous code.
cladmi
left a comment
There was a problem hiding this comment.
I am also in favor of testing in C code, that what we have been doing for the last months.
I have some remarks inline:
- some problems were already there before but it would be good to fix them
- have more information in the firmware output but be more concise
- python test script reliability.
|
|
||
| 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+)") |
There was a problem hiding this comment.
Now that we are using python3 none of the string required the u in front anymore.
| 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) |
There was a problem hiding this comment.
Here you can replace (\d+) by the value of i or if renamed delay. It would prevent issue when testing with text taken from node before make reset.
| 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)) |
There was a problem hiding this comment.
sleep_exp would not be necessary as it would have matched against the value of i.
| 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 |
There was a problem hiding this comment.
This break should be an exit(1), not print failed then success…
It's a good time to fix it.
|
|
||
| int main(void) | ||
| { | ||
| xtimer_sleep(3); |
There was a problem hiding this comment.
This xtimer_sleep(3) break my tests when doing make flash test on some boards as the test could match the child.expect(u"This test will call xtimer_usleep for values from (\d+) down to (\d+)") line before make reset is done.
There was a problem hiding this comment.
Any suggestions on how to fix this? Increase the sleep?
| /* 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) |
There was a problem hiding this comment.
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.
tests/xtimer_usleep_short/main.c
Outdated
|
|
||
| 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); |
There was a problem hiding this comment.
Inconsistent with first letter lowercase.
|
I can do a PR on your branch if you want for the updating script changes (on monday though). |
|
@cladmi feel free to contribute. |
4cb9371 to
3b621d8
Compare
…usleep_short: add expected runtime
3b621d8 to
bfe9884
Compare
|
I'm still against having any evaluation in the (test) application, specifically this delay margin. IMHO its up to the human tester or a high layer test framework to decide whether the test passes or fails according to the values reported/printed. It might also be that we only want to evaluate if a PR improves or degrades the sleep time precision, and don't want to look that much into the actual margin. |
|
I'll dismiss my review for now, but I want to stress the point that we should keep the code of the test application as simple as possible. And to me that means just print the values needed to make a proper decision but leave that to the tester or auto test framework, i.e. if the test passes or not. But it seams that is a more general discussion and needs to be resolved within a larger group. |
Don't like it but won't block it either.
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
In some cases the sleep time is very long compared to the expected sleep time.
This pr adds a functionality to test against the expected sleep time.
If the sleep time is far of the expected sleep time an error is thrown.