Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions test/unit-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,51 @@ if( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} )
message( FATAL_ERROR "In-source build is not allowed. Please build in a separate directory, such as ${PROJECT_SOURCE_DIR}/build." )
endif()

set(SANITIZE "" CACHE STRING "Comma-separated list of compiler sanitizers to enable; empty string disables.")
if(NOT ${SANITIZE} STREQUAL "")
set( SANITIZE "" CACHE STRING "Comma-separated list of compiler sanitizers to enable; empty string disables." )
if( NOT ${SANITIZE} STREQUAL "" )
add_compile_options(-fsanitize=${SANITIZE} -fno-sanitize-recover)
add_link_options(-fsanitize=${SANITIZE} -fno-sanitize-recover)
endif()

# Align with: test/build-combination/CMakeLists.txt
add_compile_options(
$<$<COMPILE_LANG_AND_ID:C,GNU>:-fdiagnostics-color=always>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-fcolor-diagnostics>

### On the road to -Wall: Forbid warnings that need not be tolerated.
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=uninitialized> # definite use of uninitialized variable
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=array-bounds> # indexing outside sized array
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=switch> # enum switch with unhandled value
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=format> # format string wrong
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=format-security> # format string missing
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=comment> # comment within a comment
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=unused-value> # "statement has no effect"
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Werror=maybe-uninitialized> # possible use of uninitialized variable
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Werror=memset-elt-size> # memsetting array by length instead of size
# FIXME (part of -Wall):
# -Werror=return-type # "control reaches end of non-void function"
# -Werror=array-parameter # name clash
# -Werror=implicit-function-declaration # need header
# -Werror=unused-but-set-variable
# -Werror=unused-variable
# -Werror=unused-function
# -Werror=unused-parameter
# -Werror=missing-braces
# -Werror=pointer-sign
# -Werror=dangling-pointer
# -Werror=vla

### Currently needed to build cleanly with Clang 19:
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Werror>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-pragma-pack>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-unused-parameter>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-return-type>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-pointer-sign>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-typedef-redefinition>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-strict-prototypes>
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-sometimes-uninitialized>
)

