Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nasa/nos3#176] Unit Tests #2

Merged
merged 18 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
5cb25f5
Fix #116, Removed command header from payload struct
havencarlson Sep 20, 2023
7b20419
Merge pull request #118 from havencarlson/fix#116
dzbaker Sep 21, 2023
f600acd
Fix #111: Use correct length filename for too large test
irowebbn Nov 30, 2023
f04f6a0
Merge pull request #112 from irowebbn/111-max_file-len-move-test
dzbaker Dec 5, 2023
dc14784
Fix #119, remove dependency on MID_BASE defines
jphickey Dec 13, 2023
77b016d
Merge pull request #120 from jphickey/fix-119-midbase
dmknutsen Dec 15, 2023
9f6138a
Fix #121, correct casting on printf format strings
jphickey Jan 10, 2024
b540e3b
Merge pull request #122 from jphickey/fix-121-formats
dzbaker Jan 11, 2024
f2b9d11
Fix #115, Adds distinct identifiers from command name
Jan 23, 2024
fe2ea87
Merge pull request #123 from chillfig/nondistinct_id
dzbaker Feb 1, 2024
20236a4
Fix #125, Adds utassert macro for logging function calls
Feb 15, 2024
ce8902c
Merge pull request #126 from chillfig/function_macros
dzbaker Feb 15, 2024
3f41af7
Fix #95, Replaces conditionally compiled code with runtime conditiona…
Jan 31, 2024
ec96b02
Merge pull request #124 from chillfig/cond_comp_code
dzbaker Mar 28, 2024
a5f1a8e
Fix #127, Adds static analysis comments and replaces strncpy with snp…
Jun 10, 2024
c83933f
Merge pull request #130 from chillfig/SA_jsc2_1
dzbaker Jun 27, 2024
659e972
Merge remote-tracking branch 'origin/main' into nos3#176-unit-tests
jlucas9 Jul 3, 2024
1427a22
[nasa/nos3#176] Change from bools to int32 across the entire applicat…
jlucas9 Jul 23, 2024
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
Prev Previous commit
Next Next commit
Fix nasa#95, Replaces conditionally compiled code with runtime condit…
…ional logic
  • Loading branch information
jdfiguer authored and jdfiguer committed Mar 28, 2024
commit 3f41af76c53c1f208d34d07bc0e3a0922f6e1dd9
2 changes: 0 additions & 2 deletions fsw/inc/ds_extern_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ typedef struct
*/
typedef struct
{
#if (DS_MOVE_FILES == true)
char Movename[DS_PATHNAME_BUFSIZE]; /**< \brief Move files to this dir after close */
#endif
char Pathname[DS_PATHNAME_BUFSIZE]; /**< \brief Path portion of filename */
char Basename[DS_BASENAME_BUFSIZE]; /**< \brief Base portion of filename */
char Extension[DS_EXTENSION_BUFSIZE]; /**< \brief Extension portion of filename */
Expand Down
1 change: 1 addition & 0 deletions fsw/src/ds_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ CFE_Status_t DS_AppInitialize(void)
memset(&DS_AppData, 0, sizeof(DS_AppData));

DS_AppData.AppEnableState = DS_DEF_ENABLE_STATE;
DS_AppData.EnableMoveFiles = DS_MOVE_FILES;

/*
** Mark files as closed
Expand Down
2 changes: 2 additions & 0 deletions fsw/src/ds_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ typedef struct

DS_HashLink_t HashLinks[DS_PACKETS_IN_FILTER_TABLE]; /**< \brief Hash table linked list elements */
DS_HashLink_t *HashTable[DS_HASH_TABLE_ENTRIES]; /**< \brief Each hash table entry is a linked list */

uint8 EnableMoveFiles; /**< \brief Whether to move files to downlink directory after close */
} DS_AppData_t;

/** \brief DS global data structure reference */
Expand Down
237 changes: 115 additions & 122 deletions fsw/src/ds_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,73 +376,73 @@ void DS_FileWriteData(int32 FileIndex, const void *FileData, uint32 DataLength)

void DS_FileWriteHeader(int32 FileIndex)
{
#if (DS_FILE_HEADER_TYPE == DS_FILE_HEADER_CFE)

DS_DestFileEntry_t *DestFile = &DS_AppData.DestFileTblPtr->File[FileIndex];
DS_AppFileStatus_t *FileStatus = &DS_AppData.FileStatus[FileIndex];
CFE_FS_Header_t CFE_FS_Header;
DS_FileHeader_t DS_FileHeader;
int32 Result;

/*
** Initialize selected parts of the cFE file header...
*/
CFE_FS_InitHeader(&CFE_FS_Header, DS_FILE_HDR_DESCRIPTION, DS_FILE_HDR_SUBTYPE);

/*
** Let cFE finish the init and write the primary header...
*/
Result = CFE_FS_WriteHeader(FileStatus->FileHandle, &CFE_FS_Header);

if (Result == sizeof(CFE_FS_Header_t))
if (DS_FILE_HEADER_TYPE == DS_FILE_HEADER_CFE)
{
/*
** Success - update file size and data rate counters...
*/
DS_AppData.FileWriteCounter++;

FileStatus->FileSize += sizeof(CFE_FS_Header_t);
FileStatus->FileGrowth += sizeof(CFE_FS_Header_t);
DS_DestFileEntry_t *DestFile = &DS_AppData.DestFileTblPtr->File[FileIndex];
DS_AppFileStatus_t *FileStatus = &DS_AppData.FileStatus[FileIndex];
CFE_FS_Header_t CFE_FS_Header;
DS_FileHeader_t DS_FileHeader;
int32 Result;

/*
** Initialize the DS file header...
** Initialize selected parts of the cFE file header...
*/
memset(&DS_FileHeader, 0, sizeof(DS_FileHeader));
DS_FileHeader.FileTableIndex = FileIndex;
DS_FileHeader.FileNameType = DestFile->FileNameType;
strncpy(DS_FileHeader.FileName, FileStatus->FileName, sizeof(DS_FileHeader.FileName));
CFE_FS_InitHeader(&CFE_FS_Header, DS_FILE_HDR_DESCRIPTION, DS_FILE_HDR_SUBTYPE);

/*
** Manually write the secondary header...
** Let cFE finish the init and write the primary header...
*/
Result = OS_write(FileStatus->FileHandle, &DS_FileHeader, sizeof(DS_FileHeader_t));
Result = CFE_FS_WriteHeader(FileStatus->FileHandle, &CFE_FS_Header);

if (Result == sizeof(DS_FileHeader_t))
if (Result == sizeof(CFE_FS_Header_t))
{
/*
** Success - update file size and data rate counters...
*/
DS_AppData.FileWriteCounter++;

FileStatus->FileSize += sizeof(DS_FileHeader_t);
FileStatus->FileGrowth += sizeof(DS_FileHeader_t);
FileStatus->FileSize += sizeof(CFE_FS_Header_t);
FileStatus->FileGrowth += sizeof(CFE_FS_Header_t);

/*
** Initialize the DS file header...
*/
memset(&DS_FileHeader, 0, sizeof(DS_FileHeader));
DS_FileHeader.FileTableIndex = FileIndex;
DS_FileHeader.FileNameType = DestFile->FileNameType;
strncpy(DS_FileHeader.FileName, FileStatus->FileName, sizeof(DS_FileHeader.FileName));

/*
** Manually write the secondary header...
*/
Result = OS_write(FileStatus->FileHandle, &DS_FileHeader, sizeof(DS_FileHeader_t));

if (Result == sizeof(DS_FileHeader_t))
{
/*
** Success - update file size and data rate counters...
*/
DS_AppData.FileWriteCounter++;

FileStatus->FileSize += sizeof(DS_FileHeader_t);
FileStatus->FileGrowth += sizeof(DS_FileHeader_t);
}
else
{
/*
** Error - send event, close file and disable destination...
*/
DS_FileWriteError(FileIndex, sizeof(DS_FileHeader_t), Result);
}
}
else
{
/*
** Error - send event, close file and disable destination...
*/
DS_FileWriteError(FileIndex, sizeof(DS_FileHeader_t), Result);
DS_FileWriteError(FileIndex, sizeof(CFE_FS_Header_t), Result);
}
}
else
{
/*
** Error - send event, close file and disable destination...
*/
DS_FileWriteError(FileIndex, sizeof(CFE_FS_Header_t), Result);
}
#endif
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand Down Expand Up @@ -761,35 +761,36 @@ void DS_FileCreateSequence(char *Buffer, uint32 Type, uint32 Count)

void DS_FileUpdateHeader(int32 FileIndex)
{
#if (DS_FILE_HEADER_TYPE == DS_FILE_HEADER_CFE)
/*
** Update CFE specific header fields...
*/
DS_AppFileStatus_t *FileStatus = &DS_AppData.FileStatus[FileIndex];
CFE_TIME_SysTime_t CurrentTime = CFE_TIME_GetTime();
int32 Result;

Result = OS_lseek(FileStatus->FileHandle, sizeof(CFE_FS_Header_t), OS_SEEK_SET);

if (Result == sizeof(CFE_FS_Header_t))
if (DS_FILE_HEADER_TYPE == DS_FILE_HEADER_CFE)
{
/* update file close time */
Result = OS_write(FileStatus->FileHandle, &CurrentTime, sizeof(CFE_TIME_SysTime_t));
/*
** Update CFE specific header fields...
*/
DS_AppFileStatus_t *FileStatus = &DS_AppData.FileStatus[FileIndex];
CFE_TIME_SysTime_t CurrentTime = CFE_TIME_GetTime();
int32 Result;

if (Result == sizeof(CFE_TIME_SysTime_t))
Result = OS_lseek(FileStatus->FileHandle, sizeof(CFE_FS_Header_t), OS_SEEK_SET);

if (Result == sizeof(CFE_FS_Header_t))
{
DS_AppData.FileUpdateCounter++;
/* update file close time */
Result = OS_write(FileStatus->FileHandle, &CurrentTime, sizeof(CFE_TIME_SysTime_t));

if (Result == sizeof(CFE_TIME_SysTime_t))
{
DS_AppData.FileUpdateCounter++;
}
else
{
DS_AppData.FileUpdateErrCounter++;
}
}
else
{
DS_AppData.FileUpdateErrCounter++;
}
}
else
{
DS_AppData.FileUpdateErrCounter++;
}
#endif
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand All @@ -800,68 +801,74 @@ void DS_FileUpdateHeader(int32 FileIndex)
void DS_FileCloseDest(int32 FileIndex)
{
DS_AppFileStatus_t *FileStatus = &DS_AppData.FileStatus[FileIndex];

#if (DS_MOVE_FILES == true)
/*
** Move file from working directory to downlink directory...
*/
int32 OS_result;
int32 PathLength;
char *FileName;
char PathName[DS_TOTAL_FNAME_BUFSIZE];
int32 OS_result;
int32 PathLength;
char * FileName;
char PathName[DS_TOTAL_FNAME_BUFSIZE];

/*
** First, close the file...
*/
OS_close(FileStatus->FileHandle);

/*
** Move file only if table has a downlink directory name...
*/
if (DS_AppData.DestFileTblPtr->File[FileIndex].Movename[0] != '\0')
if (DS_AppData.EnableMoveFiles == DS_ENABLED)
{
/*
** Make sure directory name does not end with slash character...
** Move file only if table has a downlink directory name...
*/
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] == '/')
if (DS_AppData.DestFileTblPtr->File[FileIndex].Movename[0] != '\0')
{
PathName[PathLength - 1] = '\0';
PathLength--;
}

/*
** Get a pointer to slash character before the filename...
*/
FileName = strrchr(FileStatus->FileName, '/');
/*
** Make sure directory name does not end with slash character...
*/
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] == '/')
{
PathName[PathLength - 1] = '\0';
PathLength--;
}

if (FileName != NULL)
{
/*
** Verify that directory name plus filename is not too large...
** Get a pointer to slash character before the filename...
*/
if ((PathLength + strlen(FileName)) < DS_TOTAL_FNAME_BUFSIZE)
FileName = strrchr(FileStatus->FileName, '/');

if (FileName != NULL)
{
/*
** Append the filename (with slash) to the directory name...
** Verify that directory name plus filename is not too large...
*/
strcat(PathName, FileName);
if ((PathLength + strlen(FileName)) < DS_TOTAL_FNAME_BUFSIZE)
{
/*
** Append the filename (with slash) to the directory name...
*/
strcat(PathName, FileName);

/*
** Use OS function to move/rename the file...
*/
OS_result = OS_mv(FileStatus->FileName, PathName);
/*
** Use OS function to move/rename the file...
*/
OS_result = OS_mv(FileStatus->FileName, PathName);

if (OS_result != OS_SUCCESS)
if (OS_result != OS_SUCCESS)
{
/*
** Error - send event but leave destination enabled...
*/
CFE_EVS_SendEvent(DS_MOVE_FILE_ERR_EID, CFE_EVS_EventType_ERROR,
"FILE MOVE error: src = '%s', tgt = '%s', result = %d", FileStatus->FileName,
PathName, (int)OS_result);
}
}
else
{
/*
** Error - send event but leave destination enabled...
*/
CFE_EVS_SendEvent(DS_MOVE_FILE_ERR_EID, CFE_EVS_EventType_ERROR,
"FILE MOVE error: src = '%s', tgt = '%s', result = %d", FileStatus->FileName,
PathName, (int)OS_result);
"FILE MOVE error: dir name = '%s', filename = '%s'", PathName, FileName);
}
}
else
Expand All @@ -870,27 +877,13 @@ void DS_FileCloseDest(int32 FileIndex)
** Error - send event but leave destination enabled...
*/
CFE_EVS_SendEvent(DS_MOVE_FILE_ERR_EID, CFE_EVS_EventType_ERROR,
"FILE MOVE error: dir name = '%s', filename = '%s'", PathName, FileName);
"FILE MOVE error: dir name = '%s', filename = 'NULL'", PathName);
}
}
else
{
/*
** Error - send event but leave destination enabled...
*/
CFE_EVS_SendEvent(DS_MOVE_FILE_ERR_EID, CFE_EVS_EventType_ERROR,
"FILE MOVE error: dir name = '%s', filename = 'NULL'", PathName);
}

/* Update the path name for reporting */
strncpy(FileStatus->FileName, PathName, sizeof(FileStatus->FileName));
/* Update the path name for reporting */
strncpy(FileStatus->FileName, PathName, sizeof(FileStatus->FileName));
}
}
#else
/*
** Close the file...
*/
OS_close(FileStatus->FileHandle);
#endif

/*
** Transmit file information telemetry...
Expand Down
2 changes: 0 additions & 2 deletions fsw/src/ds_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#if (DS_FILE_HEADER_TYPE == DS_FILE_HEADER_CFE)
/**
* \brief DS File Header (follows cFE file header at start of file)
*/
Expand All @@ -49,7 +48,6 @@ typedef struct

char FileName[DS_TOTAL_FNAME_BUFSIZE]; /**< \brief On-board filename */
} DS_FileHeader_t;
#endif

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
Expand Down
16 changes: 9 additions & 7 deletions fsw/src/ds_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ CFE_Status_t DS_TableInit(void)
bool NeedToLoadFilterTable = false;
uint16 TableRegisterFlags = CFE_TBL_OPT_SNGL_BUFFER | CFE_TBL_OPT_LOAD_DUMP;

#if (DS_MAKE_TABLES_CRITICAL == 1)
TableRegisterFlags |= CFE_TBL_OPT_CRITICAL;
#endif
if (DS_MAKE_TABLES_CRITICAL == 1)
{
TableRegisterFlags |= CFE_TBL_OPT_CRITICAL;
}

/*
** If registration fails for either table then the DS app will
Expand Down Expand Up @@ -909,10 +910,11 @@ CFE_Status_t DS_TableCreateCDS(void)
DS_AppData.FileStatus[i].FileCount = DataStoreBuffer[i];
}

#if (DS_CDS_ENABLE_STATE == 1)
/* Only restore enable/disable state if configured */
DS_AppData.AppEnableState = (uint8)DataStoreBuffer[DS_DEST_FILE_CNT];
#endif
if (DS_CDS_ENABLE_STATE == 1)
{
/* Only restore enable/disable state if configured */
DS_AppData.AppEnableState = (uint8)DataStoreBuffer[DS_DEST_FILE_CNT];
}
}
}

Expand Down
Loading