tests: drivers: can: api: Add negative test for can_send()
Check error codes when sending invalid frames: - too big data payload; - wrong set of flags. Signed-off-by: Sebastian Głąb <sebastian.glab@nordicsemi.no>
This commit is contained in:
parent
2616720ee2
commit
8023a58c2a
2 changed files with 66 additions and 0 deletions
|
@ -238,6 +238,45 @@ ZTEST(canfd, test_canfd_get_capabilities)
|
|||
"CAN FD loopback mode not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test sending CAN FD frame with too big payload.
|
||||
*/
|
||||
ZTEST(canfd, test_send_fd_dlc_out_of_range)
|
||||
{
|
||||
struct can_frame frame = {
|
||||
.flags = CAN_FRAME_FDF | CAN_FRAME_BRS,
|
||||
.id = TEST_CAN_STD_ID_1,
|
||||
.dlc = CANFD_MAX_DLC + 1U,
|
||||
};
|
||||
int err;
|
||||
|
||||
Z_TEST_SKIP_IFNDEF(CONFIG_RUNTIME_ERROR_CHECKS);
|
||||
|
||||
err = can_send(can_dev, &frame, TEST_SEND_TIMEOUT, NULL, NULL);
|
||||
zassert_equal(err, -EINVAL, "wrong error on sending invalid frame (err %d)", err);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test error when CAN FD Error State Indicator (ESI) is send without FD format flag (FDF).
|
||||
*
|
||||
* 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)
|
||||
{
|
||||
struct can_frame frame = {
|
||||
.flags = CAN_FRAME_ESI,
|
||||
.id = TEST_CAN_STD_ID_1,
|
||||
.dlc = 0,
|
||||
};
|
||||
int err;
|
||||
|
||||
Z_TEST_SKIP_IFNDEF(CONFIG_RUNTIME_ERROR_CHECKS);
|
||||
|
||||
err = can_send(can_dev, &frame, TEST_SEND_TIMEOUT, NULL, NULL);
|
||||
zassert_equal(err, -ENOTSUP, "wrong error on sending invalid frame (err %d)", err);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test send/receive with standard (11-bit) CAN IDs and classic CAN frames.
|
||||
*/
|
||||
|
|
|
@ -856,6 +856,33 @@ ZTEST(can_classic, test_send_ext_id_out_of_range)
|
|||
send_invalid_frame(can_dev, &frame);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test sending standard (11-bit ID) CAN frame with too big payload.
|
||||
*/
|
||||
ZTEST(can_classic, test_send_std_id_dlc_of_range)
|
||||
{
|
||||
struct can_frame frame = {
|
||||
.id = TEST_CAN_STD_ID_1,
|
||||
.dlc = CAN_MAX_DLC + 1U,
|
||||
};
|
||||
|
||||
send_invalid_frame(can_dev, &frame);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test sending extended (29-bit ID) CAN frame with too big payload.
|
||||
*/
|
||||
ZTEST(can_classic, test_send_ext_id_dlc_of_range)
|
||||
{
|
||||
struct can_frame frame = {
|
||||
.flags = CAN_FRAME_IDE,
|
||||
.id = TEST_CAN_EXT_ID_1,
|
||||
.dlc = CAN_MAX_DLC + 1U,
|
||||
};
|
||||
|
||||
send_invalid_frame(can_dev, &frame);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test send/receive with standard (11-bit) CAN IDs.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue