Skip to content

Commit

Permalink
tests: drivers: i2s: ZTest ordering issue fix
Browse files Browse the repository at this point in the history
The test was executing the expected functions
out of order. I have created a config functions
and explicitly declared them to be setup functions
for this ZTest framework.

Signed-off-by: Emilio Benavente <[email protected]>
  • Loading branch information
EmilioCBen authored and fabiobaltieri committed Jan 6, 2023
1 parent d4cfc35 commit 3ffc64a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 51 deletions.
5 changes: 4 additions & 1 deletion tests/drivers/i2s/i2s_speed/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@
#include <zephyr/kernel.h>
#include <zephyr/ztest.h>

ZTEST_SUITE(drivers_i2s_speed, NULL, NULL, NULL, NULL, NULL);
extern void *test_i2s_speed_configure(void);
extern void *test_i2s_speed_rxtx_configure(void);
ZTEST_SUITE(drivers_i2s_speed, NULL, test_i2s_speed_configure, NULL, NULL, NULL);
ZTEST_SUITE(drivers_i2s_speed_both_rxtx, NULL, test_i2s_speed_rxtx_configure, NULL, NULL, NULL);
102 changes: 52 additions & 50 deletions tests/drivers/i2s/i2s_speed/src/test_i2s_speed.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,31 +178,6 @@ static int configure_stream(const struct device *dev_i2s, enum i2s_dir dir)
return TC_PASS;
}

/** Configure I2S TX transfer. */
ZTEST(drivers_i2s_speed, test_i2s_tx_transfer_configure)
{
int ret;

dev_i2s_tx = DEVICE_DT_GET_OR_NULL(I2S_DEV_NODE_TX);
zassert_not_null(dev_i2s_tx, "transfer device not found");
zassert(device_is_ready(dev_i2s_tx), "transfer device not ready");

ret = configure_stream(dev_i2s_tx, I2S_DIR_TX);
zassert_equal(ret, TC_PASS);
}

/** Configure I2S RX transfer. */
ZTEST(drivers_i2s_speed, test_i2s_rx_transfer_configure)
{
int ret;

dev_i2s_rx = DEVICE_DT_GET_OR_NULL(I2S_DEV_NODE_RX);
zassert_not_null(dev_i2s_rx, "receive device not found");
zassert(device_is_ready(dev_i2s_rx), "receive device not ready");

ret = configure_stream(dev_i2s_rx, I2S_DIR_RX);
zassert_equal(ret, TC_PASS);
}

/** @brief Short I2S transfer.
*
Expand Down Expand Up @@ -373,37 +348,14 @@ ZTEST(drivers_i2s_speed, test_i2s_transfer_long)
zassert_equal(num_verified, NUM_BLOCKS, "Invalid RX blocks received");
}

ZTEST(drivers_i2s_speed, test_i2s_dir_both_transfer_configure)
{
int ret;

dev_i2s_rxtx = DEVICE_DT_GET_OR_NULL(I2S_DEV_NODE_RX);
zassert_not_null(dev_i2s_rxtx, "receive device not found");
zassert(device_is_ready(dev_i2s_rxtx), "receive device not ready");

ret = configure_stream(dev_i2s_rxtx, I2S_DIR_BOTH);
zassert_equal(ret, TC_PASS);

/* Check if the tested driver supports the I2S_DIR_BOTH value.
* Use the DROP trigger for this, as in the current state of the driver
* (READY, both TX and RX queues empty) it is actually a no-op.
*/
ret = i2s_trigger(dev_i2s_rxtx, I2S_DIR_BOTH, I2S_TRIGGER_DROP);
dir_both_supported = (ret == 0);

if (IS_ENABLED(CONFIG_I2S_TEST_USE_I2S_DIR_BOTH)) {
zassert_true(dir_both_supported,
"I2S_DIR_BOTH value is supposed to be supported.");
}
}

/** @brief Short I2S transfer using I2S_DIR_BOTH.
*
* - START trigger starts both the transmission and reception.
* - Sending / receiving a short sequence of data returns success.
* - DRAIN trigger empties the transmit queue and stops both streams.
*/
ZTEST(drivers_i2s_speed, test_i2s_dir_both_transfer_short)
ZTEST(drivers_i2s_speed_both_rxtx, test_i2s_dir_both_transfer_short)
{
if (!dir_both_supported) {
TC_PRINT("I2S_DIR_BOTH value is not supported.\n");
Expand Down Expand Up @@ -470,7 +422,7 @@ ZTEST(drivers_i2s_speed, test_i2s_dir_both_transfer_short)
* - Sending / receiving a long sequence of data returns success.
* - DRAIN trigger empties the transmit queue and stops both streams.
*/
ZTEST(drivers_i2s_speed, test_i2s_dir_both_transfer_long)
ZTEST(drivers_i2s_speed_both_rxtx, test_i2s_dir_both_transfer_long)
{
if (!dir_both_supported) {
TC_PRINT("I2S_DIR_BOTH value is not supported.\n");
Expand Down Expand Up @@ -543,3 +495,53 @@ ZTEST(drivers_i2s_speed, test_i2s_dir_both_transfer_long)
}
zassert_equal(num_verified, NUM_BLOCKS, "Invalid RX blocks received");
}

void *test_i2s_speed_configure(void)
{
/* Configure I2S TX transfer. */
int ret;

dev_i2s_tx = DEVICE_DT_GET_OR_NULL(I2S_DEV_NODE_TX);
zassert_not_null(dev_i2s_tx, "transfer device not found");
zassert(device_is_ready(dev_i2s_tx), "transfer device not ready");

ret = configure_stream(dev_i2s_tx, I2S_DIR_TX);
zassert_equal(ret, TC_PASS);

/* Configure I2S RX transfer. */
dev_i2s_rx = DEVICE_DT_GET_OR_NULL(I2S_DEV_NODE_RX);
zassert_not_null(dev_i2s_rx, "receive device not found");
zassert(device_is_ready(dev_i2s_rx), "receive device not ready");

ret = configure_stream(dev_i2s_rx, I2S_DIR_RX);
zassert_equal(ret, TC_PASS);

return 0;
}

void *test_i2s_speed_rxtx_configure(void)
{
int ret;

/* Configure I2S Dir Both transfer. */
dev_i2s_rxtx = DEVICE_DT_GET_OR_NULL(I2S_DEV_NODE_RX);
zassert_not_null(dev_i2s_rxtx, "receive device not found");
zassert(device_is_ready(dev_i2s_rxtx), "receive device not ready");

ret = configure_stream(dev_i2s_rxtx, I2S_DIR_BOTH);
zassert_equal(ret, TC_PASS);

/* Check if the tested driver supports the I2S_DIR_BOTH value.
* Use the DROP trigger for this, as in the current state of the driver
* (READY, both TX and RX queues empty) it is actually a no-op.
*/
ret = i2s_trigger(dev_i2s_rxtx, I2S_DIR_BOTH, I2S_TRIGGER_DROP);
dir_both_supported = (ret == 0);

if (IS_ENABLED(CONFIG_I2S_TEST_USE_I2S_DIR_BOTH)) {
zassert_true(dir_both_supported,
"I2S_DIR_BOTH value is supposed to be supported.");
}

return 0;
}

0 comments on commit 3ffc64a

Please sign in to comment.