Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -768,9 +768,21 @@ jobs:
with:
programs: '["debug"]'

# x86_64 Android, against the Windows package (which ships Android's libraries): the tester's
# tests and the default library's, under every memory model, built with the package's compiler
# and run on an x86_64 emulator. The other ABIs are linked only (test-compile-android-link).
test_android:
name: Android emulator
needs: [defaultlib_commit, build_on_windows]
uses: ./.github/workflows/test-android.yml
with:
package: artifact
defaultlib_sha: ${{ needs.defaultlib_commit.outputs.sha }}

create_release:
needs: [build_on_windows, build_on_linux, test_defaultlib_windows, test_defaultlib_linux,
test_wasm_windows, test_wasm_linux, test_debug_programs_windows, test_debug_programs_linux]
test_wasm_windows, test_wasm_linux, test_debug_programs_windows, test_debug_programs_linux,
test_android]
name: Create Release
runs-on: ubuntu-latest
steps:
Expand Down
157 changes: 157 additions & 0 deletions .github/workflows/test-android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
name: Test - Android (emulator)

# The tester's tests and the default library's, built for x86_64 Android (API 29) under -mm=gc, rc,
# none and own with a Windows package's compiler and Android libraries, and run on an x86_64 Android
# emulator (tslang/test/android/run_tests.mjs). The package ships Android's libraries only for
# Windows, so Windows builds the programs and Linux, which has KVM, runs the emulator.
#
# create-release.yml calls it with the package it has just built (package: artifact). A pull request
# that changes the runner, and a manual run, test the latest published release's package.

on:
workflow_call:
inputs:
package:
description: "artifact: this run's tslang-windows-asset; release: the latest published release's Windows package"
type: string
default: release
defaultlib_sha:
description: the TypeScriptCompilerDefaultLib commit the package's default library was built from (default its main)
type: string
default: ''
pull_request:
branches: [ main ]
paths:
- 'tslang/test/android/**'
- 'tslang/test/suites.mjs'
- '.github/workflows/test-android.yml'
workflow_dispatch:

jobs:
build:
name: Build Android tests (x86_64)
runs-on: windows-2025-vs2026
timeout-minutes: 60
env:
TOOL_PATH: ${{ github.workspace }}\__tslang
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 24

- name: Clone Default Library
shell: pwsh
env:
DEFAULTLIB_SHA: ${{ inputs.defaultlib_sha }}
run: |
git clone https://github.com/ASDAlexander77/TypeScriptCompilerDefaultLib.git
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
if ($env:DEFAULTLIB_SHA) {
git -C TypeScriptCompilerDefaultLib checkout --detach $env:DEFAULTLIB_SHA
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}

