go: honor [go-test].force_race and the test_race/test_msan/test_asan fields - #23640
Open
aegis-cipherowl wants to merge 1 commit into
Open
Conversation
…t_asan` fields `prepare_go_test_binary` built its `GoBuildOptionsFromTargetRequest` without `for_tests=True`. `go_extract_build_options_from_target` only populates `test_target_fields` when that flag is set, and it gates both the `[go-test].force_race` branch and the `go_package` `test_race` field (likewise for msan/asan). `go_package` also does not carry the non-test `race`/`cgo_enabled` fields, so `GoBuildOptionsFieldSet` does not apply to it either. The net effect was that the only field the resolution chain could still reach was `race` on the owning `go_mod` target -- both documented ways to enable the race detector for a test were silently ignored, and tests kept passing while no longer detecting races. Regression tests use a real unsynchronised write rather than the `race` build constraint, because package analysis passes `CGO_ENABLED` and `EXTRA_BUILD_TAGS` but never the `race` tag, so `//go:build race` files are not selected even when `-race` reaches the compiler. Verified red/green: both positive tests fail on the unfixed tree and pass with this change, and the default-off control passes either way. Introduced in pantsbuild#17825.
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.
prepare_go_test_binarybuilds itsGoBuildOptionsFromTargetRequestwithoutfor_tests=True:go_extract_build_options_from_targetonly populatestest_target_fieldswhen that flag is set:and
test_target_fieldsgates both the[go-test].force_racebranch and thego_package(test_race=...)field (likewisetest_msan/test_asan).go_packagealso does not carry the non-testrace/cgo_enabledfields, soGoBuildOptionsFieldSetdoes not apply to it either and that fallback misses as well. The net effect is that the only field the resolution chain can still reach israceon the owninggo_mod, so both documented ways to enable the race detector for a test are silently ignored — tests keep passing while no longer detecting races.Introduced in #17825, which split test-binary production from running it.
The existing coverage in
build_opts_test.pypassesfor_tests=Trueexplicitly, which is why it never caught the buggy caller.Fix
Pass
for_tests=True. One line.Tests
Three tests in
test_test.py, exercising[go-test].force_race,go_package(test_race=True), and a default-off control so the probe cannot pass for the wrong reason.They use a real unsynchronised write rather than a
//go:build racefile. That was my first attempt, and it does not work: package analysis passesCGO_ENABLEDandEXTRA_BUILD_TAGSbut never theracebuild tag, so//go:build racefiles are not selected even when-racedoes reach the compiler. That looks like a separate gap and I have deliberately left it alone here — happy to file it separately if it is not already known.Verified red/green on macOS/arm64:
test_race_detector_enabled_by_force_race_optiontest_race_detector_enabled_by_test_race_fieldtest_race_detector_disabled_by_defaultThe tests skip on platforms where
race_detector_supported()is false.Note:
build_opts_test.py::test_runtime_check_enable_fields_work_as_expected[msan|asan]andtest_test.py::test_external_test_with_use_coveragealready fail on my machine on an unmodifiedmain, so they are unrelated to this change.