Skip to content

Commit d42bd33

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
Add E2E-tested examples, fix CGo pointer bugs, add GitHub CI
Examples: - Add 12 new examples covering audio, camera, EGL, GLES, input, media, NNAPI, sensor, thermal, trace, hardware buffer, surface texture, window - All 59 examples verified passing on Android emulator (E2E) - Remove 7 non-runnable examples (font, vulkan, net, media/extractor-info) Code generator fixes: - Fix capigen return value conversion for opaque pointer types: use direct cast instead of incorrect double-dereference that caused SIGSEGV - Fix capigen ** parameter handling: pin both outer and inner pointers with runtime.Pinner to satisfy CGo's pointer check (fixes gles2/gles3) - Fix nnapi/model_add_operand.go: pin struct with Go pointer fields CI/Testing: - Add .github/workflows/ci.yml with unit tests, golangci-lint, example cross-compilation, and manual-trigger emulator E2E job - Add .golangci.yml configuration - Add e2e/run-examples.sh and Makefile e2e-examples target - Add examples/build_test.go for Go test-based cross-compilation check - Fix 14 golangci-lint warnings across tools packages
1 parent 4a202ef commit d42bd33

64 files changed

Lines changed: 3145 additions & 1281 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
13+
env:
14+
ANDROID_NDK_VERSION: r27c
15+
ANDROID_NDK_DIR_NAME: "27.2.12479018"
16+
17+
jobs:
18+
test:
19+
name: Unit Tests & Lint
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- uses: actions/setup-go@v5
25+
with:
26+
go-version: "1.24"
27+
28+
- name: Run unit tests
29+
run: make test
30+
31+
- name: Lint
32+
uses: golangci/golangci-lint-action@v9
33+
with:
34+
version: latest
35+
args: --timeout=5m ./tools/...
36+
37+
check-examples:
38+
name: Cross-compile Examples
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v4
42+
43+
- uses: actions/setup-go@v5
44+
with:
45+
go-version: "1.24"
46+
47+
- name: Install Android NDK
48+
run: |
49+
mkdir -p "$HOME/Android/Sdk/ndk"
50+
wget -q "https://dl.google.com/android/repository/android-ndk-${ANDROID_NDK_VERSION}-linux.zip" -O /tmp/ndk.zip
51+
unzip -q /tmp/ndk.zip -d "$HOME/Android/Sdk/ndk/"
52+
mv "$HOME/Android/Sdk/ndk/android-ndk-${ANDROID_NDK_VERSION}" "$HOME/Android/Sdk/ndk/${ANDROID_NDK_DIR_NAME}"
53+
54+
- name: Cross-compile examples for Android arm64
55+
run: make check-examples
56+
57+
e2e-examples:
58+
name: E2E Examples (Emulator)
59+
runs-on: ubuntu-latest
60+
if: github.event_name == 'workflow_dispatch'
61+
steps:
62+
- uses: actions/checkout@v4
63+
64+
- uses: actions/setup-go@v5
65+
with:
66+
go-version: "1.24"
67+
68+
- name: Enable KVM
69+
run: |
70+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
71+
sudo udevadm control --reload-rules
72+
sudo udevadm trigger --name-match=kvm
73+
74+
- name: Install Android SDK components
75+
uses: android-actions/setup-android@v3
76+
with:
77+
packages: |
78+
platform-tools
79+
emulator
80+
system-images;android-35;google_apis;x86_64
81+
platforms;android-35
82+
83+
- name: Install Android NDK
84+
run: |
85+
mkdir -p "$ANDROID_HOME/ndk"
86+
wget -q "https://dl.google.com/android/repository/android-ndk-${ANDROID_NDK_VERSION}-linux.zip" -O /tmp/ndk.zip
87+
unzip -q /tmp/ndk.zip -d "$ANDROID_HOME/ndk/"
88+
mv "$ANDROID_HOME/ndk/android-ndk-${ANDROID_NDK_VERSION}" "$ANDROID_HOME/ndk/${ANDROID_NDK_DIR_NAME}"
89+
90+
- name: Create AVD
91+
run: |
92+
echo "no" | avdmanager create avd \
93+
-n e2e_examples -k "system-images;android-35;google_apis;x86_64" --force
94+
95+
- name: Start emulator
96+
run: |
97+
$ANDROID_HOME/emulator/emulator \
98+
-avd e2e_examples -no-window -no-audio -no-boot-anim \
99+
-gpu swiftshader_indirect -no-metrics &
100+
echo "Waiting for emulator boot..."
101+
adb wait-for-device
102+
for i in $(seq 1 60); do
103+
RESULT=$(adb shell getprop sys.boot_completed 2>/dev/null | tr -d '\r\n')
104+
if [ "$RESULT" = "1" ]; then
105+
echo "Emulator booted after ~$((i*5))s"
106+
break
107+
fi
108+
sleep 5
109+
done
110+
111+
- name: Run examples E2E
112+
run: make e2e-examples

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ e2e/e2e_test
77
_build/
88
capi/manifests/.gen_*.yaml
99

