-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests: Convert SPI Loopback test to ZTEST and clean up structure of file #86383
tests: Convert SPI Loopback test to ZTEST and clean up structure of file #86383
Conversation
} | ||
|
||
ZTEST_SUITE(spi_loopback, NULL, spi_loopback_setup, NULL, NULL, NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this not required to have this macro?
ZTEST_SUITE(spi_loopback, NULL, NULL, NULL, NULL, NULL);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean by this comment, This PR is updating the test to use multiple Ztest cases and suites
470a367
to
7cfa9a9
Compare
49b78c0
to
2cf6b7e
Compare
@decsny , this fails on frdm_k64f with below log
|
That's weird, because frdm_k64f is the main one I was using to develop this PR, do you have any special modification? I'm not seeing a failing on my board, I also tried with DSPI DMA testcase which looks like you used here. and still passes. Also is what you shared the whole log or is there more, right now I'm assuming your log is saying it hanged since it is incomplete? |
Maybe this is my board issue, as it is OK on your board, and all other platforms in my board farm. |
Hello @decsny tests/drivers/spi/spi_loopback/drivers.spi.loopback, nucleo_f207zg/stm32f207xx Main error :
tests/drivers/spi/spi_loopback/drivers.spi.loopback.internal, stm32f3_disco@B/stm32f303xc ( Main error:
I am analyzing to understand what introduces these regressions |
AFAIK, this is not a failure, or a regression, the test hardcoded skipped these tests before, the only new thing is now we use Note "assumption failed" is not the same as "assertion failed", failing an assumption is a skip, just like your log shows, that is intentional. If you don't want to skip those tests for STM32 DMA, then that is outside the scope of this PR, I am just keeping what is there right now but converting it to use ZTest APIs properly. If you weren't aware the platform was skipping those tests before, that's another advantage to use ZTest I guess because it makes it clear in the log. |
Thanks for your explanation, it's very clear. It seems good for the scope of this PR. It could be that twister considers "assumption failed" is the same as "assertion failed" when report tests status. |
@djiatsaf-st it's no problem if we should figure out why does a skip cause a twister fail before this merges, no rush from my point of view, maybe some change can be made on the PR |
BTW @tbursztyka this PR will require your review |
2cf6b7e
to
3c541c8
Compare
I don't know why is twister / ztest considering the skips as fails, but don't have time to look into this and it's pretty minor, so I just converted the zassume calls into just a conditional and TC_PRINT and return, so they should pass now. @djiatsaf-st @hakehuang @tbursztyka @teburd please help review, I'd like to get this change in sooner than later to facilitate more testing additions during this cycle |
3c541c8
to
ca098fb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Othewise LGTM
LOG_ERR("Code %d", ret); | ||
zassert_false(ret, "SPI transceive failed"); | ||
return -1; | ||
if (ret != -ENOTSUP) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should remain ret == -ENOTSUP
or handle the case when this condition is met.
Without this, we don't handle the case where ret is equal to -ENOTSUP (-134), and the test will fail on this assertion: zassert_false(ret, "SPI transceive failed, code %d", ret);
because ret is true.
The test failed on boards like Nucleo_F207ZG, Nucleo_F429ZI, Nucleo_F746ZG, Nucleo_H743ZI, Nucleo_WB55RG, etc., which don't support async call with the log :
Assertion failed at WEST_TOPDIR/zephyr/tests/drivers/spi/spi_loopback/src/spi.c:384: spi_loopback_test_spi_async_call: (ret is true)
SPI transceive failed, code -134
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
woops, this definitely was a major typo, that would have skipped the whole test case for everybody except the ones who were meant to skip it, thanks for catching this
ca098fb
to
4517935
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was indeed very much cluttered and the output not as normalized at ZTEST can get.
That's a really nice one, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And while we are at it, we should remove the __used
attribute instances, it is actually for functions not variables.
printf("SPI test on buffers TX/RX %p/%p, frame size = %d" | ||
#ifdef CONFIG_DMA | ||
", DMA enabled" | ||
#ifdef CONFIG_NOCACHE_MEMORY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#ifdef CONFIG_NOCACHE_MEMORY | |
#ifndef CONFIG_NOCACHE_MEMORY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Following the boy scout rule, since I am using this test a lot lately and going to improve it, the first step will be to clean up the structure of the file. The following changes are made: - Remove unused #includes - Condense some #if #else macro defines or make into single line, to simplify the readability of the preprocessor code - Move definitions around so that related things are all next to each other, instead of randomly scattered around the file - Create section header comments for broadly related things in the file to improve developer navigation experience - Introduce macro for copy pasted print buf size calculation - A few minor comment edits Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
There was a lot of copy paste of this code: int ret; ret = spi_transceive_dt(spec, &tx, &rx); if (ret) { LOG_ERR("Code %d", ret); zassert_false(ret, "SPI transceive failed"); return ret; } This is quite redundant and can be simplified. Also, return is not needed because a failed zassert will not continue to return anyways. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
More boy scout rule, I noticed every single test case was using different variations of C syntax to declare the buffers, this is inconvenient to the reader, make a standard way to declare buffers used for the test. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
Instead of having a bunch of giant if conditions and just running all the test cases from one actual ZTest case, convert all the test cases into proper ZTest test cases. Removing the returns is now required because otherwise there will be compiler warnings, and they were never doing anything anyways in the event of zassert fail. ZTest cases are meant to report pass or fail with ztest paradigm, not with return values and log messages. Also move the test of the spi lock/release to a separate test suite since it is not really testing an actual bus transfer, but rather a that a feature in the SPI API is respected. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
Since we are using ZTest, if we use the ZTest paradigm properly, we don't need a logging module, since ZTest already logs what it does. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
3068d01
4517935
to
3068d01
Compare
rebased and took suggestions from @JarmouniA to fix the print statement |
Since I am working a lot with this test lately, I am following the boy scout rule and cleaning up this test file. This change-set mostly only addresses code structure and makes minimal functional changes to the test. More information is in the commit descriptions, and I tried to make each patch as reviewable as possible since this test is used by many platforms.
I plan to make a follow-up PR to introduce more test cases to this test to avoid many of the bugs that NXP has discovered existing when using the LPSPI driver that were not caught by any testing.