Repository navigation
Let tests replace the IBV wrapper instead of editing it - #181
Merged
Merged
Conversation
Tests used to fake libibverbs by writing into the library's own wrapper through funcsForTest() and setting its public is_initialized field, then copying the saved table back. Entries a test didn't fake still called the real libibverbs, with fake pointers. IBVWrapper now has a second constructor that takes an IbvFuncs table and loads nothing, and setIbvForTest() installs a wrapper for ibv() to return, like setStateForTest(). ibv() checks the override before creating the library's own wrapper, so tests that install fakes never load libibverbs. is_initialized is private, with a read-only is_initialized(), and funcsForTest() is removed. - Add hipObjTest::ScopedFakeIbv (test/unit/fake-ibv.h), which installs a wrapper built from fakes for its lifetime and restores the previous one. replace() switches fakes mid-test. - The fixtures build their fakes from an empty table, so a verb a test doesn't fake is a null call rather than a call into libibverbs. The IbvFakeInstall and FakeDestroyVerbs classes become functions that return the fakes. - Add test-ibv-lazy-load, which checks in a program of its own that libibverbs isn't loaded until the first ibv() call. - Add a test that HIPOBJ_DMABUF set after the program starts is honored by a wrapper created afterward. - test-seams checks that setIbvForTest() redirects ibv(). Co-Authored-By: Claude <noreply@anthropic.com>
derobins
requested review from
akolliasAMD,
gaoikawa,
jordan-turbofish,
kurtmcmillan,
riley-dixon,
sbates130272 and
zbyrne
as code owners
October 13, 2026 08:54
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The test seam and fixture migrations preserve resource lifetimes while preventing unintended calls into libibverbs.
0 open findings
What changed in this PR
Refactors libibverbs test seams so tests install isolated fake wrappers without loading or modifying the production wrapper.
Changes:
- Adds
ScopedFakeIbvand wrapper override support. - Migrates fixtures to explicit fake function tables.
- Adds lazy-loading and runtime environment-setting tests.
| File | Description |
|---|---|
src/common/ibv-wrapper.h |
Adds fake-table construction and override APIs. |
src/common/ibv-wrapper.cpp |
Implements wrapper overrides and initialization encapsulation. |
src/hipobj.cpp |
Uses the read-only initialization accessor. |
test/integration/rdma-test-server/rdma_server.cpp |
Updates initialization checking. |
test/unit/CMakeLists.txt |
Registers the lazy-loading test. |
test/unit/fake-ibv.h |
Adds scoped fake-wrapper management. |
test/unit/fake-device.h |
Stores the scoped fake wrapper. |
test/unit/fake-device.cpp |
Installs isolated fake verbs. |
test/unit/test-api-exceptions.cpp |
Replaces fake verbs safely during tests. |
test/unit/test-buffer-registration.cpp |
Migrates registration tests to the new seam. |
test/unit/test-ibv-dmabuf.cpp |
Tests replacement wrappers and environment rereading. |
test/unit/test-ibv-lazy-load.cpp |
Verifies first-use libibverbs loading. |
test/unit/test-seams.cpp |
Tests redirection through the IBV seam. |
test/unit/test-thread-safety.cpp |
Migrates thread-safety fixtures to isolated fakes. |
test/unit/test-v2-conflict.cpp |
Uses replaceable fake verb tables. |
test/unit/test-v2-connref.cpp |
Migrates fault tests to scoped fakes. |
test/unit/test-v2-random.cpp |
Installs fake PSN-related verbs. |
test/unit/test-v2-registry.cpp |
Migrates registry fixtures to scoped fakes. |
test/unit/test-v2-server.cpp |
Installs scoped no-op destruction verbs. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tests used to fake libibverbs by writing into the library's own wrapper through funcsForTest() and setting its public is_initialized field, then copying the saved table back. Entries a test didn't fake still called the real libibverbs, with fake pointers.
IBVWrapper now has a second constructor that takes an IbvFuncs table and loads nothing, and setIbvForTest() installs a wrapper for ibv() to return, like setStateForTest(). ibv() checks the override before creating the library's own wrapper, so tests that install fakes never load libibverbs. is_initialized is private, with a read-only is_initialized(), and funcsForTest() is removed.