main 3a10209

test.yml RawHistoryFolder

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

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close