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

Add UtAssert bit field check macros #1135

Closed
jphickey opened this issue Aug 25, 2021 · 2 comments · Fixed by #1136 or #1138
Closed

Add UtAssert bit field check macros #1135

jphickey opened this issue Aug 25, 2021 · 2 comments · Fixed by #1136 or #1138
Assignees
Labels
enhancement unit-test Tickets related to the OSAL unit testing (functional and/or coverage)
Milestone

Comments

@jphickey
Copy link
Contributor

jphickey commented Aug 25, 2021

Is your feature request related to a problem? Please describe.
Bit fields are a common method of storing multiple boolean values into a single data field. UtAssert should provide macros that aid in testing code that uses this type of storage.

Describe the solution you'd like
Add some new UtAssert macros to check bit fields. These macros should include in the log the raw value of the bit field being checked (as a hex number) as well as the specific mask bits being checked for. Two forms should be included, one which passes if the bit(s) are set, and one which passes if the bit(s) are not set.

This should be able to use the same underlying Generic assert helper function, just with a different macro wrapper around it that checks a bit mask.

Describe alternatives you've considered
May use the existing UtAssert_UINT32_EQ/NEQ, in either of these forms:

  1. UtAssert_INT32_EQ(BitField, BitField | CHECK_BITS)
  2. UtAssert_INT32_EQ(BitField & CHECK_BITS, CHECK_BITS)

Downsides: the resulting log is not quite as concise as it should be:

  • Its not clear that this is a bitmask check - as it is logged as a normal value check.
  • Only either the raw value (form 1) or the bitmask value (form 2) will be logged. It will not log both pieces of info.
  • Values will be logged in decimal/base-10 by default which is not easy to read when examining bit flags - base-16 is preferable.

All of the above should be solvable by simply making a different wrapper macro around the existing UtAssert_GenericUnsignedCompare function.

Additional context
See nasa/cFE#1860 for a use case

Requester Info
Joseph Hickey, Vantage Systems, Inc.

@jphickey jphickey added enhancement unit-test Tickets related to the OSAL unit testing (functional and/or coverage) labels Aug 25, 2021
@jphickey
Copy link
Contributor Author

Another downside/limitation to using UtAssert_INT32_EQ in the form that it shows the raw value (1) is that it evaluates the BitField twice - meaning it cannot be directly checked from a return value of a function call. It has to be stored on the stack, which has its own downside (i.e. if the value was from a function call, it should log the actual function being called too, not just the stack variable name that was tested).

@jphickey jphickey self-assigned this Aug 25, 2021
@jphickey
Copy link
Contributor Author

This seems like such a low-hanging fruit, I will submit a quick PR.

jphickey added a commit to jphickey/osal that referenced this issue Aug 25, 2021
Add a pair of macros that can confirm a value has bits set or
does not have bits set.  By using bitmask-aware macros, the logged
information can include both the raw/actual value as well as the
specific bits being tested.
astrogeco added a commit that referenced this issue Aug 27, 2021
@skliper skliper added this to the 6.0.0 milestone Sep 24, 2021
jphickey pushed a commit to jphickey/osal that referenced this issue Aug 10, 2022
Fix nasa#1134, Add UtDebug output to CFE_ES_WriteToSysLog stub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement unit-test Tickets related to the OSAL unit testing (functional and/or coverage)
Projects
None yet
2 participants