Skip to content

Commit

Permalink
Merge pull request #216 from thnkslprpt:fix-215-convert-init-syslog-w…
Browse files Browse the repository at this point in the history
…rites-to-events

Fix #215, Convert syslog writes during initialization to events
  • Loading branch information
dzbaker committed Mar 21, 2024
2 parents 2cfa23f + a71b471 commit 7b62604
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
22 changes: 13 additions & 9 deletions fsw/inc/sample_app_eventids.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@
#ifndef SAMPLE_APP_EVENTS_H
#define SAMPLE_APP_EVENTS_H

#define SAMPLE_APP_RESERVED_EID 0
#define SAMPLE_APP_INIT_INF_EID 1
#define SAMPLE_APP_CC_ERR_EID 2
#define SAMPLE_APP_NOOP_INF_EID 3
#define SAMPLE_APP_RESET_INF_EID 4
#define SAMPLE_APP_MID_ERR_EID 5
#define SAMPLE_APP_CMD_LEN_ERR_EID 6
#define SAMPLE_APP_PIPE_ERR_EID 7
#define SAMPLE_APP_VALUE_INF_EID 8
#define SAMPLE_APP_RESERVED_EID 0
#define SAMPLE_APP_INIT_INF_EID 1
#define SAMPLE_APP_CC_ERR_EID 2
#define SAMPLE_APP_NOOP_INF_EID 3
#define SAMPLE_APP_RESET_INF_EID 4
#define SAMPLE_APP_MID_ERR_EID 5
#define SAMPLE_APP_CMD_LEN_ERR_EID 6
#define SAMPLE_APP_PIPE_ERR_EID 7
#define SAMPLE_APP_VALUE_INF_EID 8
#define SAMPLE_APP_CR_PIPE_ERR_EID 9
#define SAMPLE_APP_SUB_HK_ERR_EID 10
#define SAMPLE_APP_SUB_CMD_ERR_EID 11
#define SAMPLE_APP_TABLE_REG_ERR_EID 12

#endif /* SAMPLE_APP_EVENTS_H */
12 changes: 8 additions & 4 deletions fsw/src/sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ CFE_Status_t SAMPLE_APP_Init(void)
status = CFE_SB_CreatePipe(&SAMPLE_APP_Data.CommandPipe, SAMPLE_APP_Data.PipeDepth, SAMPLE_APP_Data.PipeName);
if (status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("Sample App: Error creating pipe, RC = 0x%08lX\n", (unsigned long)status);
CFE_EVS_SendEvent(SAMPLE_APP_CR_PIPE_ERR_EID, CFE_EVS_EventType_ERROR,
"Sample App: Error creating SB Command Pipe, RC = 0x%08lX", (unsigned long)status);
}
}

Expand All @@ -159,7 +160,8 @@ CFE_Status_t SAMPLE_APP_Init(void)
status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(SAMPLE_APP_SEND_HK_MID), SAMPLE_APP_Data.CommandPipe);
if (status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("Sample App: Error Subscribing to HK request, RC = 0x%08lX\n", (unsigned long)status);
CFE_EVS_SendEvent(SAMPLE_APP_SUB_HK_ERR_EID, CFE_EVS_EventType_ERROR,
"Sample App: Error Subscribing to HK request, RC = 0x%08lX", (unsigned long)status);
}
}

Expand All @@ -171,7 +173,8 @@ CFE_Status_t SAMPLE_APP_Init(void)
status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(SAMPLE_APP_CMD_MID), SAMPLE_APP_Data.CommandPipe);
if (status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("Sample App: Error Subscribing to Command, RC = 0x%08lX\n", (unsigned long)status);
CFE_EVS_SendEvent(SAMPLE_APP_SUB_CMD_ERR_EID, CFE_EVS_EventType_ERROR,
"Sample App: Error Subscribing to Commands, RC = 0x%08lX", (unsigned long)status);
}
}

Expand All @@ -184,7 +187,8 @@ CFE_Status_t SAMPLE_APP_Init(void)
CFE_TBL_OPT_DEFAULT, SAMPLE_APP_TblValidationFunc);
if (status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("Sample App: Error Registering Example Table, RC = 0x%08lX\n", (unsigned long)status);
CFE_EVS_SendEvent(SAMPLE_APP_TABLE_REG_ERR_EID, CFE_EVS_EventType_ERROR,
"Sample App: Error Registering Example Table, RC = 0x%08lX", (unsigned long)status);
}
else
{
Expand Down
17 changes: 9 additions & 8 deletions unit-test/coveragetest/coveragetest_sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,29 +149,30 @@ void Test_SAMPLE_APP_Init(void)
/* nominal case should return CFE_SUCCESS */
UtAssert_INT32_EQ(SAMPLE_APP_Init(), CFE_SUCCESS);

/* trigger a failure for each of the sub-calls,
* and confirm a write to syslog for each.
* Note that this count accumulates, because the status
* is _not_ reset between these test cases. */
/*
* Trigger a failure for each of the sub-calls, and confirm a write to syslog for
* failure to register with EVS, and that an event is generated for subsequent error paths.
* Note that the stub counts accumulate, because the status is _not_ reset between test cases.
*/
UT_SetDeferredRetcode(UT_KEY(CFE_EVS_Register), 1, CFE_EVS_INVALID_PARAMETER);
UtAssert_INT32_EQ(SAMPLE_APP_Init(), CFE_EVS_INVALID_PARAMETER);
UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 1);

UT_SetDeferredRetcode(UT_KEY(CFE_SB_CreatePipe), 1, CFE_SB_BAD_ARGUMENT);
UtAssert_INT32_EQ(SAMPLE_APP_Init(), CFE_SB_BAD_ARGUMENT);
UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 2);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 2); /* 1 from previous nominal case, 1 from this error path */

UT_SetDeferredRetcode(UT_KEY(CFE_SB_Subscribe), 1, CFE_SB_BAD_ARGUMENT);
UtAssert_INT32_EQ(SAMPLE_APP_Init(), CFE_SB_BAD_ARGUMENT);
UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 3);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 3); /* 1 additional event sent from this error path */

UT_SetDeferredRetcode(UT_KEY(CFE_SB_Subscribe), 2, CFE_SB_BAD_ARGUMENT);
UtAssert_INT32_EQ(SAMPLE_APP_Init(), CFE_SB_BAD_ARGUMENT);
UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 4);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 4); /* 1 additional event sent from this error path */

UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Register), 1, CFE_TBL_ERR_INVALID_OPTIONS);
UtAssert_INT32_EQ(SAMPLE_APP_Init(), CFE_TBL_ERR_INVALID_OPTIONS);
UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 5);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 6); /* 1 from table registration error, 1 from successful init event */
}

/*
Expand Down

0 comments on commit 7b62604

Please sign in to comment.