Skip to content

Commit 1d04dcd

Browse files
committed
termux ci: smoke-test the cross-built binary in emulated termux (qemu docker)
1 parent ec200e7 commit 1d04dcd

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

‎.github/workflows/termux.yml‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,48 @@ jobs:
7070
name: 3code-termux-arm64
7171
path: 3code-termux-arm64.tar.gz
7272

73+
smoke:
74+
# Run the cross-built binary inside an emulated Termux (qemu-aarch64
75+
# + bionic, provided by termux/termux-docker). The x86 runner can't
76+
# execute the binary natively, so this container is the only way to
77+
# catch startup failures (dlopen paths, tmpdir, TLS) without a phone.
78+
needs: build
79+
runs-on: ubuntu-22.04
80+
steps:
81+
- uses: actions/checkout@v4
82+
- uses: actions/download-artifact@v4
83+
with:
84+
name: 3code-termux-arm64
85+
86+
- name: Smoke test in emulated Termux
87+
run: |
88+
set -e
89+
tar xzf 3code-termux-arm64.tar.gz
90+
# The image's Termux tree is owned by uid/gid 1000 (system); run
91+
# the container as that user so pkg and $HOME behave.
92+
CID=$(docker create -t --platform linux/arm64 --user 1000:1000 \
93+
termux/termux-docker:latest sleep 900)
94+
docker start $CID >/dev/null
95+
trap 'docker rm -f $CID >/dev/null 2>&1 || true' EXIT
96+
docker exec $CID mkdir -p /data/data/com.termux/files/usr/tmp
97+
docker cp 3code-termux-arm64/3code $CID:/data/data/com.termux/files/usr/tmp/3code
98+
docker exec -t -e THREECODE_ALLOW_ROOT=1 $CID \
99+
/data/data/com.termux/files/usr/tmp/3code --version
100+
# --help exits 2 (ExitUsage) by design; assert it runs at all.
101+
docker exec -t -e THREECODE_ALLOW_ROOT=1 $CID sh -c \
102+
'/data/data/com.termux/files/usr/tmp/3code --help > /dev/null; \
103+
test $? -eq 2'
104+
# TLS init is the fragile part on Termux: the openssl wrapper
105+
# dlopens libssl.so.3/libcrypto.so.3 at module init, and it only
106+
# works when DT_RUNPATH (asserted in the build job) points at the
107+
# Termux lib dir. A bare --version doesn't touch TLS; this tiny
108+
# program does a verified handshake the same way api.nim does.
109+
docker cp tests/android_tlscheck.nim $CID:/data/data/com.termux/files/usr/tmp/
110+
docker exec -t $CID sh -lc \
111+
'command -v nim >/dev/null || pkg install -y nim >/dev/null 2>&1; \
112+
nim c -r -d:ssl /data/data/com.termux/files/usr/tmp/android_tlscheck.nim' \
113+
| grep -q 'tls handshake ok'
114+
73115
- name: Upload artifact to 3code.capocasa.dev
74116
if: github.ref == 'refs/heads/main'
75117
run: |

‎tests/android_tlscheck.nim‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## TLS smoke check for the Termux CI smoke job (termux.yml). Compiled and
2+
## run inside the emulated Termux container against the freshly built
3+
## android binary's runtime environment: the openssl wrapper dlopens
4+
## libssl.so.3/libcrypto.so.3 at module init, which only resolves when the
5+
## binary's DT_RUNPATH points at the Termux lib dir (see config.nims). A
6+
## verified handshake exercises exactly the code path api.nim depends on.
7+
import std/net, std/nativesockets
8+
9+
let ctx = newContext(verifyMode = CVerifyPeer)
10+
let s = newSocket()
11+
ctx.wrapSocket(s)
12+
s.connect("github.com", Port(443))
13+
echo "tls handshake ok"
14+
s.close()

0 commit comments

Comments
 (0)