Make unit tests runnable on macOS#3018
Merged
chenBright merged 1 commit intoapache:masterfrom Jul 6, 2025
Merged
Conversation
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.
What problem does this PR solve?
Issue Number:
Problem Summary:
When running brpc unit tests binaries (e.g., test_butil) on macOS, the program exits with an error from gflags:
After investigating, I found that the error occurs at the point where a validator is registered for a flag:
Using lldb to debug the test binary, I discovered that the
DEFINE_boolandBUTIL_VALIDATE_GFLAGaccess different instances of gflags:DEFINE_boolaccesses the gflags instance intest_butilBUTIL_VALIDATE_GFLAGaccesses the gflags instance inlibbrpc.dbg.dylibOn macOS, the test binary links against:
libbrpc.dbg.dylib(which already statically links tolibgflags.a)libgflags.aBecause macOS uses a two-level namespace model, symbols from separate static libraries are not unified across dynamic libraries and executables. As a result, there are two isolated instances of gflags — one in the test binary, and one in the dylib. Consequently, the flag is registered in one instance, but the validator is registered in the other, leading to registration failure.
To resolve this, we should avoid linking
libgflags.a(and other static dependencies like protobuf) into the test binary if they are already linked insidelibbrpc.dbg.dylib. This ensures that all gflags-related macros operate on a single shared instance, and the validator registration works as expected.What is changed and the side effects?
Changed:
Side effects:
Performance effects:
Breaking backward compatibility:
Check List: