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

Unit test macros and example use with SB #492

Merged
merged 3 commits into from
May 8, 2020

Conversation

CDKnightNASA
Copy link
Contributor

@CDKnightNASA CDKnightNASA commented Jan 24, 2020

Describe the contribution
sample macro-ification of UT code for CCB consideration.
Partial implementation of #491
Fix #418

Testing performed
made SB unit tests and confirmed all passed.

Expected behavior changes
simplified UT code

System(s) tested on
Debian Linux

Contributor Info - All information REQUIRED for consideration of pull request
[email protected]

EDIT: Added this fixes #418

@CDKnightNASA
Copy link
Contributor Author

Initial skim through -- I like the fact that it gets rid of so much redundant code.

I do have some requests though - Could we make the macro use UT Assert directly, rather than doing an sprintf and UT_Text() call? I implemented a similar macro on other apps, and an example can be seen in the sample_lib UT code here:

https://github.com/nasa/sample_lib/blob/09d5ff7f8cb46d98ee1f88b107b9761147d620d3/unit-test/coveragetest/sample_lib_coveragetest_common.h#L45-L59

Basically the macro is to call a function, and assert on the int32 return value. The macro may even be part of UT assert itself so it doesn't need to be re-implemented, although this does allow each component to customize it so that might be useful too.

I've committed changes that use UtAssertEx() calls instead of my code. :D

@CDKnightNASA CDKnightNASA added CCB:Ready Ready for discussion at the Configuration Control Board (CCB) enhancement labels Feb 11, 2020
@astrogeco astrogeco added this to the 6.8.0 milestone Feb 12, 2020
@astrogeco
Copy link
Contributor

astrogeco commented Feb 12, 2020

CCB 20200212 - Approved concept, @CDKnightNASA will go forward with implementation and update macros for reporting values and prefixes etc.

@CDKnightNASA CDKnightNASA added help wanted and removed CCB:Ready Ready for discussion at the Configuration Control Board (CCB) labels Feb 12, 2020
@skliper skliper changed the title sample fix for #491 Unit test macros and example use with SB Feb 25, 2020
@CDKnightNASA
Copy link
Contributor Author

Note that the UtAssertEx function always generates an entry in the stdout, so the sb_UT would generate ~1,800 "tests" instead of the 182 of the trunk. I assume the latter is the "correct" behavior?

@jphickey
Copy link
Contributor

jphickey commented Mar 5, 2020

I actually prefer to see all the test cases.

The only exception is if it is a sanity check of the test case itself i.e. like a test buffer being of sufficient size or otherwise using UT assert API to check for fundamental flaws in the test case itself as opposed to the FSW function outputs. (In this case the "pass" messages really are just clutter).

But in any case where it is checking the output of the FSW code, it should make an entry in the log. The count doesn't matter. Note you can also separately suppress "pass" output and show only failures if the log file gets too big.

@CDKnightNASA
Copy link
Contributor Author

A lot of checks in sb_UT are checking of setup steps to make sure the setup is correct...So if you want to see all of the setup steps in the log...?

A good example is Test_CreatePipe_MaxPipes() which calls CreatePipe CFE_PLATFORM_SB_MAX_PIPES + 1 times, and reports each CreatePipe, even though we only really care about the last one and only really care if it (or any prev. calls) fails.

@skliper
Copy link
Contributor

skliper commented Apr 9, 2020

I think we discussed this? If not, my suggestion is just keep a status or check that they all create and report success or failure once. No benefit to the reporting being inside the loop.

Oh, and break up the success and failure calls. Do the successful creation loop first, report if it passed or failed, then do the +1.

edit added 2nd statement.

@CDKnightNASA
Copy link
Contributor Author

I actually prefer to see all the test cases.

The only exception is if it is a sanity check of the test case itself i.e. like a test buffer being of sufficient size or otherwise using UT assert API to check for fundamental flaws in the test case itself as opposed to the FSW function outputs. (In this case the "pass" messages really are just clutter).

But in any case where it is checking the output of the FSW code, it should make an entry in the log. The count doesn't matter. Note you can also separately suppress "pass" output and show only failures if the log file gets too big.

Nice thing is with macros, we could have a single #define to enable/disable the SETUP/TEARDOWN/etc. reporting.

