Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 (fix): Make test-unit target execution on macOS by disabling CGO_ENABLED #1453

Conversation

camilamacedo86
Copy link
Contributor

@camilamacedo86 camilamacedo86 commented Nov 13, 2024

In Linux environments, it is necessary to set CGO_ENABLED=1 for running unit tests with the -race flag, as illustrated in this example: GitHub Actions Run.

However, enabling CGO_ENABLED on macOS can lead to issues, including warnings such as:

 ld: warning: ‘/private/var/folders/xf/_py4d4yn7qqdlr5pym3pxvnc0000gn/T/go-link-38050737/000012.o’ has malformed LC_DYSYMTAB, expected 98 undefined symbols to start at index 1626, found 95 undefined symbols starting at index 1626

By disabling it, everything works fine on Mac OS. Example:

 $ make test-unit
rm -rf /Users/camiladeomacedo/go/src/github.com/operator-framework/operator-controller/coverage/unit && mkdir -p /Users/camiladeomacedo/go/src/github.com/operator-framework/operator-controller/coverage/unit
eval $(/Users/camiladeomacedo/go/bin/setup-envtest-v0.0.0-20240820183333-e6c3d139d2b6 use -p env 1.31.x ) && \
            CGO_ENABLED=0 go test \
                -tags 'containers_image_openpgp' \
                -cover -coverprofile /Users/camiladeomacedo/go/src/github.com/operator-framework/operator-controller/coverage/unit.out \
                -count=1 -race -short \
                github.com/operator-framework/operator-controller/api/v1 github.com/operator-framework/operator-controller/cmd/manager github.com/operator-framework/operator-controller/internal/action github.com/operator-framework/operator-controller/internal/action/error github.com/operator-framework/operator-controller/internal/applier github.com/operator-framework/operator-controller/internal/authentication github.com/operator-framework/operator-controller/internal/bundleutil github.com/operator-framework/operator-controller/internal/catalogmetadata/cache github.com/operator-framework/operator-controller/internal/catalogmetadata/client github.com/operator-framework/operator-controller/internal/catalogmetadata/compare github.com/operator-framework/operator-controller/internal/catalogmetadata/filter github.com/operator-framework/operator-controller/internal/conditionsets github.com/operator-framework/operator-controller/internal/contentmanager github.com/operator-framework/operator-controller/internal/contentmanager/cache github.com/operator-framework/operator-controller/internal/contentmanager/source github.com/operator-framework/operator-controller/internal/contentmanager/source/internal github.com/operator-framework/operator-controller/internal/controllers github.com/operator-framework/operator-controller/internal/features github.com/operator-framework/operator-controller/internal/finalizers github.com/operator-framework/operator-controller/internal/httputil github.com/operator-framework/operator-controller/internal/labels github.com/operator-framework/operator-controller/internal/resolve github.com/operator-framework/operator-controller/internal/rukpak/convert github.com/operator-framework/operator-controller/internal/rukpak/operator-registry github.com/operator-framework/operator-controller/internal/rukpak/preflights/crdupgradesafety github.com/operator-framework/operator-controller/internal/rukpak/source github.com/operator-framework/operator-controller/internal/rukpak/util github.com/operator-framework/operator-controller/internal/scheme github.com/operator-framework/operator-controller/internal/version \
                -test.gocoverdir=/Users/camiladeomacedo/go/src/github.com/operator-framework/operator-controller/coverage/unit
	github.com/operator-framework/operator-controller/cmd/manager		coverage: 0.0% of statements
ok  	github.com/operator-framework/operator-controller/api/v1	1.732s	coverage: 0.8% of statements
	github.com/operator-framework/operator-controller/internal/applier	coverage: 0.0% of statements
?   	github.com/operator-framework/operator-controller/internal/conditionset[no test files]
	github.com/operator-framework/operator-controller/internal/contentmanager		coverage: 0.0% of statements
ok  	github.com/operator-framework/operator-controller/internal/action	5.519s	coverage: 30.0% of statements
ok  	github.com/operator-framework/operator-controller/internal/action/error4.436s	coverage: 94.1% of statements
ok  	github.com/operator-framework/operator-controller/internal/authentication	2.163s	coverage: 69.6% of statements
ok  	github.com/operator-framework/operator-controller/internal/bundleutil	4.232s	coverage: 90.9% of statements
ok  	github.com/operator-framework/operator-controller/internal/catalogmetadata/cache	3.640s	coverage: 85.5% of statements
	github.com/operator-framework/operator-controller/internal/contentmanager/source/internal		coverage: 0.0% of statements
