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

Test CI with nss_preload. #15

Merged
merged 1 commit into from
Nov 1, 2023
Merged

Conversation

apognu
Copy link
Contributor

@apognu apognu commented Oct 26, 2023

This pull requests creates the foundation to be able to test this library end to end. Right now, it uses the mock interface and dummy users to verify behavior, which completely circumvents calls to libc and therefore to NSS.

This adds new tests, which runs must be separate from the general tests, and require the use of libnss_wrapper in LD_PRELOAD to add fixture users that are actually going to be returned by libc.

Note that the existing tests cannot be run with this, because the "current user" that it uses is not present in the fixtured data.

All mocked tests are defined under a feature called test-integration and will only be executed when the feature is set. Also, and I am not entirely satisfied by this, in order to only run the new tests when wrapping NSS, they are all prefixed with mocked_ right now (I neither like the naming nor the concept). We then only execute tests with that prefix for that phase.

Ultimately, the three rounds of tests that are performed are:

  • cargo test: same as before, nothing changes
  • LD_PRELOAD=... cargo test --features test-integration mocked_: run new unit tests
  • LD_PRELOAD=... cargo test --features test-integration --test '*': run new integration tests

That way, current users can still run the usual test suite without any impact, and CI (or users willing to install libnss_wrapper) can run the whole suite.

I have taken the liberty to rewrite some of the unit test in base.rs to take advantage of the fixtures (in a separate test module for clarity) to show how it could be done.

Please add remarks, this came out of a prototype, and there are some things I am still not a fan of.

Related to #14.

Note: the serial_test crate was added to prevent unit tests that actually interact with libc from running in parallel, to prevent known thread-safety issues.

Copy link
Member

@gierens gierens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apognu LGTM! Thanks for your contribution! ... and @PThorpe92 thanks for reviewing!

@gierens gierens merged commit f1ab55e into rustadopt:main Nov 1, 2023
4 checks passed
@gierens gierens linked an issue Nov 2, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add integration/mocked tests with libnss_wrapper
3 participants