Skip to content

Commit df553bd

Browse files
authored
Update Cellular_CommonInit error handling (#163)
* Update Cellular_CommonInit error handling * Update size table * Update CBMC for Cellular_CommonInit
1 parent f1097fb commit df553bd

6 files changed

Lines changed: 307 additions & 46 deletions

File tree

docs/doxygen/include/size_table.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<tr>
2626
<td>cellular_common_api.c</td>
2727
<td><center>0.7K</center></td>
28-
<td><center>0.6K</center></td>
28+
<td><center>0.7K</center></td>
2929
</tr>
3030
<tr>
3131
<td>cellular_common.c</td>
@@ -45,6 +45,6 @@
4545
<tr>
4646
<td><b>Total estimates</b></td>
4747
<td><b><center>15.1K</center></b></td>
48-
<td><b><center>13.6K</center></b></td>
48+
<td><b><center>13.7K</center></b></td>
4949
</tr>
5050
</table>

source/cellular_common_api.c

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,25 +146,58 @@ CellularError_t Cellular_CommonInit( CellularHandle_t * pCellularHandle,
146146
CellularError_t cellularStatus = CELLULAR_SUCCESS;
147147
CellularContext_t * pContext = NULL;
148148

149-
/* Init the common library. */
150-
cellularStatus = _Cellular_LibInit( pCellularHandle, pCommInterface, pTokenTable );
151-
152-
/* Init the module. */
153-
if( cellularStatus == CELLULAR_SUCCESS )
149+
if( pCellularHandle == NULL )
154150
{
155-
pContext = *pCellularHandle;
156-
cellularStatus = Cellular_ModuleInit( pContext, &pContext->pModuleContext );
151+
LogError( ( "Cellular_CommonInit pCellularHandle is NULL." ) );
152+
cellularStatus = CELLULAR_INVALID_HANDLE;
157153
}
158-
159-
/* Setup UE, URC and query register status. */
160-
if( cellularStatus == CELLULAR_SUCCESS )
154+
else if( pCommInterface == NULL )
161155
{
162-
cellularStatus = Cellular_ModuleEnableUE( pContext );
156+
LogError( ( "Cellular_CommonInit pCommInterface is NULL." ) );
157+
cellularStatus = CELLULAR_BAD_PARAMETER;
163158
}
164-
165-
if( cellularStatus == CELLULAR_SUCCESS )
159+
else if( pTokenTable == NULL )
160+
{
161+
LogError( ( "Cellular_CommonInit pTokenTable is NULL." ) );
162+
cellularStatus = CELLULAR_BAD_PARAMETER;
163+
}
164+
else
166165
{
167-
cellularStatus = Cellular_ModuleEnableUrc( pContext );
166+
/* Init the common library. */
167+
cellularStatus = _Cellular_LibInit( pCellularHandle, pCommInterface, pTokenTable );
168+
169+
if( cellularStatus == CELLULAR_SUCCESS )
170+
{
171+
pContext = ( CellularContext_t * ) ( *pCellularHandle );
172+
173+
cellularStatus = Cellular_ModuleInit( pContext, &pContext->pModuleContext );
174+
175+
if( cellularStatus == CELLULAR_SUCCESS )
176+
{
177+
cellularStatus = Cellular_ModuleEnableUE( pContext );
178+
179+
if( cellularStatus == CELLULAR_SUCCESS )
180+
{
181+
cellularStatus = Cellular_ModuleEnableUrc( pContext );
182+
}
183+
184+
if( cellularStatus != CELLULAR_SUCCESS )
185+
{
186+
/* Clean up the resource allocated by cellular module here if
187+
* Cellular_ModuleEnableUE or Cellular_ModuleEnableUrc returns
188+
* error. */
189+
( void ) Cellular_ModuleCleanUp( pContext );
190+
}
191+
}
192+
193+
if( cellularStatus != CELLULAR_SUCCESS )
194+
{
195+
/* Clean up the resource in cellular common library if any of the
196+
* module port function returns error. Error returned by _Cellular_LibInit
197+
* is already handled in the implementation. */
198+
( void ) _Cellular_LibCleanup( pContext );
199+
}
200+
}
168201
}
169202

170203
return cellularStatus;

test/cbmc/proofs/Cellular_CommonInit/Cellular_CommonInit_harness.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,7 @@ void harness()
9696
* Initialize the member of Cellular_CommonInit.
9797
****************************************************************/
9898

99-
Cellular_CommonInit( nondet_bool() ? NULL : &pHandle, &CellularCommInterface, &tokenTable );
99+
Cellular_CommonInit( nondet_bool() ? NULL : &pHandle,
100+
nondet_bool() ? NULL : &CellularCommInterface,
101+
nondet_bool() ? NULL : &tokenTable );
100102
}

test/cbmc/proofs/Cellular_CommonInit/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ HARNESS_ENTRY=harness
2424
HARNESS_FILE=Cellular_CommonInit_harness
2525
PROOF_UID = Cellular_CommonInit
2626

27-
DEFINES +=
27+
DEFINES += -DCBMC_TEST_CELLULAR_MODULE_RETURN_ERROR=1
2828
INCLUDES +=
2929

3030
PROOF_SOURCES += $(PROOFDIR)/$(HARNESS_FILE).c
@@ -35,4 +35,6 @@ PROOF_SOURCES += $(SRCDIR)/test/cbmc/sources/cellular_modules.c
3535
PROJECT_SOURCES += $(SRCDIR)/source/cellular_common_api.c
3636
PROJECT_SOURCES += $(SRCDIR)/source/cellular_common.c
3737

38+
UNWINDSET += __CPROVER_file_local_cellular_common_c_libClose.0:20
39+
3840
include ../Makefile.common

test/cbmc/sources/cellular_modules.c

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,41 +33,64 @@
3333
/* Include paths for public enums, structures, and macros. */
3434
#include "cellular_common_portable.h"
3535

36-
CellularError_t Cellular_ModuleInit( const CellularContext_t * pContext,
37-
void ** ppModuleContext )
38-
{
39-
CellularError_t ret = nondet_int();
36+
#if ( CBMC_TEST_CELLULAR_MODULE_RETURN_ERROR == 1 )
4037

41-
__CPROVER_assume( ret >= CELLULAR_SUCCESS && ret <= CELLULAR_UNKNOWN );
42-
return ret;
43-
}
38+
CellularError_t Cellular_ModuleInit( const CellularContext_t * pContext,
39+
void ** ppModuleContext )
40+
{
41+
CellularError_t ret = nondet_int();
4442

43+
__CPROVER_assume( ret >= CELLULAR_SUCCESS && ret <= CELLULAR_UNKNOWN );
44+
return ret;
45+
}
4546

46-
CellularError_t Cellular_ModuleCleanUp( const CellularContext_t * pContext )
47-
{
48-
CellularError_t ret = nondet_int();
47+
CellularError_t Cellular_ModuleCleanUp( const CellularContext_t * pContext )
48+
{
49+
CellularError_t ret = nondet_int();
4950

50-
__CPROVER_assume( ret >= CELLULAR_SUCCESS && ret <= CELLULAR_UNKNOWN );
51-
return ret;
52-
}
51+
__CPROVER_assume( ret >= CELLULAR_SUCCESS && ret <= CELLULAR_UNKNOWN );
52+
return ret;
53+
}
5354

55+
CellularError_t Cellular_ModuleEnableUE( CellularContext_t * pContext )
56+
{
57+
CellularError_t ret = nondet_int();
5458

55-
CellularError_t Cellular_ModuleEnableUE( CellularContext_t * pContext )
56-
{
57-
CellularError_t ret = nondet_int();
59+
__CPROVER_assume( ret >= CELLULAR_SUCCESS && ret <= CELLULAR_UNKNOWN );
60+
return ret;
61+
}
5862

59-
__CPROVER_assume( ret >= CELLULAR_SUCCESS && ret <= CELLULAR_UNKNOWN );
60-
return ret;
61-
}
63+
CellularError_t Cellular_ModuleEnableUrc( CellularContext_t * pContext )
64+
{
65+
CellularError_t ret = nondet_int();
6266

67+
__CPROVER_assume( ret >= CELLULAR_SUCCESS && ret <= CELLULAR_UNKNOWN );
68+
return ret;
69+
}
6370

64-
CellularError_t Cellular_ModuleEnableUrc( CellularContext_t * pContext )
65-
{
66-
CellularError_t ret = nondet_int();
71+
#else /* #if ( CBMC_TEST_CELLULAR_MODULE_NO_ERROR == 1 ) */
6772

68-
__CPROVER_assume( ret >= CELLULAR_SUCCESS && ret <= CELLULAR_UNKNOWN );
69-
return ret;
70-
}
73+
CellularError_t Cellular_ModuleInit( const CellularContext_t * pContext,
74+
void ** ppModuleContext )
75+
{
76+
return CELLULAR_SUCCESS;
77+
}
7178

79+
CellularError_t Cellular_ModuleCleanUp( const CellularContext_t * pContext )
80+
{
81+
return CELLULAR_SUCCESS;
82+
}
83+
84+
CellularError_t Cellular_ModuleEnableUE( CellularContext_t * pContext )
85+
{
86+
return CELLULAR_SUCCESS;
87+
}
88+
89+
CellularError_t Cellular_ModuleEnableUrc( CellularContext_t * pContext )
90+
{
91+
return CELLULAR_SUCCESS;
92+
}
93+
94+
#endif /* #if ( CBMC_TEST_CELLULAR_MODULE_NO_ERROR == 1 ) */
7295

7396
/* ========================================================================== */

0 commit comments

Comments
 (0)