Skip to content

Commit

Permalink
Improve Validation of Config (#1084)
Browse files Browse the repository at this point in the history
* Check FreeRTOSConfig and validate more ipconfig

* Add a few more checks

* Uncrustify: triggered by comment.

* check for counting semaphores

* resolve pedantic error with static assert

* resolve type limit error

* remove extraneous line

* fix type error

* remove 0 check due to portMAX_DELAY sign extending

---------

Co-authored-by: Paul Bartell <[email protected]>
Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: Tony Josi <[email protected]>
  • Loading branch information
4 people authored Mar 14, 2024
1 parent a7d2930 commit 4364e78
Showing 1 changed file with 86 additions and 19 deletions.
105 changes: 86 additions & 19 deletions source/include/FreeRTOSIPConfigDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@
#define ASSERT_CONCAT( a, b ) ASSERT_CONCAT_( a, b )
#ifdef __COUNTER__
#define STATIC_ASSERT( e ) \
; enum { ASSERT_CONCAT( static_assert_, __COUNTER__ ) = ( 1 / ( int ) ( !!( e ) ) ) }
enum { ASSERT_CONCAT( static_assert_, __COUNTER__ ) = ( 1 / ( int ) ( !!( e ) ) ) }
#else
#define STATIC_ASSERT( e ) \
; enum { ASSERT_CONCAT( assert_line_, __LINE__ ) = ( 1 / ( int ) ( !!( e ) ) ) }
enum { ASSERT_CONCAT( assert_line_, __LINE__ ) = ( 1 / ( int ) ( !!( e ) ) ) }
#endif
#endif /* ifdef static_assert */

Expand Down Expand Up @@ -136,19 +136,51 @@

/*---------------------------------------------------------------------------*/

/*===========================================================================*/
/* MACROS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
/* FreeRTOSConfig CHECKS */
/*===========================================================================*/

/*---------------------------------------------------------------------------*/

/*
* pdFREERTOS_ERRNO_EAFNOSUPPORT
*
* Address family not supported by protocol.
*
* Note: Now included in FreeRTOS-Kernel/projdefs.h, so this serves as a
* temporary kernel version check. To be removed in a future version.
* Note: pdFREERTOS_ERRNO_EAFNOSUPPORT is now included in
* FreeRTOS-Kernel/projdefs.h, defined here for backwards compatibility.
*/

#ifndef pdFREERTOS_ERRNO_EAFNOSUPPORT
#define pdFREERTOS_ERRNO_EAFNOSUPPORT 97
#endif

#if ( INCLUDE_vTaskDelay == 0 )
#error INCLUDE_vTaskDelay must be set to 1
#endif

#if ( INCLUDE_xTaskGetCurrentTaskHandle == 0 )
#error INCLUDE_xTaskGetCurrentTaskHandle must be set to 1
#endif

#if ( configSUPPORT_DYNAMIC_ALLOCATION == 0 )
#error configSUPPORT_DYNAMIC_ALLOCATION must be set to 1
#endif

#if ( configUSE_COUNTING_SEMAPHORES == 0 )
#error configUSE_COUNTING_SEMAPHORES must be set to 1
#endif

/*---------------------------------------------------------------------------*/

/*===========================================================================*/
/* MACROS */
/* FreeRTOSConfig CHECKS */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*===========================================================================*/
Expand Down Expand Up @@ -315,9 +347,7 @@
#error ipconfigRA_SEARCH_TIME_OUT_MSEC must be at least 0
#endif

#if ( ipconfigRA_SEARCH_TIME_OUT_MSEC > SIZE_MAX )
#error ipconfigRA_SEARCH_TIME_OUT_MSEC must be at most portMAX_DELAY * portTICK_PERIOD_MS
#endif
STATIC_ASSERT( ipconfigRA_SEARCH_TIME_OUT_MSEC <= ( portMAX_DELAY * portTICK_PERIOD_MS ) );

/*---------------------------------------------------------------------------*/

Expand Down Expand Up @@ -365,9 +395,7 @@
#error ipconfigRA_IP_TEST_TIME_OUT_MSEC must be at least 0
#endif

#if ( ipconfigRA_IP_TEST_TIME_OUT_MSEC > SIZE_MAX )
#error ipconfigRA_IP_TEST_TIME_OUT_MSEC must be at most portMAX_DELAY * portTICK_PERIOD_MS
#endif
STATIC_ASSERT( ipconfigRA_IP_TEST_TIME_OUT_MSEC <= ( portMAX_DELAY * portTICK_PERIOD_MS ) );

/*---------------------------------------------------------------------------*/

Expand Down Expand Up @@ -463,6 +491,8 @@
#define ipconfigMAX_IP_TASK_SLEEP_TIME pdMS_TO_TICKS( 10000 )
#endif

STATIC_ASSERT( ipconfigMAX_IP_TASK_SLEEP_TIME <= portMAX_DELAY );

/*---------------------------------------------------------------------------*/

/*===========================================================================*/
Expand Down Expand Up @@ -981,6 +1011,12 @@
#define ipconfigPHY_LS_HIGH_CHECK_TIME_MS ( 15000 )
#endif

#if ( ipconfigPHY_LS_HIGH_CHECK_TIME_MS < 0 )
#error ipconfigPHY_LS_HIGH_CHECK_TIME_MS must be at least 0
#endif

STATIC_ASSERT( pdMS_TO_TICKS( ipconfigPHY_LS_HIGH_CHECK_TIME_MS ) <= portMAX_DELAY );

/*---------------------------------------------------------------------------*/

/*
Expand All @@ -996,6 +1032,12 @@
#define ipconfigPHY_LS_LOW_CHECK_TIME_MS ( 1000 )
#endif

#if ( ipconfigPHY_LS_LOW_CHECK_TIME_MS < 0 )
#error ipconfigPHY_LS_LOW_CHECK_TIME_MS must be at least 0
#endif

STATIC_ASSERT( pdMS_TO_TICKS( ipconfigPHY_LS_LOW_CHECK_TIME_MS ) <= portMAX_DELAY );

/*---------------------------------------------------------------------------*/

/*
Expand All @@ -1015,7 +1057,7 @@
*
* Type: size_t
* Unit: count of ports
* Minimum: 0
* Minimum: 1
* Maximum: 32
*
* There can be at most 32 PHY ports, but in most cases there are 4 or less.
Expand All @@ -1025,6 +1067,14 @@
#define ipconfigPHY_MAX_PORTS ( 4 )
#endif

#if ( ipconfigPHY_MAX_PORTS < 1 )
#error ipconfigPHY_MAX_PORTS must be at least 1
#endif

#if ( ipconfigPHY_MAX_PORTS > 32 )
#error ipconfigPHY_MAX_PORTS must be at most 32
#endif

/*---------------------------------------------------------------------------*/

/*===========================================================================*/
Expand Down Expand Up @@ -1136,6 +1186,10 @@
#define ipconfigIP_TASK_STACK_SIZE_WORDS configMINIMAL_STACK_SIZE
#endif

STATIC_ASSERT( ipconfigIP_TASK_STACK_SIZE_WORDS >= configMINIMAL_STACK_SIZE );

STATIC_ASSERT( ipconfigIP_TASK_STACK_SIZE_WORDS <= SIZE_MAX );

/*---------------------------------------------------------------------------*/

/*
Expand Down Expand Up @@ -1310,9 +1364,7 @@
#error ipconfigTCP_HANG_PROTECTION_TIME must be at least 0
#endif

#if ( ipconfigTCP_HANG_PROTECTION_TIME > SIZE_MAX )
#error ipconfigTCP_HANG_PROTECTION_TIME must be at most portMAX_DELAY / configTICK_RATE_HZ
#endif
STATIC_ASSERT( ipconfigTCP_HANG_PROTECTION_TIME <= ( portMAX_DELAY / configTICK_RATE_HZ ) );

/*---------------------------------------------------------------------------*/

Expand Down Expand Up @@ -1379,9 +1431,7 @@
#error ipconfigTCP_KEEP_ALIVE_INTERVAL must be at least 0
#endif

#if ( ipconfigTCP_KEEP_ALIVE_INTERVAL > SIZE_MAX )
#error ipconfigTCP_KEEP_ALIVE_INTERVAL must be at most portMAX_DELAY / configTICK_RATE_HZ
#endif
STATIC_ASSERT( ipconfigTCP_KEEP_ALIVE_INTERVAL <= ( portMAX_DELAY / configTICK_RATE_HZ ) );

/*---------------------------------------------------------------------------*/

Expand Down Expand Up @@ -1713,6 +1763,8 @@
#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS pdMS_TO_TICKS( 20 )
#endif

STATIC_ASSERT( ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS <= portMAX_DELAY );

/*---------------------------------------------------------------------------*/

/*
Expand Down Expand Up @@ -1850,6 +1902,12 @@
#error Invalid ipconfigSELECT_USES_NOTIFY configuration
#endif

#if ipconfigIS_ENABLED( ipconfigSELECT_USES_NOTIFY )
#if ( configUSE_TASK_NOTIFICATIONS == 0 )
#error configUSE_TASK_NOTIFICATIONS must be 1 if ipconfigSELECT_USES_NOTIFY is enabled
#endif
#endif

/*---------------------------------------------------------------------------*/

/*
Expand Down Expand Up @@ -1894,6 +1952,8 @@
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME portMAX_DELAY
#endif

STATIC_ASSERT( ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME <= portMAX_DELAY );

/*---------------------------------------------------------------------------*/

/*
Expand All @@ -1920,6 +1980,8 @@
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME portMAX_DELAY
#endif

STATIC_ASSERT( ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME <= portMAX_DELAY );

/*---------------------------------------------------------------------------*/

/*
Expand Down Expand Up @@ -2156,7 +2218,6 @@
#endif

#if ( ( ipconfigUSE_DHCP != ipconfigDISABLE ) && ( ipconfigNETWORK_MTU < 586 ) )

#error ipconfigNETWORK_MTU needs to be at least 586 to use DHCP
#endif

Expand Down Expand Up @@ -2308,6 +2369,8 @@
#endif
#endif

STATIC_ASSERT( ipconfigMAXIMUM_DISCOVER_TX_PERIOD <= portMAX_DELAY );

/*---------------------------------------------------------------------------*/

/*===========================================================================*/
Expand Down Expand Up @@ -2504,6 +2567,8 @@
#define ipconfigDNS_RECEIVE_BLOCK_TIME_TICKS pdMS_TO_TICKS( 5000 )
#endif

STATIC_ASSERT( ipconfigDNS_RECEIVE_BLOCK_TIME_TICKS <= portMAX_DELAY );

/*---------------------------------------------------------------------------*/

/*
Expand All @@ -2525,6 +2590,8 @@
#define ipconfigDNS_SEND_BLOCK_TIME_TICKS pdMS_TO_TICKS( 500 )
#endif

STATIC_ASSERT( ipconfigDNS_SEND_BLOCK_TIME_TICKS <= portMAX_DELAY );

/*---------------------------------------------------------------------------*/

/*
Expand Down

0 comments on commit 4364e78

Please sign in to comment.