tests/xtimer_mutex_lock_timeout: New test#12008
tests/xtimer_mutex_lock_timeout: New test#12008MichelRottleuthner merged 6 commits intoRIOT-OS:masterfrom
Conversation
1b48933 to
98de62e
Compare
MichelRottleuthner
left a comment
There was a problem hiding this comment.
Thanks for working on this! I added some comments inline. One general remark: would it make sense to also check if the timeout is actually working in the low-prio case? I.e a case where the timeout is actually triggered (maybe even with a check to see if the timing is correct)?
|
|
||
| mutex_lock(test_mutex); | ||
| thread_wakeup(main_thread_pid); | ||
| while (msg_try_receive(&msg) == -1) {} |
There was a problem hiding this comment.
first: why not just blocking call of msg_receive instead of this loop? second: why use msg send/recv here at all? shouldn't the thread_sleep() + thread_wakeup() be enough to lock the mutex in the low prio thread before the main thread continues?
There was a problem hiding this comment.
after thread wakeup the main thread runs anyways. I don't need that line it is only to better understand what is happening (the thread waits but is still runnable)
The thread should only check receive once.
I can remove it if it is more confusing than helpful.
| mutex_unlock(test_mutex); | ||
| (void)irq_disable(); | ||
| puts("THREAD low prio: exiting low"); | ||
| msg_send_int(&msg, main_thread_pid); |
There was a problem hiding this comment.
why msg_send_int? This is clearly not called from interrupt context
There was a problem hiding this comment.
to join threads. Only way to wait for a thread to finish that has a lower prio as far as I know(is done this way in posix reaper implementation)
There was a problem hiding this comment.
msg_send_int does not yield but still unblocks the other thread.
There was a problem hiding this comment.
I will split it in a function with documentation
There was a problem hiding this comment.
I added a function for it.
|
There are more tests I want that are currently failing. tracking #11660 |
|
I want to rebase this pr before it gets merged. |
|
@MichelRottleuthner What do you think after the changes and comments I made? |
|
@MichelRottleuthner Could you look at this? What do you think after the changes and comments I made? |
MichelRottleuthner
left a comment
There was a problem hiding this comment.
Thanks for keep bugging me.. and sorry for the delay ;) The changes you made are fine. But I still found some documentation things, see below. After that it should be ready for merge, so feel free to already suqash everything together as needed since the changes are small enough to still keep track.
| { "mutex_timeout_long_locked", "locked mutex with long timeout", | ||
| cmd_test_xtimer_mutex_lock_timeout_long_locked, }, | ||
| { "mutex_timeout_long_locked_low", | ||
| "locked mutex from lower prio thread function with long timeout", |
There was a problem hiding this comment.
actually the description part of the command is confusing as its not really explaining what happens here. Somewhere in the test it should be explained in clear to understand language what the test checks, what kind of guarantee this implies and by that what it means if the test fails. Maybe for the short description in the command something like "checks if xtimer_mutex_lock_timeout can acquire a mutex that was previously locked by a lower prio thread" would be better to understand for a random dude looking at this test for the first time. Also the terms low and long are not very precise here. I guess you want to express something like longer than needed i.e. the timeout is big enough that we are absolutely sure the timeout should never actually be triggered if everything is working fine. And too short as in "the timeout is so small that we know it should always trigger if everything works.
There was a problem hiding this comment.
The description should be something short because a long one is difficult to read. If a "random dude" wants to know what the test does he should read the documentation. I would almost say the command and description is currently too long. I agree that the description is currently not perfect. What do you think about locked mutex with long timeout tested with 2 threads
The part: locked mutex with long timeout is to be consistent with the other commands.
LONG means the timer does not spin(timeout longer than XTIMER_BACKOFF).
NOT that is does not trigger.
It should trigger in cmd_test_xtimer_mutex_lock_timeout_long_locked.
It is only called LONG because there will be a test with a short one (meaning the timer will spin). This test will be added as soon as the bugs are removed because it fails at the moment.
tracking pr to show what my goal is (how I will remove the bugs)#11660
LOW and LONG are not meant to be precise. It is only short for lower than main thread and longer than XTIMER_BACKOFF. How much longer/lower is irrelevant for the test.
To sum it up for me a help description should be short. I am not against changing the description. And long and low are chosen on purpose.
There was a problem hiding this comment.
Ok thanks for the clarification. After understanding your intentions for the naming (long) I still think its not precise. I.e. as a reader you don't get the relevant information - that is "no-spin", how about using that instead?.
To sum it up for me a help description should be short.
I agree. but it should also be as clear as possible because otherwise its no help ;) How about lock low-prio-locked-mutex from high-prio-thread (no-spin timeout)
There was a problem hiding this comment.
(the dashes are meant to make it more clear which word modifies what)
There was a problem hiding this comment.
mutex_timeout_long_locked_low lock low-prio-locked-mutex from high-prio-thread (no-spin timeout) is a little difficult to read
There was a problem hiding this comment.
I changed it.
There was a problem hiding this comment.
True - but if you know where the description starts its not really worse than before. and at least it more unambiguous...
There was a problem hiding this comment.
Would you also change the "long" part of the other descriptions to "no-spin" to make it consistent again?
|
Working on it Friday. |
0c14824 to
b90b7ab
Compare
|
please also have a look at the commit message restrictions that Travis is complaining about |
|
|
missclick wanted to comment. |
62f6e8e to
6566051
Compare
done |
|
Hmm seems the test is now too big for some arduino boards and a small nucleo. Do you think we can shrink it down a bit? I think it would preferable to have it working on as many platforms as possible.
|
|
I added the same |
754b768 to
8e6bb25
Compare
|
Travis fails because of fixups. (rebase after @MichelRottleuthner sees my changes) |
|
OK I looked thru the new fixup commits. Feel free to squash and rebase. |
printing emty line after each test function to make the test easier to read
Two Functions cmd_test_xtimer_mutex_lock_timeout_low_prio_thread and thread_low_prio_test are added. This testfunction will test xtimer_mutex_lock_timeout with two threads (main thread and lower prio than main thread). The main thread creates another thread and sleeps. While the main thread sleeps the other thread takes the mutex and wakes the main thread up. Then the main thread calls xtimer_mutex_lock_timeout and the second thread unlocks the mutex and the main thread gets it and waits for the created thread to end. Has test messages showing the thread count. To make sure the created thread ends. (test messages may be removed in the future)
The function will terminate the thread and send the message m to target_pid.
"(no-spin timeout)" instead of "long timeout" to make it consistent
8e6bb25 to
15349ea
Compare
Ok. Done. |
MichelRottleuthner
left a comment
There was a problem hiding this comment.
All requests were addressed, testing on native and nucleo-l476rg showed no problems for me, code looks fine -> ACK
Tracking: pr #11660
Contribution description
Implements a new function for
xtimer_mutex_lock_timeoutto make sure the function works with threads. The new function testsxtimer_mutex_lock_timeoutby locking the mutex from another thread, callingxtimer_mutex_lock_timeoutand unlocking the mutex from the other thread before the timeout ends.(The test also shows that the created thread exits/ends)
The test also prints a empty line after each test function to make it easier to read and removes a wrong include.
Testing procedure
BOARD=native make -C tests/xtimer_mutex_lock_timeout/ flash testit outputs:
Issues/PRs references
tracking #11660