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