Skip to content

Commit 7da14a2

Browse files
committed
Unittest: Fix building with -Werror=uninitialized
1 parent 4b81c00 commit 7da14a2

21 files changed

+362
-649
lines changed

test/unit-test/FreeRTOS_BitConfig/FreeRTOS_BitConfig_utest.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,14 @@ void test_xBitConfig_read_uc_xHasError( void )
158158
void test_xBitConfig_read_uc_OutOfBoundRead( void )
159159
{
160160
BitConfig_t xConfig, * pxConfig = &xConfig;
161-
uint8_t * pucData;
162161
BaseType_t xResult = pdFALSE;
163162

164163
memset( pxConfig, 0, sizeof( BitConfig_t ) );
165164
pxConfig->xHasError = pdFALSE;
166165
pxConfig->uxIndex = 1;
167166
pxConfig->uxSize = SIZE_OF_BINARY_STREAM;
168167

169-
xResult = xBitConfig_read_uc( pxConfig, pucData, SIZE_OF_BINARY_STREAM );
168+
xResult = xBitConfig_read_uc( pxConfig, NULL, SIZE_OF_BINARY_STREAM );
170169

171170
TEST_ASSERT_EQUAL( pdFALSE, xResult );
172171
TEST_ASSERT_EQUAL( pdTRUE, pxConfig->xHasError );
@@ -463,13 +462,13 @@ void test_ulBitConfig_read_32_HappyPath( void )
463462

464463
void test_vBitConfig_write_uc_xHasError( void )
465464
{
466-
BitConfig_t xConfig;
467-
uint8_t * pucData;
465+
BitConfig_t xConfig = { 0 };
468466

469-
memset( &xConfig, 0, sizeof( BitConfig_t ) );
470467
xConfig.xHasError = pdTRUE;
471468

472-
vBitConfig_write_uc( &xConfig, pucData, SIZE_OF_BINARY_STREAM );
469+
vBitConfig_write_uc( &xConfig, NULL, SIZE_OF_BINARY_STREAM );
470+
471+
TEST_ASSERT_EQUAL( pdTRUE, xConfig.xHasError );
473472
}
474473

475474
/**
@@ -480,15 +479,13 @@ void test_vBitConfig_write_uc_xHasError( void )
480479

481480
void test_vBitConfig_write_uc_OutOfBoundWrite( void )
482481
{
483-
BitConfig_t xConfig;
484-
uint8_t * pucData;
482+
BitConfig_t xConfig = { 0 };
485483

486-
memset( &xConfig, 0, sizeof( BitConfig_t ) );
487484
xConfig.xHasError = pdFALSE;
488485
xConfig.uxIndex = SIZE_OF_BINARY_STREAM;
489486
xConfig.uxSize = SIZE_OF_BINARY_STREAM;
490487

491-
vBitConfig_write_uc( &xConfig, pucData, SIZE_OF_BINARY_STREAM );
488+
vBitConfig_write_uc( &xConfig, NULL, SIZE_OF_BINARY_STREAM );
492489

493490
TEST_ASSERT_EQUAL( pdTRUE, xConfig.xHasError );
494491
}

test/unit-test/FreeRTOS_DNS_Networking/FreeRTOS_DNS_Networking_utest.c

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -132,36 +132,18 @@ void test_CreateSocket_success( void )
132132
TEST_ASSERT_EQUAL( ( Socket_t ) 235, s );
133133
}
134134

135-
/**
136-
* @brief Ensures that when the socket could not be created or could not be found, null is returned
137-
*/
138-
void test_BindSocket_fail( void )
139-
{
140-
struct freertos_sockaddr xAddress;
141-
Socket_t xSocket;
142-
uint16_t usPort;
143-
uint32_t ret;
144-
145-
FreeRTOS_bind_ExpectAnyArgsAndReturn( 0 );
146-
147-
ret = DNS_BindSocket( xSocket, usPort );
148-
149-
TEST_ASSERT_EQUAL( 0, ret );
150-
}
151-
152135
/**
153136
* @brief Happy path!
154137
*/
155138
void test_BindSocket_success( void )
156139
{
157140
struct freertos_sockaddr xAddress;
158-
Socket_t xSocket;
159-
uint16_t usPort;
141+
struct xSOCKET xSocket;
160142
uint32_t ret;
161143

162144
FreeRTOS_bind_ExpectAnyArgsAndReturn( 1 );
163145

164-
ret = DNS_BindSocket( xSocket, usPort );
146+
ret = DNS_BindSocket( &xSocket, 80 );
165147

166148
TEST_ASSERT_EQUAL( 1, ret );
167149
}

test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,9 @@ void test_DNS_ReadNameField_success_empty_uxRemainingBytes( void )
129129
uint8_t pucByte[ 300 ];
130130
size_t ret;
131131
ParseSet_t xSet = { 0 };
132-
size_t uxDestLen;
133132

134133
memset( pucByte, 0x00, 300 );
135-
ret = DNS_ReadNameField( &xSet, uxDestLen );
134+
ret = DNS_ReadNameField( &xSet, sizeof( xSet ) );
136135
TEST_ASSERT_EQUAL( 0, ret );
137136
}
138137

