tests: drivers: spi_controller_peripheral: improve async test case

In test cases checking async API, use async API
for both controller and peripheral devices.

Signed-off-by: Nikodem Kastelik <nikodem.kastelik@nordicsemi.no>
This commit is contained in:
Nikodem Kastelik 2024-05-29 14:37:51 +02:00 committed by Fabio Baltieri
commit 77e875a0b7

View file

@ -35,6 +35,10 @@ static struct k_poll_signal async_sig = K_POLL_SIGNAL_INITIALIZER(async_sig);
static struct k_poll_event async_evt = static struct k_poll_event async_evt =
K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL, K_POLL_MODE_NOTIFY_ONLY, &async_sig); K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL, K_POLL_MODE_NOTIFY_ONLY, &async_sig);
static struct k_poll_signal async_sig_spim = K_POLL_SIGNAL_INITIALIZER(async_sig_spim);
static struct k_poll_event async_evt_spim =
K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL, K_POLL_MODE_NOTIFY_ONLY, &async_sig_spim);
#define MEMORY_SECTION(node) \ #define MEMORY_SECTION(node) \
COND_CODE_1(DT_NODE_HAS_PROP(node, memory_regions), \ COND_CODE_1(DT_NODE_HAS_PROP(node, memory_regions), \
(__attribute__((__section__( \ (__attribute__((__section__( \
@ -55,6 +59,7 @@ struct test_data {
struct spi_buf_set *stx_set; struct spi_buf_set *stx_set;
struct spi_buf_set *srx_set; struct spi_buf_set *srx_set;
struct spi_buf bufs[8]; struct spi_buf bufs[8];
bool async;
}; };
static struct test_data tdata; static struct test_data tdata;
@ -85,8 +90,26 @@ static void work_handler(struct k_work *work)
struct test_data *td = CONTAINER_OF(dwork, struct test_data, test_work); struct test_data *td = CONTAINER_OF(dwork, struct test_data, test_work);
int rv; int rv;
if (!td->async) {
rv = spi_transceive_dt(&spim, td->mtx_set, td->mrx_set); rv = spi_transceive_dt(&spim, td->mtx_set, td->mrx_set);
if (rv == 0) { if (rv == 0) {
k_sem_give(&td->sem);
}
} else {
rv = spi_transceive_signal(spim.bus, &spim.config, td->mtx_set, td->mrx_set,
&async_sig_spim);
zassert_equal(rv, 0);
rv = k_poll(&async_evt_spim, 1, K_MSEC(200));
zassert_false(rv, "one or more events are not ready");
rv = async_evt_spim.signal->result;
zassert_equal(rv, 0);
/* Reinitializing for next call */
async_evt_spim.signal->signaled = 0U;
async_evt_spim.state = K_POLL_STATE_NOT_READY;
k_sem_give(&td->sem); k_sem_give(&td->sem);
} }
} }
@ -181,6 +204,7 @@ static void run_test(bool m_same_size, bool s_same_size, bool async)
int periph_rv; int periph_rv;
int srx_len; int srx_len;
tdata.async = async;
rv = k_work_schedule(&tdata.test_work, K_MSEC(10)); rv = k_work_schedule(&tdata.test_work, K_MSEC(10));
zassert_equal(rv, 1); zassert_equal(rv, 1);