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

Fix #387, Update minor out-of-family naming/consistency issues in CF #388

Conversation

thnkslprpt
Copy link
Contributor

@thnkslprpt thnkslprpt commented Jun 6, 2023

Checklist

Describe the contribution

  • Fixes Some minor out-of-family naming/consistency issues in CF could be updated #387
    • Add event for CreatePipe() failure during initialization (and created a new matching EID: CF_CR_PIPE_ERR_EID) + clarified different EIDs for pipe creation errors during initialization of the app, and separate EID for errors during CF Channel pipe creation (CF_CR_CHANNEL_PIPE_ERR_EID).
    • In CF_HkCmd(): Use CFE_SB_TimeStampMsg() instead of CFE_MSG_SetMsgTime() and use the CFE_MSG_PTR conversion macro - CF was the only app remaining to use CFE_MSG_SetMsgTime()
    • Add memset at the beginning of the initialization routine to zero-out the global data structure (defensive programming, and for consistency - almost all of the cFS modules/apps do this)
    • Remove check of the return value of CFE_EVS_SendEvent() reporting initialization success - this is very out-of-family for cFS and also inconsistent - CF does not check the return value of any other calls to CFE_EVS_SendEvent()
    • Remove null check in CF_AppMain() after successful call to CFE_SB_ReceiveBuffer() - out-of-family with cFS and also redundant (CFE_SB_ReceiveBuffer() with a successful return guarantees the returned pointer to be non-NULL)
       

Minor changes:

  • Comment in CF_CmdAbandon_Txn() noted incorrect parameter cannot be NULL - corrected this
  • Rename tlm_header to TelemetryHeader
  • Rename run_status to RunStatus
  • Rename cmd_pipe to CmdPipe
  • Rename Software Bus command pipe message pointer variables (CFE_SB_Buffer_t types) from msg to BufPtr
  • Rename msg_id to MessageID
  • Move 'Cmd' to end of command function names (e.g. CF_CmdNoop() changed to CF_NoopCmd())
  • Rename CF_CmdReset() to CF_ResetCountersCmd() - more clear and specific, and in line with vast majority of cFS incl. cFE (also amended the matching type CF_ResetCmd_t to CF_ResetCountersCmd_t)
  • Rename CF_Init() to CF_AppInit()
  • Removed a couple of unnessesasary header #includes - cf_verify.h in cf_clist.c and

Note: CF does not verify length for non-command MIDs received in the app pipe (CF_WAKE_UP_MID and CF_SEND_HK_MID) - it would be worthwhile to rectify this at some point.

cFE and the other apps are generally inconsistent on this - some don't check non-command MIDs, some use a single VerifyLength function to check all MIDs arriving, some use separate VerifyLength functions for command and non-command MIDs...

Testing performed
GitHub CI actions all passing successfully (incl. Build + Run, Unit/Functional Tests etc.).

Expected behavior changes
Minor changes as noted above, no significant changes to behavior.

Aligning aberrant naming to the predominant patterns in cFS improves usability and eases future maintenance.

Contributor Info
Avi Weiss @thnkslprpt

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.

@dzbaker dzbaker requested a review from chillfig June 8, 2023 18:14
@chillfig chillfig self-requested a review June 15, 2023 18:38
Copy link
Contributor

@chillfig chillfig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To safely remove the assignment to the status variable and maintain functional behavior, CFE_SUCCESS must be guaranteed at cf_app.c line 255. Is it?

Rationale given for removing the update of the status at that line is:

"this is very out-of-family for cFS and also inconsistent - CF does not check the return value of any other calls to CFE_EVS_SendEvent()"

However, examples of this check exist at:
https://github.com/nasa/HK/blob/406ec64b6428131230f2c9dac4f2f32452e04c7e/fsw/src/hk_app.c#L207

https://github.com/nasa/SCH/blob/dbaf51ebbcffe1177997880d0f555c7d489217f5/fsw/src/sch_app.c#L345

@@ -248,13 +252,8 @@ CFE_Status_t CF_Init(void)

if (status == CFE_SUCCESS)
{
status =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thnkslprpt Would you please expand on why the status init is removed here?

Copy link
Contributor Author

@thnkslprpt thnkslprpt Jun 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes correct - of the 10 main apps only HK and CF currently check the return of the CFE_EVS_SendEvent() reporting successful initialization. MD assigns it to the Result variable but does not report on failure. In cFE, only the SB module checks the return of this call to CFE_EVS_SendEvent(), all of the other modules do not do so.

In general, out of several thousand invocations of CFE_EVS_SendEvent() across cFS, its return value is only checked a handful of times. In CF specifically, there are 141 calls to CFE_EVS_SendEvent() (just in flight code) and this is the only place that the return value is assigned/checked.

If an app is already confirmed to be successfully registered with EVS (as is the case here), it's almost inconceivable that the call to CFE_EVS_SendEvent() will fail.

It seems undesirable for an app to exit (through failure of the init routine, and then setting RunStatus to CFE_ES_RunStatus_APP_ERROR) just because the event/notification of successful initialization failed for some reason (again, highly improbable if already confirmed registered with EVS).

This change is not essential (it can be left as it is) it's more just for the sake of consistency (almost all apps and cFE modules just call CFE_EVS_SendEvent() to report successful initialization, without checking its return value or assigning it to their Status/Result variables).

@thnkslprpt thnkslprpt requested a review from chillfig June 23, 2023 00:19
@skliper
Copy link
Contributor

skliper commented Jun 27, 2023

For length check and command handling inconsistencies, hopefully nasa/cFE#2038 will eventually resolve this across all of cFS.

Copy link
Contributor

@chillfig chillfig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concur with changes and justification for check return value omission is appreciated. Although, as discussed at the 6/22/2023 cFS community board, cFS is a community-built product with many developers who worked different apps and so it may be unwise to always use justification of consistency to make all the submodules/apps of cFS behave the same.

@thnkslprpt thnkslprpt force-pushed the fix-387-update-minor-naming-and-consistency-issues branch from 7aa196a to 6a7d0be Compare August 19, 2023 07:24
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL-coding-standard found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.

@thnkslprpt thnkslprpt force-pushed the fix-387-update-minor-naming-and-consistency-issues branch from 6a7d0be to a19fb2c Compare October 26, 2023 12:39
@thnkslprpt thnkslprpt force-pushed the fix-387-update-minor-naming-and-consistency-issues branch 3 times, most recently from 454f902 to 69277a8 Compare December 3, 2023 02:34
@thnkslprpt
Copy link
Contributor Author

Concur with changes...

@chillfig Justin - slight change since your approval due to a merge conflict resolution. There are now 2 separate EIDs for the different pipe creation error locations: CF_CR_CHANNEL_PIPE_ERR_EID and CF_CR_PIPE_ERR_EID

Copy link
Contributor

@jphickey jphickey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this changeset, but it overlaps with other recent PRs. We should rebase it, but only after the other pending items.

@thnkslprpt thnkslprpt force-pushed the fix-387-update-minor-naming-and-consistency-issues branch 3 times, most recently from b505df0 to 716b89d Compare December 6, 2023 08:15
msg = NULL;

while (CFE_ES_RunLoop(&CF_AppData.run_status))
while (CFE_ES_RunLoop(&CF_AppData.RunStatus))

Check warning

Code scanning / CodeQL

Side effect in a Boolean expression Warning

This Boolean expression is not side-effect free.
fsw/src/cf_app.c Fixed Show fixed Hide fixed
fsw/src/cf_app.c Fixed Show fixed Hide fixed
fsw/src/cf_cmd.c Fixed Show fixed Hide fixed
fsw/src/cf_cmd.c Fixed Show fixed Hide fixed
fsw/src/cf_cmd.c Fixed Show fixed Hide fixed
fsw/src/cf_cmd.c Fixed Show fixed Hide fixed
fsw/src/cf_cmd.c Fixed Show fixed Hide fixed
@@ -513,7 +513,7 @@
*-----------------------------------------------------------------*/
void CF_AbandonCmd(const CF_AbandonCmd_t *msg)
{
if (CF_TsnChanAction(&msg->Payload, "abandon", CF_CmdAbandon_Txn, NULL) > 0)
if (CF_TsnChanAction(&msg->Payload, "abandon", CF_Abandon_TxnCmd, NULL) > 0)

Check warning

Code scanning / CodeQL-coding-standard

Side effect in a Boolean expression

This Boolean expression is not side-effect free.
@@ -480,7 +480,7 @@
*-----------------------------------------------------------------*/
void CF_CancelCmd(const CF_CancelCmd_t *msg)
{
if (CF_TsnChanAction(&msg->Payload, "cancel", CF_CmdCancel_Txn, NULL) > 0)
if (CF_TsnChanAction(&msg->Payload, "cancel", CF_Cancel_TxnCmd, NULL) > 0)

Check warning

Code scanning / CodeQL-coding-standard

Side effect in a Boolean expression

This Boolean expression is not side-effect free.
@thnkslprpt thnkslprpt force-pushed the fix-387-update-minor-naming-and-consistency-issues branch 5 times, most recently from b3d8a4f to 2cbc05b Compare December 6, 2023 11:06
@thnkslprpt
Copy link
Contributor Author

I like this changeset, but it overlaps with other recent PRs. We should rebase it, but only after the other pending items.

No worries Joe @jphickey - I'll try to keep it up-to-date. Feel free to merge it whenever it suits.

@thnkslprpt thnkslprpt force-pushed the fix-387-update-minor-naming-and-consistency-issues branch from 2cbc05b to f2d7e54 Compare December 10, 2023 07:57
@thnkslprpt thnkslprpt force-pushed the fix-387-update-minor-naming-and-consistency-issues branch from f2d7e54 to bdabfd7 Compare December 16, 2023 03:24
@thnkslprpt thnkslprpt force-pushed the fix-387-update-minor-naming-and-consistency-issues branch 2 times, most recently from 88fa0fe to e441c8e Compare January 14, 2024 07:24

/* first, verify command length */
if (len == expected_lengths[cmd])
{
/* if valid, process command */
if (fns[cmd])
{
fns[cmd](msg);
fns[cmd](BufPtr);

Check notice

Code scanning / CodeQL

Use of non-constant function pointer Note

This call does not go through a const function pointer.
@@ -61,7 +61,7 @@
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
CFE_Status_t CF_ResetCmd(const CF_ResetCmd_t *msg)
CFE_Status_t CF_ResetCountersCmd(const CF_ResetCountersCmd_t *msg)

Check notice

Code scanning / CodeQL

Function too long Note

CF_ResetCountersCmd has too many lines (63, while 60 are allowed).
@@ -39,13 +39,13 @@
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_ProcessGroundCommand(const CFE_SB_Buffer_t *msg)
void CF_ProcessGroundCommand(const CFE_SB_Buffer_t *BufPtr)

Check notice

Code scanning / CodeQL

Function too long Note

CF_ProcessGroundCommand has too many lines (83, while 60 are allowed).
@@ -61,7 +61,7 @@
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
CFE_Status_t CF_ResetCmd(const CF_ResetCmd_t *msg)
CFE_Status_t CF_ResetCountersCmd(const CF_ResetCountersCmd_t *msg)

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
@@ -39,13 +39,13 @@
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_ProcessGroundCommand(const CFE_SB_Buffer_t *msg)
void CF_ProcessGroundCommand(const CFE_SB_Buffer_t *BufPtr)

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
@@ -129,30 +129,30 @@
* See description in cf_app.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_AppPipe(const CFE_SB_Buffer_t *msg)
void CF_AppPipe(const CFE_SB_Buffer_t *BufPtr)

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
@@ -186,13 +186,16 @@
* See description in cf_app.h for argument/return detail
*
*-----------------------------------------------------------------*/
CFE_Status_t CF_Init(void)
CFE_Status_t CF_AppInit(void)

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
@thnkslprpt thnkslprpt force-pushed the fix-387-update-minor-naming-and-consistency-issues branch from e441c8e to 9a01790 Compare January 14, 2024 07:40
@thnkslprpt thnkslprpt force-pushed the fix-387-update-minor-naming-and-consistency-issues branch from 9a01790 to 191c62f Compare March 24, 2024 02:19
fsw/src/cf_dispatch.h Fixed Show fixed Hide fixed
@thnkslprpt thnkslprpt force-pushed the fix-387-update-minor-naming-and-consistency-issues branch from 191c62f to 5b54245 Compare March 24, 2024 08:04
@dzbaker dzbaker added the CCB:Ready Ready for discussion at the Configuration Control Board (CCB) label Jul 5, 2024
@@ -536,7 +536,7 @@
*-----------------------------------------------------------------*/
CFE_Status_t CF_AbandonCmd(const CF_AbandonCmd_t *msg)
{
if (CF_TsnChanAction(&msg->Payload, "abandon", CF_CmdAbandon_Txn, NULL) > 0)
if (CF_TsnChanAction(&msg->Payload, "abandon", CF_Abandon_TxnCmd, NULL) > 0)

Check warning

Code scanning / CodeQL

Side effect in a Boolean expression Warning

This Boolean expression is not side-effect free.
@@ -501,7 +501,7 @@
*-----------------------------------------------------------------*/
CFE_Status_t CF_CancelCmd(const CF_CancelCmd_t *msg)
{
if (CF_TsnChanAction(&msg->Payload, "cancel", CF_CmdCancel_Txn, NULL) > 0)
if (CF_TsnChanAction(&msg->Payload, "cancel", CF_Cancel_TxnCmd, NULL) > 0)

Check warning

Code scanning / CodeQL

Side effect in a Boolean expression Warning

This Boolean expression is not side-effect free.
@dzbaker
Copy link
Contributor

dzbaker commented Sep 26, 2024

Hi @thnkslprpt, apologies about the delay with this PR. I'd like to get it into the next round of PR reviews. Would you be able to resolve the merge conflict/unit test workflow failure?

@thnkslprpt thnkslprpt force-pushed the fix-387-update-minor-naming-and-consistency-issues branch from 4710faa to e1cc63c Compare September 27, 2024 06:57
@thnkslprpt thnkslprpt force-pushed the fix-387-update-minor-naming-and-consistency-issues branch from e1cc63c to f928452 Compare September 27, 2024 07:16
@thnkslprpt
Copy link
Contributor Author

Hi @thnkslprpt, apologies about the delay with this PR. I'd like to get it into the next round of PR reviews. Would you be able to resolve the merge conflict/unit test workflow failure?

I think it's good to go now @dzbaker

@dzbaker dzbaker added CCB:Approved and removed CCB:Ready Ready for discussion at the Configuration Control Board (CCB) labels Oct 3, 2024
@dzbaker dzbaker merged commit f7b1f89 into nasa:main Oct 3, 2024
16 checks passed
@thnkslprpt thnkslprpt deleted the fix-387-update-minor-naming-and-consistency-issues branch October 3, 2024 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some minor out-of-family naming/consistency issues in CF could be updated
7 participants