- name: Download the package (this run's)
if: inputs.package == 'artifact'
uses: actions/download-artifact@v4
with:
name: tslang-windows-asset

- name: Download the package (the latest release's)
if: inputs.package != 'artifact'
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release download --repo ${{ github.repository }} --pattern '*-windows-x64.zip'
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

- name: Unpack the package
shell: pwsh
run: |
$zip = Get-ChildItem -Filter '*-windows-x64.zip' | Select-Object -First 1
Write-Host "package: $($zip.Name)"
Expand-Archive -Path $zip.FullName -DestinationPath $env:TOOL_PATH
Remove-Item $zip.FullName
New-Item -ItemType Directory -Force -Path TypeScriptCompilerDefaultLib\__build | Out-Null
Move-Item -Path (Join-Path $env:TOOL_PATH 'defaultlib') -Destination TypeScriptCompilerDefaultLib\__build\defaultlib -ErrorAction Stop
& (Join-Path $env:TOOL_PATH 'tslang.exe') --version

- name: Build the tests for x86_64 Android
shell: pwsh
working-directory: ${{ github.workspace }}/tslang/test/android
run: |
$ndk = if ($env:ANDROID_NDK_LATEST_HOME) { $env:ANDROID_NDK_LATEST_HOME } else { $env:ANDROID_NDK_HOME }
if (-not $ndk) { Write-Error "no Android NDK on this runner (ANDROID_NDK_LATEST_HOME / ANDROID_NDK_HOME)"; exit 1 }
node run_tests.mjs --build "--tslang=$(Join-Path $env:TOOL_PATH 'tslang.exe')" `
"--default-lib-repo=${{ github.workspace }}\TypeScriptCompilerDefaultLib" `
"--android-lib=$(Join-Path $env:TOOL_PATH 'android\x86_64\lib')" "--android-ndk-path=$ndk" -j4
$code = $LASTEXITCODE
if ($code -ne 0) { Get-Content out\results.txt -ErrorAction SilentlyContinue }
tar -czf android-tests.tgz -C out .
exit $code

- name: Upload the tests
uses: actions/upload-artifact@v4
with:
name: android-tests
path: tslang/test/android/android-tests.tgz
retention-days: 1

run:
name: Run Android tests (x86_64 emulator, API 29)
needs: build
runs-on: ubuntu-24.04
timeout-minutes: 90
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 24

- name: Download the tests
uses: actions/download-artifact@v4
with:
name: android-tests
path: tslang/test/android

- name: Unpack the tests
working-directory: ${{ github.workspace }}/tslang/test/android
shell: bash
run: mkdir -p out && tar -xzf android-tests.tgz -C out && rm android-tests.tgz && du -sh out

# the emulator needs KVM, which the runner has but does not open to its user
- name: Enable KVM
shell: bash
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

- name: Run the tests on the emulator
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
arch: x86_64
target: default
cores: 4
ram-size: 4096M
disable-animations: true
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -no-snapshot
script: cd tslang/test/android && node run_tests.mjs --run --adb=adb || { cat out/results.txt; exit 1; }

- name: Keep the results
if: always()
uses: actions/upload-artifact@v4
with:
name: android-test-results
path: tslang/test/android/out/results.txt
retention-days: 7
if-no-files-found: ignore
1 change: 1 addition & 0 deletions tslang/test/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
out*/
43 changes: 43 additions & 0 deletions tslang/test/android/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Running the tests on Android

[run_tests.mjs](run_tests.mjs) builds the tester's tests and the default library's tests for
Android, and runs them on a device or an emulator through adb. Which tests there are, and when one
passes, is shared with the wasm tests: [../suites.mjs](../suites.mjs).

node run_tests.mjs [--build | --run] [--suite=tester,defaultlib] [--mm=gc,rc,none,own] [--abi=x86_64] [-j<n>] [filter]

- `--build` compiles every test with `-mtriple=<abi's triple, API 29> --opt` and links it through
the NDK (`ANDROID_NDK_HOME` or `--android-ndk-path`). It uses the Android default library, the
collector and the async runtime: `scripts\build_gc_release_android.bat`,
`scripts\build_tslang_runtime_release_android.bat` and the default library's
`scripts\build_android.bat`, or a release package's (`--android-lib=<package>\android\<abi>\lib`).
Each program is stripped. The programs and `manifest.json` go to `out/`.
- `--run` needs only adb and `out/`. It runs one leg (a suite under a model) at a time in
`/data/local/tmp/tslang-tests`: it pushes the leg's programs, runs them on the device four at a
time, each under `timeout` and a memory limit, and pulls back each one's exit code and the last
lines of its output. The summary and every failure are written to `out/results.txt`.
- With neither flag it does both.

The tests in [android_skips.txt](android_skips.txt) are skipped, each with its reason. So are the
default library's tests marked `// gc only` (except under gc) or `// not own` (under own). Under
`-mm=own`, a test that does not compile for the host either is listed as NATIVE, as in the wasm
runner.

## An emulator

An x86_64 system image runs the x86_64 programs natively. For example, with the Android SDK:

sdkmanager "system-images;android-29;default;x86_64" "emulator" "platform-tools"
avdmanager create avd -n tslang_api29_x86_64 -k "system-images;android-29;default;x86_64"
emulator -avd tslang_api29_x86_64 -no-window -no-audio -no-boot-anim -no-snapshot -memory 2048

arm64-v8a and armeabi-v7a programs need an arm device: an x86_64 emulator runs them only through
its binary translator, which is not reliable enough to test with.

## In CI

[test-android.yml](../../../.github/workflows/test-android.yml) builds the x86_64 programs on
Windows, with a Windows package's compiler and Android libraries (the only package that ships
them), and runs them on an API 29 x86_64 emulator on Linux. A release runs it against the package
it has just built (`test_android` in `create-release.yml`); a pull request that changes the runner
runs it against the latest published release.
10 changes: 10 additions & 0 deletions tslang/test/android/android_skips.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Tests run_tests.mjs does not run on Android: `<file> [<abi or model>,...] # <reason>`, every leg
# when none is given.

# cannot work on Android
00cppvtable_hidden_return.ts # its hand-made vtable slots return a record the MSVC way: Windows only, as in ctest
fetch.ts # (default library) fetch(): Android's default library has no HTTP (no libcurl in the NDK), so the request throws
json.ts none # (default library) builds a 100000-character string a character at a time: -mm=none frees none of the ~5 GB

# fails natively under the same model too (not run natively under it by ctest)
00global_interface_initializer.ts own # asserts "a field read" (native own: the same assert)
Loading
Loading