diff --git a/.github/workflows/check-android-run-tests-on-emulator.sh b/.github/workflows/check-android-run-tests-on-emulator.sh new file mode 100755 index 0000000000..82d946cede --- /dev/null +++ b/.github/workflows/check-android-run-tests-on-emulator.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -e + +adb wait-for-device +while [[ -z "$(adb shell getprop sys.boot_completed | tr -d '\r')" ]]; do sleep 1; done + +any_failures=0 +for test in $(find target/${{ matrix.target }}/debug/deps/ -type f -executable ! -name "*.so" -name "*-*"); do + adb push "$test" /data/local/tmp/ + adb shell chmod +x /data/local/tmp/$(basename "$test") + adb shell /data/local/tmp/$(basename "$test") || any_failures=1 +done + +exit $any_failures diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index a490c722a1..5134115c51 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -136,3 +136,61 @@ jobs: (github.event_name == 'pull_request' && !github.event.pull_request.draft) || (github.event_name != 'workflow_dispatch' && github.event_name != 'pull_request') uses: ./.github/workflows/bench.yml + + test-android: + runs-on: ubuntu-latest + + strategy: + matrix: + include: + - target: x86_64-linux-android + emulator-arch: x86_64 + # Note that x86_64 image is only available for API 21+. See + # https://github.com/ReactiveCircus/android-emulator-runner?tab=readme-ov-file#configurations. + api-level: 21 + - target: i686-linux-android + emulator-arch: x86 + api-level: 19 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install JDK + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '21' + + - name: Install Android SDK + uses: android-actions/setup-android@v3 + + - name: Install Android NDK + run: sdkmanager --install "ndk;25.2.9519653" + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + target: ${{ matrix.target }} + + - uses: Swatinem/rust-cache@v2 + + - name: Install cargo-ndk + run: cargo install cargo-ndk + + - name: Build unit tests for Android + run: cargo ndk -t ${{ matrix.target }} test --no-run + + - name: Enable KVM group perms + 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: Set up Android Emulator and run tests + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: ${{ matrix.api-level }} + arch: ${{ matrix.emulator-arch }} + script: .github/workflows/check-android-run-tests-on-emulator.sh