diff --git a/fsw/src/ds_appdefs.h b/fsw/src/ds_appdefs.h index b538a08..44efcdf 100644 --- a/fsw/src/ds_appdefs.h +++ b/fsw/src/ds_appdefs.h @@ -49,9 +49,8 @@ #define DS_INDEX_NONE -1 /**< \brief Packet filter table look-up = not found */ -#define DS_PATH_SEPARATOR '/' /**< \brief File system path separator */ -#define DS_EMPTY_STRING "" /**< \brief Empty string buffer entries in DS tables */ -#define DS_STRING_TERMINATOR '\0' /**< \brief ASCIIZ string terminator character */ +#define DS_PATH_SEPARATOR '/' /**< \brief File system path separator */ +#define DS_EMPTY_STRING "" /**< \brief Empty string buffer entries in DS tables */ #define DS_TABLE_VERIFY_ERR 0xFFFFFFFF /**< \brief Table verification error return value */ diff --git a/fsw/src/ds_cmds.c b/fsw/src/ds_cmds.c index 4f65125..6e332ef 100644 --- a/fsw/src/ds_cmds.c +++ b/fsw/src/ds_cmds.c @@ -763,7 +763,7 @@ void DS_CmdSetDestPath(const CFE_SB_Buffer_t *BufPtr) ** Set path portion of destination table filename... */ pDest = &DS_AppData.DestFileTblPtr->File[DS_DestPathCmd->FileTableIndex]; - strcpy(pDest->Pathname, DS_DestPathCmd->Pathname); + strncpy(pDest->Pathname, DS_DestPathCmd->Pathname, sizeof(pDest->Pathname)); /* ** Notify cFE that we have modified the table data... @@ -833,7 +833,7 @@ void DS_CmdSetDestBase(const CFE_SB_Buffer_t *BufPtr) ** Set base portion of destination table filename... */ pDest = &DS_AppData.DestFileTblPtr->File[DS_DestBaseCmd->FileTableIndex]; - strcpy(pDest->Basename, DS_DestBaseCmd->Basename); + strncpy(pDest->Basename, DS_DestBaseCmd->Basename, sizeof(pDest->Basename)); /* ** Notify cFE that we have modified the table data... @@ -903,7 +903,7 @@ void DS_CmdSetDestExt(const CFE_SB_Buffer_t *BufPtr) ** Set extension portion of destination table filename... */ pDest = &DS_AppData.DestFileTblPtr->File[DS_DestExtCmd->FileTableIndex]; - strcpy(pDest->Extension, DS_DestExtCmd->Extension); + strncpy(pDest->Extension, DS_DestExtCmd->Extension, sizeof(pDest->Extension)); /* ** Notify cFE that we have modified the table data... @@ -1366,7 +1366,8 @@ void DS_CmdGetFileInfo(const CFE_SB_Buffer_t *BufPtr) /* ** Set current open filename... */ - strcpy(DS_FileInfoPkt.FileInfo[i].FileName, DS_AppData.FileStatus[i].FileName); + strncpy(DS_FileInfoPkt.FileInfo[i].FileName, DS_AppData.FileStatus[i].FileName, + sizeof(DS_FileInfoPkt.FileInfo[i].FileName)); } } diff --git a/fsw/src/ds_file.c b/fsw/src/ds_file.c index 768bb78..a8e77d4 100644 --- a/fsw/src/ds_file.c +++ b/fsw/src/ds_file.c @@ -398,7 +398,7 @@ void DS_FileWriteHeader(int32 FileIndex) */ memset(&CFE_FS_Header, 0, sizeof(CFE_FS_Header)); CFE_FS_Header.SubType = DS_FILE_HDR_SUBTYPE; - strcpy(CFE_FS_Header.Description, DS_FILE_HDR_DESCRIPTION); + strncpy(CFE_FS_Header.Description, DS_FILE_HDR_DESCRIPTION, sizeof(CFE_FS_Header.Description)); /* ** Let cFE finish the init and write the primary header... @@ -421,7 +421,7 @@ void DS_FileWriteHeader(int32 FileIndex) memset(&DS_FileHeader, 0, sizeof(DS_FileHeader)); DS_FileHeader.FileTableIndex = FileIndex; DS_FileHeader.FileNameType = DestFile->FileNameType; - strcpy(DS_FileHeader.FileName, FileStatus->FileName); + strncpy(DS_FileHeader.FileName, FileStatus->FileName, sizeof(DS_FileHeader.FileName)); /* ** Manually write the secondary header... @@ -501,7 +501,7 @@ void DS_FileCreateDest(uint32 FileIndex) */ DS_FileCreateName(FileIndex); - if (FileStatus->FileName[0] != DS_STRING_TERMINATOR) + if (FileStatus->FileName[0] != 0) { /* ** Success - create a new destination file... @@ -574,128 +574,73 @@ void DS_FileCreateName(uint32 FileIndex) DS_DestFileEntry_t *DestFile = &DS_AppData.DestFileTblPtr->File[FileIndex]; DS_AppFileStatus_t *FileStatus = &DS_AppData.FileStatus[FileIndex]; int32 TotalLength = 0; - int32 WorknameLen = 2 * DS_TOTAL_FNAME_BUFSIZE; - char Workname[WorknameLen]; + char Workname[2 * DS_TOTAL_FNAME_BUFSIZE]; char Sequence[DS_TOTAL_FNAME_BUFSIZE]; - Workname[0] = DS_STRING_TERMINATOR; - Sequence[0] = DS_STRING_TERMINATOR; + /* Copy in path */ + CFE_SB_MessageStringGet(Workname, DestFile->Pathname, NULL, sizeof(Workname), sizeof(DestFile->Pathname)); + TotalLength = strlen(Workname); - /* - ** Start with the path portion of the filename... - */ - strncpy(Workname, DestFile->Pathname, WorknameLen - 1); - Workname[WorknameLen - 1] = '\0'; - TotalLength = strlen(Workname); - - /* - ** Add a path separator (if needed) before appending the base name... - */ if (TotalLength > 0) { + /* Add separator if needed */ if (Workname[TotalLength - 1] != DS_PATH_SEPARATOR) { - /* if there's room, write the path separator and a new terminating - character. If there's not room, this will be caught by the - next condition */ - if (TotalLength != (WorknameLen - 1)) - { - Workname[TotalLength] = DS_PATH_SEPARATOR; - Workname[TotalLength + 1] = DS_STRING_TERMINATOR; - } + /* There's always space since Workname is twice the size of Pathname */ + Workname[TotalLength++] = DS_PATH_SEPARATOR; } - } - else - { - /* If path name is empty, start with the path separator. This should - * not happen because the path name is verified as non-empty in - * DS_TableVerifyDestFileEntry */ - CFE_EVS_SendEvent(DS_FILE_CREATE_EMPTY_PATH_ERR_EID, CFE_EVS_EventType_ERROR, - "FILE NAME error: Path empty. dest = %d, path = '%s'", (int)FileIndex, DestFile->Pathname); - - /* - ** Something needs to get fixed before we try again... - */ - DS_AppData.FileStatus[FileIndex].FileState = DS_DISABLED; - - return; - } - /* - ** Verify that the path plus the base portion is not too large... - */ - if ((strlen(Workname) + strlen(DestFile->Basename)) < DS_TOTAL_FNAME_BUFSIZE) - { - /* - ** Append the base portion to the path portion... - */ - strcat(Workname, DestFile->Basename); + /* Add base name */ + CFE_SB_MessageStringGet(&Workname[TotalLength], DestFile->Basename, NULL, sizeof(Workname) - TotalLength, + sizeof(DestFile->Basename)); + TotalLength = strlen(Workname); - /* - ** Create the sequence portion of the filename... - */ + /* Create the sequence portion of the filename */ DS_FileCreateSequence(Sequence, DestFile->FileNameType, FileStatus->FileCount); - /* - ** Verify that the path/base plus the sequence portion is not too large... - */ - if ((strlen(Workname) + strlen(Sequence)) < DS_TOTAL_FNAME_BUFSIZE) - { - /* - ** Append the sequence portion to the path/base portion... - */ - strcat(Workname, Sequence); + /* Sequence is always null terminated so can use strncat */ + strncat(&Workname[TotalLength], Sequence, sizeof(Workname) - TotalLength - 1); + TotalLength = strlen(Workname); - /* - ** Check for an optional file extension... - */ - if (strlen(DestFile->Extension) > 0) + /* Only add extension if not empty */ + if (DestFile->Extension[0] != '\0') + { + /* Add a "." character (if needed) before appending the extension */ + if (DestFile->Extension[0] != '.') { - /* - ** Add a "." character (if needed) before appending the extension... - */ - if (DestFile->Extension[0] != '.') - { - strcat(Workname, "."); - } - - /* - ** Append the extension portion to the path/base+sequence portion... - */ - strcat(Workname, DestFile->Extension); + strncat(Workname, ".", sizeof(Workname) - strlen(Workname) - 1); + TotalLength++; } - /* - ** Final test - is "path/base+sequence.extension" length valid?... - */ - if (strlen(Workname) < DS_TOTAL_FNAME_BUFSIZE) - { - /* - ** Success - copy workname to filename buffer... - */ - strcpy(FileStatus->FileName, Workname); - } + /* Append the extension portion to the path/base+sequence portion */ + CFE_SB_MessageStringGet(&Workname[TotalLength], DestFile->Extension, NULL, sizeof(Workname) - TotalLength, + sizeof(DestFile->Extension)); } - } - if (FileStatus->FileName[0] == DS_STRING_TERMINATOR) + /* Confirm working name fits */ + if (strlen(Workname) < DS_TOTAL_FNAME_BUFSIZE) + { + /* Success - copy workname to filename buffer */ + strcpy(FileStatus->FileName, Workname); + } + else + { + /* Error - send event and disable destination */ + CFE_EVS_SendEvent(DS_FILE_NAME_ERR_EID, CFE_EVS_EventType_ERROR, + "FILE NAME error: dest = %d, path = '%s', base = '%s', seq = '%s', ext = '%s'", + (int)FileIndex, DestFile->Pathname, DestFile->Basename, Sequence, DestFile->Extension); + DS_AppData.FileStatus[FileIndex].FileState = DS_DISABLED; + } + } + else { - /* - ** Error - send event and disable destination... - */ - CFE_EVS_SendEvent(DS_FILE_NAME_ERR_EID, CFE_EVS_EventType_ERROR, - "FILE NAME error: dest = %d, path = '%s', base = '%s', seq = '%s', ext = '%s'", - (int)FileIndex, DestFile->Pathname, DestFile->Basename, Sequence, DestFile->Extension); - - /* - ** Something needs to get fixed before we try again... - */ + /* Send event and disable for invalid path */ + CFE_EVS_SendEvent(DS_FILE_CREATE_EMPTY_PATH_ERR_EID, CFE_EVS_EventType_ERROR, + "FILE NAME error: Path empty. dest = %d, path = '%s'", (int)FileIndex, DestFile->Pathname); DS_AppData.FileStatus[FileIndex].FileState = DS_DISABLED; } - return; - } /* End of DS_FileCreateName() */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -742,7 +687,7 @@ void DS_FileCreateSequence(char *Buffer, uint32 Type, uint32 Count) /* ** Add string terminator... */ - Buffer[DS_SEQUENCE_DIGITS] = DS_STRING_TERMINATOR; + Buffer[DS_SEQUENCE_DIGITS] = '\0'; } else if (Type == DS_BY_TIME) { @@ -817,14 +762,14 @@ void DS_FileCreateSequence(char *Buffer, uint32 Type, uint32 Count) /* ** Step 7: Add string terminator... */ - Buffer[DS_TERM_INDEX] = DS_STRING_TERMINATOR; + Buffer[DS_TERM_INDEX] = '\0'; } else { /* ** Bad filename type, init buffer as empty... */ - Buffer[0] = DS_STRING_TERMINATOR; + Buffer[0] = '\0'; } return; @@ -903,7 +848,8 @@ void DS_FileCloseDest(int32 FileIndex) /* ** Make sure directory name does not end with slash character... */ - strcpy(PathName, DS_AppData.DestFileTblPtr->File[FileIndex].Movename); + CFE_SB_MessageStringGet(PathName, DS_AppData.DestFileTblPtr->File[FileIndex].Movename, NULL, sizeof(PathName), + sizeof(DS_AppData.DestFileTblPtr->File[FileIndex].Movename)); PathLength = strlen(PathName); if (PathName[PathLength - 1] == '/') { @@ -960,12 +906,10 @@ void DS_FileCloseDest(int32 FileIndex) CFE_EVS_SendEvent(DS_MOVE_FILE_ERR_EID, CFE_EVS_EventType_ERROR, "FILE MOVE error: dir name = '%s', filename = '%s'", PathName, FileName); } - } - /* - ** Get the directory name... - */ - strncpy(FileStatus->FileName, PathName, sizeof(PathName)); + /* Update the path name for reporting */ + strncpy(FileStatus->FileName, PathName, sizeof(PathName)); + } #else /* ** Close the file... @@ -1082,7 +1026,7 @@ void DS_FileTransmit(DS_AppFileStatus_t *FileStatus) /* ** Set current open filename... */ - strcpy(PktBuf->Pkt.FileInfo.FileName, FileStatus->FileName); + strncpy(PktBuf->Pkt.FileInfo.FileName, FileStatus->FileName, sizeof(PktBuf->Pkt.FileInfo.FileName)); /* ** Timestamp and send file info telemetry... diff --git a/fsw/src/ds_table.c b/fsw/src/ds_table.c index 72e846c..89694e7 100644 --- a/fsw/src/ds_table.c +++ b/fsw/src/ds_table.c @@ -828,8 +828,8 @@ bool DS_TableVerifyCount(uint32 SequenceCount) void DS_TableSubscribe(void) { DS_PacketEntry_t *FilterPackets = NULL; - CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; - int32 i = 0; + CFE_SB_MsgId_t MessageID; + int32 i; FilterPackets = DS_AppData.FilterTblPtr->Packet; @@ -863,8 +863,8 @@ void DS_TableSubscribe(void) void DS_TableUnsubscribe(void) { DS_PacketEntry_t *FilterPackets = NULL; - CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; - int32 i = 0; + CFE_SB_MsgId_t MessageID; + int32 i; FilterPackets = DS_AppData.FilterTblPtr->Packet; diff --git a/unit-test/ds_file_tests.c b/unit-test/ds_file_tests.c index 4dd3bfa..f9d792c 100644 --- a/unit-test/ds_file_tests.c +++ b/unit-test/ds_file_tests.c @@ -45,65 +45,6 @@ #include #include -int32 TestDataLength = 10; - -/* Some minimal hooks for OS functions for which the usual stubs have too much - * implementation */ -void UT_OS_CLOSE_SuccessHandler(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) -{ - // UT_Stub_SetReturnValue(FuncKey, OS_SUCCESS); - int32 status = OS_SUCCESS; - UT_Stub_GetInt32StatusCode(Context, &status); -} /* end UT_OS_CLOSE_SuccessHandler */ - -void UT_OS_CLOSE_FailHandler(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) -{ - // return OS_ERROR; - int32 status = OS_ERROR; - UT_Stub_GetInt32StatusCode(Context, &status); - -} /* end UT_OS_CLOSE_FailHandler */ - -void UT_CFE_FS_WriteHeader_FailHandler(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) -{ - // return -1; - int32 status = -1; - UT_Stub_GetInt32StatusCode(Context, &status); - -} /* end UT_CFE_FS_WriteHeader_FailHandler */ - -void UT_CFE_FS_WriteHeader_SuccessHandler(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) -{ - // return sizeof(CFE_FS_Header_t); - int32 status = sizeof(CFE_FS_Header_t); - UT_Stub_GetInt32StatusCode(Context, &status); - -} /* end UT_CFE_FS_WriteHeader_SuccessHandler */ - -void UT_OS_write_FailHandler(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) -{ - // return -1; - int32 status = -1; - UT_Stub_GetInt32StatusCode(Context, &status); - -} /* end UT_OS_write_FailHandler */ - -void UT_OS_write_SuccessHandler(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) -{ - // return sizeof(DS_FileHeader_t); - int32 status = sizeof(DS_FileHeader_t); - UT_Stub_GetInt32StatusCode(Context, &status); - -} /* end UT_OS_write_SuccessHandler */ - -void UT_OS_write_DataHandler(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) -{ - // return 10; - int32 status = TestDataLength; - UT_Stub_GetInt32StatusCode(Context, &status); - -} /* end UT_OS_write_DataHandler */ - void UT_CFE_TIME_Print_CustomHandler(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context) { char *PrintBuffer = UT_Hook_GetArgValueByName(Context, "PrintBuffer", char *); @@ -112,29 +53,8 @@ void UT_CFE_TIME_Print_CustomHandler(void *UserObj, UT_EntryKey_t FuncKey, const } /* * Helper Functions - * - * This file ds_file.c has several functions which call other functions within - * the same file. This section includes utilities used to complete the setup - * steps which require the called functions to succeed. */ -void UT_DS_SetupFileUpdateHeaderSuccess(void) -{ -#if (DS_FILE_HEADER_TYPE == DS_FILE_HEADER_CFE) - UT_SetDefaultReturnValue(UT_KEY(OS_lseek), sizeof(CFE_FS_Header_t)); - UT_SetDefaultReturnValue(UT_KEY(OS_write), sizeof(CFE_TIME_SysTime_t)); -#endif -} - -void UT_DS_SetupFileCloseDestSuccess(void) -{ - - UT_SetHandlerFunction(UT_KEY(OS_close), &UT_OS_CLOSE_SuccessHandler, NULL); -#if (DS_MOVE_FILES == true) - UT_SetDefaultReturnValue(UT_KEY(OS_mv), OS_SUCCESS); -#endif -} - void UT_DS_SetDestFileEntry(DS_DestFileEntry_t *DestFileEntryPtr) { strncpy(DestFileEntryPtr->Pathname, "path", sizeof(DestFileEntryPtr->Pathname)); @@ -322,8 +242,6 @@ void DS_FileSetupWrite_Test_Nominal(void) UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_Size, sizeof(forced_Size), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &forced_CmdCode, sizeof(forced_CmdCode), false); - UT_SetHandlerFunction(UT_KEY(OS_close), &UT_OS_CLOSE_SuccessHandler, NULL); - DS_AppData.FileStatus[FileIndex].FileHandle = DS_UT_OBJID_1; DS_AppData.DestFileTblPtr->File[FileIndex].MaxFileSize = 100; @@ -348,9 +266,6 @@ void DS_FileSetupWrite_Test_FileHandleClosed(void) UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_Size, sizeof(forced_Size), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &forced_CmdCode, sizeof(forced_CmdCode), false); - UT_SetHandlerFunction(UT_KEY(OS_close), &UT_OS_CLOSE_SuccessHandler, NULL); - UT_SetHandlerFunction(UT_KEY(OS_OpenCreate), &UT_OS_write_SuccessHandler, NULL); - DS_AppData.DestFileTblPtr->File[FileIndex].MaxFileSize = 100; UT_DS_SetDestFileEntry(&DS_AppData.DestFileTblPtr->File[FileIndex]); DS_AppData.DestFileTblPtr->File[FileIndex].FileNameType = DS_BY_COUNT; @@ -358,12 +273,15 @@ void DS_FileSetupWrite_Test_FileHandleClosed(void) DS_AppData.FileStatus[FileIndex].FileCount = 0; DS_AppData.FileStatus[FileIndex].FileSize = 3; + /* Fail writing the header so the data won't write */ + UT_SetDefaultReturnValue(UT_KEY(CFE_FS_WriteHeader), -1); + /* Execute the function being tested */ UtAssert_VOIDCALL(DS_FileSetupWrite(FileIndex, &UT_CmdBuf.Buf)); /* Verify results */ - UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); - UtAssert_STUB_COUNT(DS_FileWriteData, 0); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); /* Don't care about subroutine event */ + UtAssert_STUB_COUNT(OS_write, 0); UtAssert_STUB_COUNT(OS_OpenCreate, 1); } /* end DS_FileSetupWrite_Test_FileHandleClosed */ @@ -374,9 +292,8 @@ void DS_FileSetupWrite_Test_MaxFileSizeExceeded(void) UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_Size, sizeof(forced_Size), false); - UT_SetHandlerFunction(UT_KEY(OS_close), &UT_OS_CLOSE_SuccessHandler, NULL); - - DS_AppData.FileStatus[FileIndex].FileHandle = DS_UT_OBJID_1; + /* Set up the handle */ + OS_OpenCreate(&DS_AppData.FileStatus[FileIndex].FileHandle, NULL, 0, 0); DS_AppData.DestFileTblPtr->File[FileIndex].MaxFileSize = 5; DS_AppData.FileStatus[FileIndex].FileSize = 10; @@ -385,9 +302,6 @@ void DS_FileSetupWrite_Test_MaxFileSizeExceeded(void) strncpy(DS_AppData.FileStatus[FileIndex].FileName, "directory1/", sizeof(DS_AppData.FileStatus[FileIndex].FileName)); - /* Set to prevent an error message that we don't care about in this test */ - UT_SetDefaultReturnValue(UT_KEY(CFE_FS_WriteHeader), sizeof(CFE_FS_Header_t)); - #if (DS_MOVE_FILES == true) strncpy(DS_AppData.DestFileTblPtr->File[FileIndex].Movename, "directory2/movename/", sizeof(DS_AppData.DestFileTblPtr->File[FileIndex].Movename)); @@ -404,7 +318,6 @@ void DS_FileSetupWrite_Test_MaxFileSizeExceeded(void) void DS_FileWriteData_Test_Nominal(void) { int32 FileIndex = 0; - uint32 DataLength = TestDataLength; size_t forced_Size = sizeof(DS_NoopCmd_t); CFE_SB_MsgId_t forced_MsgID = CFE_SB_ValueToMsgId(DS_CMD_MID); CFE_MSG_FcnCode_t forced_CmdCode = DS_NOOP_CC; @@ -413,18 +326,13 @@ void DS_FileWriteData_Test_Nominal(void) UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_Size, sizeof(forced_Size), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &forced_CmdCode, sizeof(forced_CmdCode), false); - /* Set to return DataLength to satisfy condition "if (Result == DataLength)" */ - // UT_SetHandlerFunction(UT_KEY(OS_write), &UT_OS_write_DataHandler, NULL); - UT_SetDefaultReturnValue(UT_KEY(OS_write), DataLength); - UT_SetHandlerFunction(UT_KEY(OS_close), &UT_OS_CLOSE_SuccessHandler, NULL); - /* Execute the function being tested */ - DS_FileWriteData(FileIndex, &UT_CmdBuf.Buf, DataLength); + DS_FileWriteData(FileIndex, &UT_CmdBuf.Buf, sizeof(UT_CmdBuf.Buf)); /* Verify results */ UtAssert_UINT32_EQ(DS_AppData.FileWriteCounter, 1); - UtAssert_UINT32_EQ(DS_AppData.FileStatus[FileIndex].FileSize, 10); - UtAssert_UINT32_EQ(DS_AppData.FileStatus[FileIndex].FileGrowth, 10); + UtAssert_UINT32_EQ(DS_AppData.FileStatus[FileIndex].FileSize, sizeof(UT_CmdBuf.Buf)); + UtAssert_UINT32_EQ(DS_AppData.FileStatus[FileIndex].FileGrowth, sizeof(UT_CmdBuf.Buf)); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); @@ -439,13 +347,15 @@ void DS_FileWriteData_Test_Error(void) CFE_SB_MsgId_t forced_MsgID = CFE_SB_ValueToMsgId(DS_CMD_MID); CFE_MSG_FcnCode_t forced_CmdCode = DS_NOOP_CC; + /* Set up the handle */ + OS_OpenCreate(&DS_AppData.FileStatus[FileIndex].FileHandle, NULL, 0, 0); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &forced_MsgID, sizeof(forced_MsgID), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &forced_Size, sizeof(forced_Size), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &forced_CmdCode, sizeof(forced_CmdCode), false); /* Set to reach error case being tested (DS_FileWriteError) */ UT_SetDefaultReturnValue(UT_KEY(OS_write), -1); - UT_SetHandlerFunction(UT_KEY(OS_close), &UT_OS_CLOSE_SuccessHandler, NULL); strncpy(DS_AppData.FileStatus[FileIndex].FileName, "directory1/", sizeof(DS_AppData.FileStatus[FileIndex].FileName)); @@ -468,12 +378,6 @@ void DS_FileWriteHeader_Test_PlatformConfigCFE_Nominal(void) DS_AppData.DestFileTblPtr->File[FileIndex].FileNameType = 1; - /* Set to satisfy condition "if (Result == sizeof(CFE_FS_Header_t))" */ - UT_SetDefaultReturnValue(UT_KEY(CFE_FS_WriteHeader), sizeof(CFE_FS_Header_t)); - - /* Set to satisfy condition "if (Result == sizeof(DS_FileHeader_t))" */ - UT_SetDefaultReturnValue(UT_KEY(OS_write), sizeof(DS_FileHeader_t)); - /* Execute the function being tested */ DS_FileWriteHeader(FileIndex); @@ -492,14 +396,14 @@ void DS_FileWriteHeader_Test_PrimaryHeaderError(void) { int32 FileIndex = 0; + /* Set up the handle */ + OS_OpenCreate(&DS_AppData.FileStatus[FileIndex].FileHandle, NULL, 0, 0); + DS_AppData.DestFileTblPtr->File[FileIndex].FileNameType = 1; DS_AppData.DestFileTblPtr->File[FileIndex].Movename[0] = '\0'; /* Set to generate primary header error */ UT_SetDefaultReturnValue(UT_KEY(CFE_FS_WriteHeader), -1); - /* Handle closure in response to the error */ - UT_SetHandlerFunction(UT_KEY(OS_close), &UT_OS_CLOSE_SuccessHandler, NULL); - /* Execute the function being tested */ DS_FileWriteHeader(FileIndex); @@ -515,18 +419,14 @@ void DS_FileWriteHeader_Test_SecondaryHeaderError(void) { int32 FileIndex = 0; + /* Set up the handle */ + OS_OpenCreate(&DS_AppData.FileStatus[FileIndex].FileHandle, NULL, 0, 0); + DS_AppData.DestFileTblPtr->File[FileIndex].FileNameType = 1; DS_AppData.DestFileTblPtr->File[FileIndex].Movename[0] = '\0'; - /* Set to satisfy condition "if (Result == sizeof(CFE_FS_Header_t))" */ - // UT_SetHandlerFunction(UT_KEY(CFE_FS_WriteHeader), &UT_CFE_FS_WriteHeader_SuccessHandler, NULL); - UT_SetDefaultReturnValue(UT_KEY(CFE_FS_WriteHeader), sizeof(CFE_FS_Header_t)); - - /* Handle closure in response to the error */ - UT_SetHandlerFunction(UT_KEY(OS_close), &UT_OS_CLOSE_SuccessHandler, NULL); /* Set to generate secondary header error */ - // UT_SetHandlerFunction(UT_KEY(OS_write), &UT_OS_write_FailHandler, NULL); UT_SetDefaultReturnValue(UT_KEY(OS_write), -1); /* Execute the function being tested */ @@ -546,13 +446,14 @@ void DS_FileWriteError_Test(void) uint32 DataLength = 10; int32 WriteResult = -1; + /* Set up the handle */ + OS_OpenCreate(&DS_AppData.FileStatus[FileIndex].FileHandle, NULL, 0, 0); + DS_AppData.DestFileTblPtr->File[FileIndex].FileNameType = 1; DS_AppData.DestFileTblPtr->File[FileIndex].Movename[0] = '\0'; strncpy(DS_AppData.FileStatus[FileIndex].FileName, "filename", sizeof(DS_AppData.FileStatus[FileIndex].FileName)); - UT_SetHandlerFunction(UT_KEY(OS_close), &UT_OS_CLOSE_SuccessHandler, NULL); - /* Execute the function being tested */ DS_FileWriteError(FileIndex, DataLength, WriteResult); @@ -576,23 +477,9 @@ void DS_FileCreateDest_Test_Nominal(void) DS_AppData.FileStatus[FileIndex].FileCount = 1; DS_AppData.FileStatus[FileIndex].FileHandle = DS_UT_OBJID_1; - /* Setup for DS_FileWriteHeader to succeed */ -#if DS_FILE_HEADER_TYPE == DS_FILE_HEADER_CFE - UT_SetDefaultReturnValue(UT_KEY(CFE_FS_WriteHeader), sizeof(CFE_FS_Header_t)); - UT_SetDefaultReturnValue(UT_KEY(OS_write), sizeof(DS_FileHeader_t)); -#endif - /* Set to fail the condition "if (Result < 0)" */ UT_SetDefaultReturnValue(UT_KEY(OS_OpenCreate), OS_SUCCESS); - /* Set to prevent error messages in subfunction DS_FileWriteHeader that we don't care about in this test */ - UT_SetHandlerFunction(UT_KEY(CFE_FS_WriteHeader), &UT_CFE_FS_WriteHeader_SuccessHandler, NULL); - -#if DS_FILE_HEADER_TYPE == DS_FILE_HEADER_CFE - /* Set to prevent error messages in subfunction DS_FileWriteHeader that we don't care about in this test */ - UT_SetHandlerFunction(UT_KEY(OS_write), &UT_OS_write_SuccessHandler, NULL); -#endif - DS_AppData.DestFileTblPtr->File[FileIndex].FileNameType = DS_BY_COUNT; /* Execute the function being tested */ @@ -620,8 +507,6 @@ void DS_FileCreateDest_Test_StringTerminate(void) { uint32 FileIndex = 0; - DS_AppData.FileStatus[FileIndex].FileName[0] = DS_STRING_TERMINATOR; - /* Execute the function being tested */ UtAssert_VOIDCALL(DS_FileCreateDest(FileIndex)); @@ -640,23 +525,9 @@ void DS_FileCreateDest_Test_NominalRollover(void) DS_AppData.FileStatus[FileIndex].FileCount = DS_MAX_SEQUENCE_COUNT; DS_AppData.FileStatus[FileIndex].FileHandle = DS_UT_OBJID_1; - /* Setup for DS_FileWriteHeader to succeed */ -#if DS_FILE_HEADER_TYPE == DS_FILE_HEADER_CFE - UT_SetDefaultReturnValue(UT_KEY(CFE_FS_WriteHeader), sizeof(CFE_FS_Header_t)); - UT_SetDefaultReturnValue(UT_KEY(OS_write), sizeof(DS_FileHeader_t)); -#endif - /* Set to fail the condition "if (Result < 0)" */ UT_SetDefaultReturnValue(UT_KEY(OS_OpenCreate), OS_SUCCESS); - /* Set to prevent error messages in subfunction DS_FileWriteHeader that we don't care about in this test */ - UT_SetHandlerFunction(UT_KEY(CFE_FS_WriteHeader), &UT_CFE_FS_WriteHeader_SuccessHandler, NULL); - -#if DS_FILE_HEADER_TYPE == DS_FILE_HEADER_CFE - /* Set to prevent error messages in subfunction DS_FileWriteHeader that we don't care about in this test */ - UT_SetHandlerFunction(UT_KEY(OS_write), &UT_OS_write_SuccessHandler, NULL); -#endif - DS_AppData.DestFileTblPtr->File[FileIndex].FileNameType = DS_BY_COUNT; DS_AppData.DestFileTblPtr->File[FileIndex].SequenceCount = 3; /* Execute the function being tested */ @@ -708,8 +579,7 @@ void DS_FileCreateDest_Test_Error(void) void DS_FileCreateDest_Test_ClosedFileHandle(void) { - int32 FileIndex = 0; - osal_id_t LocalFileHandle = OS_OBJECT_ID_UNDEFINED; + int32 FileIndex = 0; DS_AppData.DestFileTblPtr->File[FileIndex].SequenceCount = 5; @@ -717,19 +587,12 @@ void DS_FileCreateDest_Test_ClosedFileHandle(void) strncpy(DS_AppData.FileStatus[FileIndex].FileName, "filename", sizeof(DS_AppData.FileStatus[FileIndex].FileName)); DS_AppData.DestFileTblPtr->File[FileIndex].FileNameType = DS_BY_COUNT; - DS_AppData.FileStatus[FileIndex].FileHandle = DS_UT_OBJID_1; DS_AppData.FileStatus[FileIndex].FileCount = 1; DS_AppData.DestFileTblPtr->File[FileIndex].Movename[0] = '\0'; - /* Set to fail the condition "if (Result < 0)" */ - UT_SetDefaultReturnValue(UT_KEY(OS_OpenCreate), OS_SUCCESS); - UT_SetDataBuffer(UT_KEY(OS_OpenCreate), &LocalFileHandle, sizeof(osal_id_t), false); - /* Set to prevent error messages in subfunction DS_FileWriteHeader that we don't care about in this test */ - UT_SetHandlerFunction(UT_KEY(CFE_FS_WriteHeader), &UT_CFE_FS_WriteHeader_SuccessHandler, NULL); - - /* Set to prevent error messages in subfunction DS_FileWriteHeader that we don't care about in this test */ - UT_SetHandlerFunction(UT_KEY(OS_write), &UT_OS_write_SuccessHandler, NULL); + /* Set to fail header write, which will call OS_close and clear the handle */ + UT_SetDefaultReturnValue(UT_KEY(CFE_FS_WriteHeader), -1); /* Execute the function being tested */ DS_FileCreateDest(FileIndex); @@ -843,7 +706,7 @@ void DS_FileCreateName_Test_Error(void) DS_AppData.DestFileTblPtr->File[FileIndex].Basename[i] = 'a'; } - DS_AppData.DestFileTblPtr->File[FileIndex].Basename[DS_TOTAL_FNAME_BUFSIZE - 1] = DS_STRING_TERMINATOR; + DS_AppData.DestFileTblPtr->File[FileIndex].Basename[DS_TOTAL_FNAME_BUFSIZE - 1] = '\0'; /* Execute the function being tested */ DS_FileCreateName(FileIndex); @@ -856,31 +719,6 @@ void DS_FileCreateName_Test_Error(void) } /* end DS_FileCreateName_Test_Error */ -void DS_FileCreateName_Test_MaxPathnameLength(void) -{ - int32 FileIndex = 0; - int32 WorknameLen = 2 * DS_TOTAL_FNAME_BUFSIZE; - int32 i; - - UT_DS_SetDestFileEntry(&DS_AppData.DestFileTblPtr->File[FileIndex]); - - /* Set to fail the condition "if (TotalLength != (WorknameLen - 1))" */ - for (i = 0; i < WorknameLen - 1; i++) - { - DS_AppData.DestFileTblPtr->File[FileIndex].Pathname[i] = 'a'; - } - - /* Execute the function being tested */ - UtAssert_VOIDCALL(DS_FileCreateName(FileIndex)); - - /* Verify results */ - UtAssert_INT32_EQ(strlen(DS_AppData.DestFileTblPtr->File[FileIndex].Pathname), WorknameLen - 1); - UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); - UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventType, CFE_EVS_EventType_ERROR); - UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, DS_FILE_NAME_ERR_EID); - -} /* end DS_FileCreateName_Test_MaxPathnameLength */ - void DS_FileCreateName_Test_PathBaseSeqTooLarge(void) { int32 FileIndex = 0; @@ -991,7 +829,7 @@ void DS_FileCreateSequence_Test_ByTime(void) int32 FileIndex = 0; CFE_TIME_SysTime_t FakeTime; - char Sequence[DS_TOTAL_FNAME_BUFSIZE]; + char Sequence[DS_TOTAL_FNAME_BUFSIZE] = ""; memset(&FakeTime, 0, sizeof(FakeTime)); @@ -1042,12 +880,6 @@ void DS_FileUpdateHeader_Test_PlatformConfigCFE_Nominal(void) { int32 FileIndex = 0; - /* Set to satisfy condition "if (Result == sizeof(CFE_FS_Header_t))" */ - UT_SetDefaultReturnValue(UT_KEY(OS_lseek), sizeof(CFE_FS_Header_t)); - - /* Set to satisfy condition "if (Result == sizeof(CFE_TIME_SysTime_t))" */ - UT_SetDefaultReturnValue(UT_KEY(OS_write), sizeof(CFE_TIME_SysTime_t)); - /* Execute the function being tested */ DS_FileUpdateHeader(FileIndex); @@ -1062,9 +894,6 @@ void DS_FileUpdateHeader_Test_WriteError(void) { int32 FileIndex = 0; - /* Set to satisfy condition "if (Result == sizeof(CFE_FS_Header_t))" */ - UT_SetDefaultReturnValue(UT_KEY(OS_lseek), sizeof(CFE_FS_Header_t)); - /* Set to fail condition "if (Result == sizeof(CFE_TIME_SysTime_t))" */ UT_SetDefaultReturnValue(UT_KEY(OS_write), -1); @@ -1100,7 +929,8 @@ void DS_FileCloseDest_Test_PlatformConfigMoveFiles_Nominal(void) { int32 FileIndex = 0; - UT_SetHandlerFunction(UT_KEY(OS_close), &UT_OS_CLOSE_SuccessHandler, NULL); + /* Set up the handle */ + OS_OpenCreate(&DS_AppData.FileStatus[FileIndex].FileHandle, NULL, 0, 0); strncpy(DS_AppData.FileStatus[FileIndex].FileName, "directory1/filename", sizeof(DS_AppData.FileStatus[FileIndex].FileName)); @@ -1125,13 +955,14 @@ void DS_FileCloseDest_Test_PlatformConfigMoveFiles_MoveError(void) { int32 FileIndex = 0; + /* Set up the handle */ + OS_OpenCreate(&DS_AppData.FileStatus[FileIndex].FileHandle, NULL, 0, 0); + strncpy(DS_AppData.FileStatus[FileIndex].FileName, "directory1/filename", sizeof(DS_AppData.FileStatus[FileIndex].FileName)); strncpy(DS_AppData.DestFileTblPtr->File[FileIndex].Movename, "directory2/movename/", sizeof(DS_AppData.DestFileTblPtr->File[FileIndex].Movename)); - UT_SetHandlerFunction(UT_KEY(OS_close), &UT_OS_CLOSE_SuccessHandler, NULL); - /* Set to generate error message DS_MOVE_FILE_ERR_EID */ UT_SetDefaultReturnValue(UT_KEY(OS_mv), -1); @@ -1153,7 +984,9 @@ void DS_FileCloseDest_Test_PlatformConfigMoveFiles_FilenameTooLarge(void) { int32 FileIndex = 0; - UT_SetHandlerFunction(UT_KEY(OS_close), &UT_OS_CLOSE_SuccessHandler, NULL); + /* Set up the handle */ + OS_OpenCreate(&DS_AppData.FileStatus[FileIndex].FileHandle, NULL, 0, 0); + strncpy(DS_AppData.FileStatus[FileIndex].FileName, "directory1/filenamefilenamefilenamefilenamefilenamefilename", sizeof(DS_AppData.FileStatus[FileIndex].FileName)); strncpy(DS_AppData.DestFileTblPtr->File[FileIndex].Movename, "directory2/movename/", @@ -1177,7 +1010,8 @@ void DS_FileCloseDest_Test_PlatformConfigMoveFiles_FilenameNull(void) { int32 FileIndex = 0; - UT_SetHandlerFunction(UT_KEY(OS_close), &UT_OS_CLOSE_SuccessHandler, NULL); + /* Set up the handle */ + OS_OpenCreate(&DS_AppData.FileStatus[FileIndex].FileHandle, NULL, 0, 0); strncpy(DS_AppData.DestFileTblPtr->File[FileIndex].Movename, "directory2/movename", sizeof(DS_AppData.DestFileTblPtr->File[FileIndex].Movename)); @@ -1202,7 +1036,8 @@ void DS_FileCloseDest_Test_MoveFilesFalse(void) { int32 FileIndex = 0; - UT_SetHandlerFunction(UT_KEY(OS_close), &UT_OS_CLOSE_SuccessHandler, NULL); + /* Set up the handle */ + OS_OpenCreate(&DS_AppData.FileStatus[FileIndex].FileHandle, NULL, 0, 0); /* Execute the function being tested */ DS_FileCloseDest(FileIndex); @@ -1222,14 +1057,14 @@ void DS_FileTestAge_Test_Nominal(void) uint32 ElapsedSeconds = 2; uint32 i; - UT_SetHandlerFunction(UT_KEY(OS_close), &UT_OS_CLOSE_SuccessHandler, NULL); + /* Set up the handle */ + OS_OpenCreate(&DS_AppData.FileStatus[FileIndex].FileHandle, NULL, 0, 0); for (i = 0; i < DS_DEST_FILE_CNT; i++) { strncpy(DS_AppData.FileStatus[i].FileName, "directory1/filename", sizeof(DS_AppData.FileStatus[i].FileName)); } - DS_AppData.FileStatus[FileIndex].FileHandle = DS_UT_OBJID_1; DS_AppData.FileStatus[FileIndex].FileAge = 0; DS_AppData.DestFileTblPtr->File[FileIndex].MaxFileAge = 3; @@ -1260,11 +1095,10 @@ void DS_FileTestAge_Test_ExceedMaxAge(void) int32 FileIndex = 0; uint32 ElapsedSeconds = 2; - DS_AppData.FileStatus[FileIndex].FileHandle = DS_UT_OBJID_1; - DS_AppData.DestFileTblPtr->File[FileIndex].MaxFileAge = 1; + /* Set up the handle */ + OS_OpenCreate(&DS_AppData.FileStatus[FileIndex].FileHandle, NULL, 0, 0); - UT_DS_SetupFileUpdateHeaderSuccess(); - UT_DS_SetupFileCloseDestSuccess(); + DS_AppData.DestFileTblPtr->File[FileIndex].MaxFileAge = 1; /* Execute the function being tested */ DS_FileTestAge(ElapsedSeconds); @@ -1536,7 +1370,6 @@ void UtTest_Setup(void) UT_DS_TEST_ADD(DS_FileCreateName_Test_NominalWithPeriod); UT_DS_TEST_ADD(DS_FileCreateName_Test_EmptyPath); UT_DS_TEST_ADD(DS_FileCreateName_Test_Error); - UT_DS_TEST_ADD(DS_FileCreateName_Test_MaxPathnameLength); UT_DS_TEST_ADD(DS_FileCreateName_Test_PathBaseSeqTooLarge); UT_DS_TEST_ADD(DS_FileCreateName_Test_PathBaseSeqExtTooLarge); UT_DS_TEST_ADD(DS_FileCreateName_Test_ExtensionZero);