@@ -145,12 +144,11 @@ void test_DNS_ReadNameField_fail_offset_dns_name( void )
145144
uint8_t pucByte[ 300 ] = { 0 };
146145
size_t ret;
147146
ParseSet_t xSet = { 0 };
148-
size_t uxDestLen;
149147

150148
memset( pucByte, 0x00, 300 );
151149
pucByte[ 0 ] = dnsNAME_IS_OFFSET;
152150

153-
ret = DNS_ReadNameField( &xSet, uxDestLen );
151+
ret = DNS_ReadNameField( &xSet, sizeof( xSet ) );
154152

155153
TEST_ASSERT_EQUAL( 0, ret );
156154
}
@@ -1284,7 +1282,7 @@ void test_DNS_ParseDNSReply_fail_small_buffer( void )
12841282
size_t uxBufferLength = sizeof( DNSMessage_t ) - 2;
12851283
BaseType_t xExpected = pdFALSE;
12861284
struct freertos_addrinfo * pxAddressInfo;
1287-
uint16_t usPort;
1285+
uint16_t usPort = 80;
12881286

12891287
ret = DNS_ParseDNSReply( pucUDPPayloadBuffer,
12901288
uxBufferLength,
@@ -1304,7 +1302,7 @@ void test_DNS_ParseDNSReply_fail_no_namefield( void )
13041302
size_t uxBufferLength = 300;
13051303
BaseType_t xExpected = pdFALSE;
13061304
struct freertos_addrinfo * pxAddressInfo;
1307-
uint16_t usPort;
1305+
uint16_t usPort = 80;
13081306

13091307
ret = DNS_ParseDNSReply( pucUDPPayloadBuffer,
13101308
uxBufferLength,
@@ -1326,7 +1324,7 @@ void test_DNS_ParseDNSReply_fail( void )
13261324
BaseType_t xExpected = pdFALSE;
13271325
int beg = sizeof( DNSMessage_t );
13281326
struct freertos_addrinfo * pxAddressInfo;
1329-
uint16_t usPort;
1327+
uint16_t usPort = 80;
13301328

13311329
memset( pucUDPPayloadBuffer, 0x00, 300 );
13321330

@@ -1353,7 +1351,7 @@ void test_DNS_ParseDNSReply_fail_empty_namefield( void )
13531351
BaseType_t xExpected = pdFALSE;
13541352
uint8_t beg = sizeof( DNSMessage_t );
13551353
struct freertos_addrinfo * pxAddressInfo;
1356-
uint16_t usPort;
1354+
uint16_t usPort = 80;
13571355

13581356
memset( pucUDPPayloadBuffer, 0x00, uxBufferLength );
13591357
pucUDPPayloadBuffer[ offsetof( DNSMessage_t, usQuestions ) ] = 4;
@@ -1382,7 +1380,7 @@ void test_DNS_ParseDNSReply_fail_not_enough_space_lt_32( void )
13821380
size_t uxBufferLength = 250;
13831381
char dns[ 64 ];
13841382
struct freertos_addrinfo * pxAddressInfo;
1385-
uint16_t usPort;
1383+
uint16_t usPort = 80;
13861384

13871385
memset( pucUDPPayloadBuffer, 0x00, uxBufferLength );
13881386
memset( dns, 'a', 64 );
@@ -1440,7 +1438,7 @@ void test_DNS_ParseDNSReply_answer_record_no_answers( void )
14401438
size_t uxBufferLength = 250;
14411439
char dns[ 64 ];
14421440
struct freertos_addrinfo * pxAddressInfo;
1443-
uint16_t usPort;
1441+
uint16_t usPort = 80;
14441442
const uint16_t usFlags = ( dnsRX_FLAGS_MASK | dnsEXPECTED_RX_FLAGS );
14451443

14461444
memset( dns, 'a', 64 );
@@ -1478,7 +1476,7 @@ void test_DNS_ParseDNSReply_answer_record_no_answers2( void )
14781476
size_t uxBufferLength = 250;
14791477
char dns[ 64 ];
14801478
struct freertos_addrinfo * pxAddressInfo;
1481-
uint16_t usPort;
1479+
uint16_t usPort = 80;
14821480
const uint16_t usFlags = dnsEXPECTED_RX_FLAGS;
14831481

14841482
memset( dns, 'a', 64 );
@@ -1516,7 +1514,7 @@ void test_DNS_ParseDNSReply_answer_record_no_questions( void )
15161514
size_t uxBufferLength = 250;
15171515
char dns[ 64 ];
15181516
struct freertos_addrinfo * pxAddressInfo;
1519-
uint16_t usPort;
1517+
uint16_t usPort = 80;
15201518
const uint16_t usFlags = dnsEXPECTED_RX_FLAGS;
15211519

15221520
memset( dns, 'a', 64 );
@@ -1561,7 +1559,7 @@ void test_DNS_ParseDNSReply_InvalidEndpointIP( void )
15611559
uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4;
15621560
size_t uxBufferLength = 250;
15631561
struct freertos_addrinfo * pxAddressInfo;
1564-
uint16_t usPort;
1562+
uint16_t usPort = 80;
15651563

15661564
xBufferAllocFixedSize = pdTRUE;
15671565
uint8_t * nullAddress = NULL;
@@ -1637,7 +1635,7 @@ void test_DNS_ParseDNSReply_InvalidEndpointType( void )
16371635
uint8_t * pucUDPPayloadBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4;
16381636
size_t uxBufferLength = 250;
16391637
struct freertos_addrinfo * pxAddressInfo;
1640-
uint16_t usPort;
1638+
uint16_t usPort = 80;
16411639

16421640
xBufferAllocFixedSize = pdTRUE;
16431641
uint8_t * nullAddress = NULL;
@@ -1719,7 +1717,7 @@ void test_DNS_ParseDNSReply_answer_record_too_many_answers( void )
17191717
size_t uxBufferLength = 250;
17201718
char dns[ 64 ];
17211719
struct freertos_addrinfo * pxAddressInfo;
1722-
uint16_t usPort;
1720+
uint16_t usPort = 80;
17231721

17241722
memset( dns, 'a', 64 );
17251723
memset( pucUDPPayloadBuffer, 0x00, uxBufferLength );
@@ -1776,7 +1774,7 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply_xBufferAllocFixedsize( void )
17761774
uint8_t * pucUDPPayloadBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4;
17771775
size_t uxBufferLength = 250;
17781776
struct freertos_addrinfo * pxAddressInfo;
1779-
uint16_t usPort;
1777+
uint16_t usPort = 80;
17801778

17811779
xBufferAllocFixedSize = pdTRUE;
17821780
uint8_t * nullAddress = NULL;
@@ -1854,7 +1852,7 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply( void )
18541852
uint8_t * pucUDPPayloadBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4;
18551853
size_t uxBufferLength = 250;
18561854
struct freertos_addrinfo * pxAddressInfo;
1857-
uint16_t usPort;
1855+
uint16_t usPort = 80;
18581856
NetworkEndPoint_t xEndPoint = { 0 };
18591857

18601858
memset( pucUDPPayloadBuffer, 0x00, uxBufferLength );
@@ -1927,7 +1925,7 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply2( void )
19271925
uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv6;
19281926
size_t uxBufferLength = 250;
19291927
struct freertos_addrinfo * pxAddressInfo;
1930-
uint16_t usPort;
1928+
uint16_t usPort = 80;
19311929
NetworkEndPoint_t xEndPoint = { 0 };
19321930

19331931
memset( pucUDPPayloadBuffer, 0x00, uxBufferLength );
@@ -2000,7 +1998,7 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply3( void )
20001998
uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4 - 1;
20011999
size_t uxBufferLength = 250;
20022000
struct freertos_addrinfo * pxAddressInfo;
2003-
uint16_t usPort;
2001+
uint16_t usPort = 80;
20042002
NetworkEndPoint_t xEndPoint = { 0 };
20052003

20062004
memset( pucUDPPayloadBuffer, 0x00, uxBufferLength );
@@ -2074,7 +2072,7 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply_diffUsType( void )
20742072
uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4;
20752073
size_t uxBufferLength = 250;
20762074
struct freertos_addrinfo * pxAddressInfo;
2077-
uint16_t usPort;
2075+
uint16_t usPort = 80;
20782076
NetworkEndPoint_t xEndPoint = { 0 };
20792077

20802078
memset( pucUDPPayloadBuffer, 0x00, uxBufferLength );
@@ -2151,7 +2149,7 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply_NullNetworkBuffer( void )
21512149
uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4;
21522150
size_t uxBufferLength = 250;
21532151
struct freertos_addrinfo * pxAddressInfo;
2154-
uint16_t usPort;
2152+
uint16_t usPort = 80;
21552153
NetworkEndPoint_t xEndPoint = { 0 };
21562154

21572155
memset( pucUDPPayloadBuffer, 0x00, uxBufferLength );
@@ -2228,7 +2226,7 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply4( void )
22282226
uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4;
22292227
size_t uxBufferLength = 250;
22302228
struct freertos_addrinfo * pxAddressInfo;
2231-
uint16_t usPort;
2229+
uint16_t usPort = 80;
22322230

22332231
memset( pucUDPPayloadBuffer, 0x00, uxBufferLength );
22342232

@@ -2299,7 +2297,7 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply5( void )
22992297
uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4;
23002298
size_t uxBufferLength = 250;
23012299
struct freertos_addrinfo * pxAddressInfo;
2302-
uint16_t usPort;
2300+
uint16_t usPort = 80;
23032301

23042302
memset( pucUDPPayloadBuffer, 0x00, uxBufferLength );
23052303

@@ -2371,7 +2369,7 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply_query_hook_false( void )
23712369
uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4;
23722370
struct freertos_addrinfo * pxAddressInfo;
23732371
struct xNetworkEndPoint xEndPoint = { 0 };
2374-
uint16_t usPort;
2372+
uint16_t usPort = 80;
23752373

23762374
memset( pucUDPPayloadBuffer, 0x0, 250 );
23772375
size_t uxBufferLength = 250;
@@ -2443,7 +2441,7 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply_null_new_netbuffer( void )
24432441
uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4;
24442442
size_t uxBufferLength = 250;
24452443
struct freertos_addrinfo * pxAddressInfo;
2446-
uint16_t usPort;
2444+
uint16_t usPort = 80;
24472445
NetworkEndPoint_t xEndPoint = { 0 };
24482446

24492447
memset( pucUDPPayloadBuffer, 0x00, uxBufferLength );
@@ -2517,7 +2515,7 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply_null_new_netbuffer2( void )
25172515
uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4;
25182516
size_t uxBufferLength = 250;
25192517
struct freertos_addrinfo * pxAddressInfo;
2520-
uint16_t usPort;
2518+
uint16_t usPort = 80;
25212519
NetworkEndPoint_t xEndPoint = { 0 };
25222520

25232521
memset( pucUDPPayloadBuffer, 0x00, uxBufferLength );
@@ -2591,7 +2589,7 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply_valid_new_netbuffer( void )
25912589
uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4;
25922590
size_t uxBufferLength = 250;
25932591
struct freertos_addrinfo * pxAddressInfo;
2594-
uint16_t usPort;
2592+
uint16_t usPort = 80;
25952593
NetworkEndPoint_t xEndPoint = { 0 };
25962594

25972595
memset( pucUDPPayloadBuffer, 0x00, uxBufferLength );
@@ -2683,7 +2681,7 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply_valid_new_netbuffer2( void )
26832681
uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4;
26842682
size_t uxBufferLength = 250;
26852683
struct freertos_addrinfo * pxAddressInfo;
2686-
uint16_t usPort;
2684+
uint16_t usPort = 80;
26872685
NetworkEndPoint_t xEndPoint = { 0 };
26882686

26892687
memset( pucUDPPayloadBuffer, 0x00, uxBufferLength );
@@ -2775,7 +2773,7 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply_valid_new_netbuffer3( void )
27752773
uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4;
27762774
size_t uxBufferLength = 250;
27772775
struct freertos_addrinfo * pxAddressInfo;
2778-
uint16_t usPort;
2776+
uint16_t usPort = 80;
27792777
NetworkEndPoint_t xEndPoint = { 0 };
27802778

27812779
memset( pucUDPPayloadBuffer, 0x00, uxBufferLength );
@@ -2948,7 +2946,7 @@ void test_parseDNSAnswer_recordstored_gt_count( void )
29482946
ip_address.xIPAddress.ulIP_IPv4 = 1234;
29492947
ip_address.xIs_IPv6 = pdFALSE;
29502948
ParseSet_t xSet = { 0 };
2951-
struct freertos_addrinfo * pxAddressInfo, * pxAddressInfo_2;
2949+
struct freertos_addrinfo * pxAddressInfo = NULL, * pxAddressInfo_2;
29522950

29532951
xSet.pxDNSMessageHeader = &pxDNSMessageHeader;
29542952
xSet.pucByte = pucByte;

test/unit-test/FreeRTOS_ICMP/FreeRTOS_ICMP_utest.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,3 @@ void test_ProcessICMPPacket_ICMPEchoReply_ImproperData( void )
249249

250250
TEST_ASSERT_EQUAL( eSuccess, eResult );
251251
}
252-
253-
void test_CastingFunctions( void )
254-
{
255-
void * pvTemp;
256-
257-
const ICMPHeader_t * pxICMPHeader = ( ( const ICMPHeader_t * ) pvTemp );
258-
}

0 commit comments

Comments
 (0)