Skip to content

Commit d3128e8

Browse files
committed
Unittest: Enable & ban specific warnings
This commit also fixes 4 of these warnings, that occured once each, namely -Werror={switch,memset-elt-size,comment,unused-value}.
1 parent 7da14a2 commit d3128e8

File tree

5 files changed

+48
-6
lines changed

5 files changed

+48
-6
lines changed

test/unit-test/CMakeLists.txt

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,51 @@ if( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} )
1818
message( FATAL_ERROR "In-source build is not allowed. Please build in a separate directory, such as ${PROJECT_SOURCE_DIR}/build." )
1919
endif()
2020

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

27+
# Align with: test/build-combination/CMakeLists.txt
28+
add_compile_options(
29+
$<$<COMPILE_LANG_AND_ID:C,GNU>:-fdiagnostics-color=always>
30+
$<$<COMPILE_LANG_AND_ID:C,Clang>:-fcolor-diagnostics>
31+
32+
### On the road to -Wall: Forbid warnings that need not be tolerated.
33+
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=uninitialized> # definite use of uninitialized variable
34+
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=array-bounds> # indexing outside sized array
35+
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=switch> # enum switch with unhandled value
36+
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=format> # format string wrong
37+
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=format-security> # format string missing
38+
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=comment> # comment within a comment
39+
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=unused-value> # "statement has no effect"
40+
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Werror=maybe-uninitialized> # possible use of uninitialized variable
41+
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Werror=memset-elt-size> # memsetting array by length instead of size
42+
# FIXME (part of -Wall):
43+
# -Werror=return-type # "control reaches end of non-void function"
44+
# -Werror=array-parameter # name clash
45+
# -Werror=implicit-function-declaration # need header
46+
# -Werror=unused-but-set-variable
47+
# -Werror=unused-variable
48+
# -Werror=unused-function
49+
# -Werror=unused-parameter
50+
# -Werror=missing-braces
51+
# -Werror=pointer-sign
52+
# -Werror=dangling-pointer
53+
# -Werror=vla
54+
55+
### Currently needed to build cleanly with Clang 19:
56+
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Werror>
57+
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-pragma-pack>
58+
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-unused-parameter>
59+
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-return-type>
60+
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-pointer-sign>
61+
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-typedef-redefinition>
62+
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-strict-prototypes>
63+
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-sometimes-uninitialized>
64+
)
65+
2766
# Set global path variables.
2867
get_filename_component( __MODULE_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE )
2968
set( MODULE_ROOT_DIR ${__MODULE_ROOT_DIR} CACHE INTERNAL "FreeRTOS-Plus-TCP repository root." )

test/unit-test/FreeRTOS_DHCPv6/FreeRTOS_DHCPv6_utest.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ static void vAddBitOperation( eTestDHCPv6BitOperationType_t eType,
127127
TEST_ASSERT_LESS_THAN( TEST_DHCPv6_BIT_OPERATION_MAX_SIZE, ulSize );
128128
memcpy( xTestDHCPv6BitOperation[ ulTestDHCPv6BitOperationWriteIndex ].val.ucValCustom, pvVal, ulSize );
129129
break;
130+
131+
case eTestDHCPv6BitOperationNone:
132+
case eTestDHCPv6BitOperationSetError:
133+
case eTestDHCPv6BitOperationReturnFalse:
134+
break;
130135
}
131136

132137
TEST_ASSERT_LESS_THAN_size_t( TEST_DHCPv6_BIT_OPERATION_DEBUG_MSG_MAX_SIZE, strlen( pucDebugMsg ) );

test/unit-test/FreeRTOS_DNS_Cache/FreeRTOS_DNS_Cache_utest.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,6 @@ void test_processDNS_CACHE_exceed_IP_entry_limit( void )
331331
pxIP_2.xIs_IPv6 = 0;
332332
pxIP_2.xIPAddress.ulIP_IPv4 = pulIP;
333333

334-
memset( pulIP_arr, 123, ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY );
335-
336334
for( i = 0; i < ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY; i++ )
337335
{
338336
pxIP[ i ].xIPAddress.ulIP_IPv4 = pulIP_arr[ i ];

test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ typedef void (* FOnDNSEvent ) ( const char * /* pcName */,
6666
static int callback_called = 0;
6767

6868
/* The second element is for the flexible array member
69-
* /* when pvPortMalloc is mocked to return this object.
69+
* when pvPortMalloc is mocked to return this object.
7070
*/
7171
static DNSCallback_t dnsCallback[ 2 ];
7272

test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1888,7 +1888,7 @@ void test_FreeRTOS_get_tx_base_InvalidParams( void )
18881888
pucReturn = FreeRTOS_get_tx_base( &xSocket );
18891889
TEST_ASSERT_EQUAL( NULL, pucReturn );
18901890

1891-
xSocket.u.xTCP.bits.bMallocError == pdTRUE_UNSIGNED;
1891+
xSocket.u.xTCP.bits.bMallocError = pdTRUE_UNSIGNED;
18921892
pucReturn = FreeRTOS_get_tx_base( &xSocket );
18931893
TEST_ASSERT_EQUAL( NULL, pucReturn );
18941894
}

0 commit comments

Comments
 (0)