# Set global path variables.
get_filename_component( __MODULE_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE )
set( MODULE_ROOT_DIR ${__MODULE_ROOT_DIR} CACHE INTERNAL "FreeRTOS-Plus-TCP repository root." )
Expand Down
17 changes: 7 additions & 10 deletions test/unit-test/FreeRTOS_BitConfig/FreeRTOS_BitConfig_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,14 @@ void test_xBitConfig_read_uc_xHasError( void )
void test_xBitConfig_read_uc_OutOfBoundRead( void )
{
BitConfig_t xConfig, * pxConfig = &xConfig;
uint8_t * pucData;
BaseType_t xResult = pdFALSE;

memset( pxConfig, 0, sizeof( BitConfig_t ) );
pxConfig->xHasError = pdFALSE;
pxConfig->uxIndex = 1;
pxConfig->uxSize = SIZE_OF_BINARY_STREAM;

xResult = xBitConfig_read_uc( pxConfig, pucData, SIZE_OF_BINARY_STREAM );
xResult = xBitConfig_read_uc( pxConfig, NULL, SIZE_OF_BINARY_STREAM );

TEST_ASSERT_EQUAL( pdFALSE, xResult );
TEST_ASSERT_EQUAL( pdTRUE, pxConfig->xHasError );
Expand Down Expand Up @@ -463,13 +462,13 @@ void test_ulBitConfig_read_32_HappyPath( void )

void test_vBitConfig_write_uc_xHasError( void )
{
BitConfig_t xConfig;
uint8_t * pucData;
BitConfig_t xConfig = { 0 };

memset( &xConfig, 0, sizeof( BitConfig_t ) );
xConfig.xHasError = pdTRUE;

vBitConfig_write_uc( &xConfig, pucData, SIZE_OF_BINARY_STREAM );
vBitConfig_write_uc( &xConfig, NULL, SIZE_OF_BINARY_STREAM );

TEST_ASSERT_EQUAL( pdTRUE, xConfig.xHasError );
}

/**
Expand All @@ -480,15 +479,13 @@ void test_vBitConfig_write_uc_xHasError( void )

void test_vBitConfig_write_uc_OutOfBoundWrite( void )
{
BitConfig_t xConfig;
uint8_t * pucData;
BitConfig_t xConfig = { 0 };

memset( &xConfig, 0, sizeof( BitConfig_t ) );
xConfig.xHasError = pdFALSE;
xConfig.uxIndex = SIZE_OF_BINARY_STREAM;
xConfig.uxSize = SIZE_OF_BINARY_STREAM;

vBitConfig_write_uc( &xConfig, pucData, SIZE_OF_BINARY_STREAM );
vBitConfig_write_uc( &xConfig, NULL, SIZE_OF_BINARY_STREAM );

TEST_ASSERT_EQUAL( pdTRUE, xConfig.xHasError );
}
Expand Down
5 changes: 5 additions & 0 deletions test/unit-test/FreeRTOS_DHCPv6/FreeRTOS_DHCPv6_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ static void vAddBitOperation( eTestDHCPv6BitOperationType_t eType,
TEST_ASSERT_LESS_THAN( TEST_DHCPv6_BIT_OPERATION_MAX_SIZE, ulSize );
memcpy( xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationWriteIndex ].val.ucValCustom, pvVal, ulSize );
break;

case eTestDHCPv6BitOperationNone:
case eTestDHCPv6BitOperationSetError:
case eTestDHCPv6BitOperationReturnFalse:
break;
}

TEST_ASSERT_LESS_THAN_size_t( TEST_DHCPv6_BIT_OPERATION_DEBUG_MSG_MAX_SIZE, strlen( pucDebugMsg ) );
Expand Down
2 changes: 0 additions & 2 deletions test/unit-test/FreeRTOS_DNS_Cache/FreeRTOS_DNS_Cache_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,6 @@ void test_processDNS_CACHE_exceed_IP_entry_limit( void )
pxIP_2.xIs_IPv6 = 0;
pxIP_2.xIPAddress.ulIP_IPv4 = pulIP;

memset( pulIP_arr, 123, ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY );

for( i = 0; i < ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY; i++ )
{
pxIP[ i ].xIPAddress.ulIP_IPv4 = pulIP_arr[ i ];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ typedef void (* FOnDNSEvent ) ( const char * /* pcName */,
static int callback_called = 0;

/* The second element is for the flexible array member
* /* when pvPortMalloc is mocked to return this object.
* when pvPortMalloc is mocked to return this object.
*/
static DNSCallback_t dnsCallback[ 2 ];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,36 +132,18 @@ void test_CreateSocket_success( void )
TEST_ASSERT_EQUAL( ( Socket_t ) 235, s );
}

/**
* @brief Ensures that when the socket could not be created or could not be found, null is returned
*/
void test_BindSocket_fail( void )
{
struct freertos_sockaddr xAddress;
Socket_t xSocket;
uint16_t usPort;
uint32_t ret;

FreeRTOS_bind_ExpectAnyArgsAndReturn( 0 );

ret = DNS_BindSocket( xSocket, usPort );

TEST_ASSERT_EQUAL( 0, ret );
}

/**
* @brief Happy path!
*/
void test_BindSocket_success( void )
{
struct freertos_sockaddr xAddress;
Socket_t xSocket;
uint16_t usPort;
struct xSOCKET xSocket;
uint32_t ret;

FreeRTOS_bind_ExpectAnyArgsAndReturn( 1 );

ret = DNS_BindSocket( xSocket, usPort );
ret = DNS_BindSocket( &xSocket, 80 );

TEST_ASSERT_EQUAL( 1, ret );
}
Expand Down
Loading
Loading