@@ -850,14 +850,17 @@ ZTEST_USER(uart_async_chain_write, test_chained_write)
850850 "RX_DISABLED timeout" );
851851}
852852
853+ #define RX_LONG_BUFFER CONFIG_TEST_LONG_BUFFER_SIZE
854+ #define TX_LONG_BUFFER (CONFIG_TEST_LONG_BUFFER_SIZE - 8)
855+
853856#if NOCACHE_MEM
854- static __aligned (32 ) uint8_t long_rx_buf [1024 ] __used __NOCACHE ;
855- static __aligned (32 ) uint8_t long_rx_buf2 [1024 ] __used __NOCACHE ;
856- static __aligned (32 ) uint8_t long_tx_buf [1000 ] __used __NOCACHE ;
857+ static __aligned (32 ) uint8_t long_rx_buf [RX_LONG_BUFFER ] __used __NOCACHE ;
858+ static __aligned (32 ) uint8_t long_rx_buf2 [RX_LONG_BUFFER ] __used __NOCACHE ;
859+ static __aligned (32 ) uint8_t long_tx_buf [TX_LONG_BUFFER ] __used __NOCACHE ;
857860#else
858- ZTEST_BMEM uint8_t long_rx_buf [1024 ];
859- ZTEST_BMEM uint8_t long_rx_buf2 [1024 ];
860- ZTEST_BMEM uint8_t long_tx_buf [1000 ];
861+ ZTEST_BMEM uint8_t long_rx_buf [RX_LONG_BUFFER ];
862+ ZTEST_BMEM uint8_t long_rx_buf2 [RX_LONG_BUFFER ];
863+ ZTEST_BMEM uint8_t long_tx_buf [TX_LONG_BUFFER ];
861864#endif /* NOCACHE_MEM */
862865ZTEST_BMEM volatile uint8_t evt_num ;
863866ZTEST_BMEM size_t long_received [2 ];
@@ -887,7 +890,7 @@ static void test_long_buffers_callback(const struct device *dev,
887890 k_sem_give (& rx_disabled );
888891 break ;
889892 case UART_RX_BUF_REQUEST :
890- uart_rx_buf_rsp (dev , next_buffer , 1024 );
893+ uart_rx_buf_rsp (dev , next_buffer , RX_LONG_BUFFER );
891894 next_buffer = (next_buffer == long_rx_buf2 ) ? long_rx_buf : long_rx_buf2 ;
892895 break ;
893896 default :
@@ -906,36 +909,41 @@ static void *long_buffers_setup(void)
906909
907910ZTEST_USER (uart_async_long_buf , test_long_buffers )
908911{
912+ size_t tx_len1 = TX_LONG_BUFFER / 2 ;
913+ size_t tx_len2 = TX_LONG_BUFFER ;
914+
909915 memset (long_rx_buf , 0 , sizeof (long_rx_buf ));
910916 memset (long_tx_buf , 1 , sizeof (long_tx_buf ));
911917
912918 uart_rx_enable (uart_dev , long_rx_buf , sizeof (long_rx_buf ), 10 * USEC_PER_MSEC );
913919
914- uart_tx (uart_dev , long_tx_buf , 500 , 200 * USEC_PER_MSEC );
920+ uart_tx (uart_dev , long_tx_buf , tx_len1 , 200 * USEC_PER_MSEC );
915921 zassert_equal (k_sem_take (& tx_done , K_MSEC (200 )), 0 , "TX_DONE timeout" );
916922 zassert_equal (k_sem_take (& rx_rdy , K_MSEC (200 )), 0 , "RX_RDY timeout" );
917- zassert_equal (long_received [0 ], 500 , "Wrong number of bytes received." );
918- zassert_equal (memcmp (long_tx_buf , long_rx_buf , 500 ),
923+ zassert_equal (long_received [0 ], tx_len1 , "Wrong number of bytes received." );
924+ zassert_equal (memcmp (long_tx_buf , long_rx_buf , tx_len1 ),
919925 0 ,
920926 "Buffers not equal" );
921927 k_msleep (10 );
922928 /* Check if instance is releasing a buffer after the timeout. */
923929 bool release_on_timeout = k_sem_take (& rx_buf_released , K_NO_WAIT ) == 0 ;
924930
925931 evt_num = 0 ;
926- uart_tx (uart_dev , long_tx_buf , 1000 , 200 * USEC_PER_MSEC );
932+ uart_tx (uart_dev , long_tx_buf , tx_len2 , 200 * USEC_PER_MSEC );
927933 zassert_equal (k_sem_take (& tx_done , K_MSEC (200 )), 0 , "TX_DONE timeout" );
928934 zassert_equal (k_sem_take (& rx_rdy , K_MSEC (200 )), 0 , "RX_RDY timeout" );
929935
930936 if (release_on_timeout ) {
931- zassert_equal (long_received [0 ], 1000 , "Wrong number of bytes received." );
937+ zassert_equal (long_received [0 ], tx_len2 , "Wrong number of bytes received." );
932938 zassert_equal (memcmp (long_tx_buf , long_rx_buf2 , long_received [0 ]), 0 ,
933939 "Buffers not equal" );
934940 } else {
935941 zassert_equal (k_sem_take (& rx_rdy , K_MSEC (200 )), 0 , "RX_RDY timeout" );
936- zassert_equal (long_received [0 ], 524 , "Wrong number of bytes received." );
937- zassert_equal (long_received [1 ], 476 , "Wrong number of bytes received." );
938- zassert_equal (memcmp (long_tx_buf , long_rx_buf + 500 , long_received [0 ]), 0 ,
942+ zassert_equal (long_received [0 ], RX_LONG_BUFFER - tx_len1 ,
943+ "Wrong number of bytes received." );
944+ zassert_equal (long_received [1 ], tx_len2 - (RX_LONG_BUFFER - tx_len1 ),
945+ "Wrong number of bytes received." );
946+ zassert_equal (memcmp (long_tx_buf , long_rx_buf + tx_len1 , long_received [0 ]), 0 ,
939947 "Buffers not equal" );
940948 zassert_equal (memcmp (long_tx_buf , long_rx_buf2 , long_received [1 ]), 0 ,
941949 "Buffers not equal" );
0 commit comments