test.yml RawHistoryFolder
1name: Test
2
3on: [push, pull_request]
4
5env:
6 QEMU_MAJOR_VERSION: "10"
7
8jobs:
9 test:
10 strategy:
11 matrix:
12 os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest, windows-latest, windows-11-arm]
13 go: ['1.25.x', '1.26.x', '1.27.0-rc.1']
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 Msys2
35 if: runner.os == 'Windows' && runner.arch != 'ARM64'
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/ebitengine/purego/internal/fakecgo=-std" -v ./...
70 env GOOS=freebsd GOARCH=arm64 go build -gcflags="github.com/ebitengine/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 if: startsWith(matrix.go, '1.27.')
79 run: |
80 # Check cross-compiling Linux binaries for minor architectures.
81 env GOOS=linux GOARCH=loong64 go build -v ./...
82 env GOOS=linux GOARCH=ppc64le go build -v ./...
83 env GOOS=linux GOARCH=riscv64 go build -v ./...
84 env GOOS=linux GOARCH=s390x go build -v ./...
85
86 - name: go build (Linux mips, Cgo)
87 # mips builds only via the Cgo fallback (CGO_ENABLED=1). See #460.
88 if: runner.os == 'Linux'
89 run: |
90 sudo apt-get update
91 sudo apt-get install -y gcc-mips-linux-gnu
92 env GOOS=linux GOARCH=mips CGO_ENABLED=1 CC=mips-linux-gnu-gcc go build -v ./...
93
94 - name: go build (plugin)
95 if: runner.os == 'Linux' || runner.os == 'macOS'
96 run:
97 # Make sure that plugin buildmode works since we save the R15 register (#254)
98 go build -buildmode=plugin ./examples/libc
99
100 - name: go mod vendor
101 if: runner.os != 'Linux'
102 run: |
103 mkdir /tmp/vendoring
104 cd /tmp/vendoring
105 go mod init foo
106 echo 'package main' > main.go
107 echo 'import (' >> main.go
108 echo ' _ "github.com/ebitengine/purego"' >> main.go
109 echo ')' >> main.go
110 echo 'func main() {}' >> main.go
111 go mod edit -replace github.com/ebitengine/purego=$GITHUB_WORKSPACE
112 go mod tidy
113 go mod vendor
114 go build -v .
115
116 - name: go test
117 run: |
118 env CGO_ENABLED=0 go test -shuffle=on -v -count=10 ./...
119 env CGO_ENABLED=1 go test -shuffle=on -v -count=10 ./...
120 # Compile without optimization to check potential stack overflow.
121 # The option '-gcflags=all=-N -l' is often used at Visual Studio Code.
122 # See also https://go.googlesource.com/vscode-go/+/HEAD/docs/debugging.md#launch.
123 env CGO_ENABLED=0 go test "-gcflags=all=-N -l" -v ./...
124 env CGO_ENABLED=1 go test "-gcflags=all=-N -l" -v ./...
125
126 - name: go test (Windows 386)
127 if: runner.os == 'Windows'
128 run: |
129 env CGO_ENABLED=0 GOARCH=386 go test -shuffle=on -v -count=10 ./...
130
131 - name: go test (Windows 386, Cgo)
132 if: runner.os == 'Windows' && runner.arch != 'ARM64'
133 run: |
134 env CGO_ENABLED=1 GOARCH=386 go test -shuffle=on -v -count=10 ./...
135
136 - name: go test (Linux 386)
137 if: ${{ runner.os == 'Linux' && runner.arch != 'ARM64' }}
138 run: |
139 sudo apt-get update
140 sudo apt-get install gcc-multilib
141 sudo apt-get install g++-multilib
142 env CGO_ENABLED=0 GOARCH=386 go test -shuffle=on -v -count=10 ./...
143 env CGO_ENABLED=1 GOARCH=386 go test -shuffle=on -v -count=10 ./...
144
145 - name: go test (Linux arm)
146 if: ${{ runner.os == 'Linux' && runner.arch == 'ARM64' }}
147 run: |
148 sudo apt-get update
149 sudo apt-get install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf libc6-armhf-cross
150
151 # Install the latest QEMU 10.x package from Debian. Ubuntu 24.04 ships QEMU 8.2
152 # which has a bug where inter-thread signal delivery (tgkill) hangs,
153 # causing TestSetuidEtc to deadlock.
154 arch=$(dpkg --print-architecture)
155 qemu_user_deb=$(
156 curl -fsSL https://ftp.debian.org/debian/pool/main/q/qemu/ |
157 grep -Eo "qemu-user_${QEMU_MAJOR_VERSION}\.[0-9.]+\+ds-[0-9]+([+~][A-Za-z0-9.+:~-]+)*_${arch}\.deb" |
158 sort -V |
159 tail -n 1
160 )
161 if [ -z "${qemu_user_deb}" ]; then
162 echo "missing qemu-user ${QEMU_MAJOR_VERSION}.x package for ${arch}" >&2
163 exit 1
164 fi
165 wget -q "https://ftp.debian.org/debian/pool/main/q/qemu/${qemu_user_deb}" -O /tmp/qemu-user.deb
166 sudo dpkg --force-depends -i /tmp/qemu-user.deb
167 sudo apt-get -f install -y
168
169 # Create symlink for the dynamic linker that QEMU expects
170 sudo ln -sf /usr/arm-linux-gnueabihf/lib/ld-linux-armhf.so.3 /lib/ld-linux.so.3
171 go env -w CC=arm-linux-gnueabihf-gcc
172 go env -w CXX=arm-linux-gnueabihf-g++
173 env GOOS=linux GOARCH=arm CGO_ENABLED=0 go test -c -o=purego-test-nocgo .
174 env QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf qemu-arm ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10
175 env GOOS=linux GOARCH=arm CGO_ENABLED=1 go test -c -o=purego-test-cgo .
176 env QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf qemu-arm ./purego-test-cgo -test.shuffle=on -test.v -test.count=10
177 go env -u CC
178 go env -u CXX
179
180 - name: go test race (no Cgo)
181 if: runner.os == 'macOS'
182 run: |
183 # -race usually requires Cgo, but macOS is an exception. See https://go.dev/doc/articles/race_detector#Requirements
184 env CGO_ENABLED=0 go test -race -shuffle=on -v -count=10 ./...
185
186 - name: go test race (Cgo)
187 if: ${{ !(runner.os == 'Windows' && runner.arch == 'ARM64') }}
188 run: |
189 env CGO_ENABLED=1 go test -race -shuffle=on -v -count=10 ./...
190
191 minor-arches:
192 strategy:
193 matrix:
194 go: ['1.25.x', '1.26.x', '1.27.0-rc.1']
195 name: Test with Go ${{ matrix.go }} on Linux minor architectures
196 runs-on: ubuntu-latest
197 defaults:
198 run:
199 shell: bash
200 steps:
201 - name: Checkout
202 uses: actions/checkout@v5
203
204 - name: Setup Go
205 uses: actions/setup-go@v6
206 with:
207 go-version: ${{ matrix.go }}
208
209 - name: Set up the prerequisites
210 run: |
211 sudo apt-get update
212 sudo apt-get install -y \
213 gcc-14-loongarch64-linux-gnu g++-14-loongarch64-linux-gnu \
214 gcc-powerpc64le-linux-gnu g++-powerpc64le-linux-gnu \
215 gcc-riscv64-linux-gnu g++-riscv64-linux-gnu \
216 gcc-s390x-linux-gnu g++-s390x-linux-gnu
217
218 # Install the latest QEMU 10.x package from Debian. Ubuntu 24.04 ships QEMU 8.2
219 # which has a bug where inter-thread signal delivery (tgkill) hangs,
220 # causing TestSetuidEtc to deadlock.
221 arch=$(dpkg --print-architecture)
222 qemu_user_deb=$(
223 curl -fsSL https://ftp.debian.org/debian/pool/main/q/qemu/ |
224 grep -Eo "qemu-user_${QEMU_MAJOR_VERSION}\.[0-9.]+\+ds-[0-9]+([+~][A-Za-z0-9.+:~-]+)*_${arch}\.deb" |
225 sort -V |
226 tail -n 1
227 )
228 if [ -z "${qemu_user_deb}" ]; then
229 echo "missing qemu-user ${QEMU_MAJOR_VERSION}.x package for ${arch}" >&2
230 exit 1
231 fi
232 wget -q "https://ftp.debian.org/debian/pool/main/q/qemu/${qemu_user_deb}" -O /tmp/qemu-user.deb
233 sudo dpkg --force-depends -i /tmp/qemu-user.deb
234 sudo apt-get -f install -y
235
236 # Verify that the expected QEMU binaries are installed and usable.
237 qemu-loongarch64 --version
238 qemu-ppc64le --version
239 qemu-riscv64 --version
240 qemu-s390x --version
241
242 - name: go test (Linux loong64)
243 run: |
244 go env -w CC=loongarch64-linux-gnu-gcc-14
245 go env -w CXX=loongarch64-linux-gnu-g++-14
246 env GOOS=linux GOARCH=loong64 CGO_ENABLED=0 go test -c -o=purego-test-nocgo .
247 env QEMU_LD_PREFIX=/usr/loongarch64-linux-gnu qemu-loongarch64 ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10
248 env GOOS=linux GOARCH=loong64 CGO_ENABLED=1 go test -c -o=purego-test-cgo .
249 env QEMU_LD_PREFIX=/usr/loongarch64-linux-gnu qemu-loongarch64 ./purego-test-cgo -test.shuffle=on -test.v -test.count=10
250 go env -u CC
251 go env -u CXX
252
253 - name: go test (Linux ppc64le)
254 run: |
255 go env -w CC=powerpc64le-linux-gnu-gcc
256 go env -w CXX=powerpc64le-linux-gnu-g++
257 env GOOS=linux GOARCH=ppc64le CGO_ENABLED=0 go test -c -o=purego-test-nocgo .
258 env QEMU_LD_PREFIX=/usr/powerpc64le-linux-gnu qemu-ppc64le ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10
259 env GOOS=linux GOARCH=ppc64le CGO_ENABLED=1 go test -c -o=purego-test-cgo .
260 env QEMU_LD_PREFIX=/usr/powerpc64le-linux-gnu qemu-ppc64le ./purego-test-cgo -test.shuffle=on -test.v -test.count=10
261 go env -u CC
262 go env -u CXX
263
264 - name: go test (Linux riscv64)
265 run: |
266 go env -w CC=riscv64-linux-gnu-gcc
267 go env -w CXX=riscv64-linux-gnu-g++
268 # Create symlink for the dynamic linker that QEMU expects
269 sudo ln -sf /usr/riscv64-linux-gnu/lib/ld-linux-riscv64-lp64d.so.1 /lib/ld.so.1
270 env GOOS=linux GOARCH=riscv64 CGO_ENABLED=0 go test -c -o=purego-test-nocgo .
271 env QEMU_LD_PREFIX=/usr/riscv64-linux-gnu qemu-riscv64 ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10
272 env GOOS=linux GOARCH=riscv64 CGO_ENABLED=1 go test -c -o=purego-test-cgo .
273 env QEMU_LD_PREFIX=/usr/riscv64-linux-gnu qemu-riscv64 ./purego-test-cgo -test.shuffle=on -test.v -test.count=10
274 go env -u CC
275 go env -u CXX
276
277 - name: go test (Linux s390x)
278 run: |
279 go env -w CC=s390x-linux-gnu-gcc
280 go env -w CXX=s390x-linux-gnu-g++
281 # CGO_ENABLED=0 is only supported on Go 1.27+ for s390x.
282 if [[ "${{ matrix.go }}" != 1.25.* && "${{ matrix.go }}" != 1.26.* ]]; then
283 env GOOS=linux GOARCH=s390x CGO_ENABLED=0 go test -c -o=purego-test-nocgo .
284 env QEMU_LD_PREFIX=/usr/s390x-linux-gnu qemu-s390x ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10
285 fi
286 env GOOS=linux GOARCH=s390x CGO_ENABLED=1 go test -c -o=purego-test-cgo .
287 env QEMU_LD_PREFIX=/usr/s390x-linux-gnu qemu-s390x ./purego-test-cgo -test.shuffle=on -test.v -test.count=10
288 go env -u CC
289 go env -u CXX
290
291 bsd:
292 strategy:
293 matrix:
294 os: ['FreeBSD', 'NetBSD']
295 go: ['1.25.8', '1.26.1']
296 name: Test with Go ${{ matrix.go }} on ${{ matrix.os }}
297 runs-on: ubuntu-22.04
298 defaults:
299 run:
300 shell: bash
301 steps:
302 - uses: actions/checkout@v5
303 - name: Run in FreeBSD
304 if: matrix.os == 'FreeBSD'
305 uses: vmactions/freebsd-vm@v1
306 with:
307 usesh: true
308 prepare: |
309 fetch https://go.dev/dl/go${{matrix.go}}.freebsd-amd64.tar.gz
310 rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.freebsd-amd64.tar.gz
311 chmod +x $GITHUB_WORKSPACE/.github/scripts/bsd_tests.sh
312 run: $GITHUB_WORKSPACE/.github/scripts/bsd_tests.sh
313 - name: Run in NetBSD
314 if: matrix.os == 'NetBSD'
315 uses: vmactions/netbsd-vm@v1
316 with:
317 usesh: true
318 prepare: |
319 ftp https://go.dev/dl/go${{matrix.go}}.netbsd-amd64.tar.gz
320 mkdir /usr/local
321 rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.netbsd-amd64.tar.gz
322 chmod +x $GITHUB_WORKSPACE/.github/scripts/bsd_tests.sh
323 run: $GITHUB_WORKSPACE/.github/scripts/bsd_tests.sh
324
325 # Android is tested on amd64 only. The emulator requires the system image
326 # architecture to match the host, and GitHub's arm64 hosted runners do not
327 # provide a usable KVM device, so there is no hosted hardware-accelerated path
328 # to an Android arm64 emulator. The arm64 struct ABI is already covered by the
329 # linux/arm64 `test` job, and Android's Bionic/cgo integration by this job.
330 android:
331 strategy:
332 fail-fast: false
333 matrix:
334 go: ['1.25.x', '1.26.x', '1.27.0-rc.1']
335 name: Test with Go ${{ matrix.go }} on Android amd64
336 runs-on: ubuntu-latest
337 defaults:
338 run:
339 shell: bash
340 steps:
341 - uses: actions/checkout@v5
342
343 - name: Setup Go
344 uses: actions/setup-go@v6
345 with:
346 go-version: ${{ matrix.go }}
347
348 # The tests compile their C libraries at run time via `go env CC`, but the
349 # emulator has no C toolchain. Every library the tests load must therefore be
350 # cross-compiled here and loaded as a prebuilt library at run time instead.
351 - name: Cross-compile the test binary and C libraries
352 run: |
353 set -eux
354 NDK="$ANDROID_NDK_LATEST_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin"
355 CC="$NDK/x86_64-linux-android21-clang"
356 mkdir -p prebuilt
357 # Build every library the tests load. Keep this in sync with the
358 # buildSharedLib callers in the tests; a missing entry surfaces as a
359 # "prebuilt lib ... no such file" failure on the emulator.
360 "$CC" -shared -Wall -Werror -fPIC -o prebuilt/structtest.so testdata/structtest/struct_test.c
361 "$CC" -shared -Wall -Werror -fPIC -o prebuilt/structreturntest.so testdata/structtest/structreturn_test.c
362 "$CC" -shared -Wall -Werror -fPIC -o prebuilt/libcbtest.so testdata/libcbtest/callback_test.c
363 "$CC" -shared -Wall -Werror -fPIC -o prebuilt/abitest.so testdata/abitest/abi_test.c
364 env GOOS=android GOARCH=amd64 CGO_ENABLED=1 CC="$CC" go test -c -o purego.test .
365
366 - name: Enable KVM
367 run: |
368 echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
369 sudo udevadm control --reload-rules
370 sudo udevadm trigger --name-match=kvm
371
372 - name: Run the test suite on the Android emulator
373 uses: reactivecircus/android-emulator-runner@v2
374 with:
375 api-level: 34
376 arch: x86_64
377 target: google_apis
378 emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim
379 script: |
380 set -eux
381 adb push purego.test /data/local/tmp/purego.test
382 adb push prebuilt /data/local/tmp/prebuilt
383 adb shell "chmod 755 /data/local/tmp/purego.test"
384 # TestSetuidEtc needs root and glibc (not Bionic) semantics; TestNestedDlopenCall
385 # needs the C++ runtime present on the device. Both are covered by the Linux
386 # runners, so skip them here rather than special-casing the emulator.
387 adb shell "cd /data/local/tmp && TMPDIR=/data/local/tmp PUREGO_TEST_PREBUILT_LIBDIR=/data/local/tmp/prebuilt ./purego.test -test.v -test.skip 'TestSetuidEtc|TestNestedDlopenCall'" | tee result.txt
388 grep -q '^PASS' result.txt
389 ! grep -q '^FAIL' result.txt
390
391 # TODO: Add an iOS job that runs the test suite on the iOS Simulator.
392 # iOS has no emulator runner equivalent: on a macOS runner the test binary must
393 # be wrapped into a .app and launched via `xcrun simctl` (or x/mobile's
394 # go_ios_exec), with the C libraries cross-compiled against the iphonesimulator
395 # SDK and loaded through PUREGO_TEST_PREBUILT_LIBDIR (as the android job does).
396 # Deprioritized because the iOS arm64 ABI matches macOS arm64, which the `test`
397 # job already runs.