Skip to content

tests/xtimer_mutex_lock_timeout: add simple case test#11679

Merged
cladmi merged 4 commits intoRIOT-OS:masterfrom
JulianHolzwarth:pr/xtimer_mutex_lock_timeout/first_tests
Jun 26, 2019
Merged

tests/xtimer_mutex_lock_timeout: add simple case test#11679
cladmi merged 4 commits intoRIOT-OS:masterfrom
JulianHolzwarth:pr/xtimer_mutex_lock_timeout/first_tests

Conversation

@JulianHolzwarth
Copy link
Contributor

@JulianHolzwarth JulianHolzwarth commented Jun 12, 2019

Contribution description

This pr implements normal test case tests for xtimer_mutex_lock_timeout in xtimer.c . As the timeout 1000us or 1 millisecond is used to make sure it does not spin. And adds a short comment for the struct it uses (mutex_thread_t). Also because the integer timeout in the struct is modified from interupt context it must be volatile.

Testing procedure

BOARD=native make -C tests/xtimer_mutex_lock timeout/ flash test
output:

...
> mutex_timeout_n_spin_unlocked
starting test: xtimer mutex lock timeout
OK
> mutex_timeout_n_spin_locked
mutex_timeout_n_spin_locked
starting test: xtimer mutex lock timeout
OK
> 

Issues/PRs references

the tracking pr: #11660

comment for mutex_thread_t
timeout is modified from interupt context so must be volatile
@JulianHolzwarth JulianHolzwarth changed the title Pr/xtimer mutex lock timeout/first tests tests/xtimer_mutex_lock_timeout Jun 12, 2019
@cladmi cladmi added Area: tests Area: tests and testing framework Area: timers Area: timer subsystems CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR labels Jun 12, 2019
@cladmi cladmi added this to the Release 2019.07 milestone Jun 12, 2019
@JulianHolzwarth JulianHolzwarth changed the title tests/xtimer_mutex_lock_timeout tests/xtimer_mutex_lock_timeout add simple case test Jun 12, 2019
@JulianHolzwarth JulianHolzwarth changed the title tests/xtimer_mutex_lock_timeout add simple case test tests/xtimer_mutex_lock_timeout: add simple case test Jun 12, 2019
@cladmi
Copy link
Contributor

cladmi commented Jun 12, 2019

The test successfully ran on arduino-mega2560 frdm-k64f frdm-kw41z msba2 mulle nrf52dk nucleo-f103rb pba-d-01-kw2x sltb001a stm32f3discovery and locally on native iotlab-m3 samr21-xpro.

Copy link
Contributor

@cladmi cladmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the functional part but still have some remarks with documentation/naming. Please see inline.

* @brief shell command to test xtimer_mutex_lock_timeout
*
* the mutex is locked before the function call and
* the timeout is greater than XTIMER_BACKOFF (no spinning)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update in the direction, "the timeout will occur while waiting on the mutex" it would explain more the case without the need to mention spinning.

* @brief shell command to test xtimer_mutex_lock_timeout
*
* the mutex is not locked before the function call and
* the timeout is greater than XTIMER_BACKOFF (no spinning)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update in the direction, "the timeout callback will be removed before triggering" it would explain more the case.

