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

Implement default handlers for APIs that set values, not all exist (needs full scrub) #2046

Open
skliper opened this issue Feb 10, 2022 · 0 comments

Comments

@skliper
Copy link
Contributor

skliper commented Feb 10, 2022

Is your feature request related to a problem? Please describe.
There aren't default handlers for all APIs that set parameters, leading to potential uninitialized variables when unit testing code that expects the parameter to be set if guaranteed by the API.

Describe the solution you'd like
For API's that initialize/set id's or really any other case where the parameter should always be set there should be a default handler to avoid uninitialized variable issues for the code under test.

Example preferred handler:

void UT_DefaultHandler_CFE_ES_GetAppID(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context)
{
CFE_ES_AppId_t *AppIdPtr = UT_Hook_GetArgValueByName(Context, "AppIdPtr", CFE_ES_AppId_t *);
int32 status;
void * IdBuff;
size_t BuffSize;
size_t Position;
UT_Stub_GetInt32StatusCode(Context, &status);
if (status >= 0)
{
UT_GetDataBuffer(UT_KEY(CFE_ES_GetAppID), &IdBuff, &BuffSize, &Position);
if (IdBuff != NULL && BuffSize == sizeof(*AppIdPtr))
{
memcpy(AppIdPtr, IdBuff, sizeof(*AppIdPtr));
}
else
{
*AppIdPtr = CFE_UT_ES_DEFAULT_APPID;
}
}
if (status < 0)
{
*AppIdPtr = CFE_ES_APPID_C(CFE_UT_ES_ID_INVALID);
}
}

Example of a missing handler - CFE_ES_CreateChildTask. At minimum for success the id should be set valid.

Describe alternatives you've considered
Initialize the passed in parameter, but when initialized to invalid if there isn't a handler to set it for the valid case the test will fail. It's better than the often silent uninitialized variable issue but for APIs that always set the parameter the burden shouldn't be on the flight code to fix the test issue.

Additional context
Planning to spawn individual issues based on identified cases, but this issue relates to a full scrub.

Requester Info
Jacob Hageman - NASA/GSFC

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

1 participant