@@ -25,39 +25,49 @@ K_SEM_DEFINE(rx_buf_released, 0, 1);
2525K_SEM_DEFINE (rx_disabled , 0 , 1 );
2626
2727static  ZTEST_BMEM  volatile  bool  failed_in_isr ;
28- static  ZTEST_BMEM  const  struct  device  * const  uart_dev  = 
29- 	DEVICE_DT_GET (UART_NODE );
28+ 
29+ struct  dut_data  {
30+ 	const  struct  device  * dev ;
31+ 	const  char  * name ;
32+ };
33+ 
34+ static  ZTEST_DMEM  struct  dut_data  duts [] =  {
35+ 	{
36+ 		.dev  =  DEVICE_DT_GET (UART_NODE ),
37+ 		.name  =  DT_NODE_FULL_NAME (UART_NODE ),
38+ 	},
39+ 	/* More instances can be added here. */ 
40+ };
41+ 
42+ static  ZTEST_BMEM  const  struct  device  * uart_dev ;
43+ static  ZTEST_BMEM  const  char  * uart_name ;
3044
3145static  void  read_abort_timeout (struct  k_timer  * timer );
3246static  K_TIMER_DEFINE (read_abort_timer , read_abort_timeout , NULL) ;
3347
3448
35- static  void  init_test (void )
36- {
37- 	__ASSERT_NO_MSG (device_is_ready (uart_dev ));
38- 	uart_rx_disable (uart_dev );
39- 	uart_tx_abort (uart_dev );
40- 	k_sem_reset (& tx_done );
41- 	k_sem_reset (& tx_aborted );
42- 	k_sem_reset (& rx_rdy );
43- 	k_sem_reset (& rx_buf_released );
44- 	k_sem_reset (& rx_disabled );
45- }
46- 
4749#ifdef  CONFIG_USERSPACE 
4850static  void  set_permissions (void )
4951{
5052	k_thread_access_grant (k_current_get (), & tx_done , & tx_aborted ,
5153			      & rx_rdy , & rx_buf_coherency , & rx_buf_released ,
5254			      & rx_disabled , uart_dev , & read_abort_timer );
55+ 
56+ 	for  (size_t  i  =  0 ; i  <  ARRAY_SIZE (duts ); i ++ ) {
57+ 		k_thread_access_grant (k_current_get (), duts [i ].dev );
58+ 	}
5359}
5460#endif 
5561
56- static  void  uart_async_test_init (void )
62+ static  void  uart_async_test_init (int   idx )
5763{
5864	static  bool  initialized ;
5965
66+ 	uart_dev  =  duts [idx ].dev ;
67+ 	uart_name  =  duts [idx ].name ;
68+ 
6069	__ASSERT_NO_MSG (device_is_ready (uart_dev ));
70+ 	TC_PRINT ("UART instance:%s\n" , uart_name );
6171	uart_rx_disable (uart_dev );
6272	uart_tx_abort (uart_dev );
6373	k_sem_reset (& tx_done );
@@ -79,7 +89,6 @@ static void uart_async_test_init(void)
7989#endif 
8090
8191	if  (!initialized ) {
82- 		init_test ();
8392		initialized  =  true;
8493#ifdef  CONFIG_USERSPACE 
8594		set_permissions ();
@@ -143,11 +152,13 @@ static void test_single_read_callback(const struct device *dev,
143152	}
144153}
145154
146- ZTEST_BMEM  volatile  uint32_t  tx_aborted_count ;
155+ static   ZTEST_BMEM  volatile  uint32_t  tx_aborted_count ;
147156
148157static  void  * single_read_setup (void )
149158{
150- 	uart_async_test_init ();
159+ 	static  int  idx ;
160+ 
161+ 	uart_async_test_init (idx ++ );
151162
152163	memset (& tdata , 0 , sizeof (tdata ));
153164	tdata .supply_second_buffer  =  true;
@@ -228,7 +239,9 @@ ZTEST_USER(uart_async_single_read, test_single_read)
228239
229240static  void  * multiple_rx_enable_setup (void )
230241{
231- 	uart_async_test_init ();
242+ 	static  int  idx ;
243+ 
244+ 	uart_async_test_init (idx ++ );
232245
233246	memset (& tdata , 0 , sizeof (tdata ));
234247	/* Reuse the callback from the single_read test case, as this test case 
@@ -375,7 +388,9 @@ static void test_chained_read_callback(const struct device *dev,
375388
376389static  void  * chained_read_setup (void )
377390{
378- 	uart_async_test_init ();
391+ 	static  int  idx ;
392+ 
393+ 	uart_async_test_init (idx ++ );
379394
380395	uart_callback_set (uart_dev , test_chained_read_callback , NULL );
381396
@@ -455,7 +470,9 @@ static void test_double_buffer_callback(const struct device *dev,
455470
456471static  void  * double_buffer_setup (void )
457472{
458- 	uart_async_test_init ();
473+ 	static  int  idx ;
474+ 
475+ 	uart_async_test_init (idx ++ );
459476
460477	uart_callback_set (uart_dev , test_double_buffer_callback , NULL );
461478
@@ -501,6 +518,7 @@ static ZTEST_BMEM uint8_t test_read_abort_rx_buf[2][100];
501518static  ZTEST_BMEM  uint8_t  test_read_abort_read_buf [100 ];
502519#endif  /* NOCACHE_MEM */ 
503520static  ZTEST_BMEM  int  test_read_abort_rx_cnt ;
521+ static  ZTEST_BMEM  bool  test_read_abort_rx_buf_req_once ;
504522
505523static  void  test_read_abort_callback (const  struct  device  * dev ,
506524			      struct  uart_event  * evt , void  * user_data )
@@ -515,14 +533,12 @@ static void test_read_abort_callback(const struct device *dev,
515533		break ;
516534	case  UART_RX_BUF_REQUEST :
517535	{
518- 		static  bool  once ;
519- 
520- 		if  (!once ) {
536+ 		if  (!test_read_abort_rx_buf_req_once ) {
521537			k_sem_give (& rx_buf_coherency );
522538			uart_rx_buf_rsp (dev ,
523539					test_read_abort_rx_buf [1 ],
524540					sizeof (test_read_abort_rx_buf [1 ]));
525- 			once  =  true;
541+ 			test_read_abort_rx_buf_req_once  =  true;
526542		}
527543		break ;
528544	}
@@ -558,8 +574,11 @@ static void read_abort_timeout(struct k_timer *timer)
558574
559575static  void  * read_abort_setup (void )
560576{
561- 	uart_async_test_init () ;
577+ 	static   int   idx ;
562578
579+ 	uart_async_test_init (idx ++ );
580+ 
581+ 	test_read_abort_rx_buf_req_once  =  false;
563582	failed_in_isr  =  false;
564583	uart_callback_set (uart_dev , test_read_abort_callback , NULL );
565584
@@ -654,7 +673,9 @@ static void test_write_abort_callback(const struct device *dev,
654673
655674static  void  * write_abort_setup (void )
656675{
657- 	uart_async_test_init ();
676+ 	static  int  idx ;
677+ 
678+ 	uart_async_test_init (idx ++ );
658679
659680	uart_callback_set (uart_dev , test_write_abort_callback , NULL );
660681
@@ -727,7 +748,9 @@ static void test_forever_timeout_callback(const struct device *dev,
727748
728749static  void  * forever_timeout_setup (void )
729750{
730- 	uart_async_test_init ();
751+ 	static  int  idx ;
752+ 
753+ 	uart_async_test_init (idx ++ );
731754
732755	uart_callback_set (uart_dev , test_forever_timeout_callback , NULL );
733756
@@ -816,8 +839,12 @@ static void test_chained_write_callback(const struct device *dev,
816839
817840static  void  * chained_write_setup (void )
818841{
819- 	uart_async_test_init ();
842+ 	static  int  idx ;
843+ 
844+ 	uart_async_test_init (idx ++ );
820845
846+ 	tx_sent  =  0 ;
847+ 	chained_write_next_buf  =  true;
821848	uart_callback_set (uart_dev , test_chained_write_callback , NULL );
822849
823850	return  NULL ;
@@ -869,11 +896,11 @@ static ZTEST_BMEM uint8_t long_tx_buf[TX_LONG_BUFFER];
869896#endif  /* NOCACHE_MEM */ 
870897static  ZTEST_BMEM  volatile  uint8_t  evt_num ;
871898static  ZTEST_BMEM  size_t  long_received [2 ];
899+ static  ZTEST_BMEM  uint8_t  * long_next_buffer ;
872900
873901static  void  test_long_buffers_callback (const  struct  device  * dev ,
874902				struct  uart_event  * evt , void  * user_data )
875903{
876- 	static  uint8_t  * next_buffer  =  long_rx_buf2 ;
877904
878905	switch  (evt -> type ) {
879906	case  UART_TX_DONE :
@@ -895,8 +922,8 @@ static void test_long_buffers_callback(const struct device *dev,
895922		k_sem_give (& rx_disabled );
896923		break ;
897924	case  UART_RX_BUF_REQUEST :
898- 		uart_rx_buf_rsp (dev , next_buffer , RX_LONG_BUFFER );
899- 		next_buffer  =  (next_buffer  ==  long_rx_buf2 ) ? long_rx_buf  : long_rx_buf2 ;
925+ 		uart_rx_buf_rsp (dev , long_next_buffer , RX_LONG_BUFFER );
926+ 		long_next_buffer  =  (long_next_buffer  ==  long_rx_buf2 ) ? long_rx_buf  : long_rx_buf2 ;
900927		break ;
901928	default :
902929		break ;
@@ -905,8 +932,12 @@ static void test_long_buffers_callback(const struct device *dev,
905932
906933static  void  * long_buffers_setup (void )
907934{
908- 	uart_async_test_init () ;
935+ 	static   int   idx ;
909936
937+ 	uart_async_test_init (idx ++ );
938+ 
939+ 	evt_num  =  0 ;
940+ 	long_next_buffer  =  long_rx_buf2 ;
910941	uart_callback_set (uart_dev , test_long_buffers_callback , NULL );
911942
912943	return  NULL ;
@@ -988,3 +1019,12 @@ ZTEST_SUITE(uart_async_write_abort, NULL, write_abort_setup,
9881019
9891020ZTEST_SUITE (uart_async_timeout , NULL , forever_timeout_setup ,
9901021		NULL , NULL , NULL );
1022+ 
1023+ void  test_main (void )
1024+ {
1025+ 	/* Run all suites for each dut UART. Setup function for each suite is picking 
1026+ 	 * next UART from the array. 
1027+ 	 */ 
1028+ 	ztest_run_all (NULL , false, ARRAY_SIZE (duts ), 1 );
1029+ 	ztest_verify_all_test_suites_ran ();
1030+ }
0 commit comments