-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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: drivers: can: api: Extend can api test #80063
tests: drivers: can: api: Extend can api test #80063
Conversation
This PR relates to #76298 |
42b4258
to
b9786a6
Compare
What does "Nrfx 6088" mean? |
"NRFX-6088" is a task number in our JIRA. |
What does bitrate of 0 bit/s mean? I see, vale of 0 is returned by can_get_bitrate_min() However, when I try to set such bitrate, I get -EINVAL. |
It means the CAN controller has no documented lower bitrate limit.
Questions like this make uncomfortable accepting any CAN related code changes from you. How would you expect a bitrate of 0 bits/second to be acceptable? |
/** | ||
* @brief Test sending CAN FD frame with too big payload. | ||
*/ | ||
ZTEST(canfd, test_send_fd_dlc_out_of_range) |
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.
There is already negative test that checks error code returned by can_send() when CAN frame ID is invalid:
https://github.com/zephyrproject-rtos/zephyr/blob/main/tests/drivers/can/api/src/classic.c#L799
Here, I add similar test. It checks that can_send() returns -EINVAL when CAN frame has invalid DLC value.
Test variant for CAN FD.
/** | ||
* @brief Test sending standard (11-bit ID) CAN frame with too big payload. | ||
*/ | ||
ZTEST(can_classic, test_send_std_id_dlc_of_range) |
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.
There is already negative test that checks error code returned by can_send() when CAN frame ID is invalid:
https://github.com/zephyrproject-rtos/zephyr/blob/main/tests/drivers/can/api/src/classic.c#L799
Here, I add similar test. It checks that can_send() returns -EINVAL when CAN frame has invalid DLC value.
Test variant for "standard" CAN with 11-bit CAN frame ID.
/** | ||
* @brief Test sending extended (29-bit ID) CAN frame with too big payload. | ||
*/ | ||
ZTEST(can_classic, test_send_ext_id_dlc_of_range) |
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.
There is already negative test that checks error code returned by can_send() when CAN frame ID is invalid:
https://github.com/zephyrproject-rtos/zephyr/blob/main/tests/drivers/can/api/src/classic.c#L799
Here, I add similar test. It checks that can_send() returns -EINVAL when CAN frame has invalid DLC value.
Test variant for "standard" CAN with 29-bit CAN frame ID.
* CAN FD Error State Indicator (ESI) indicates that the transmitting node is | ||
* in error-passive state. Only valid in combination with CAN_FRAME_FDF. | ||
*/ | ||
ZTEST(canfd, test_send_fd_incorrect_esi) |
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.
There is already negative test that checks error code returned by can_send() when CAN frame ID is invalid:
https://github.com/zephyrproject-rtos/zephyr/blob/main/tests/drivers/can/api/src/classic.c#L799
Here, I add similar test. It checks that can_send() returns -EINVAL when CAN frame has invalid set of flags (explanation in lines 262-263, copied from API description).
/** | ||
* @brief Test setting a too low data phase bitrate. | ||
*/ | ||
ZTEST_USER(canfd, test_set_bitrate_data_too_low) |
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.
There is already negative test that checks error code returned by can_set_bitrate_data() when bitrate value is too high:
https://github.com/zephyrproject-rtos/zephyr/blob/main/tests/drivers/can/api/src/canfd.c#L401
Here, I add similar test. It checks that can_set_bitrate_data() returns -ENOTSUP when bitrate value is too low.
/** | ||
* @brief Test setting a too low bitrate. | ||
*/ | ||
ZTEST_USER(can_classic, test_set_bitrate_too_low) |
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.
There is already negative test that checks error code returned by can_set_bitrate() when bitrate value is too high:
https://github.com/zephyrproject-rtos/zephyr/blob/main/tests/drivers/can/api/src/classic.c#L492
Here, I add similar test. It checks that can_set_bitrate() returns -ENOTSUP when bitrate value is too low.
/** | ||
* @brief Test adding filter without callback. | ||
*/ | ||
ZTEST(can_classic, test_add_filter_without_callback) |
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.
There is a set of negative tests which check that can_add_rx_filter() returns -EINVAL when filter is incorrect:
https://github.com/zephyrproject-rtos/zephyr/blob/main/tests/drivers/can/api/src/classic.c#L637
Here, I check that error code is returned when user tries to set filter without callback function.
tests/drivers/can/api/src/common.c
Outdated
@@ -244,3 +244,13 @@ void can_common_test_setup(can_mode_t initial_mode) | |||
err = can_start(can_dev); | |||
zassert_equal(err, 0, "failed to start CAN controller (err %d)", err); | |||
} | |||
|
|||
void before_test(void *not_used) |
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 is improvement.
Test cases assume that CAN is started when test begins.
There are test that stop CAN, do testing, re-start CAN.
If such test fails on assertion then test execution is terminated. As a result, CAN is not restarted and precondition (CAN started) is not meet for remaining tests.
Here, I add code that is executed before each test. I ignore error code
-EALREADY if the device is already started.
https://docs.zephyrproject.org/latest/doxygen/html/group__can__interface.html#ga343456749eec6144a91bacae0d94b114
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.
Please remove this part. This is not sufficient for restoring the CAN controller to a default state in all failure scenarios (e.g. installed filters, but test case failed) and as such provide limited value.
If needed, we can move this to a separate PR/issue.
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 is not sufficient for restoring the CAN controller to a default state (...)"
You are right, "test case setup function" doesn't restore other CAN parameters such as installed filters, bitrate, timing, etc.
Removing.
It is undocumented feature.
I consider this a personal attack. I will consult my supervisor on how to proceed. |
Right, let's get that added to the doxygen for
I'm sorry, that was not the intention, but you are opening PRs for adding CAN subsystem API-level tests, yet comments/questions like the above makes me unsure if you have the insight into the CAN subsystem needed to do so. |
b9786a6
to
9f6aeea
Compare
tests/drivers/can/api/src/common.c
Outdated
@@ -244,3 +244,13 @@ void can_common_test_setup(can_mode_t initial_mode) | |||
err = can_start(can_dev); | |||
zassert_equal(err, 0, "failed to start CAN controller (err %d)", err); | |||
} | |||
|
|||
void before_test(void *not_used) |
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.
Please remove this part. This is not sufficient for restoring the CAN controller to a default state in all failure scenarios (e.g. installed filters, but test case failed) and as such provide limited value.
If needed, we can move this to a separate PR/issue.
9f6aeea
to
dd20708
Compare
Check that error is reported when CAN filter is added without callback function. Signed-off-by: Sebastian Głąb <[email protected]>
There is negative test for too high bitrate. Add test that checks too low bitrate. Signed-off-by: Sebastian Głąb <[email protected]>
There is negative test for too high data bitrate. Add test that checks too low data bitrate. Signed-off-by: Sebastian Głąb <[email protected]>
Check error codes when sending invalid frames: - too big data payload; - wrong set of flags. Signed-off-by: Sebastian Głąb <[email protected]>
dd20708
to
801d7e4
Compare
Bring in additional CAN tests: nrfconnect/sdk-zephyr#2151 zephyrproject-rtos/zephyr#80063 Signed-off-by: Sebastian Głąb <[email protected]>
Bring in additional CAN tests: nrfconnect/sdk-zephyr#2151 zephyrproject-rtos/zephyr#80063 Signed-off-by: Sebastian Głąb <[email protected]>
Fallout from misunderstanding the CAN_FRAME_ESI flag fixed here: #80380 |
"Fix the test for sending frames with the CAN_FRAME_ESI flag set. Sending frames with this flag set in software is never allowed." That proves what You stated - I don't have sufficient knowledge to work on task "NRFX-6088: Extend testing for CAN". |
From the other side: IMHO, there should be more tests: Scenario 3 in "classic CAN": |
Bring in additional CAN tests: nrfconnect/sdk-zephyr#2151 zephyrproject-rtos/zephyr#80063 Signed-off-by: Sebastian Głąb <[email protected]>
(Removed as it doesn't restore CAN configuration fully.)
// tests: drivers: can: api: Set default CAN state before each test
// Tests assume that CAN is started.
// When previous test stops CAN and fails on assertion then remaining tests may fail.
// Start CAN before every tests. Ignore error code returned when starting CAN that is already started.
tests: drivers: can: api: Add negative test for can_send()
Check error codes when sending invalid frames:
(Removed as there are dependencies to CAN core clock frequency and timing setting.)
// tests: drivers: can: api: Check value returned by can_get_bitrate_max()
// Function can_get_bitrate_max() shall return maximum supported bitrate for the CAN controller/transceiver combination.
// Check if that bitrate can be set with can_set_bitrate_data().
(Removed as there are dependencies to CAN core clock frequency and timing setting.)
// tests: drivers: can: api: Check value returned by can_get_bitrate_min()
// Function can_get_bitrate_min() shall return minimum supported bitrate for the CAN controller/transceiver combination.
// Check if that bitrate can be set with can_set_bitrate().
tests: drivers: can: api: Add negative test for can_set_bitrate_data()
There is negative test for too high data bitrate.
Add test that checks too low data bitrate.
tests: drivers: can: api: Add negative test for can_set_bitrate()
There is negative test for too high bitrate.
Add test that checks too low bitrate.
tests: drivers: can: api: Add negative test for can_add_rx_filter()
Check that error is reported when CAN filter is added without callback function.