From 96fd76edda9f3b7daab12850e3ce6b6435c5c3d6 Mon Sep 17 00:00:00 2001 From: Mahesh Mahadevan Date: Thu, 4 Feb 2021 16:13:20 -0600 Subject: [PATCH] tests: i2s: Fix i2s_states_test test suite 1. Update the way test_i2s_state_error_neg test handles RX overflow. 2. Clean up after test_i2s_state_stopping_neg test in case the receiving channel is stuck in the STOPPING State if the data was received prior to calling the STOP trigger. Signed-off-by: Mahesh Mahadevan --- .../drivers/i2s/i2s_api/src/test_i2s_states.c | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/drivers/i2s/i2s_api/src/test_i2s_states.c b/tests/drivers/i2s/i2s_api/src/test_i2s_states.c index 67a9215f69a..fc7de0cfc53 100644 --- a/tests/drivers/i2s/i2s_api/src/test_i2s_states.c +++ b/tests/drivers/i2s/i2s_api/src/test_i2s_states.c @@ -340,6 +340,12 @@ void test_i2s_state_stopping_neg(void) ret = rx_block_read(dev_i2s_rx, 0); zassert_equal(ret, TC_PASS, NULL); + + /* This is incase the RX channel is stuck in STOPPING state. + * Clear out the state before running the next test. + */ + ret = i2s_trigger(dev_i2s_rx, I2S_DIR_RX, I2S_TRIGGER_DROP); + zassert_equal(ret, 0, "RX DROP trigger failed"); } /** @brief Verify all failure cases in ERROR state. @@ -380,14 +386,19 @@ void test_i2s_state_error_neg(void) /* Wait for transmission to finish */ k_sleep(K_MSEC(200)); - /* Read all available data blocks in RX queue */ - for (int i = 0; i < NUM_RX_BLOCKS; i++) { - ret = rx_block_read(dev_i2s_rx, 0); - zassert_equal(ret, TC_PASS, NULL); - } + /* Read one data block, expect success even if RX queue is already in + * the error state. + */ + ret = rx_block_read(dev_i2s_rx, 0); + zassert_equal(ret, TC_PASS, NULL); - /* Attempt to read one more data block, expect an error */ - ret = i2s_buf_read(dev_i2s_rx, rx_buf, &rx_size); + /* Attempt to read more data blocks than are available in the RX queue */ + for (int i = 0; i < NUM_RX_BLOCKS; i++) { + ret = i2s_buf_read(dev_i2s_rx, rx_buf, &rx_size); + if (ret != 0) { + break; + } + } zassert_equal(ret, -EIO, "RX overrun error not detected"); /* Send invalid triggers, expect failure */