Skip to content

Commit

Permalink
tests: drivers: can: fd: test returned error codes when started/stopped
Browse files Browse the repository at this point in the history
Add tests for the required error return codes when the CAN controller is
started/stopped.

Signed-off-by: Henrik Brix Andersen <[email protected]>
  • Loading branch information
henrikbrixandersen authored and fabiobaltieri committed Sep 13, 2022
1 parent 94d3702 commit 6cdb418
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/drivers/can/canfd/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
* @}
*/

/**
* Test bitrates in bits/second.
*/
#define TEST_BITRATE 1000000

/**
* Test sample points in per mille.
*/
#define TEST_SAMPLE_POINT 750


/**
* @brief Test timeouts.
Expand Down Expand Up @@ -380,6 +390,36 @@ ZTEST(canfd, test_send_receive_mixed)
&test_std_frame_fd_1, &test_std_frame_2);
}

/**
* @brief Test setting bitrate is not allowed while started.
*/
ZTEST_USER(canfd, test_set_bitrate_data_while_started)
{
int err;

err = can_set_bitrate_data(can_dev, TEST_BITRATE);
zassert_not_equal(err, 0, "changed data bitrate while started");
zassert_equal(err, -EBUSY, "wrong error return code (err %d)", err);
}

/**
* @brief Test setting timing is not allowed while started.
*/
ZTEST_USER(canfd, test_set_timing_data_while_started)
{
struct can_timing timing;
int err;

timing.sjw = CAN_SJW_NO_CHANGE;

err = can_calc_timing_data(can_dev, &timing, TEST_BITRATE, TEST_SAMPLE_POINT);
zassert_ok(err, "failed to calculate data timing (err %d)", err);

err = can_set_timing(can_dev, &timing);
zassert_not_equal(err, 0, "changed data timing while started");
zassert_equal(err, -EBUSY, "wrong error return code (err %d)", err);
}

void *canfd_setup(void)
{
int err;
Expand Down

0 comments on commit 6cdb418

Please sign in to comment.