tests/libc_newlib: fix pointers comparison for llvm#10014
tests/libc_newlib: fix pointers comparison for llvm#10014miri64 merged 1 commit intoRIOT-OS:masterfrom
Conversation
|
Maybe not being able to to the comparison is a real problem, but I cannot really say. Let's already see the result of murdock in #9809 |
|
This is indeed weird. The assembly looks like clang decides at compile time that the comparison is wrong. Replacing the comparison with |
|
@cladmi here's the diff against master for the shorter fix: https://gist.github.com/1acb9d37be0ef35057309a6ee2d4e5da |
Nice, I will replace to use this. |
There was a problem hiding this comment.
Except for static tests, Murdock is happy with this PR here and and when run with #9809.
I also ran the test on both native and samr21-xpro, both compiled with either GCC and clang.
I have however some comments regarding the output messages.
You may squash when addressed (and if you like mark @kaspar030 as a co-author).
| #ifdef MODULE_NEWLIB_NANO | ||
| /* Nano maps iprintf to printf */ | ||
| TEST_ASSERT(iprintf == printf); | ||
| TEST_ASSERT_MESSAGE((printf - iprintf) == 0, "iprintf == printf"); |
There was a problem hiding this comment.
I think this output might be confusing. The message is given when iprintf != printf, so this is what should be printed.
There was a problem hiding this comment.
Hm, intuitively I agreed, but a plain TEST_ASSERT(<expression>) also prints just the failed expression, not the opposite. So all the TEST_ASSERT* have an implicit assertion "<msg>" failed.
There was a problem hiding this comment.
True, but with e.g. TEST_ASSERT_EQUAL_INT it tells you "This is not as expected, this is what I expect" (faked with changing an expected value in tests-core:
.......................................
core_cib_tests.test_cib_get__overflow (tests/unittests/tests-core/tests-core-cib.c 48) exp 4 was 3
....................................................
run 91 failures 1
There was a problem hiding this comment.
True. Thing is, we have
TEST_ASSERT(1==0) -> core_cib_tests.test_cib_get__overflow (tests/unittests/tests-core/tests-core-cib.c 48) 1==0,
but then want to tweak a custom message to essentially say the opposite, e.g.,
TEST_ASSERT_MESSAGE(1==0, "1 != 0") -> core_cib_tests.test_cib_get__overflow (tests/unittests/tests-core/tests-core-cib.c 48) 1 != 0?
(do I make sense? 😉)
There was a problem hiding this comment.
(do I make sense? 😉)
Yes, at least I see (from the beginning btw) where you are coming from. I'm just arguing that for TEST_ASSERT() we can't really change what is happening. The CPP is just printing #exp, because it's the sane (and most efficient) thing to do. However, for TEST_ASSERT_MESSAGE we have more freedom, so we should use it and print a more intuitive output. But in the end it is purely based on taste of how to do it IMHO, so let's @cladmi decide, what he thinks is best for his test ;-).
There was a problem hiding this comment.
I prefer keeping the "default" embunit behavior, show the condition that failed in the message on assert.
In master with the error I had:
018-09-25 14:45:58,501 - INFO # main(): This is RIOT! (Version: 2018.10-devel-855-g028bc-hal-HEAD)
2018-09-25 14:45:58,503 - INFO # Newlib/nano test
2018-09-25 14:45:58,503 - INFO # .
2018-09-25 14:45:58,509 - INFO # tests.test_newlib (tests/libc_newlib/main.c 66) iprintf == printf
2018-09-25 14:45:58,509 - INFO #
2018-09-25 14:45:58,511 - INFO # run 1 failures 1
And I only changed the condition to (iprintf- printf)==0 because it made it work for llvm but wanted to keep the same message.
With only TEST_ASSERT we would also have (iprintf - printf) == 0 so for me would feel strange to do the opposite of the normal behavior.
| #else | ||
| /* Normal newlib does not */ | ||
| TEST_ASSERT(iprintf != printf); | ||
| TEST_ASSERT_MESSAGE((printf - iprintf) != 0, "iprintf != printf"); |
There was a problem hiding this comment.
Dito (just with iprintf == printf)
See #10014 (comment): "[…] in the end it is purely based on taste of how to do it IMHO, so let's @cladmi decide, what he thinks is best for his test ;-)."
|
@miri64 thanks for the co-author trick, I will do it. |
|
(please squash ;-)) |
With llvm and samr21-xpro, I could not directly do 'printf == iprintf'. But doing `(printf - iprintf) == 0` correctly checked if they are equal. Co-authored-by: Kaspar Schleiser <kaspar@schleiser.de>
3e62363 to
ba2a8df
Compare
|
Squashed now waiting for the "CI: run tests". |
Contribution description
With llvm and samr21-xpro, I could not directly do 'printf == iprintf'.
And I could not cast them to an integer value in a portable way.
So I use real function pointers for this.
However comparing
printf_addrwithiprintf_addrdoes not work ifthere is not the memcmp to somehow 'force them' to be pointers...
So I used the 'memcmp' for the comparison.
Testing procedure
Run
make clean flash test BOARD=samr21-xpro TOOLCHAIN=llvmand it should work.I tested with
pic32-wifireand also tested to disablenewlib-nanoornano.specsfor the samr21-xpro to test the error cases.Issues/PRs references
Found by #9809