2021-11-18 14:27:30 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*
 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-08 17:39:38 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  SPDX - FileCopyrightText :  2015 - 2022  Espressif  Systems  ( Shanghai )  CO  LTD 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-18 14:27:30 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  SPDX - License - Identifier :  Apache - 2.0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 15:51:02 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-30 19:31:51 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <string.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 13:40:42 +11:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "unity.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "test_utils.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-26 10:17:46 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "freertos/FreeRTOS.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "freertos/task.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-01 18:25:23 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "esp_netif.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-26 10:17:46 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "lwip/sockets.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2020-02-29 15:02:53 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "sdkconfig.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-18 14:27:30 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "memory_checks.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 15:51:02 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-16 16:33:30 +07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								const  esp_partition_t  * get_test_data_partition ( void ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 13:40:42 +11:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-04 16:42:22 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    /* This finds "flash_test" partition defined in partition_table_unit_test_app.csv */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    const  esp_partition_t  * result  =  esp_partition_find_first ( ESP_PARTITION_TYPE_DATA , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            ESP_PARTITION_SUBTYPE_ANY ,  " flash_test " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 13:40:42 +11:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    TEST_ASSERT_NOT_NULL ( result ) ;  /* means partition table set wrong */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-30 19:31:51 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-16 16:33:30 +07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								void  test_case_uses_tcpip ( void ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-26 10:17:46 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // Can be called more than once, does nothing on subsequent calls
 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-01 18:25:23 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    esp_netif_init ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-26 10:17:46 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // Allocate all sockets then free them
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // (First time each socket is allocated some one-time allocations happen.)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    int  sockets [ CONFIG_LWIP_MAX_SOCKETS ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    for  ( int  i  =  0 ;  i  <  CONFIG_LWIP_MAX_SOCKETS ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        int  type  =  ( i  %  2  = =  0 )  ?  SOCK_DGRAM  :  SOCK_STREAM ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        int  family  =  ( i  %  3  = =  0 )  ?  PF_INET6  :  PF_INET ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        sockets [ i ]  =  socket ( family ,  type ,  IPPROTO_IP ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    for  ( int  i  =  0 ;  i  <  CONFIG_LWIP_MAX_SOCKETS ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        close ( sockets [ i ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // Allow LWIP tasks to finish initialising themselves
 
							 
						 
					
						
							
								
									
										
										
										
											2022-02-08 17:39:38 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    vTaskDelay ( 25  /  portTICK_PERIOD_MS ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-26 10:17:46 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-09-01 18:25:23 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    printf ( " Note: esp_netif_init() has been called. Until next reset, TCP/IP task will periodicially allocate memory and consume CPU time. \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-26 10:17:46 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    // Reset the leak checker as LWIP allocates a lot of memory on first run
 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-18 14:27:30 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    test_utils_record_free_mem ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    test_utils_set_leak_level ( 0 ,  ESP_LEAK_TYPE_CRITICAL ,  ESP_COMP_LEAK_GENERAL ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    test_utils_set_leak_level ( CONFIG_UNITY_CRITICAL_LEAK_LEVEL_LWIP ,  ESP_LEAK_TYPE_CRITICAL ,  ESP_COMP_LEAK_LWIP ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-26 10:17:46 +10:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-12-13 16:58:34 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// wait user to send "Enter" key or input parameter
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  void  wait_user_control ( char *  parameter_buf ,  uint8_t  buf_len ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    char  * buffer  =  parameter_buf ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    char  sign [ 5 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    uint8_t  buffer_len  =  buf_len  -  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( parameter_buf  = =  NULL )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        buffer  =  sign ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        buffer_len  =  sizeof ( sign )  -  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2020-07-13 21:33:23 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    // workaround that unity_gets (esp_rom_uart_rx_string) will not set '\0' correctly
 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-13 16:58:34 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    bzero ( buffer ,  buffer_len ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    unity_gets ( buffer ,  buffer_len ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-30 19:31:51 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// signal functions, used for sync between unity DUTs for multiple devices cases
 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-13 16:58:34 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								void  unity_wait_for_signal_param ( const  char *  signal_name ,  char *  parameter_buf ,  uint8_t  buf_len ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-30 19:31:51 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-13 16:58:34 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    printf ( " Waiting for signal: [%s]! \n " ,  signal_name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    if  ( parameter_buf  = =  NULL )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        printf ( " Please press  \" Enter \"  key once any board send this signal. \n " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        printf ( " Please input parameter value from any board send this signal and press  \" Enter \"  key. \n " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    wait_user_control ( parameter_buf ,  buf_len ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-30 19:31:51 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-12-13 16:58:34 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								void  unity_send_signal_param ( const  char *  signal_name ,  const  char  * parameter ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-30 19:31:51 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2018-12-13 16:58:34 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    if  ( parameter  = =  NULL )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        printf ( " Send signal: [%s]! \n " ,  signal_name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        printf ( " Send signal: [%s][%s]! \n " ,  signal_name ,  parameter ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								bool  unity_util_convert_mac_from_string ( const  char *  mac_str ,  uint8_t  * mac_addr ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    uint8_t  loop  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    uint8_t  tmp  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    const  char  * start ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    char  * stop ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    for  ( loop  =  0 ;  loop  <  6 ;  loop + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        start  =  mac_str  +  loop  *  3 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        tmp  =  strtol ( start ,  & stop ,  16 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( stop  -  start  = =  2  & &  ( * stop  = =  ' : '  | |  ( * stop  = =  0  & &  loop  = =  5 ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            mac_addr [ loop ]  =  tmp ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-30 19:31:51 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-02-27 11:57:00 +11:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# define EXHAUST_MEMORY_ENTRIES 100 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								struct  test_utils_exhaust_memory_record_s  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    int  * entries [ EXHAUST_MEMORY_ENTRIES ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								test_utils_exhaust_memory_rec  test_utils_exhaust_memory ( uint32_t  caps ,  size_t  limit ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    int  idx  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    test_utils_exhaust_memory_rec  rec  =  calloc ( 1 ,  sizeof ( struct  test_utils_exhaust_memory_record_s ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    TEST_ASSERT_NOT_NULL_MESSAGE ( rec ,  " test_utils_exhaust_memory: not enough free memory to allocate record structure! " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    while  ( idx  <  EXHAUST_MEMORY_ENTRIES )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        size_t  free_caps  =  heap_caps_get_largest_free_block ( caps ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        if  ( free_caps  < =  limit )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            return  rec ;  // done!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        rec - > entries [ idx ]  =  heap_caps_malloc ( free_caps  -  limit ,  caps ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        TEST_ASSERT_NOT_NULL_MESSAGE ( rec - > entries [ idx ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                                     " test_utils_exhaust_memory: something went wrong while freeing up memory, is another task using heap? " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        heap_caps_check_integrity_all ( true ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        idx + + ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    TEST_FAIL_MESSAGE ( " test_utils_exhaust_memory: The heap with the requested caps is too fragmented, increase EXHAUST_MEMORY_ENTRIES or defrag the heap! " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    abort ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								void  test_utils_free_exhausted_memory ( test_utils_exhaust_memory_rec  rec ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    for  ( int  i  =  0 ;  i  <  EXHAUST_MEMORY_ENTRIES ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        free ( rec - > entries [ i ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    free ( rec ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}