Skip to content

Commit 035d583

Browse files
committed
tests: rtio: Add testcase to validate OP_DELAY
Providing a set of SQEs with varying delays in different orders. Test validates each delay is completed at the right amount (and the CQEs are received in the right order). Signed-off-by: Luis Ubieda <[email protected]>
1 parent 2ec7b38 commit 035d583

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

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

+56
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,62 @@ ZTEST(rtio_api, test_rtio_cqe_count_overflow)
649649
}
650650
}
651651

652+
#define RTIO_DELAY_NUM_ELEMS 10
653+
654+
RTIO_DEFINE(r_delay, RTIO_DELAY_NUM_ELEMS, RTIO_DELAY_NUM_ELEMS);
655+
656+
ZTEST(rtio_api, test_rtio_delay)
657+
{
658+
int res;
659+
struct rtio *r = &r_delay;
660+
struct rtio_sqe *sqe;
661+
struct rtio_cqe *cqe;
662+
663+
uint8_t expected_expiration_order[RTIO_DELAY_NUM_ELEMS] = {4, 3, 2, 1, 0, 5, 6, 7, 8, 9};
664+
665+
for (size_t i = 0; i < RTIO_DELAY_NUM_ELEMS; i++) {
666+
sqe = rtio_sqe_acquire(r);
667+
zassert_not_null(sqe, "Expected a valid sqe");
668+
669+
/** Half of the delays will be earlier than the previous one submitted.
670+
* The other half will be later.
671+
*/
672+
if (i < (RTIO_DELAY_NUM_ELEMS / 2)) {
673+
rtio_sqe_prep_delay(sqe, K_SECONDS(100 - i), (void *)i);
674+
} else {
675+
rtio_sqe_prep_delay(sqe, K_SECONDS(100 - 4 + i), (void *)i);
676+
}
677+
}
678+
679+
res = rtio_submit(r, 0);
680+
zassert_ok(res, "Should return ok from rtio_execute");
681+
682+
cqe = rtio_cqe_consume(r);
683+
zassert_is_null(cqe, "There should not be a cqe since delay has not expired");
684+
685+
/** Wait until we expect delays start expiring */
686+
k_sleep(K_SECONDS(100 - (RTIO_DELAY_NUM_ELEMS / 2)));
687+
688+
for (size_t i = 0; i < RTIO_DELAY_NUM_ELEMS; i++) {
689+
k_sleep(K_SECONDS(1));
690+
691+
TC_PRINT("consume %d\n", i);
692+
cqe = rtio_cqe_consume(r);
693+
zassert_not_null(cqe, "Expected a valid cqe");
694+
zassert_ok(cqe->result, "Result should be ok");
695+
696+
size_t expired_id = (size_t)(cqe->userdata);
697+
698+
zassert_equal(expected_expiration_order[i], expired_id,
699+
"Expected order not valid. Obtained: %d, expected: %d",
700+
expired_id, expected_expiration_order[i]);
701+
702+
rtio_cqe_release(r, cqe);
703+
704+
cqe = rtio_cqe_consume(r);
705+
zassert_is_null(cqe, "There should not be a cqe since next delay has not expired");
706+
}
707+
}
652708

653709
#define THROUGHPUT_ITERS 100000
654710
RTIO_DEFINE(r_throughput, SQE_POOL_SIZE, CQE_POOL_SIZE);

0 commit comments

Comments
 (0)