2525#include <stdlib.h>
2626#include <string.h>
2727
28+ #ifdef CONFIG_TEST_HW_FLOW_CONTROL
29+ #define TEST_BACKEND_RECEIVE_BUFFER_SIZE 256
30+ #else
31+ #define TEST_BACKEND_RECEIVE_BUFFER_SIZE 4096
32+ #endif
33+
2834/*************************************************************************************************/
2935/* Mock pipe */
3036/*************************************************************************************************/
@@ -36,7 +42,7 @@ K_SEM_DEFINE(receive_ready_sem, 0, 1);
3642/*************************************************************************************************/
3743/* Buffers */
3844/*************************************************************************************************/
39- static uint8_t backend_receive_buffer [4096 ];
45+ static uint8_t backend_receive_buffer [TEST_BACKEND_RECEIVE_BUFFER_SIZE ];
4046static uint8_t backend_transmit_buffer [4096 ];
4147RING_BUF_DECLARE (transmit_ring_buf , 4096 );
4248static uint8_t receive_buffer [4096 ];
@@ -131,21 +137,32 @@ static int transmit_prng(uint32_t remaining)
131137
132138static int receive_prng (void )
133139{
134- int ret = 0 ;
140+ int ret ;
141+
142+ if (k_sem_take (& receive_ready_sem , K_SECONDS (1 ))) {
143+ return - ETIMEDOUT ;
144+ }
145+
146+ if (IS_ENABLED (CONFIG_TEST_HW_FLOW_CONTROL )) {
147+ k_msleep (100 );
148+ }
135149
136- if (k_sem_take (& receive_ready_sem , K_NO_WAIT ) == 0 ) {
137- ret = modem_pipe_receive (pipe , receive_buffer , sizeof (receive_buffer ));
138- if (ret < 0 ) {
150+ ret = modem_pipe_receive (pipe , receive_buffer , sizeof (receive_buffer ));
151+ if (ret == 0 ) {
152+ return - ENODATA ;
153+ }
154+
155+ if (ret < 0 ) {
156+ return - EFAULT ;
157+ }
158+
159+ for (uint32_t i = 0 ; i < (uint32_t )ret ; i ++ ) {
160+ if (receive_prng_random () != receive_buffer [i ]) {
139161 return - EFAULT ;
140162 }
141- for (uint32_t i = 0 ; i < (uint32_t )ret ; i ++ ) {
142- if (receive_prng_random () != receive_buffer [i ]) {
143- return - EFAULT ;
144- }
145- }
146- printk ("RX: %u\n" , (uint32_t )ret );
147163 }
148164
165+ printk ("RX: %u\n" , (uint32_t )ret );
149166 return ret ;
150167}
151168
@@ -157,9 +174,9 @@ static void *test_modem_backend_uart_setup(void)
157174 const struct modem_backend_uart_config config = {
158175 .uart = uart ,
159176 .receive_buf = backend_receive_buffer ,
160- .receive_buf_size = 1024 ,
177+ .receive_buf_size = sizeof ( backend_receive_buffer ) ,
161178 .transmit_buf = backend_transmit_buffer ,
162- .transmit_buf_size = 1024 ,
179+ .transmit_buf_size = sizeof ( backend_transmit_buffer ) ,
163180 };
164181
165182 pipe = modem_backend_uart_init (& uart_backend , & config );
@@ -172,12 +189,12 @@ static void test_modem_backend_uart_before(void *f)
172189 prng_reset ();
173190 ring_buf_reset (& transmit_ring_buf );
174191 k_sem_reset (& receive_ready_sem );
175- __ASSERT_NO_MSG (modem_pipe_open (pipe , K_SECONDS (10 )) == 0 );
192+ __ASSERT_NO_MSG (modem_pipe_open (pipe , K_SECONDS (1 )) == 0 );
176193}
177194
178195static void test_modem_backend_uart_after (void * f )
179196{
180- __ASSERT_NO_MSG (modem_pipe_close (pipe , K_SECONDS (10 )) == 0 );
197+ __ASSERT_NO_MSG (modem_pipe_close (pipe , K_SECONDS (1 )) == 0 );
181198}
182199
183200/*************************************************************************************************/
@@ -201,7 +218,6 @@ ZTEST(modem_backend_uart_suite, test_transmit_receive)
201218 ret = receive_prng ();
202219 zassert (ret > -1 , "Received data is corrupted" );
203220 received += (uint32_t )ret ;
204- k_yield ();
205221 }
206222 }
207223}
0 commit comments