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 all commits
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
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
2 changes: 0 additions & 2 deletions fsw/inc/ds_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,6 @@ typedef struct
*/
typedef struct
{
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief cFE Software Bus command message header */

CFE_SB_MsgId_t MessageID; /**< \brief Message ID to add to Packet Filter Table */
} DS_AddRemoveMid_Payload_t;

Expand Down
7 changes: 4 additions & 3 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 Expand Up @@ -357,15 +358,15 @@ void DS_AppSendHkCmd(void)
Status = CFE_TBL_GetInfo(&FilterTblInfo, FilterTblName);
if (Status == CFE_SUCCESS)
{
strncpy(PayloadPtr->FilterTblFilename, FilterTblInfo.LastFileLoaded, OS_MAX_PATH_LEN - 1);
PayloadPtr->FilterTblFilename[OS_MAX_PATH_LEN - 1] = '\0';
snprintf(PayloadPtr->FilterTblFilename, OS_MAX_PATH_LEN, "%s", FilterTblInfo.LastFileLoaded);
}
else
{
/* If the filter table name is invalid, send an event and erase any
* stale/misleading filename from the HK packet */
CFE_EVS_SendEvent(DS_APPHK_FILTER_TBL_ERR_EID, CFE_EVS_EventType_ERROR,
"Invalid filter tbl name in DS_AppSendHkCmd. Name=%s, Err=0x%08X", FilterTblName, Status);
"Invalid filter tbl name in DS_AppSendHkCmd. Name=%s, Err=0x%08X", FilterTblName,
(unsigned int)Status);

memset(PayloadPtr->FilterTblFilename, 0, sizeof(PayloadPtr->FilterTblFilename));
}
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
2 changes: 1 addition & 1 deletion fsw/src/ds_appdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

#define DS_PATH_SEPARATOR '/' /**< \brief File system path separator */

#define DS_TABLE_VERIFY_ERR 0xFFFFFFFF /**< \brief Table verification error return value */
#define DS_TABLE_VERIFY_ERR -1 /**< \brief Table verification error return value */

#define DS_FILE_HEADER_NONE 0 /**< \brief File header type is NONE */
#define DS_FILE_HEADER_CFE 1 /**< \brief File header type is CFE */
Expand Down
56 changes: 28 additions & 28 deletions fsw/src/ds_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -962,11 +962,11 @@

void DS_CloseFileCmd(const CFE_SB_Buffer_t *BufPtr)
{
const DS_CloseFile_Payload_t *DS_CloseFileCmd;
const DS_CloseFile_Payload_t *PayloadPtr;

DS_CloseFileCmd = DS_GET_CMD_PAYLOAD(BufPtr, DS_CloseFileCmd_t);
PayloadPtr = DS_GET_CMD_PAYLOAD(BufPtr, DS_CloseFileCmd_t);

if (DS_TableVerifyFileIndex(DS_CloseFileCmd->FileTableIndex) == false)
if (DS_TableVerifyFileIndex(PayloadPtr->FileTableIndex) == false)
{
/*
** Invalid destination file table index...
Expand All @@ -975,23 +975,23 @@

CFE_EVS_SendEvent(DS_CLOSE_CMD_ERR_EID, CFE_EVS_EventType_ERROR,
"Invalid DEST CLOSE command arg: file table index = %d",
(int)DS_CloseFileCmd->FileTableIndex);
(int)PayloadPtr->FileTableIndex);
}
else
{
/*
** Close destination file (if the file was open)...
*/
if (OS_ObjectIdDefined(DS_AppData.FileStatus[DS_CloseFileCmd->FileTableIndex].FileHandle))
if (OS_ObjectIdDefined(DS_AppData.FileStatus[PayloadPtr->FileTableIndex].FileHandle))
{
DS_FileUpdateHeader(DS_CloseFileCmd->FileTableIndex);
DS_FileCloseDest(DS_CloseFileCmd->FileTableIndex);
DS_FileUpdateHeader(PayloadPtr->FileTableIndex);
DS_FileCloseDest(PayloadPtr->FileTableIndex);
}

DS_AppData.CmdAcceptedCounter++;

CFE_EVS_SendEvent(DS_CLOSE_CMD_EID, CFE_EVS_EventType_INFORMATION, "DEST CLOSE command: file table index = %d",
(int)DS_CloseFileCmd->FileTableIndex);
(int)PayloadPtr->FileTableIndex);
}
}

