tests/event_wait_timeout: Fix for 8bit platforms#12776
tests/event_wait_timeout: Fix for 8bit platforms#12776kaspar030 merged 5 commits intoRIOT-OS:masterfrom
Conversation
|
This took me ages to understand why the xtimer which was more distant in the future was added in |
|
I confirm this PR is fixing There are other issues reported by Murdock with Maybe @smlng could also have a look since he already worked on fixing xtimer macros. |
kaspar030
left a comment
There was a problem hiding this comment.
We're using "LU" everywhere else instead of casts to type.
sys/include/timex.h
Outdated
| * @brief The number of microseconds per second | ||
| */ | ||
| #define US_PER_SEC (1000000U) | ||
| #define US_PER_SEC ((uint32_t)1000000U) |
There was a problem hiding this comment.
Can we please use (1000000LU)?
There was a problem hiding this comment.
I tried that, but that yielded 100+ compilation errors as PRIu32 expects unsigned int, not unsinged long. Even though they are the same. But the cast clearly doesn't work, as other code is using US_PER_SEC in preprocessor #if statements. They don't work with types...
There was a problem hiding this comment.
Can you keep the UL here but add the cast where needed in tests/xtimer_msg ?
There was a problem hiding this comment.
Let me first try to weasel around this by using U on systems with sizeof(unsinged) == sizeof(uint32_t)andLUon other systems. With usingLU` unconditionally, the number of compilation issues was huge...
Also: I think users can rightfully expect that PRIu32 should work with something like e.g. US_PER_SEC * 200. The only way to solve this (except for the casts to uint32_t) is to make the postfix dependent on the integer width.
There was a problem hiding this comment.
OK. The current approach at least works locally. Let's wait for Murdock to confirm.
There was a problem hiding this comment.
uff, but it is mega hacky and different to everywhere else in the code.
There was a problem hiding this comment.
... but also quite contained and practical...
There was a problem hiding this comment.
Still fails (which I currently fail to understand). I need to think about this for some time. Maybe there is a cleaner solution that just didn't occur to me yet.
There was a problem hiding this comment.
OK. On ESP32 without an explicit #include <limits.h> is needed. (I was pretty sure that an #include <stdint.h> should have also provided UINT_MAX, but maybe I was wrong.)
|
OK. With the code now (hopefully!) compiling on all platforms, so that The only two other solutions I have in mind are:
|
|
@kaspar030: What is the verdict on this? Summing up the approaches to fix the issue that were discussed so far, and their pros and cons:
|
How many are there? Maybe fixing those is the best option? Throughout the codebase, we've been using integer literals with type suffixes as needed.
This shouldn't happen, as C has legal implicit type conversions, right? |
For unsigned this should be indeed be safe. It seems I had the issue with signed
So in the current case |
b82ec01 to
b9376f0
Compare
|
I have to rebase in order to be able to fix issues in |
The test currently uses static globals for communication without any protection. This could lead optimizing C compilers to deduce that access to those are not needed (e.g. with LTO enabled). Using C11 atomics is the easiest way to tell the compiler that those accesses are used for communication between two different threads of execution (here: between the ISR and the main thread).
The macros US_PER_MS and friends are assumed to be 32 bit unsigned integers by users. However, e.g. on AVR a `1000U` is only 16 bit long. Thus, e.g. `xtimer_usleep(100 * US_PER_MS)` will wrap around and only sleep for ~34ms. This commit declares them as unsigned long, which is on all currently supported platforms 32 bit wide.
37a8bf2 to
9f75501
Compare
|
All green now. Time to cross this issue of the list :-) |
|
@kaspar030: You're comments are addressed and all is green. |
|
Thanks for the review! |
Contribution description
US_PER_MSand friends to be safely used whensizeof(unsigned) < sizeof(uint32_t). Citing the commit message:This commit ensures that they are treated as 32 bit unsigned integers on all
platforms.
Testing procedure
tests/event_wait_timeoutshould now work on ATmegaIssues/PRs references
Tick second item in #12651