10-
# Built binaries (go build outputs)
10+
# Built binaries (go build outputs in repo root)
1111
/basic-loop
1212
/capigen
13+
/capture-session
1314
/check-permissions
15+
/event-loop
1416
/headerspec
1517
/idiomgen
1618
/manager
1719
/null
1820
/obb-manager
21+
/offscreen-render
1922
/overview
2023
/specgen
2124
/sync-fences

.golangci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: "2"
2+
3+
run:
4+
timeout: 5m
5+
6+
linters:
7+
enable:
8+
- errcheck
9+
- govet
10+
- ineffassign
11+
- staticcheck
12+
- unused
13+
14+
formatters:
15+
enable:
16+
- gofmt
17+
18+
issues:
19+
max-issues-per-linter: 0
20+
max-same-issues: 0

Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ FIXTURE_MODULES := $(notdir $(wildcard tools/pkg/specgen/testdata/*/))
1717
NDK_SYSROOT := $(NDK_PATH)/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include
1818
C2FFI_BIN ?= c2ffi
1919

20-
.PHONY: all capi specs idiomatic clean regen fixtures test e2e e2e-build
20+
.PHONY: all capi specs idiomatic clean regen fixtures test lint check-examples e2e e2e-build e2e-examples
2121

2222
all: specs capi idiomatic
2323

@@ -85,6 +85,15 @@ regen: clean specs capi idiomatic
8585
test:
8686
go test $$(go list ./... | grep -v -E '/(capi|e2e|examples)/|/ndk/[a-z][a-z0-9]*$$') -count=1
8787

88+
lint:
89+
golangci-lint run ./tools/...
90+
91+
# Cross-compile all examples for Android arm64 to catch compile errors (requires NDK)
92+
check-examples:
93+
CGO_ENABLED=1 GOOS=android GOARCH=arm64 \
94+
CC=$(NDK_PATH)/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android35-clang \
95+
go build ./examples/...
96+
8897
# Cross-compile E2E test binary for Android x86_64 (requires NDK)
8998
e2e-build:
9099
CGO_ENABLED=1 GOOS=android GOARCH=amd64 \
@@ -95,6 +104,10 @@ e2e-build:
95104
e2e: e2e-build
96105
ANDROID_HOME=$(dir $(NDK_PATH)) ./e2e/run.sh
97106

107+
# Run all examples on Android emulator (requires running emulator + NDK)
108+
e2e-examples:
109+
./e2e/run-examples.sh
110+
98111
clean:
99112
@for m in $(MODULES); do rm -rf "capi/$$m/"; done
100113
rm -rf spec/generated/

capi/aaudio/aaudio.go

Lines changed: 18 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

capi/asset/asset.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)