Expand Down Expand Up @@ -1096,7 +1096,7 @@
/*
** Set current open filename...
*/
strncpy(FileInfoPtr->FileName, DS_AppData.FileStatus[i].FileName, sizeof(FileInfoPtr->FileName));
snprintf(FileInfoPtr->FileName, sizeof(FileInfoPtr->FileName), "%s", DS_AppData.FileStatus[i].FileName);
}
}

Expand All @@ -1115,16 +1115,16 @@

void DS_AddMIDCmd(const CFE_SB_Buffer_t *BufPtr)
{
const DS_AddRemoveMid_Payload_t *DS_AddMidCmd;
const DS_AddRemoveMid_Payload_t *PayloadPtr;
DS_PacketEntry_t * pPacketEntry = NULL;
DS_FilterParms_t * pFilterParms = NULL;
int32 FilterTableIndex = 0;
int32 HashTableIndex = 0;
int32 i = 0;

DS_AddMidCmd = DS_GET_CMD_PAYLOAD(BufPtr, DS_AddMidCmd_t);
PayloadPtr = DS_GET_CMD_PAYLOAD(BufPtr, DS_AddMidCmd_t);

if (!CFE_SB_IsValidMsgId(DS_AddMidCmd->MessageID))
if (!CFE_SB_IsValidMsgId(PayloadPtr->MessageID))
{
/*
** Invalid packet message ID - can be anything but unused...
Expand All @@ -1133,7 +1133,7 @@

CFE_EVS_SendEvent(DS_ADD_MID_CMD_ERR_EID, CFE_EVS_EventType_ERROR,
"Invalid ADD MID command arg: invalid MID = 0x%08lX",
(unsigned long)CFE_SB_MsgIdToValue(DS_AddMidCmd->MessageID));
(unsigned long)CFE_SB_MsgIdToValue(PayloadPtr->MessageID));
}
else if (DS_AppData.FilterTblPtr == (DS_FilterTable_t *)NULL)
{
Expand All @@ -1145,7 +1145,7 @@
CFE_EVS_SendEvent(DS_ADD_MID_CMD_ERR_EID, CFE_EVS_EventType_ERROR,
"Invalid ADD MID command: filter table is not loaded");
}
else if ((FilterTableIndex = DS_TableFindMsgID(DS_AddMidCmd->MessageID)) != DS_INDEX_NONE)
else if ((FilterTableIndex = DS_TableFindMsgID(PayloadPtr->MessageID)) != DS_INDEX_NONE)

Check warning

Code scanning / CodeQL

Side effect in a Boolean expression Warning

This Boolean expression is not side-effect free.
{
/*
** New message ID is already in packet filter table...
Expand All @@ -1154,7 +1154,7 @@

CFE_EVS_SendEvent(DS_ADD_MID_CMD_ERR_EID, CFE_EVS_EventType_ERROR,
"Invalid ADD MID command: MID = 0x%08lX is already in filter table at index = %d",
(unsigned long)CFE_SB_MsgIdToValue(DS_AddMidCmd->MessageID), (int)FilterTableIndex);
(unsigned long)CFE_SB_MsgIdToValue(PayloadPtr->MessageID), (int)FilterTableIndex);
}
else if ((FilterTableIndex = DS_TableFindMsgID(CFE_SB_INVALID_MSG_ID)) == DS_INDEX_NONE)
{
Expand All @@ -1173,10 +1173,10 @@
*/
pPacketEntry = &DS_AppData.FilterTblPtr->Packet[FilterTableIndex];

pPacketEntry->MessageID = DS_AddMidCmd->MessageID;
pPacketEntry->MessageID = PayloadPtr->MessageID;

/* Add the message ID to the hash table as well */
HashTableIndex = DS_TableAddMsgID(DS_AddMidCmd->MessageID, FilterTableIndex);
HashTableIndex = DS_TableAddMsgID(PayloadPtr->MessageID, FilterTableIndex);

for (i = 0; i < DS_FILTERS_PER_PACKET; i++)
{
Expand All @@ -1190,7 +1190,7 @@
pFilterParms->Algorithm_O = 0;
}

CFE_SB_SubscribeEx(DS_AddMidCmd->MessageID, DS_AppData.CmdPipe, CFE_SB_DEFAULT_QOS, DS_PER_PACKET_PIPE_LIMIT);
CFE_SB_SubscribeEx(PayloadPtr->MessageID, DS_AppData.CmdPipe, CFE_SB_DEFAULT_QOS, DS_PER_PACKET_PIPE_LIMIT);
/*
** Notify cFE that we have modified the table data...
*/
Expand All @@ -1200,7 +1200,7 @@

CFE_EVS_SendEvent(DS_ADD_MID_CMD_EID, CFE_EVS_EventType_INFORMATION,
"ADD MID command: MID = 0x%08lX, filter index = %d, hash index = %d",
(unsigned long)CFE_SB_MsgIdToValue(DS_AddMidCmd->MessageID), (int)FilterTableIndex,
(unsigned long)CFE_SB_MsgIdToValue(PayloadPtr->MessageID), (int)FilterTableIndex,
(int)HashTableIndex);
}
}
Expand All @@ -1213,18 +1213,18 @@

void DS_RemoveMIDCmd(const CFE_SB_Buffer_t *BufPtr)
{
const DS_AddRemoveMid_Payload_t *DS_RemoveMidCmd;
const DS_AddRemoveMid_Payload_t *PayloadPtr;

DS_PacketEntry_t *pPacketEntry = NULL;
DS_FilterParms_t *pFilterParms = NULL;
int32 FilterTableIndex = 0;
int32 HashTableIndex = 0;
int32 i = 0;

DS_RemoveMidCmd = DS_GET_CMD_PAYLOAD(BufPtr, DS_RemoveMidCmd_t);
FilterTableIndex = DS_TableFindMsgID(DS_RemoveMidCmd->MessageID);
PayloadPtr = DS_GET_CMD_PAYLOAD(BufPtr, DS_RemoveMidCmd_t);
FilterTableIndex = DS_TableFindMsgID(PayloadPtr->MessageID);

if (!CFE_SB_IsValidMsgId(DS_RemoveMidCmd->MessageID))
if (!CFE_SB_IsValidMsgId(PayloadPtr->MessageID))
{
/*
** Invalid packet message ID - can be anything but unused...
Expand All @@ -1233,7 +1233,7 @@

CFE_EVS_SendEvent(DS_REMOVE_MID_CMD_ERR_EID, CFE_EVS_EventType_ERROR,
"Invalid REMOVE MID command arg: invalid MID = 0x%08lX",
(unsigned long)CFE_SB_MsgIdToValue(DS_RemoveMidCmd->MessageID));
(unsigned long)CFE_SB_MsgIdToValue(PayloadPtr->MessageID));
}
else if (DS_AppData.FilterTblPtr == (DS_FilterTable_t *)NULL)
{
Expand All @@ -1254,12 +1254,12 @@

CFE_EVS_SendEvent(DS_REMOVE_MID_CMD_ERR_EID, CFE_EVS_EventType_ERROR,
"Invalid REMOVE MID command: MID = 0x%08lX is not in filter table",
(unsigned long)CFE_SB_MsgIdToValue(DS_RemoveMidCmd->MessageID));
(unsigned long)CFE_SB_MsgIdToValue(PayloadPtr->MessageID));
}
else
{
/* Convert MID into hash table index */
HashTableIndex = DS_TableHashFunction(DS_RemoveMidCmd->MessageID);
HashTableIndex = DS_TableHashFunction(PayloadPtr->MessageID);

/*
** Reset used packet filter entry for used message ID...
Expand All @@ -1283,7 +1283,7 @@
pFilterParms->Algorithm_O = 0;
}

CFE_SB_Unsubscribe(DS_RemoveMidCmd->MessageID, DS_AppData.CmdPipe);
CFE_SB_Unsubscribe(PayloadPtr->MessageID, DS_AppData.CmdPipe);

/*
** Notify cFE that we have modified the table data...
Expand All @@ -1294,7 +1294,7 @@

CFE_EVS_SendEvent(DS_REMOVE_MID_CMD_EID, CFE_EVS_EventType_INFORMATION,
"REMOVE MID command: MID = 0x%08lX, filter index = %d, hash index = %d",
(unsigned long)CFE_SB_MsgIdToValue(DS_RemoveMidCmd->MessageID), (int)FilterTableIndex,
(unsigned long)CFE_SB_MsgIdToValue(PayloadPtr->MessageID), (int)FilterTableIndex,
(int)HashTableIndex);
}
}
Expand Down
2 changes: 1 addition & 1 deletion fsw/src/ds_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

#include <stdio.h>

bool DS_VerifyLength(const CFE_SB_Buffer_t *BufPtr, size_t ExpectedLength, uint16 FailEventID, const char *CommandName)
int32 DS_VerifyLength(const CFE_SB_Buffer_t *BufPtr, size_t ExpectedLength, uint16 FailEventID, const char *CommandName)

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
{
size_t ActualLength = 0;

Expand Down
Loading
Loading