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

TBL missing coverage in cfe_tbl_api.c function CFE_TBL_Update #1838

Open
nmullane opened this issue Aug 18, 2021 · 1 comment
Open

TBL missing coverage in cfe_tbl_api.c function CFE_TBL_Update #1838

nmullane opened this issue Aug 18, 2021 · 1 comment

Comments

@nmullane
Copy link
Contributor

Is your feature request related to a problem? Please describe.
CFE_TBL_Update function contains two hard to reach lines (953-954) that remains untested, preventing us from reaching 100% line coverage. It's actually just one uncovered line, but lcov thinks it's two.

    : 919:  /* Verify access rights and get a valid Application ID for calling App */
   6: 920:  Status = CFE_TBL_ValidateAccess(TblHandle, &ThisAppId);
    : 921: 
   6: 922:  if (Status == CFE_SUCCESS)
    : 923:  {
    : 924:      /* Get pointers to pertinent records in registry and handles */
   4: 925:      AccessDescPtr = &CFE_TBL_Global.Handles[TblHandle];
   4: 926:      RegRecPtr     = &CFE_TBL_Global.Registry[AccessDescPtr->RegIndex];
    : 927: 
   4: 928:      Status = CFE_TBL_UpdateInternal(TblHandle, RegRecPtr, AccessDescPtr);
    : 929: 
   4: 930:      if (Status != CFE_SUCCESS)
    : 931:      {
   2: 932:          CFE_ES_WriteToSysLog("%s: App(%lu) fail to update Tbl '%s' (Stat=0x%08X)\n", __func__,
   2: 933:                               CFE_RESOURCEID_TO_ULONG(ThisAppId), RegRecPtr->Name, (unsigned int)Status);
    : 934:      }
    : 935:  }
    : 936:  else
    : 937:  {
   2: 938:      CFE_ES_WriteToSysLog("%s: App(%lu) does not have access to Tbl Handle=%d\n", __func__,
    : 939:                           CFE_RESOURCEID_TO_ULONG(ThisAppId), (int)TblHandle);
    : 940:  }
    : 941: 
   6: 942:  if (Status != CFE_TBL_ERR_BAD_APP_ID)
    : 943:  {
    : 944:      /* Translate AppID of caller into App Name */
   6: 945:      CFE_ES_GetAppName(AppName, ThisAppId, sizeof(AppName));
    : 946:  }
    : 947: 
    : 948:  /* On Error conditions, notify ground of screw up */
   6: 949:  if (Status < 0)
    : 950:  {
   2: 951:      if (RegRecPtr != NULL)
    : 952:      {
## 0: 953:          CFE_EVS_SendEventWithAppID(CFE_TBL_UPDATE_ERR_EID, CFE_EVS_EventType_ERROR, CFE_TBL_Global.TableTaskAppId,
## 0: 954:                                     "%s Failed to Update '%s', Status=0x%08X", AppName, RegRecPtr->Name,
    : 955:                                     (unsigned int)Status);
    : 956:      }
    : 957:      else
    : 958:      {
   2: 959:          CFE_EVS_SendEventWithAppID(CFE_TBL_UPDATE_ERR_EID, CFE_EVS_EventType_ERROR, CFE_TBL_Global.TableTaskAppId,
    : 960:                                     "%s Failed to Update '?', Status=0x%08X", AppName, (unsigned int)Status);
    : 961:      }
    : 962:  }

Describe the solution you'd like
These lines should be safe to leave uncovered because they do not contain any potential to access a NULL pointer or anything else similarly dangerous.

Additional context
Line 953 is currently impossible to reach because CFE_TBL_UpdateInternal does not throw any error status codes (< 0), so the only way to trigger the if statement on line 949 is from CFE_TBL_ValidateAccess on line 920 which would always mean RegRecPtr is NULL. Thus the if statement on line 951 can never be true, leaving line 953 uncovered.

Requester Info
Niall Mullane - GSFC 582 Intern

@skliper skliper changed the title Missing coverage in cfe_tbl_api.c function CFE_TBL_Update TBL missing coverage in cfe_tbl_api.c function CFE_TBL_Update Aug 26, 2021
@avan989
Copy link
Contributor

avan989 commented Jun 7, 2023

The targeted condition is:

  1. Status < 0 and RegRecPtr != NULL

By default RegRecPtr is NULL. The only way to update RegRecPtr is by taking the following path:

  1. CFE_TBL_ValidateAccess -> Return CFE_SUCCESS -> CFE_TBL_UpdateInternal (cfe_tbl_internal.c)
  2. CFE_TBL_UpdateInternal (Not a stub) also updates "Status" but only with the following possible value:
    a. CFE_SUCCESS 0
    b. CFE_TBL_INFO_NO_UPDATE_PENDING 0x4c000017
    c. CFE_TBL_INFO_TABLE_LOCKED 0x4c000018

There is no way to have both Status < 0 and RegRecPtr != NULL without changing the implementation. Code Coverage is not possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants