@@ -649,6 +649,62 @@ ZTEST(rtio_api, test_rtio_cqe_count_overflow)
649
649
}
650
650
}
651
651
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 (10 - i ), (void * )i );
674
+ } else {
675
+ rtio_sqe_prep_delay (sqe , K_SECONDS (10 - 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 (10 - (RTIO_DELAY_NUM_ELEMS / 2 )));
687
+
688
+ for (int 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
+ (int )expired_id , (int )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
+ }
652
708
653
709
#define THROUGHPUT_ITERS 100000
654
710
RTIO_DEFINE (r_throughput , SQE_POOL_SIZE , CQE_POOL_SIZE );
0 commit comments