Skip to content

Commit

Permalink
Add in incremental read routine and unit test. Ref #nasa/issues/956
Browse files Browse the repository at this point in the history
  • Loading branch information
jsjoberg01 committed Oct 20, 2020
1 parent dc3d62b commit 620b194
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
31 changes: 31 additions & 0 deletions fsw/cfe-core/src/es/cfe_es_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,37 @@ void CFE_ES_SysLogClear_Unsync(void);
*/
void CFE_ES_SysLogReadStart_Unsync(CFE_ES_SysLogReadBuffer_t *Buffer);

/**
* \brief Initialize Buffer for an incremental reading the system log
*
* This a helper function is intended to initialize the Buffer contents, assuming
* the Buffer was passed into CFE_ES_SysLogReadStart_Unsync at some time prior.
* This function supports incremental reading of the syslog buffer over time
* for systems that will send logs down in packets as opposed to logging to disk.
*
* This incremental reading of logs is only supported if set to OVERWRITE mode,
* otherwise the behavior will mimic a call to CFE_ES_SysLogReadStart_Unsync.
*
* This incremental reading of logs is only supported if CFE_ES_SysLogReadStart_Unsync
* has been called once previously on the Buffer, otherwise the behavior will mimic a
* call to CFE_ES_SysLogReadStart_Unsync.
*
* This function uses the Buffers current (as passed in) LastOffset from a previous
* read log data, and the current state of the syslog log buffer to intialize the
* buffer to read data logged since the Buffer's LastOffset.
*
* \param Buffer A local buffer which will be initialized based on its current LastOffset
* to read unread data from the syslog buffer.
*
* \note This function requires external thread synchronization
* \note This function requires Buffer has been initialized at some point by
* CFE_ES_SysLogReadStart_Unsync, but only once.
* \note This function requires the logs be set to OVERWRITE mode.
* \sa CFE_ES_SysLogReadData()
*/
void CFE_ES_SysLogIncReadInit_Unsync(CFE_ES_SysLogReadBuffer_t *Buffer);



/**
* \brief Write a printf-style formatted string to the system log
Expand Down
36 changes: 36 additions & 0 deletions fsw/cfe-core/src/es/cfe_es_syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,42 @@ void CFE_ES_SysLogReadStart_Unsync(CFE_ES_SysLogReadBuffer_t *Buffer)
Buffer->BlockSize = 0;
} /* End of CFE_ES_SysLogReadStart_Unsync() */


/*
* -----------------------------------------------------------------
* CFE_ES_SysLogIncReadInit_Unsync --
* Initialize Buffer for an incremental reading the system log
* -----------------------------------------------------------------
*/
void CFE_ES_SysLogIncReadInit_Unsync(CFE_ES_SysLogReadBuffer_t *Buffer)
{
if ( ( CFE_ES_ResetDataPtr->SystemLogMode != CFE_ES_LogMode_OVERWRITE ) ||
( Buffer->LastOffset > CFE_ES_ResetDataPtr->SystemLogEndIdx ) )
{
CFE_ES_SysLogReadStart_Unsync(Buffer);
}
else
{
/* LastOffset is left at its passed in position. */
/* Since CFE_ES_SysLogReadStart_Unsync has been called, no new line
* logic added. */
if ( CFE_ES_ResetDataPtr->SystemLogWriteIdx < Buffer->LastOffset )
{
Buffer->SizeLeft = CFE_ES_ResetDataPtr->SystemLogEndIdx -
Buffer->LastOffset +
CFE_ES_ResetDataPtr->SystemLogWriteIdx;
}
else
{
Buffer->SizeLeft = CFE_ES_ResetDataPtr->SystemLogWriteIdx -
Buffer->LastOffset;
}
Buffer->BlockSize = 0;
Buffer->EndIdx = CFE_ES_ResetDataPtr->SystemLogEndIdx;
}
} /* End of CFE_ES_SysLogIncReadInit_Unsync() */


/*
* -----------------------------------------------------------------
* CFE_ES_SysLogAppend_Unsync() --
Expand Down
33 changes: 33 additions & 0 deletions fsw/cfe-core/unit-test/es_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -6416,6 +6416,39 @@ void TestSysLog(void)
"CFE_ES_SysLogDump",
"Multiple reads and writes to sys log");

/* Test Incremental Reading without wrap*/
ES_ResetUnitTest();
CFE_ES_ResetDataPtr->SystemLogMode = CFE_ES_LogMode_OVERWRITE;
CFE_ES_ResetDataPtr->SystemLogEndIdx = sizeof(CFE_ES_ResetDataPtr->SystemLog) - 1;
CFE_ES_ResetDataPtr->SystemLogWriteIdx = CFE_ES_ResetDataPtr->SystemLogEndIdx - 1;
SysLogBuffer.LastOffset = CFE_ES_ResetDataPtr->SystemLogWriteIdx - 2;;

CFE_ES_SysLogIncReadInit_Unsync(&SysLogBuffer);

UT_Report(__FILE__, __LINE__,
SysLogBuffer.EndIdx == (sizeof(CFE_ES_ResetDataPtr->SystemLog) - 1) &&
SysLogBuffer.BlockSize == 0 &&
SysLogBuffer.SizeLeft == 2,
"CFE_ES_SysLogIncReadInit_Unsync",
"Incremental read without wrap");

/* Test Incremental Reading with wrap*/
ES_ResetUnitTest();
CFE_ES_ResetDataPtr->SystemLogMode = CFE_ES_LogMode_OVERWRITE;
CFE_ES_ResetDataPtr->SystemLogEndIdx = sizeof(CFE_ES_ResetDataPtr->SystemLog) - 1;
SysLogBuffer.LastOffset = 3;
CFE_ES_ResetDataPtr->SystemLogWriteIdx = 2;

CFE_ES_SysLogIncReadInit_Unsync(&SysLogBuffer);

UT_Report(__FILE__, __LINE__,
SysLogBuffer.EndIdx == (sizeof(CFE_ES_ResetDataPtr->SystemLog) - 1) &&
SysLogBuffer.LastOffset == 3 &&
SysLogBuffer.BlockSize == 0 &&
SysLogBuffer.SizeLeft == (SysLogBuffer.EndIdx - 3 + 2),
"CFE_ES_SysLogIncReadInit_Unsync",
"Incremental read with wrap");

/* Test "message got truncated" */
ES_ResetUnitTest();
memset(TmpString, 'a', CFE_ES_MAX_SYSLOG_MSG_SIZE);
Expand Down

0 comments on commit 620b194

Please sign in to comment.