Skip to content

Commit

Permalink
CBMC proof harness type fixes
Browse files Browse the repository at this point in the history
These changes add necessary forward declarations (or system headers
includes) and address inconsistencies in how we invoke functions from
CBMC proof harnesses as compared to their original signatures.
  • Loading branch information
tautschnig committed Apr 15, 2024
1 parent 2557f84 commit 8fc7582
Show file tree
Hide file tree
Showing 25 changed files with 59 additions and 18 deletions.
2 changes: 2 additions & 0 deletions test/cbmc/proofs/Malloc_FreeRTOS/Malloc_FreeRTOS_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
/* FreeRTOS includes for OTA library. */
#include "ota_os_freertos.h"

#include <stdlib.h>

void * pvPortMalloc( size_t size )
{
return malloc( size );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "cbor.h"
#include "ota_cbor_private.h"

#include <stdlib.h>

/* Stub to return CBORerror type. */
CborError returnCborError()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
/* Ota Agent includes. */
#include "ota.h"

#include <stdlib.h>

void OTA_GetStatistics_harness()
{
OtaErr_t err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
#include "ota_private.h"
#include "FreeRTOSConfig.h"

#include <stdlib.h>

void OtaReceiveEvent_FreeRTOS_harness()
{
OtaEventContext_t * pEventCtx;
OtaOsStatus_t osStatus;
void * pEventMsg;
uint32_t timeout;

void * pEventMsg = ( void * ) malloc( sizeof( OtaEventMsg_t ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "ota_os_freertos.h"
#include "FreeRTOSConfig.h"

#include <stdlib.h>

void otaCallback( OtaTimerId_t otaTimerId )
{
__CPROVER_assert( otaTimerId == OtaRequestTimer || otaTimerId == OtaSelfTestTimer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include <poll.h>
#include <mqueue.h>

int nondet_int();

/* Counter for the number of iterations. */
static int count = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
/* Counter for the number of iterations. */
static int count = 0;

int nondet_int();

int poll( struct pollfd * fds,
nfds_t nfds,
int timeout )
Expand Down
2 changes: 2 additions & 0 deletions test/cbmc/proofs/closeFileHandler/closeFileHandler_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
/* Ota Agent includes. */
#include "ota.h"

#include <stdlib.h>

OtaErr_t __CPROVER_file_local_ota_c_closeFileHandler( const OtaEventData_t * pEventData );

void closeFileHandler_harness()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
#define MAX_NUM_BASE64_DATA 4U

/* Declaration of the mangled name static function which is created by CBMC for static functions. */
Base64Status_t __CPROVER_file_local_ota_base64_c_decodeBase64IndexBuffer( uint8_t * pDest,
const size_t destLen,
size_t * pResultLen,
Base64Status_t __CPROVER_file_local_ota_base64_c_decodeBase64IndexBuffer( uint32_t * pDest,
uint32_t * destLen,
const uint8_t * pEncodedData,
const size_t encodedLen );
const size_t encodedLen,
size_t * pResultLen );

void decodeBase64IndexBuffer_harness()
{
Expand Down
2 changes: 2 additions & 0 deletions test/cbmc/proofs/executeHandler/executeHandler_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
/* Ota Agent includes. */
#include "ota.h"

#include <stdlib.h>

void __CPROVER_file_local_ota_c_executeHandler( uint32_t index,
const OtaEventMsg_t * const pEventMsg );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
#include <stdlib.h>

extern OtaAgentContext_t otaAgent;
extern uint32_t extractAndStoreArray( const char * pKey,
const char * pValueInJson,
size_t valueLength,
void * pParamAdd,
uint32_t * pParamSizeAdd );
extern DocParseErr_t extractAndStoreArray( const char * pKey,
const char * pValueInJson,
size_t valueLength,
void * pParamAdd,
uint32_t * pParamSizeAdd );

void extractAndStoreArray_harness()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
extern OtaAgentContext_t otaAgent;
extern void freeFileContextMem( OtaFileContext_t * const pFileContext );

__CPROVER_bool nondet_bool();

void freeFileContextMem_harness()
{
OtaInterfaces_t otaInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ static OtaErr_t getFileContextFromJob( const char * pRawMsg,
uint32_t messageLength,
OtaFileContext_t ** pFileContext );

__CPROVER_bool nondet_bool();

DocParseErr_t parseJobDoc( const JsonDocParam_t * pJsonExpectedParams,
uint16_t numJobParams,
const char * pJson,
Expand Down Expand Up @@ -84,7 +86,7 @@ DocParseErr_t parseJobDoc( const JsonDocParam_t * pJsonExpectedParams,

void getFileContextFromJob_harness()
{
OtaFileContext_t * pFileContext;
OtaFileContext_t * pFileContext = &fileContext;
OtaInterfaces_t otaInterface;
char rawMsg[ OTA_DATA_BLOCK_SIZE ];
uint32_t messageLength;
Expand All @@ -110,5 +112,5 @@ void getFileContextFromJob_harness()
* Agent specifically in receiveAndProcessOTAEvent function.*/
otaAgent.pOtaInterface = &otaInterface;

( void ) getFileContextFromJob( &rawMsg, messageLength, &fileContext );
( void ) getFileContextFromJob( rawMsg, messageLength, &pFileContext );
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void handleJobParsingError_harness()
/* handleJobParsingError is only called with otaAgent.fileContext as it's argument.
* otaAgent.fileContext.pJobName is pointing to a local buffer which is initialized in initializeLocalBuffers
* function which is again called in OTA_Init.*/
fileContext.pJobName = &jobNameBuffer;
fileContext.pJobName = jobNameBuffer;

/* Havoc otaAgent to non-deterministically set all the bytes in
* the structure. */
Expand Down
2 changes: 2 additions & 0 deletions test/cbmc/proofs/otaClose/otaClose_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ extern OtaDataInterface_t otaDataInterface;
extern OtaAgentContext_t otaAgent;
extern bool otaClose( OtaFileContext_t * const pFileContext );

__CPROVER_bool nondet_bool();

void otaClose_harness()
{
OtaFileContext_t * pFileContext;
Expand Down
2 changes: 2 additions & 0 deletions test/cbmc/proofs/parseJSONbyModel/parseJSONbyModel_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "ota.h"
#include "core_json.h"

#include <stdlib.h>

extern OtaAgentContext_t otaAgent;
extern JsonDocParam_t otaJobDocModelParamStructure[ OTA_NUM_JOB_PARAMS ];
extern DocParseErr_t parseJSONbyModel( const char * pJson,
Expand Down
10 changes: 5 additions & 5 deletions test/cbmc/proofs/processDataBlock/processDataBlock_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
#include <stdlib.h>

extern OtaAgentContext_t otaAgent;
extern uint32_t processDataBlock( OtaFileContext_t * pFileContext,
uint32_t uBlockIndex,
uint32_t uBlockSize,
OtaPalStatus_t * pCloseResult,
uint8_t * pPayload );
extern IngestResult_t processDataBlock( OtaFileContext_t * pFileContext,
uint32_t uBlockIndex,
uint32_t uBlockSize,
OtaPalStatus_t * pCloseResult,
uint8_t * pPayload );

/* Stub to validate incoming data block. */
bool validateDataBlock( const OtaFileContext_t * pFileContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "FreeRTOS.h"
#include "timers.h"

#include <stdlib.h>

/* Declaration of the mangled name function created by CBMC for static functions.*/
void __CPROVER_file_local_ota_os_freertos_c_requestTimerCallback( TimerHandle_t timer );

Expand Down
2 changes: 2 additions & 0 deletions test/cbmc/proofs/resetEventQueue/resetEventQueue_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "ota.h"
#include <stdlib.h>

void resetEventQueue( void );

OtaOsStatus_t recv( OtaEventContext_t * pEventCtx,
void * pEventMsg,
uint32_t timeout )
Expand Down
2 changes: 2 additions & 0 deletions test/cbmc/proofs/resumeHandler/resumeHandler_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
/* Ota Agent includes. */
#include "ota.h"

#include <stdlib.h>

/* Mangled name definition of the static function. */
OtaErr_t __CPROVER_file_local_ota_c_resumeHandler( const OtaEventData_t * pEventData );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "FreeRTOS.h"
#include "timers.h"

#include <stdlib.h>

/* Declaration of the mangled name function created by CBMC for static functions.*/
void __CPROVER_file_local_ota_os_freertos_c_selfTestTimerCallback( TimerHandle_t timer );

Expand Down
2 changes: 2 additions & 0 deletions test/cbmc/proofs/shutdownHandler/shutdownHandler_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
/* Ota Agent includes. */
#include "ota.h"

#include <stdlib.h>

OtaErr_t __CPROVER_file_local_ota_c_shutdownHandler( const OtaEventData_t * pEventData );

void shutdownHandler_harness()
Expand Down
2 changes: 2 additions & 0 deletions test/cbmc/proofs/stringBuilder/stringBuilder_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
*/
#include "ota_mqtt_private.h"

#include <stdlib.h>

/* Declaration of the mangled name function generated by CBMC for static functions. */
size_t __CPROVER_file_local_ota_mqtt_c_stringBuilder( char * pBuffer,
size_t bufferSizeBytes,
Expand Down
2 changes: 2 additions & 0 deletions test/cbmc/proofs/suspendHandler/suspendHandler_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
/* Ota Agent includes. */
#include "ota.h"

#include <stdlib.h>

OtaErr_t __CPROVER_file_local_ota_c_suspendHandler( const OtaEventData_t * pEventData );

void suspendHandler_harness()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ extern OtaJobParseErr_t verifyActiveJobStatus( OtaFileContext_t * pFileContext,
OtaFileContext_t ** pFinalFile,
bool * pUpdateJob );

__CPROVER_bool nondet_bool();

void verifyActiveJobStatus_harness()
{
OtaInterfaces_t otaInterface;
Expand Down

0 comments on commit 8fc7582

Please sign in to comment.