Skip to content

Commit eb09070

Browse files
ubiedafabiobaltieri
authored andcommitted
tests: rtio: Add testcase to demonstrate multishot aborted on errors
By forcing IODEV test to throw errors and verifying no more CQE's are coming through after the forced error. Signed-off-by: Luis Ubieda <[email protected]>
1 parent 18b3faa commit eb09070

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

tests/subsys/rtio/rtio_api/src/rtio_iodev_test.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ struct rtio_iodev_test_data {
2828

2929
/* Lock around kicking off next timer */
3030
struct k_spinlock lock;
31+
32+
/* Mocked result to receive by the IODEV */
33+
int result;
3134
};
3235

3336
static void rtio_iodev_test_next(struct rtio_iodev_test_data *data, bool completion)
@@ -81,7 +84,7 @@ static void rtio_iodev_await_signaled(struct rtio_iodev_sqe *iodev_sqe, void *us
8184
{
8285
struct rtio_iodev_test_data *data = userdata;
8386

84-
rtio_iodev_test_complete(data, 0);
87+
rtio_iodev_test_complete(data, data->result);
8588
}
8689

8790
static void rtio_iodev_timer_fn(struct k_timer *tm)
@@ -94,7 +97,7 @@ static void rtio_iodev_timer_fn(struct k_timer *tm)
9497

9598
switch (iodev_sqe->sqe.op) {
9699
case RTIO_OP_NOP:
97-
rtio_iodev_test_complete(data, 0);
100+
rtio_iodev_test_complete(data, data->result);
98101
break;
99102
case RTIO_OP_RX:
100103
rc = rtio_sqe_rx_buf(iodev_sqe, 16, 16, &buf, &buf_len);
@@ -104,7 +107,7 @@ static void rtio_iodev_timer_fn(struct k_timer *tm)
104107
}
105108
/* For reads the test device copies from the given userdata */
106109
memcpy(buf, ((uint8_t *)iodev_sqe->sqe.userdata), 16);
107-
rtio_iodev_test_complete(data, 0);
110+
rtio_iodev_test_complete(data, data->result);
108111
break;
109112
case RTIO_OP_AWAIT:
110113
rtio_iodev_sqe_await_signal(iodev_sqe, rtio_iodev_await_signaled, data);
@@ -139,6 +142,14 @@ void rtio_iodev_test_init(struct rtio_iodev *test)
139142
data->txn_head = NULL;
140143
data->txn_curr = NULL;
141144
k_timer_init(&data->timer, rtio_iodev_timer_fn, NULL);
145+
data->result = 0;
146+
}
147+
148+
void rtio_iodev_test_set_result(struct rtio_iodev *test, int result)
149+
{
150+
struct rtio_iodev_test_data *data = test->data;
151+
152+
data->result = result;
142153
}
143154

144155
#define RTIO_IODEV_TEST_DEFINE(name) \

tests/subsys/rtio/rtio_api/src/test_rtio_api.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,46 @@ ZTEST_USER(rtio_api, test_rtio_multishot)
532532
}
533533
}
534534

535+
ZTEST(rtio_api, test_rtio_multishot_are_not_resubmitted_when_failed)
536+
{
537+
int res;
538+
struct rtio_sqe sqe;
539+
struct rtio_cqe cqe;
540+
struct rtio_sqe *handle;
541+
struct rtio *r = &r_simple;
542+
uint8_t *buffer = NULL;
543+
uint32_t buffer_len = 0;
544+
545+
for (int i = 0 ; i < MEM_BLK_SIZE; i++) {
546+
mempool_data[i] = i;
547+
}
548+
549+
rtio_sqe_prep_read_multishot(&sqe, (struct rtio_iodev *)&iodev_test_simple, 0,
550+
mempool_data);
551+
res = rtio_sqe_copy_in_get_handles(r, &sqe, &handle, 1);
552+
zassert_ok(res);
553+
554+
rtio_iodev_test_set_result(&iodev_test_simple, -EIO);
555+
556+
rtio_submit(r, 1);
557+
558+
/** The multi-shot SQE should fail, transmit the result and stop resubmitting. */
559+
zassert_equal(1, rtio_cqe_copy_out(r, &cqe, 1, K_MSEC(100)));
560+
zassert_equal(cqe.result, -EIO, "Result should be %d but got %d", -EIO, cqe.result);
561+
562+
/* No more CQE's coming as it should be aborted */
563+
zassert_equal(0, rtio_cqe_copy_out(r, &cqe, 1, K_MSEC(100)),
564+
"Should not get more CQEs after the error CQE");
565+
566+
rtio_sqe_drop_all(r);
567+
568+
/* Flush any pending CQEs */
569+
while (rtio_cqe_copy_out(r, &cqe, 1, K_MSEC(1000)) != 0) {
570+
rtio_cqe_get_mempool_buffer(r, &cqe, &buffer, &buffer_len);
571+
rtio_release_buffer(r, buffer, buffer_len);
572+
}
573+
}
574+
535575
RTIO_DEFINE(r_transaction, SQE_POOL_SIZE, CQE_POOL_SIZE);
536576

537577
RTIO_IODEV_TEST_DEFINE(iodev_test_transaction0);

0 commit comments

Comments
 (0)