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 #97, check only format string in UT event test #99

Merged
merged 1 commit into from
Sep 21, 2020

Conversation

jphickey
Copy link
Contributor

@jphickey jphickey commented Sep 17, 2020

Describe the contribution
For example "SendEvent" tests in sample_app, do not pass the test string through vsnprintf() to get a fully rendered output. Instead test only that the format string matches. This is my recommended approach.

Note that the "fully-rendered" output is affected my many external variables and is not necessarily going to be consistent. The most recent example is in #87/#94 which is the reason for this change, but it also can be affected by things totally outside of CFE like the user's locale settings in the OS.

Fixes #97

Testing performed
Build and run sample_app unit tests

Expected behavior changes
Fixes current failure in integration candidate 2020-09-15.

System(s) tested on
Ubuntu 20.04

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

The fully-rendered strings are not entirely consistent, affected
by many external factors outside the control of the test cases.

There was even a warning in the comment against doing this, but
it was included nonetheless as an example of how it can be done.
This now keeps the original example but keeps it in the comment only,
and converts the actual test to follow the recommended practice of
only testing the spec/format string, not the fully-rendered string.

This should be much more stable going forward, and should work with
both CCSDS v1 and v2 configs.
@jphickey jphickey changed the base branch from main to integration-candidate September 17, 2020 17:19
@jphickey
Copy link
Contributor Author

Note this also fixes #87, just differently than PR #94 did.

@jphickey jphickey linked an issue Sep 17, 2020 that may be closed by this pull request
@astrogeco
Copy link
Contributor

I think we can fast track this. If this was a cFE, PSP, or OSAL ticket I wouldn't but since it's just a coverage test for sample_app I'm fine with not having it go through a super thorough review. Plus I think I kind of understand the intent of the change.

@skliper skliper added CCB:FastTrack enhancement New feature or request labels Sep 21, 2020
@skliper skliper added this to the 1.3.0 milestone Sep 21, 2020
@skliper
Copy link
Contributor

skliper commented Sep 21, 2020

As an "example" I'd actually think it would be nice to show how you can do either via #99... have a string to test the format or a string to test the simulated output and skip if NULL. Or even in the second case use strstr and allow a substring match to pass?

Not a big deal though, just examples to help the user create whatever works for them (which I think #99 already meets that intent as-is).

@yammajamma yammajamma merged commit 7992f8b into integration-candidate Sep 21, 2020
@jphickey
Copy link
Contributor Author

As an "example" I'd actually think it would be nice to show how you can do either

I was thinking about this, and one way to make it safer might be to to do the snprintf() on both sides - i.e. the reference and the hook. That is, instead of hardcoding the complete reference string as:

UT_CheckEvent_Setup(&EventTest, SAMPLE_INVALID_MSGID_ERR_EID, "SAMPLE: invalid command packet,MID = 0xffff");

We could instead call "snprintf" here using the expected format and args and generate the complete reference string that way. It would accomplish the objective of validating all the arguments, while still adapting to changes from external symbols (i.e. like the specific value of CFE_SB_MSGID_INVALID, etc).

@skliper
Copy link
Contributor

skliper commented Sep 21, 2020

I like that approach. How about if the format was a macro in the flight code (easier to document, less repetition of characters in testing and more resilient since then the format string is always just defined in one location). I'm not a fan of how the format is essentially defined 3 different times already in cFE, two in the events header file:

https://github.com/nasa/cFE/blob/60917a2d7e23b32419a9b11b0d2c0bd722d7c35e/fsw/cfe-core/src/inc/cfe_tbl_events.h#L58-L68

Then finally in the implementation the third:

https://github.com/nasa/cFE/blob/60917a2d7e23b32419a9b11b0d2c0bd722d7c35e/fsw/cfe-core/src/tbl/cfe_tbl_task.c#L217

Which illustrates inconsistent documentation since they don't match...

@skliper skliper deleted the fix-97-ut-check-format branch February 1, 2021 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CCB:FastTrack enhancement New feature or request
Projects
None yet
4 participants