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 #1344, UT assert stub return values #1352

Merged
merged 1 commit into from
Feb 2, 2023

Conversation

jphickey
Copy link
Contributor

Checklist (Please check before submitting)

Describe the contribution
Improves default support for return values of sizes other than 32 bits. Previously this required a custom handler for any value that was not a 32 bit integer. With this update any integer value can be used, and a value translation will occur if the size is different. Thus boolean values, 8,16, and 64-bit ints can be configured through the same basic API without needing to add a handler.
Fixes #1344

Testing performed
Build and run all tests, including CFS app tests, to confirm all still run as expected.

Expected behavior changes
No change to existing behavior - all currently-implemented test cases should continue to behave as they have in the past, whether they used a 32-bit integer return or if they had a custom hook/handler.

Going forward, it should no longer be required to implement a custom handler for the sole purpose of adjusting the size of the return value in case it is not a 32-bit integer. As a fallback default, any return value that is unset by a test will be memset to 0. So a pointer stub return will get NULL, a boolean will get FALSE, and any numeric value of any time will be zero.

The UT_SetDeferredRetcode and UT_SetDefaultReturnValue functions now accept a UT_IntReturn_t value instead of int32. This typedef is defined using the C99 ptrdiff_t type, which will be 64 bits in size on modern hardware. When passing by value from an int32, this should be transparent, but it is large enough to also allow test cases to pass in pointer values here without truncating.

System(s) tested on
Debian

Additional context
API to set return values is still numeric in nature. This adds some framework to allow fully-typed values and abstract objects bigger than ptrdiff_t values to be returned, but there is no API yet - that can be added in a future change.

Contributor Info - All information REQUIRED for consideration of pull request
Joseph Hickey, Vantage Systems, Inc.

Improves default support for return values of sizes other than 32 bits.
Previously this required a custom handler for any value that was not a
32 bit integer.  With this update any integer value can be used, and a
value translation will occur if the size is differnt.  Thus boolean
values, 8,16, and 64-bit ints can be configured through the same basic
API without needing to add a handler.
--StubPtr->Data.Rc.Count;
/* For "unknown" types the pointer is stored directly - this allows for ANY return type of ANY size,
* but requires that the caller maintain the buffer in scope until the test completes */
StubPtr->Data.Rvc.Buf.IndirectPtr = ValuePtr;

Check warning

Code scanning / CodeQL-security

Local variable address stored in non-local memory

A stack address which arrived via a [parameter](1) may be assigned to a non-local variable.
@dzbaker dzbaker added this to the Equuleus milestone Jan 19, 2023
@dzbaker dzbaker added the CCB:Ready Pull request is ready for discussion at the Configuration Control Board (CCB) label Jan 19, 2023
@dzbaker
Copy link
Collaborator

dzbaker commented Jan 19, 2023

CCB 19 January 2023: Will review after next release.

@dzbaker dzbaker requested a review from chillfig January 19, 2023 19:17
@dzbaker dzbaker added CCB:Approved Indicates code review and approval by community CCB and removed CCB:Ready Pull request is ready for discussion at the Configuration Control Board (CCB) labels Feb 2, 2023
dzbaker added a commit to nasa/cFS that referenced this pull request Feb 2, 2023
*Combines:*

osal v6.0.0-rc4+dev187

**Includes:**

*osal*
- nasa/osal#1352

Co-authored by: Joseph Hickey <jphickey@users.noreply.github.com>
@dzbaker dzbaker mentioned this pull request Feb 2, 2023
2 tasks
@dzbaker dzbaker merged commit 97709af into nasa:main Feb 2, 2023
dzbaker added a commit to nasa/cFS that referenced this pull request Feb 2, 2023
*Combines:*

osal v6.0.0-rc4+dev187

**Includes:**

*osal*
- nasa/osal#1352

Co-authored by: Joseph Hickey <jphickey@users.noreply.github.com>
dzbaker added a commit to nasa/cFS that referenced this pull request Feb 3, 2023
*Combines:*

osal v6.0.0-rc4+dev191

**Includes:**

*osal*
- nasa/osal#1352
- nasa/osal#1362

Co-authored by: Joseph Hickey <jphickey@users.noreply.github.com>
@jphickey jphickey deleted the fix-1344-utassert-stub-retvals branch February 3, 2023 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CCB:Approved Indicates code review and approval by community CCB Equuleus-rc1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add better support for pointer return values in UT assert
4 participants