Makefile: add -gcflags=all=-l to gnmi_server tests for gomonkey compatibility#604
Open
sigabrtv1-ui wants to merge 1 commit intosonic-net:masterfrom
Open
Makefile: add -gcflags=all=-l to gnmi_server tests for gomonkey compatibility#604sigabrtv1-ui wants to merge 1 commit intosonic-net:masterfrom
sigabrtv1-ui wants to merge 1 commit intosonic-net:masterfrom
Conversation
…tibility gomonkey patches function pointers at the machine-code level and requires inlining to be disabled (-gcflags=all=-l) to work correctly. Without this flag, ApplyFunc() patches are silently ignored at runtime — the real functions run instead, causing tests that mock OS/auth calls (e.g. user.Lookup, UserPwAuth) to fail with Unauthenticated errors. Add the flag to both check_gotest and check_gotest_junit targets for the gnmi_server / INTEGRATION_ENV_PKGS invocations so that tests using gomonkey (e.g. TestGnsiAuthzRotation in PR sonic-net#549) work as expected. Signed-off-by: sigabrtv1-ui <sig.abrt.v1@gmail.com>
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Author
|
@zbud-msft @FengPan-Frank — companion to #603. Adds -gcflags=all=-l to gnmi_server test invocations so gomonkey patches work correctly. Without this flag, ApplyFunc patches are silently no-ops, causing auth mocks to be ignored and every test to fail with Unauthenticated. |
sigabrtv1-ui
pushed a commit
to sigabrtv1-ui/sonic-gnmi
that referenced
this pull request
Mar 9, 2026
Go 1.23's compiler inlines more aggressively than 1.19, breaking gomonkey patches in sonic_service_client tests (TestGetFileStat panics with nil pointer dereference because the method patch is bypassed). Add -gcflags=all=-l to INTEGRATION_BASIC_PKGS test run to disable inlining and allow gomonkey to patch reliably. Related: PR sonic-net#604 adds the same flag to gnmi_server tests. Signed-off-by: Dawei Huang <daweihuang@microsoft.com>
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.
Problem
Tests in
gnmi_serverthat usegomonkey.ApplyFunc()to mock OS/auth functions (e.g.user.Lookup,UserPwAuth) silently fail to patch because the binary is built with inlining enabled. gomonkey patches function pointers at the machine-code level and requires inlining to be disabled to work correctly.Without
-gcflags=all=-l,ApplyFunc()patches are no-ops at runtime — the real functions execute instead — causing tests to get real authentication failures:This is blocking PR #549 (gNSI Authz frontend implementation) which has failed on every CI run.
Fix
Add
-gcflags=all=-lto thego testinvocations forgnmi_server(incheck_gotest) andINTEGRATION_ENV_PKGS(incheck_gotest_junit). This flag disables inlining so gomonkey can insert its patches at the function entry points.The flag has no effect on production binaries and does not break any other tests — it only makes the test binary slightly larger and marginally slower to compile.
References