Skip to content

Commit afd2e70

Browse files
tony-josi-awskarkhazmarkrtuttleactions-user
authored
Fix CBMC proofs for socket (#719)
* fixed cbmc proof for vSocketBind * Use CBMC XML output to enable VSCode debugger (#673) Prior to this commit, CBMC would emit logging information in plain text format, which does not contain information required for the CBMC VSCode debugger. This commit makes CBMC use XML instead of plain text. Co-authored-by: Mark Tuttle <[email protected]> * fix cbmc proof for vSocketWakeUpUser * add check with multiple endpoints * NULL assume to assignment * adding non determinitic number of end points * adding commit review suggestions * Uncrustify: triggered by comment. --------- Co-authored-by: Kareem Khazem <[email protected]> Co-authored-by: Mark Tuttle <[email protected]> Co-authored-by: GitHub Action <[email protected]>
1 parent 91b6855 commit afd2e70

File tree

10 files changed

+74
-19
lines changed

10 files changed

+74
-19
lines changed

test/cbmc/patches/FreeRTOSConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
* is set to 2 so the formatting functions are included without the stdio.h being
128128
* included in tasks.c. That is because this project defines its own sprintf()
129129
* functions. */
130-
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
130+
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
131131

132132
/* Assert call defined for debug builds. */
133133
extern void vAssertCalled( const char * pcFile,

test/cbmc/proofs/Makefile.template

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,38 +119,36 @@ goto:
119119
# Ignore the return code for CBMC, so that we can still generate the
120120
# report if the proof failed. If the proof failed, we separately fail
121121
# the entire job using the check-cbmc-result rule.
122-
cbmc.txt: $(ENTRY).goto
123-
-cbmc $(CBMCFLAGS) $(SOLVER) --unwinding-assertions --trace @RULE_INPUT@ > $@ 2>&1
122+
cbmc.xml: $(ENTRY).goto
123+
-cbmc $(CBMCFLAGS) $(SOLVER) --unwinding-assertions --trace --xml-ui @RULE_INPUT@ > $@ 2>&1
124124

125125
property.xml: $(ENTRY).goto
126126
cbmc $(CBMCFLAGS) --unwinding-assertions --show-properties --xml-ui @RULE_INPUT@ > $@ 2>&1
127127

128128
coverage.xml: $(ENTRY).goto
129129
cbmc $(CBMCFLAGS) --cover location --xml-ui @RULE_INPUT@ > $@ 2>&1
130130

131-
cbmc: cbmc.txt
131+
cbmc: cbmc.xml
132132

133133
property: property.xml
134134

135135
coverage: coverage.xml
136136

137-
report: cbmc.txt property.xml coverage.xml
137+
report: cbmc.xml property.xml coverage.xml
138138
$(VIEWER) \
139139
--goto $(ENTRY).goto \
140140
--srcdir $(FREERTOS_PLUS_TCP) \
141-
--blddir $(FREERTOS_PLUS_TCP) \
142-
--htmldir html \
143-
--srcexclude "(.@FORWARD_SLASH@doc|.@FORWARD_SLASH@tests|.@FORWARD_SLASH@vendors)" \
144-
--result cbmc.txt \
141+
--reportdir report \
142+
--result cbmc.xml \
145143
--property property.xml \
146-
--block coverage.xml
144+
--coverage coverage.xml
147145

148-
# This rule depends only on cbmc.txt and has no dependents, so it will
146+
# This rule depends only on cbmc.xml and has no dependents, so it will
149147
# not block the report from being generated if it fails. This rule is
150148
# intended to fail if and only if the CBMC safety check that emits
151-
# cbmc.txt yielded a proof failure.
152-
check-cbmc-result: cbmc.txt
153-
grep -e "^VERIFICATION SUCCESSFUL" $^
149+
# cbmc.xml yielded a proof failure.
150+
check-cbmc-result: cbmc.xml
151+
grep '<cprover-status>SUCCESS</cprover-status>' $^
154152

155153
# ____________________________________________________________________
156154
# Rules
@@ -160,7 +158,7 @@ check-cbmc-result: cbmc.txt
160158
clean:
161159
@RM@ $(OBJS) $(ENTRY).goto
162160
@RM@ $(ENTRY)[0-9].goto $(ENTRY)[0-9].txt
163-
@RM@ cbmc.txt property.xml coverage.xml TAGS TAGS-*
161+
@RM@ cbmc.xml property.xml coverage.xml TAGS TAGS-*
164162
@RM@ *~ \#*
165163
@RM@ queue_datastructure.h
166164

test/cbmc/proofs/Socket/vSocketBind/ALLOW_ETHERNET_DRIVER_FILTERS_PACKETS/Makefile.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
"ALLOW_TCP":"1",
66
"CBMCFLAGS":
77
[
8-
"--unwind 1"
8+
"--unwind 1",
9+
"--unwindset FreeRTOS_FindEndPointOnIP_IPv4.0:3"
910
],
1011
"OBJS":
1112
[
1213
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto",
14+
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto",
1315
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Sockets.goto",
1416
"$(ENTRY)_harness.goto"
1517
],

test/cbmc/proofs/Socket/vSocketBind/ALLOW_ETHERNET_DRIVER_FILTERS_PACKETS/vSocketBind_harness.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber )
4949

5050
void harness()
5151
{
52+
/* Add few endpoints */
53+
pxNetworkEndPoints = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
54+
__CPROVER_assume( pxNetworkEndPoints != NULL );
55+
56+
if( nondet_bool() )
57+
{
58+
pxNetworkEndPoints->pxNext = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
59+
__CPROVER_assume( pxNetworkEndPoints->pxNext != NULL );
60+
pxNetworkEndPoints->pxNext->pxNext = NULL;
61+
}
62+
else
63+
{
64+
pxNetworkEndPoints->pxNext = NULL;
65+
}
66+
5267
FreeRTOS_Socket_t * pxSocket = ensure_FreeRTOS_Socket_t_is_allocated();
5368

5469
__CPROVER_assume( pxSocket != NULL );

test/cbmc/proofs/Socket/vSocketBind/ALLOW_SOCKET_SEND_WITHOUT_BIND/Makefile.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
"ALLOW_SEND_WITHOUT_BIND":"1",
44
"CBMCFLAGS":
55
[
6-
"--unwind 1"
6+
"--unwind 1",
7+
"--unwindset FreeRTOS_FindEndPointOnIP_IPv4.0:3"
78
],
89
"OBJS":
910
[
1011
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto",
12+
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto",
1113
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Sockets.goto",
1214
"$(ENTRY)_harness.goto"
1315
],

test/cbmc/proofs/Socket/vSocketBind/ALLOW_SOCKET_SEND_WITHOUT_BIND/vSocketBind_harness.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber )
4747

4848
void harness()
4949
{
50+
/* Add few endpoints */
51+
pxNetworkEndPoints = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
52+
__CPROVER_assume( pxNetworkEndPoints != NULL );
53+
54+
if( nondet_bool() )
55+
{
56+
pxNetworkEndPoints->pxNext = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
57+
__CPROVER_assume( pxNetworkEndPoints->pxNext != NULL );
58+
pxNetworkEndPoints->pxNext->pxNext = NULL;
59+
}
60+
else
61+
{
62+
pxNetworkEndPoints->pxNext = NULL;
63+
}
64+
5065
FreeRTOS_Socket_t * pxSocket = ensure_FreeRTOS_Socket_t_is_allocated();
5166

5267
__CPROVER_assume( pxSocket != NULL );

test/cbmc/proofs/Socket/vSocketBind/DONT_ALLOW_SOCKET_SEND_WITHOUT_BIND/Makefile.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
"ALLOW_SEND_WITHOUT_BIND":"0",
44
"CBMCFLAGS":
55
[
6-
"--unwind 1"
6+
"--unwind 1",
7+
"--unwindset FreeRTOS_FindEndPointOnIP_IPv4.0:3"
78
],
89
"OBJS":
910
[
1011
"$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/list.goto",
12+
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Routing.goto",
1113
"$(FREERTOS_PLUS_TCP)/source/FreeRTOS_Sockets.goto",
1214
"$(ENTRY)_harness.goto"
1315
],

test/cbmc/proofs/Socket/vSocketBind/DONT_ALLOW_SOCKET_SEND_WITHOUT_BIND/vSocketBind_harness.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber )
4747

4848
void harness()
4949
{
50+
/* Add few endpoints */
51+
pxNetworkEndPoints = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
52+
__CPROVER_assume( pxNetworkEndPoints != NULL );
53+
54+
if( nondet_bool() )
55+
{
56+
pxNetworkEndPoints->pxNext = ( NetworkEndPoint_t * ) malloc( sizeof( NetworkEndPoint_t ) );
57+
__CPROVER_assume( pxNetworkEndPoints->pxNext != NULL );
58+
pxNetworkEndPoints->pxNext->pxNext = NULL;
59+
}
60+
else
61+
{
62+
pxNetworkEndPoints->pxNext = NULL;
63+
}
64+
5065
FreeRTOS_Socket_t * pxSocket = ensure_FreeRTOS_Socket_t_is_allocated();
5166

5267
__CPROVER_assume( pxSocket != NULL );

test/cbmc/proofs/Socket/vSocketWakeUpUser/vSocketWakeUpUser_harness.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup,
130130
return uxReturnBits;
131131
}
132132

133+
void SocketWakeupCallback_Stub( struct xSOCKET * pxSocket )
134+
{
135+
__CPROVER_assert( pxSocket != NULL,
136+
"The pxSocket cannot be NULL" );
137+
}
133138

134139
void harness()
135140
{
@@ -138,7 +143,7 @@ void harness()
138143
__CPROVER_assume( pxSocket != NULL );
139144
__CPROVER_assume( pxSocket != FREERTOS_INVALID_SOCKET );
140145

141-
pxSocket->pxUserWakeCallback = safeMalloc( sizeof( SocketWakeupCallback_t ) );
146+
pxSocket->pxUserWakeCallback = SocketWakeupCallback_Stub;
142147

143148
pxSocket->pxSocketSet = safeMalloc( sizeof( struct xSOCKET_SET ) );
144149

test/cbmc/proofs/utility/memory_assignments.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ FreeRTOS_Socket_t * ensure_FreeRTOS_Socket_t_is_allocated()
2020
pxSocket->u.xTCP.rxStream = safeMalloc( sizeof( StreamBuffer_t ) );
2121
pxSocket->u.xTCP.txStream = safeMalloc( sizeof( StreamBuffer_t ) );
2222
pxSocket->u.xTCP.pxPeerSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) );
23+
pxSocket->pxEndPoint = safeMalloc( sizeof( NetworkEndPoint_t ) );
2324
}
2425

2526
return pxSocket;

0 commit comments

Comments
 (0)