@CDKnightNASA CDKnightNASA marked this pull request as draft April 17, 2020 21:12
@CDKnightNASA CDKnightNASA added CCB:Ready Ready for discussion at the Configuration Control Board (CCB) unit-test labels Apr 17, 2020
@CDKnightNASA
Copy link
Contributor Author

I've taken a fresh crack at this, modeling it more like the OSAL unit test macros, to make them semantically clear as to what the tests are doing. I have some questions for the CCB:

  1. func ok or some compilers not support?
  2. One test per fn or multiple tests? All test fn's call UT_Report() only at the end so reporting is inconsistent.
  3. Should assert() report on success or only on failure (as it currently does)?
  4. On a failed "setup" function call, should test drop through?

@astrogeco
Copy link
Contributor

astrogeco commented Apr 22, 2020

CCB 20200422 - Discussed. House them in ut_support so they can be used in all subsystems. Will benefit from a targeted review.

@CDKnightNASA CDKnightNASA removed the CCB:Ready Ready for discussion at the Configuration Control Board (CCB) label Apr 22, 2020
@CDKnightNASA
Copy link
Contributor Author

FYI I've written up a page in the wiki (that could be incorporated into the git repo):

https://github.com/nasa/cFE/wiki/Unit-Test-Coding-Standards

@CDKnightNASA
Copy link
Contributor Author

some more updates, squashed commit

@skliper
Copy link
Contributor

skliper commented Apr 24, 2020

I'd like the CCB to consider merging in the ut_support.c/h changes whether or not the sb_UT.c changes are accepted, so that future unit test code can use the new macros. I can make it a separate pull request, if folks would rather.

Separate may be easier? Although I don't foresee any issues with accepting sb_UT.c. I would like to get the support changes in quickly such that we can start updating the rest as soon as the core code updates are done.

@skliper
Copy link
Contributor

skliper commented Apr 24, 2020

Note I just fought with es_UT for a while and almost lost, can't wait to update it.

@skliper
Copy link
Contributor

skliper commented Apr 24, 2020

Great! Want to run just sb_UT and drop the test log on here?

o.txt

I thought it was going to output the expected and actual values? I may have missed it...

@CDKnightNASA
Copy link
Contributor Author

Great! Want to run just sb_UT and drop the test log on here?

o.txt

I thought it was going to output the expected and actual values? I may have missed it...

Only on a failed test.

@skliper skliper added the CCB:Ready Ready for discussion at the Configuration Control Board (CCB) label Apr 28, 2020
@astrogeco
Copy link
Contributor

CCB 2020-04-29 : APPROVED

@astrogeco astrogeco added CCB-20200429 CCB:Approved Indicates code review and approval by community CCB and removed CCB:Ready Ready for discussion at the Configuration Control Board (CCB) labels May 5, 2020
@astrogeco astrogeco changed the base branch from master to integration-candidate May 8, 2020 18:02
@astrogeco
Copy link
Contributor

@CDKnightNASA can you resolve the conflicts?

@CDKnightNASA
Copy link
Contributor Author

working this, lots of conflicts. :/

@CDKnightNASA
Copy link
Contributor Author

conflicts resolved

@skliper skliper removed the conflicts label May 8, 2020
@astrogeco astrogeco merged commit 0c1bb9c into nasa:integration-candidate May 8, 2020
@CDKnightNASA
Copy link
Contributor Author

I have some other goofs to commit, plus some cleanup to use the new macros, will push them within the hour.

@skliper
Copy link
Contributor

skliper commented May 8, 2020

@CDKnightNASA once merged to IC, it's easier if you open a new pr

@CDKnightNASA
Copy link
Contributor Author

@CDKnightNASA once merged to IC, it's easier if you open a new pr

Ok, sorry I broke some of the MID abstraction in sb_UT...Given how many other changes in PSP, OSAL, etc. it is difficult for me to test my changes anyways until everything settles back into all of the master branches. :o

@skliper skliper mentioned this pull request May 11, 2020
@skliper skliper removed this from the 6.8.0 milestone May 11, 2020
skliper added a commit to skliper/cFE that referenced this pull request May 11, 2020
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 enhancement help wanted invalid unit-test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants