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

gcc "--wrap" argument and stubs for OS-provided functions #382

Closed
CDKnightNASA opened this issue Mar 24, 2020 · 7 comments
Closed

gcc "--wrap" argument and stubs for OS-provided functions #382

CDKnightNASA opened this issue Mar 24, 2020 · 7 comments
Assignees
Labels

Comments

@CDKnightNASA
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I've been frustrated that we don't have unit tests for checking that OSAL properly handles error conditions when calling OS functions (like open, read, socket, accept, etc.) Apparently if we define --wrap=open, then all calls to open() will go to our open() function and the OS-provided open will be renamed as __wrap_open(). I suggest this be used to stub most/all OS calls and we can add unit tests for such things as running out of memory/storage/file descriptors and also support unit testing in sandboxed environments (don't know if Travis CI sandboxes) where such things as network calls are disabled.

Describe the solution you'd like
Stub functions for OS functions.

Describe alternatives you've considered
Been looking around for alternatives and haven't seen any.

Additional context
Add any other context about the feature request here.

Requester Info
Christopher.D.Knight@nasa.gov

@CDKnightNASA CDKnightNASA self-assigned this Mar 24, 2020
@jphickey
Copy link
Contributor

But we do have OSAL coverage tests, in the "unit-test-coverage" directory.

GCC wrap options have been brought up before in years past. Problem is we do not want to rely on tool-specific features to run coverage tests.

The framework that exists today AFAIK can do all we need it to, so I'm not sure about why we would need to add new dependencies or other ways of doing the same things?

@CDKnightNASA
Copy link
Contributor Author

It's my understanding that the OSAL unit tests check that OSAL functions handle bad inputs but do they also check that OSAL handles error conditions reported by the underlying OS call? And for some calls, it may be difficult/impossible to call OSAL functions in such a way as to force the underlying OS call to fail. Sure, I can call OS_open("/bin/bash", OS_READ_WRITE, 0644) which will force the open() call to return an error...Do we do this sort of thing?

@jphickey
Copy link
Contributor

Yes, this is precisely the point of the unit-test-coverage directory. It redirects the OS/C library calls to alternative/mock functions which can be controlled like any other stub functions.

Note that historically this was a separate build, but this will be changing in #362 such that the coverage will be built whenever ENABLE_UNIT_TESTS is true.

Also note that only the shared and vxworks layers are implemented for full coverage; posix and rtems are not currently implemented (never were). So the caveat with always building the coverage tests is that you'll get a coverage test for vxworks regardless of what OS you actually use.

@jphickey
Copy link
Contributor

But also note - this is a separate issue from simply having a functional test for a given API. The functional test uses the real function, not a mock/stub.

@skliper
Copy link
Contributor

skliper commented Mar 24, 2020

Note the goal is eventually ENABLE_UNIT_TESTS=true would build full coverage tests for all implementations (via mocks/stubs), but short term is just to add what's currently implemented.

@CDKnightNASA
Copy link
Contributor Author

going to close this ticket and ruminate on this topic. :D

@jphickey
Copy link
Contributor

Oh yeah, the other issue with --wrap gcc/ld feature is that it generally only works well for functions which you have an existing system header/prototype for. Meaning it doesn't work so well when building the e.g. VxWorks coverage test to run on a POSIX host (which we do).

The preprocessor-based remap done in the current UT coverage build, while a little complicated, does not depending on system headers at all, so you can build coverage test for anything regardless of what you are actually running it on.

@astrogeco astrogeco added invalid and removed invalid labels Sep 28, 2020
jphickey pushed a commit to jphickey/osal that referenced this issue Aug 10, 2022
Fixes nasa#361, nasa#373, nasa#374, nasa#381
Code reviewed and approved at 20191023 and 30 CCBs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants