Skip to content

Let tests replace the IBV wrapper instead of editing it - #181

Merged
derobins merged 1 commit into
developfrom
derobins/moar_not_before_cleanup
Oct 13, 2026
Merged

derobins merged 1 commit into
developfrom
derobins/moar_not_before_cleanup

Conversation

@derobins

Copy link
Copy Markdown
Collaborator

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().

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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 ScopedFakeIbv and 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.

@derobins
derobins merged commit 2e00dcf into develop Oct 13, 2026
31 checks passed
@derobins
derobins deleted the derobins/moar_not_before_cleanup branch October 13, 2026 09:09
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.

2 participants