ok  	github.com/operator-framework/operator-controller/internal/catalogmetadata/client	5.946s	coverage: 86.8% of statements
ok  	github.com/operator-framework/operator-controller/internal/catalogmetadata/compare	2.887s	coverage: 100.0% of statements
ok  	github.com/operator-framework/operator-controller/internal/catalogmetadata/filter	3.269s	coverage: 89.7% of statements
ok  	github.com/operator-framework/operator-controller/internal/contentmanager/cache	1.573s	coverage: 78.7% of statements
ok  	github.com/operator-framework/operator-controller/internal/contentmanager/source	2.003s	coverage: 71.4% of statements
?   	github.com/operator-framework/operator-controller/internal/labels	[no test files]
	github.com/operator-framework/operator-controller/internal/features	coverage: 0.0% of statements
	github.com/operator-framework/operator-controller/internal/finalizers	coverage: 0.0% of statements
?   	github.com/operator-framework/operator-controller/internal/rukpak/operator-registry	[no test files]
	github.com/operator-framework/operator-controller/internal/scheme	coverage: 0.0% of statements
	github.com/operator-framework/operator-controller/internal/version	coverage: 0.0% of statements
ok  	github.com/operator-framework/operator-controller/internal/controllers	10.413s	coverage: 76.4% of statements
ok  	github.com/operator-framework/operator-controller/internal/httputil	2.413s	coverage: 69.2% of statements
ok  	github.com/operator-framework/operator-controller/internal/resolve	3.158s	coverage: 96.7% of statements
ok  	github.com/operator-framework/operator-controller/internal/rukpak/convert	2.500s	coverage: 71.5% of statements
ok  	github.com/operator-framework/operator-controller/internal/rukpak/preflights/crdupgradesafety	2.965s	coverage: 98.4% of statements
ok  	github.com/operator-framework/operator-controller/internal/rukpak/sourc3.507s	coverage: 81.1% of statements
ok  	github.com/operator-framework/operator-controller/internal/rukpak/util	3.227s	coverage: 92.6% of statements

Description

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

@camilamacedo86 camilamacedo86 requested a review from a team as a code owner November 13, 2024 11:39
Copy link

netlify bot commented Nov 13, 2024

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit dc5721c
🔍 Latest deploy log https://app.netlify.com/sites/olmv1/deploys/67349307d50c0000088e2eaa
😎 Deploy Preview https://deploy-preview-1453--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

In Linux environments, it is necessary to set `CGO_ENABLED=1` for running unit tests with the `-race` flag. However, enabling CGO_ENABLED on macOS can lead to issues, including warnings such as:

```
 ld: warning: ‘/private/var/folders/xf/_py4d4yn7qqdlr5pym3pxvnc0000gn/T/go-link-38050737/000012.o’ has malformed LC_DYSYMTAB, expected 98 undefined symbols to start at index 1626, found 95 undefined symbols starting at index 1626
```

By disabling it all works fine.
PS.: we do not enable CGO for our builds
@camilamacedo86 camilamacedo86 changed the title 🌱 Remove CGO_ENABLED=1 from test-unit target to fix tests on Mac OS 🌱 (fix): Make test-unit target execution on macOS by disabling CGO_ENABLED Nov 13, 2024
@joelanford
Copy link
Member

Are you sure the race detector is actually doing what it is supposed to be doing if we set CGO_ENABLED=0?

From https://go.dev/doc/articles/race_detector

The race detector requires cgo to be enabled, and on non-Darwin systems requires an installed C compiler. The race detector supports linux/amd64, linux/ppc64le, linux/arm64, linux/s390x, freebsd/amd64, netbsd/amd64, darwin/amd64, darwin/arm64, and windows/amd64.

The warnings are harmless (but I agree also annoying and clutter the output) golang/go#61229

@camilamacedo86
Copy link
Contributor Author

Ignore, for mac we should also use flag

From https://go.dev/doc/articles/race_detector

The race detector requires cgo to be enabled, and on non-Darwin systems requires an installed C compiler. The race detector supports linux/amd64, linux/ppc64le, linux/arm64, linux/s390x, freebsd/amd64, netbsd/amd64, darwin/amd64, darwin/arm64, and windows/amd64.

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