Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions modules/tbl/fsw/src/cfe_tbl_task_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,17 +430,20 @@ CFE_Status_t CFE_TBL_LoadCmd(const CFE_TBL_LoadCmd_t *data)
}

CFE_TBL_TxnUnlockRegistry(&Txn);
}

if (Status == CFE_SUCCESS)
{
Status = CFE_TBL_ValidateFileIsLoadable(&Txn, &Header.Tbl);
}
if (Status == CFE_SUCCESS)
{
Status = CFE_TBL_ValidateFileIsLoadable(&Txn, &Header.Tbl);
}

if (Status == CFE_SUCCESS)
{
/* Read the file content into the working buffer */
Status = CFE_TBL_LoadContentFromFile(&Txn, FileDescriptor, Header.Tbl.Offset, Header.Tbl.NumBytes);
if (Status == CFE_SUCCESS)
{
/* Read the file content into the working buffer */
Status = CFE_TBL_LoadContentFromFile(&Txn, FileDescriptor, Header.Tbl.Offset, Header.Tbl.NumBytes);
}

/* Done with the file now -- must always close the file regardless of what happened */
OS_close(FileDescriptor);
}

/* If all the above worked out, then set the meta info in the load buffer */
Expand Down
16 changes: 16 additions & 0 deletions modules/tbl/ut-coverage/tbl_ut_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ void Test_CFE_TBL_LoadCmd(void)
UT_SetDefaultReturnValue(UT_KEY(OS_OpenCreate), OS_ERROR);
UtAssert_INT32_EQ(CFE_TBL_LoadCmd(&LoadCmd), CFE_SUCCESS);
CFE_UtAssert_COUNTER_INCR(CFE_TBL_Global.CommandErrorCounter);
UtAssert_STUB_COUNT(OS_close, 0);

/* Test response to inability to find the table in the registry */
UT_InitData_TBL();
Expand All @@ -317,6 +318,7 @@ void Test_CFE_TBL_LoadCmd(void)
UtAssert_INT32_EQ(CFE_TBL_LoadCmd(&LoadCmd), CFE_SUCCESS);
CFE_UtAssert_COUNTER_INCR(CFE_TBL_Global.CommandErrorCounter);
CFE_UtAssert_EVENTSENT(CFE_TBL_NO_SUCH_TABLE_ERR_EID);
UtAssert_STUB_COUNT(OS_close, 1);

/* The rest of the tests will use registry 0, note empty name matches */
RegRec0Ptr->OwnerAppId = AppID;
Expand All @@ -330,6 +332,7 @@ void Test_CFE_TBL_LoadCmd(void)
UtAssert_INT32_EQ(CFE_TBL_LoadCmd(&LoadCmd), CFE_SUCCESS);
CFE_UtAssert_COUNTER_INCR(CFE_TBL_Global.CommandErrorCounter);
UT_TBL_Config(RegRec0Ptr)->DumpOnly = false;
UtAssert_STUB_COUNT(OS_close, 1);

/* Test attempt to load a table with a load already pending */
UT_InitData_TBL();
Expand All @@ -338,6 +341,7 @@ void Test_CFE_TBL_LoadCmd(void)
UT_TBL_SetupLoadBuff(RegRec0Ptr, false, 0);
UtAssert_INT32_EQ(CFE_TBL_LoadCmd(&LoadCmd), CFE_SUCCESS);
CFE_UtAssert_COUNTER_INCR(CFE_TBL_Global.CommandErrorCounter);
UtAssert_STUB_COUNT(OS_close, 1);

/* Test where the file isn't dump only and passes table checks, get a
* working buffer, and there is an extra byte (more data than header
Expand All @@ -362,6 +366,7 @@ void Test_CFE_TBL_LoadCmd(void)
UT_SetReadHeader(&StdFileHeader, sizeof(StdFileHeader));
UtAssert_INT32_EQ(CFE_TBL_LoadCmd(&LoadCmd), CFE_SUCCESS);
CFE_UtAssert_COUNTER_INCR(CFE_TBL_Global.CommandCounter);
UtAssert_STUB_COUNT(OS_close, 1);

/* Test with differing amount of data from header's claim */
UT_InitData_TBL();
Expand All @@ -370,6 +375,7 @@ void Test_CFE_TBL_LoadCmd(void)
UT_SetReadHeader(&StdFileHeader, sizeof(StdFileHeader));
UtAssert_INT32_EQ(CFE_TBL_LoadCmd(&LoadCmd), CFE_SUCCESS);
CFE_UtAssert_COUNTER_INCR(CFE_TBL_Global.CommandErrorCounter);
UtAssert_STUB_COUNT(OS_close, 1);

/* Test with no working buffers available */
UT_InitData_TBL();
Expand All @@ -382,6 +388,7 @@ void Test_CFE_TBL_LoadCmd(void)
UtAssert_INT32_EQ(CFE_TBL_LoadCmd(&LoadCmd), CFE_SUCCESS);
CFE_UtAssert_COUNTER_INCR(CFE_TBL_Global.CommandErrorCounter);
CFE_UtAssert_EVENTSENT(CFE_TBL_NO_WORK_BUFFERS_ERR_EID);
UtAssert_STUB_COUNT(OS_close, 1);

/* Test with interal CFE_TBL_GetWorkingBuffer error (memcpy with matching address */
UT_InitData_TBL();
Expand All @@ -393,6 +400,7 @@ void Test_CFE_TBL_LoadCmd(void)
UT_SetReadHeader(&StdFileHeader, sizeof(StdFileHeader));
UtAssert_INT32_EQ(CFE_TBL_LoadCmd(&LoadCmd), CFE_SUCCESS);
CFE_UtAssert_COUNTER_INCR(CFE_TBL_Global.CommandErrorCounter);
UtAssert_STUB_COUNT(OS_close, 1);

/* Test with table header indicating data beyond size of the table */
UT_InitData_TBL();
Expand All @@ -401,13 +409,15 @@ void Test_CFE_TBL_LoadCmd(void)
UT_SetReadHeader(&StdFileHeader, sizeof(StdFileHeader));
UtAssert_INT32_EQ(CFE_TBL_LoadCmd(&LoadCmd), CFE_SUCCESS);
CFE_UtAssert_COUNTER_INCR(CFE_TBL_Global.CommandErrorCounter);
UtAssert_STUB_COUNT(OS_close, 1);

/* Test with table header indicating no data in the file */
UT_InitData_TBL();
UT_TBL_SetupHeader(&TblFileHeader, 0, 0, CFE_TBL_RegRecGetName(RegRec0Ptr));
UT_SetReadHeader(&StdFileHeader, sizeof(StdFileHeader));
UtAssert_INT32_EQ(CFE_TBL_LoadCmd(&LoadCmd), CFE_SUCCESS);
CFE_UtAssert_COUNTER_INCR(CFE_TBL_Global.CommandErrorCounter);
UtAssert_STUB_COUNT(OS_close, 1);

/* Test where file has partial load for uninitialized table and offset
* is non-zero
Expand All @@ -423,6 +433,7 @@ void Test_CFE_TBL_LoadCmd(void)
UtAssert_INT32_EQ(CFE_TBL_LoadCmd(&LoadCmd), CFE_SUCCESS);
CFE_UtAssert_COUNTER_INCR(CFE_TBL_Global.CommandErrorCounter);
CFE_UtAssert_EVENTSENT(CFE_TBL_PARTIAL_LOAD_ERR_EID);
UtAssert_STUB_COUNT(OS_close, 1);

/* Test where file has the wrong name in the header */
UT_InitData_TBL();
Expand All @@ -433,6 +444,7 @@ void Test_CFE_TBL_LoadCmd(void)
UtAssert_INT32_EQ(CFE_TBL_LoadCmd(&LoadCmd), CFE_SUCCESS);
CFE_UtAssert_COUNTER_INCR(CFE_TBL_Global.CommandErrorCounter);
CFE_UtAssert_EVENTSENT(CFE_TBL_NO_SUCH_TABLE_ERR_EID);
UtAssert_STUB_COUNT(OS_close, 1);

/* Test where file has partial load for uninitialized table and offset
* is zero
Expand All @@ -444,13 +456,15 @@ void Test_CFE_TBL_LoadCmd(void)
UT_SetReadHeader(&StdFileHeader, sizeof(StdFileHeader));
UtAssert_INT32_EQ(CFE_TBL_LoadCmd(&LoadCmd), CFE_SUCCESS);
CFE_UtAssert_COUNTER_INCR(CFE_TBL_Global.CommandErrorCounter);
UtAssert_STUB_COUNT(OS_close, 1);

/* Test response to inability to read the file header */
UT_InitData_TBL();
UT_TBL_ClearLoadPending(RegRec0Ptr);
UT_SetDeferredRetcode(UT_KEY(CFE_FS_ReadHeader), 1, sizeof(CFE_FS_Header_t) - 1);
UtAssert_INT32_EQ(CFE_TBL_LoadCmd(&LoadCmd), CFE_SUCCESS);
CFE_UtAssert_COUNTER_INCR(CFE_TBL_Global.CommandErrorCounter);
UtAssert_STUB_COUNT(OS_close, 1);

/* Test where file has partial load for initialized table and offset
* is non-zero
Expand All @@ -463,6 +477,7 @@ void Test_CFE_TBL_LoadCmd(void)
UtAssert_INT32_EQ(CFE_TBL_LoadCmd(&LoadCmd), CFE_SUCCESS);
CFE_UtAssert_EVENTSENT(CFE_TBL_ZERO_LENGTH_LOAD_ERR_EID);
CFE_UtAssert_COUNTER_INCR(CFE_TBL_Global.CommandErrorCounter);
UtAssert_STUB_COUNT(OS_close, 1);

/* Test where file has partial load for initialized table and offset
* is non-zero
Expand All @@ -473,6 +488,7 @@ void Test_CFE_TBL_LoadCmd(void)
UT_SetReadHeader(&StdFileHeader, sizeof(StdFileHeader));
UtAssert_INT32_EQ(CFE_TBL_LoadCmd(&LoadCmd), CFE_SUCCESS);
CFE_UtAssert_COUNTER_INCR(CFE_TBL_Global.CommandErrorCounter);
UtAssert_STUB_COUNT(OS_close, 1);
}

/*
Expand Down
Loading