Skip to content

Commit

Permalink
Merge pull request #286 from havencarlson/fix#285-goto
Browse files Browse the repository at this point in the history
Fix #285, flatten logic in CF_CFDP_InitEngine() to fix bug
  • Loading branch information
dzbaker authored Jul 21, 2022
2 parents eba87df + 22e2855 commit 0774746
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 45 deletions.
86 changes: 41 additions & 45 deletions fsw/src/cf_cfdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1031,58 +1031,54 @@ int32 CF_CFDP_InitEngine(void)
"CF: failed to create pipe %s, returned 0x%08lx", nbuf, (unsigned long)ret);
break;
}
else

ret = CFE_SB_SubscribeLocal(CFE_SB_ValueToMsgId(CF_AppData.config_table->chan[i].mid_input),
CF_AppData.engine.channels[i].pipe,
CF_AppData.config_table->chan[i].pipe_depth_input);
if (ret != CFE_SUCCESS)
{
CFE_EVS_SendEvent(CF_EID_ERR_INIT_SUB, CFE_EVS_EventType_ERROR,
"CF: failed to subscribe to MID 0x%lx, returned 0x%08lx",
(unsigned long)CF_AppData.config_table->chan[i].mid_input, (unsigned long)ret);
break;
}

if (CF_AppData.config_table->chan[i].sem_name[0])
{
ret = CFE_SB_SubscribeLocal(CFE_SB_ValueToMsgId(CF_AppData.config_table->chan[i].mid_input),
CF_AppData.engine.channels[i].pipe,
CF_AppData.config_table->chan[i].pipe_depth_input);
if (ret != CFE_SUCCESS)
ret = OS_CountSemGetIdByName(&CF_AppData.engine.channels[i].sem_id,
CF_AppData.config_table->chan[i].sem_name);
if (ret != OS_SUCCESS)
{
CFE_EVS_SendEvent(CF_EID_ERR_INIT_SUB, CFE_EVS_EventType_ERROR,
"CF: failed to subscribe to MID 0x%lx, returned 0x%08lx",
(unsigned long)CF_AppData.config_table->chan[i].mid_input, (unsigned long)ret);
CFE_EVS_SendEvent(CF_EID_ERR_INIT_SEM, CFE_EVS_EventType_ERROR,
"CF: failed to get sem id for name %s, error=%ld",
CF_AppData.config_table->chan[i].sem_name, (long)ret);
break;
}
else if (CF_AppData.config_table->chan[i].sem_name[0])
{
ret = OS_CountSemGetIdByName(&CF_AppData.engine.channels[i].sem_id,
CF_AppData.config_table->chan[i].sem_name);
if (ret != OS_SUCCESS)
{
CFE_EVS_SendEvent(CF_EID_ERR_INIT_SEM, CFE_EVS_EventType_ERROR,
"CF: failed to get sem id for name %s, error=%ld",
CF_AppData.config_table->chan[i].sem_name, (long)ret);
break;
}
else
{
for (j = 0; j < CF_NUM_TRANSACTIONS_PER_CHANNEL; ++j, ++t)
{
int k;

t->chan_num = i;
CF_FreeTransaction(t);

for (k = 0; k < CF_Direction_NUM; ++k, ++c)
{
CF_Assert((chunk_mem_offset + CF_DIR_MAX_CHUNKS[k][i]) <= CF_NUM_CHUNKS_ALL_CHANNELS);
CF_ChunkListInit(&c->chunks, CF_DIR_MAX_CHUNKS[k][i],
&CF_AppData.engine.chunk_mem[chunk_mem_offset]);
chunk_mem_offset += CF_DIR_MAX_CHUNKS[k][i];
CF_CList_InitNode(&c->cl_node);
CF_CList_InsertBack(&CF_AppData.engine.channels[i].cs[k], &c->cl_node);
}
}
}

for (j = 0; j < CF_NUM_HISTORIES_PER_CHANNEL; ++j)
{
CF_History_t *h = &CF_AppData.engine.histories[(i * CF_NUM_HISTORIES_PER_CHANNEL) + j];
CF_CList_InitNode(&h->cl_node);
CF_CList_InsertBack_Ex(&CF_AppData.engine.channels[i], CF_QueueIdx_HIST_FREE, &h->cl_node);
}
}
for (j = 0; j < CF_NUM_TRANSACTIONS_PER_CHANNEL; ++j, ++t)
{
int k;

t->chan_num = i;
CF_FreeTransaction(t);

for (k = 0; k < CF_Direction_NUM; ++k, ++c)
{
CF_Assert((chunk_mem_offset + CF_DIR_MAX_CHUNKS[k][i]) <= CF_NUM_CHUNKS_ALL_CHANNELS);
CF_ChunkListInit(&c->chunks, CF_DIR_MAX_CHUNKS[k][i], &CF_AppData.engine.chunk_mem[chunk_mem_offset]);
chunk_mem_offset += CF_DIR_MAX_CHUNKS[k][i];
CF_CList_InitNode(&c->cl_node);
CF_CList_InsertBack(&CF_AppData.engine.channels[i].cs[k], &c->cl_node);
}
}

for (j = 0; j < CF_NUM_HISTORIES_PER_CHANNEL; ++j)
{
CF_History_t *h = &CF_AppData.engine.histories[(i * CF_NUM_HISTORIES_PER_CHANNEL) + j];
CF_CList_InitNode(&h->cl_node);
CF_CList_InsertBack_Ex(&CF_AppData.engine.channels[i], CF_QueueIdx_HIST_FREE, &h->cl_node);
}
}

if (ret == CFE_SUCCESS)
Expand Down
1 change: 1 addition & 0 deletions unit-test/cf_cfdp_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ void Test_CF_CFDP_InitEngine(void)
UT_CFDP_SetupBasicTestState(UT_CF_Setup_NONE, NULL, NULL, NULL, NULL, &config);
UtAssert_INT32_EQ(CF_CFDP_InitEngine(), 0);
UtAssert_BOOL_TRUE(CF_AppData.engine.enabled);
UtAssert_STUB_COUNT(CF_FreeTransaction, CF_NUM_TRANSACTIONS_PER_CHANNEL);

/* nominal call, with sem */
UT_CFDP_SetupBasicTestState(UT_CF_Setup_NONE, NULL, NULL, NULL, NULL, &config);
Expand Down

0 comments on commit 0774746

Please sign in to comment.