/**
* Foward declarations
*/
static int cmd_test_xtimer_mutex_lock_timeout_greater_backoff(int argc,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe update the function names to not mention 'backoff' but more what is tested, so testing with a free mutex and long timeout. Would match the documentation updates.

Same for the other function.

mutex_t *mutex;
thread_t *thread;
int timeout;
volatile int timeout;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with the change, the value is modified in another context.

mutex_t test_mutex = MUTEX_INIT;

/* timeout at one millisecond (1000 us) to make sure it does not spin. */
if (xtimer_mutex_lock_timeout(&test_mutex, 1000) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put the 1000 as a macro with the comment before so it can be re-used in both functions.

@cladmi cladmi added Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines labels Jun 12, 2019
@JulianHolzwarth
Copy link
Contributor Author

I changed the documentation/naming. Do you have more suggestions and are you ok with my changes? @cladmi

Copy link
Contributor

@cladmi cladmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor fixups inside. You can squash them directly.

Please squash everything, I will do a final round of check after.

child.sendline("help")
if child.expect_exact(["> ", pexpect.TIMEOUT], timeout=1) == 0:
break
child.sendline("mutex_timeout_n_spin_unlocked")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests commands must also be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@cladmi cladmi removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jun 12, 2019
@JulianHolzwarth JulianHolzwarth force-pushed the pr/xtimer_mutex_lock_timeout/first_tests branch from 5dc42d4 to 50e9ac4 Compare June 12, 2019 16:34
@cladmi cladmi added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jun 13, 2019
@cladmi
Copy link
Contributor

cladmi commented Jun 13, 2019

Was notified IRL. Thanks for inline updating the documentation, I did not notice it was the documentation for the other function. https://github.com/RIOT-OS/RIOT/compare/5dc42d4f21306349841c1542d2471da685f3709a..50e9ac4d547ab8749f6b53f93f2c7baa89521ae4

@cladmi cladmi removed the Reviewed: 3-testing The PR was tested according to the maintainer guidelines label Jun 13, 2019
@cladmi
Copy link
Contributor

cladmi commented Jun 13, 2019

I re-read with more details and currently the tests do not verify that the mutex was indeed taken or not.

@JulianHolzwarth
Copy link
Contributor Author

JulianHolzwarth commented Jun 14, 2019

I re-read with more details and currently the tests do not verify that the mutex was indeed taken or not.

The new commit checks it.

@JulianHolzwarth
Copy link
Contributor Author

JulianHolzwarth commented Jun 14, 2019

Should be checking it (if mutex locked) now correctly.
@cladmi

@cladmi
Copy link
Contributor

cladmi commented Jun 26, 2019

I get the expected output for the test, on samr21-xpro

Type '/exit' to exit.                                                                                                                                                                                                                                                                     
2019-06-26 15:13:41,145 - INFO # main(): This is RIOT! (Version: buildtest)                                                                                                                                                                                                               
2019-06-26 15:13:41,147 - INFO # Starting shell...                                                                                                                                                                                                                                        
> mutex_timeout_long_unlocked                                                                                                                                                                                                                                                             
2019-06-26 15:13:41,188 - INFO #  help                                                                                                                                                                                                                                                    
2019-06-26 15:13:41,191 - INFO # Command              Description                                                                                                                                                                                                                         
2019-06-26 15:13:41,195 - INFO # ---------------------------------------                                                                                                                                                                                                                  
2019-06-26 15:13:41,200 - INFO # mutex_timeout_long_unlocked unlocked mutex with long timeout                                                                                                                                                                                             
2019-06-26 15:13:41,205 - INFO # mutex_timeout_long_locked locked mutex with long timeout                                                                                                                                                                                                 
> 2019-06-26 15:13:41,242 - INFO #  mutex_timeout_long_unlocked                                                                                                                                                                                                                           
2019-06-26 15:13:41,246 - INFO # starting test: xtimer mutex lock timeout                                                                                                                                                                                                                 
2019-06-26 15:13:41,247 - INFO # OK                                                                                                                                                                                                                                                       
> mutex_timeout_long_locked                                                                                                                                                                                                                                                               
2019-06-26 15:13:41,302 - INFO #  mutex_timeout_long_locked                                                                                                                                                                                                                               
2019-06-26 15:13:41,306 - INFO # starting test: xtimer mutex lock timeout                                                                                                                                                                                                                 
2019-06-26 15:13:41,307 - INFO # OK

and the test successfully ran on arduino-mega2560 cc2650-launchpad frdm-k64f frdm-kw41z msba2 mulle nrf52dk nucleo-f103rb pba-d-01-kw2x sltb001a stm32f3discovery and locally on native iotlab-m3 samr21-xpro.

Please squash.

Adding a first normal test case where the mutex is unlocked and the timeout is long.
The timer will not trigger in this test and instead wil be removed after getting the mutex.
New test function cmd_test_xtimer_mutex_lock_timeout_long_locked.
In this test the mutex is locked and the timeout is long.
When it works the thread continues running and stops waiting for the mutex and
the function will return that it did not get the mutex.
@JulianHolzwarth JulianHolzwarth force-pushed the pr/xtimer_mutex_lock_timeout/first_tests branch from 99078f4 to b3d2324 Compare June 26, 2019 13:35
@JulianHolzwarth
Copy link
Contributor Author

JulianHolzwarth commented Jun 26, 2019

@cladmi I squashed.

Copy link
Contributor

@cladmi cladmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, reviewed and tested on many boards.

Note for reference: this currently only test the simple cases where the mutex is not changed while waiting, and the timing is not analyzed.

@cladmi cladmi merged commit eab0a88 into RIOT-OS:master Jun 26, 2019
@cladmi
Copy link
Contributor

cladmi commented Jun 26, 2019

First pull request merged! Well done.

@JulianHolzwarth
Copy link
Contributor Author

Thank you.

@JulianHolzwarth JulianHolzwarth deleted the pr/xtimer_mutex_lock_timeout/first_tests branch June 26, 2019 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: tests Area: tests and testing framework Area: timers Area: timer subsystems CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: run tests If set, CI server will run tests on hardware for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants