test.yml RawHistoryFolder
1name: Test
2
3on: [push, pull_request]
4
5env:
6 QEMU_VERSION: "10.2.1+ds-1"
7
8jobs:
9 test:
10 strategy:
11 matrix:
12 os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest, windows-latest]
13 go: ['1.18.x', '1.19.x', '1.20.x', '1.21.x', '1.22.x', '1.23.x', '1.24.x', '1.25.x', '1.26.x']
14 name: Test with Go ${{ matrix.go }} on ${{ matrix.os }}
15 runs-on: ${{ matrix.os }}
16 defaults:
17 run:
18 shell: bash
19 steps:
20 - name: Git
21 run: |
22 # See actions/checkout#135
23 git config --global core.autocrlf false
24 git config --global core.eol lf
25
26 - name: Checkout
27 uses: actions/checkout@v5
28
29 - name: Setup Go
30 uses: actions/setup-go@v6
31 with:
32 go-version: ${{ matrix.go }}
33
34 - name: Set up the prerequisites
35 if: runner.os == 'Windows'
36 uses: msys2/setup-msys2@v2
37
38 - name: go vet
39 run: |
40 env CGO_ENABLED=0 go vet -v ./...
41
42 - name: gofmt
43 run: test -z "$(gofmt -s -l .)"
44
45 - name: go build
46 run: |
47 go build -v ./...
48 # Compile without optimization to check potential stack overflow.
49 # The option '-gcflags=all=-N -l' is often used at Visual Studio Code.
50 # See also https://go.googlesource.com/vscode-go/+/HEAD/docs/debugging.md#launch and the issue hajimehoshi/ebiten#2120.
51 go build "-gcflags=all=-N -l" -v ./...
52
53 # Check cross-compiling Windows binaries.
54 env GOOS=windows GOARCH=386 go build -v ./...
55 env GOOS=windows GOARCH=amd64 go build -v ./...
56 env GOOS=windows GOARCH=arm64 go build -v ./...
57
58 # Check cross-compiling macOS binaries.
59 env GOOS=darwin GOARCH=amd64 go build -v ./...
60 env GOOS=darwin GOARCH=arm64 go build -v ./...
61
62 # Check cross-compiling Linux binaries.
63 env GOOS=linux GOARCH=amd64 go build -v ./...
64 env GOOS=linux GOARCH=arm64 go build -v ./...
65
66 # Check cross-compiling FreeBSD binaries.
67 # gcflags -std is necessary to make fakecgo the Cgo for
68 # FreeBSD to add the symbols that libc.so depends on.
69 env GOOS=freebsd GOARCH=amd64 go build -gcflags="github.com/bnema/purego/internal/fakecgo=-std" -v ./...
70 env GOOS=freebsd GOARCH=arm64 go build -gcflags="github.com/bnema/purego/internal/fakecgo=-std" -v ./...
71
72 # Check cross-compiling NetBSD binaries.
73 env GOOS=netbsd GOARCH=amd64 go build -v ./...
74 env GOOS=netbsd GOARCH=arm64 go build -v ./...
75
76 - name: go build (Linux minor architectures)
77 # Test them only on the latest Go to reduce CI time.
78 # s390x cannot be tested here as it requires Cgo.
79 if: startsWith(matrix.go, '1.26.')
80 run: |
81 # Check cross-compiling Linux binaries for minor architectures.
82 env GOOS=linux GOARCH=loong64 go build -v ./...
83 env GOOS=linux GOARCH=ppc64le go build -v ./...
84 env GOOS=linux GOARCH=riscv64 go build -v ./...
85
86 - name: go build (plugin)
87 if: runner.os == 'Linux' || runner.os == 'macOS'
88 run:
89 # Make sure that plugin buildmode works since we save the R15 register (#254)
90 go build -buildmode=plugin ./examples/libc
91
92 - name: go mod vendor
93 if: runner.os != 'Linux'
94 run: |
95 mkdir /tmp/vendoring
96 cd /tmp/vendoring
97 go mod init foo
98 echo 'package main' > main.go
99 echo 'import (' >> main.go
100 echo ' _ "github.com/bnema/purego"' >> main.go
101 echo ')' >> main.go
102 echo 'func main() {}' >> main.go
103 go mod edit -replace github.com/bnema/purego=$GITHUB_WORKSPACE
104 go mod tidy
105 go mod vendor
106 go build -v .
107
108 - name: go test
109 run: |
110 env CGO_ENABLED=0 go test -shuffle=on -v -count=10 ./...
111 env CGO_ENABLED=1 go test -shuffle=on -v -count=10 ./...
112 # Compile without optimization to check potential stack overflow.
113 # The option '-gcflags=all=-N -l' is often used at Visual Studio Code.
114 # See also https://go.googlesource.com/vscode-go/+/HEAD/docs/debugging.md#launch.
115 env CGO_ENABLED=0 go test "-gcflags=all=-N -l" -v ./...
116 env CGO_ENABLED=1 go test "-gcflags=all=-N -l" -v ./...
117
118 - name: go test (Windows 386)
119 if: runner.os == 'Windows'
120 run: |
121 env CGO_ENABLED=0 GOARCH=386 go test -shuffle=on -v -count=10 ./...
122 env CGO_ENABLED=1 GOARCH=386 go test -shuffle=on -v -count=10 ./...
123
124 - name: go test (Linux 386)
125 if: ${{ runner.os == 'Linux' && runner.arch != 'ARM64' }}
126 run: |
127 sudo apt-get update
128 sudo apt-get install gcc-multilib
129 sudo apt-get install g++-multilib
130 env CGO_ENABLED=0 GOARCH=386 go test -shuffle=on -v -count=10 ./...
131 env CGO_ENABLED=1 GOARCH=386 go test -shuffle=on -v -count=10 ./...
132
133 - name: go test (Linux arm)
134 if: ${{ runner.os == 'Linux' && runner.arch == 'ARM64' }}
135 run: |
136 sudo apt-get update
137 sudo apt-get install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf libc6-armhf-cross
138
139 # Install QEMU 10.x from Debian trixie. Ubuntu 24.04 ships QEMU 8.2
140 # which has a bug where inter-thread signal delivery (tgkill) hangs,
141 # causing TestSetuidEtc to deadlock.
142 wget -q https://ftp.debian.org/debian/pool/main/q/qemu/qemu-user_${QEMU_VERSION}_arm64.deb -O /tmp/qemu-user.deb
143 wget -q https://ftp.debian.org/debian/pool/main/q/qemu/qemu-user-binfmt_${QEMU_VERSION}_arm64.deb -O /tmp/qemu-user-binfmt.deb
144 sudo dpkg --force-depends -i /tmp/qemu-user.deb /tmp/qemu-user-binfmt.deb
145 sudo apt-get -f install -y
146
147 # Create symlink for the dynamic linker that QEMU expects
148 sudo ln -sf /usr/arm-linux-gnueabihf/lib/ld-linux-armhf.so.3 /lib/ld-linux.so.3
149 go env -w CC=arm-linux-gnueabihf-gcc
150 go env -w CXX=arm-linux-gnueabihf-g++
151 env GOOS=linux GOARCH=arm CGO_ENABLED=0 go test -c -o=purego-test-nocgo .
152 env QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf qemu-arm ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10
153 env GOOS=linux GOARCH=arm CGO_ENABLED=1 go test -c -o=purego-test-cgo .
154 env QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf qemu-arm ./purego-test-cgo -test.shuffle=on -test.v -test.count=10
155 go env -u CC
156 go env -u CXX
157
158 - name: go test race (no Cgo)
159 if: ${{ runner.os == 'macOS' && !startsWith(matrix.go, '1.18.') && !startsWith(matrix.go, '1.19.') }}
160 run: |
161 # -race usually requires Cgo, but macOS is an exception. See https://go.dev/doc/articles/race_detector#Requirements
162 env CGO_ENABLED=0 go test -race -shuffle=on -v -count=10 ./...
163
164 - name: go test race (Cgo)
165 if: ${{ !startsWith(matrix.go, '1.18.') && !startsWith(matrix.go, '1.19.') }}
166 run: |
167 env CGO_ENABLED=1 go test -race -shuffle=on -v -count=10 ./...
168
169 minor-arches:
170 strategy:
171 matrix:
172 # Test only the latest two Go versions to save CI time.
173 # See https://go.dev/doc/devel/release#policy
174 go: ['1.25.x', '1.26.x']
175 name: Test with Go ${{ matrix.go }} on Linux minor architectures
176 runs-on: ubuntu-latest
177 defaults:
178 run:
179 shell: bash
180 steps:
181 - name: Checkout
182 uses: actions/checkout@v5
183
184 - name: Setup Go
185 uses: actions/setup-go@v6
186 with:
187 go-version: ${{ matrix.go }}
188
189 - name: Set up the prerequisites
190 run: |
191 sudo apt-get update
192 sudo apt-get install -y \
193 gcc-14-loongarch64-linux-gnu g++-14-loongarch64-linux-gnu \
194 gcc-powerpc64le-linux-gnu g++-powerpc64le-linux-gnu \
195 gcc-riscv64-linux-gnu g++-riscv64-linux-gnu \
196 gcc-s390x-linux-gnu g++-s390x-linux-gnu
197
198 # Install QEMU 10.x from Debian trixie. Ubuntu 24.04 ships QEMU 8.2
199 # which has a bug where inter-thread signal delivery (tgkill) hangs,
200 # causing TestSetuidEtc to deadlock.
201 wget -q https://ftp.debian.org/debian/pool/main/q/qemu/qemu-user_${QEMU_VERSION}_amd64.deb -O /tmp/qemu-user.deb
202 wget -q https://ftp.debian.org/debian/pool/main/q/qemu/qemu-user-binfmt_${QEMU_VERSION}_amd64.deb -O /tmp/qemu-user-binfmt.deb
203 sudo dpkg --force-depends -i /tmp/qemu-user.deb /tmp/qemu-user-binfmt.deb
204 sudo apt-get -f install -y
205
206 # Verify that the expected QEMU binaries are installed and usable.
207 qemu-loongarch64 --version
208 qemu-ppc64le --version
209 qemu-riscv64 --version
210 qemu-s390x --version
211
212 - name: go test (Linux loong64)
213 run: |
214 go env -w CC=loongarch64-linux-gnu-gcc-14
215 go env -w CXX=loongarch64-linux-gnu-g++-14
216 env GOOS=linux GOARCH=loong64 CGO_ENABLED=0 go test -c -o=purego-test-nocgo .
217 env QEMU_LD_PREFIX=/usr/loongarch64-linux-gnu qemu-loongarch64 ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10
218 env GOOS=linux GOARCH=loong64 CGO_ENABLED=1 go test -c -o=purego-test-cgo .
219 env QEMU_LD_PREFIX=/usr/loongarch64-linux-gnu qemu-loongarch64 ./purego-test-cgo -test.shuffle=on -test.v -test.count=10
220 go env -u CC
221 go env -u CXX
222
223 - name: go test (Linux ppc64le)
224 run: |
225 go env -w CC=powerpc64le-linux-gnu-gcc
226 go env -w CXX=powerpc64le-linux-gnu-g++
227 env GOOS=linux GOARCH=ppc64le CGO_ENABLED=0 go test -c -o=purego-test-nocgo .
228 env QEMU_LD_PREFIX=/usr/powerpc64le-linux-gnu qemu-ppc64le ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10
229 env GOOS=linux GOARCH=ppc64le CGO_ENABLED=1 go test -c -o=purego-test-cgo .
230 env QEMU_LD_PREFIX=/usr/powerpc64le-linux-gnu qemu-ppc64le ./purego-test-cgo -test.shuffle=on -test.v -test.count=10
231 go env -u CC
232 go env -u CXX
233
234 - name: go test (Linux riscv64)
235 run: |
236 go env -w CC=riscv64-linux-gnu-gcc
237 go env -w CXX=riscv64-linux-gnu-g++
238 # Create symlink for the dynamic linker that QEMU expects
239 sudo ln -sf /usr/riscv64-linux-gnu/lib/ld-linux-riscv64-lp64d.so.1 /lib/ld.so.1
240 env GOOS=linux GOARCH=riscv64 CGO_ENABLED=0 go test -c -o=purego-test-nocgo .
241 env QEMU_LD_PREFIX=/usr/riscv64-linux-gnu qemu-riscv64 ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10
242 env GOOS=linux GOARCH=riscv64 CGO_ENABLED=1 go test -c -o=purego-test-cgo .
243 env QEMU_LD_PREFIX=/usr/riscv64-linux-gnu qemu-riscv64 ./purego-test-cgo -test.shuffle=on -test.v -test.count=10
244 go env -u CC
245 go env -u CXX
246
247 - name: go test (Linux s390x)
248 run: |
249 go env -w CC=s390x-linux-gnu-gcc
250 go env -w CXX=s390x-linux-gnu-g++
251 env GOOS=linux GOARCH=s390x CGO_ENABLED=1 go test -c -o=purego-test-cgo .
252 env QEMU_LD_PREFIX=/usr/s390x-linux-gnu qemu-s390x ./purego-test-cgo -test.shuffle=on -test.v -test.count=10
253 go env -u CC
254 go env -u CXX
255
256 bsd:
257 strategy:
258 matrix:
259 os: ['FreeBSD', 'NetBSD']
260 # Test only the latest two Go versions to save CI time.
261 # See https://go.dev/doc/devel/release#policy
262 go: ['1.25.8', '1.26.1']
263 name: Test with Go ${{ matrix.go }} on ${{ matrix.os }}
264 runs-on: ubuntu-22.04
265 defaults:
266 run:
267 shell: bash
268 steps:
269 - uses: actions/checkout@v5
270 - name: Run in FreeBSD
271 if: matrix.os == 'FreeBSD'
272 uses: vmactions/freebsd-vm@v1
273 with:
274 usesh: true
275 prepare: |
276 fetch https://go.dev/dl/go${{matrix.go}}.freebsd-amd64.tar.gz
277 rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.freebsd-amd64.tar.gz
278 chmod +x $GITHUB_WORKSPACE/.github/scripts/bsd_tests.sh
279 run: $GITHUB_WORKSPACE/.github/scripts/bsd_tests.sh
280 - name: Run in NetBSD
281 if: matrix.os == 'NetBSD'
282 uses: vmactions/netbsd-vm@v1
283 with:
284 usesh: true
285 prepare: |
286 ftp https://go.dev/dl/go${{matrix.go}}.netbsd-amd64.tar.gz
287 mkdir /usr/local
288 rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.netbsd-amd64.tar.gz
289 chmod +x $GITHUB_WORKSPACE/.github/scripts/bsd_tests.sh
290 run: $GITHUB_WORKSPACE/.github/scripts/bsd_tests.sh