Skip to content

Commit

Permalink
Add CI workflow to run android tests on mobile phones (#13024)
Browse files Browse the repository at this point in the history
Add a new workflow to cross-compile and run tests on Android devices.

It breaks out the Android target from the matrix
`cross_compile_and_test`. I think it makes sense to do so as Android has
its own matrix to run tests on multiple devices.

Currently this will only run on postsubmit due to the limited capacity
of the mobile devices.
  • Loading branch information
Jerry Wu authored Apr 19, 2023
1 parent 81cf28c commit e4e2398
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 11 deletions.
144 changes: 144 additions & 0 deletions .github/workflows/build_and_test_android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Copyright 2023 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# Workflow for android cross-compilation and tests jobs. It is designed to be
# called from the main workflow ci.yml. The concurrency of this workflow is
# controlled by the caller's job.

name: Build and test android

on:
workflow_call:
inputs:
runner-group:
required: true
type: string
runner-env:
required: true
type: string
write-caches:
required: true
type: string
is-pr:
required: true
type: boolean
build-dir:
required: true
type: string
build-dir-archive:
required: true
type: string
build-dir-gcs-artifact:
required: true
type: string

env:
# This duplicates the variable from ci.yml. The variable needs to be in env
# instead of the outputs of setup because it contains the run attempt and we
# want that to be the current attempt, not whatever attempt the setup step
# last ran in. It therefore can't be passed in via inputs because the env
# context isn't available there.
GCS_DIR: gs://iree-github-actions-${{ github.event_name == 'pull_request' && 'presubmit' || 'postsubmit' }}-artifacts/${{ github.run_id }}/${{ github.run_attempt }}

jobs:
cross_compile:
runs-on:
- self-hosted # must come first
- runner-group=${{ inputs.runner-group }}
- environment=${{ inputs.runner-env }}
- cpu
- os-family=Linux
env:
HOST_BUILD_DIR: ${{ inputs.build-dir }}
HOST_BUILD_DIR_ARCHIVE: ${{ inputs.build-dir-archive }}
HOST_BUILD_DIR_GCS_ARTIFACT: ${{ inputs.build-dir-gcs-artifact }}
IREE_WRITE_REMOTE_CCACHE: ${{ inputs.write-caches }}
outputs:
target-build-dir: ${{ steps.build.outputs.target-build-dir }}
target-build-dir-archive: ${{ steps.archive.outputs.target-build-dir-archive }}
target-build-dir-gcs-artifact: ${{ steps.upload.outputs.target-build-dir-gcs-artifact }}
steps:
- name: "Checking out repository"
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
- name: "Checking out runtime submodules"
run: ./build_tools/scripts/git/update_runtime_submodules.sh
- name: "Downloading build dir archive"
run: gcloud storage cp "${HOST_BUILD_DIR_GCS_ARTIFACT}" "${HOST_BUILD_DIR_ARCHIVE}"
- name: "Extracting build dir archive"
run: tar -xf "${HOST_BUILD_DIR_ARCHIVE}" "${HOST_BUILD_DIR}/install"
- name: "Build cross-compiling target"
id: build
env:
TARGET_BUILD_DIR: build-android-arm_64
run: |
./build_tools/github_actions/docker_run.sh \
--env "IREE_CCACHE_GCP_TOKEN=$(gcloud auth application-default print-access-token)" \
--env "IREE_WRITE_REMOTE_CCACHE=${IREE_WRITE_REMOTE_CCACHE}" \
--env "CCACHE_NAMESPACE=${DOCKER_IMAGE}" \
--env "IREE_TARGET_BUILD_DIR=${TARGET_BUILD_DIR}" \
--env "BUILD_PRESET=test" \
--env "IREE_HOST_BIN_DIR=${HOST_BUILD_DIR}/install/bin" \
gcr.io/iree-oss/android@sha256:3f641d25786b1e5e430ee4cacb8bfe57540fda5ecaa7ca2802c179c26e77ce09 \
build_tools/cmake/build_android.sh
echo "target-build-dir=${TARGET_BUILD_DIR}" >> "${GITHUB_OUTPUT}"
- name: "Creating archive of target build dir"
id: archive
env:
TARGET_BUILD_DIR: ${{ steps.build.outputs.target-build-dir }}
TARGET_BUILD_DIR_ARCHIVE: build-android-arm_64.tar
run: |
tar -cf "${TARGET_BUILD_DIR_ARCHIVE}" \
--exclude="*.o" \
--exclude="*.a" \
"${TARGET_BUILD_DIR}"
echo "target-build-dir-archive=${TARGET_BUILD_DIR_ARCHIVE}" >> "${GITHUB_OUTPUT}"
- name: "Uploading target build dir archive"
id: upload
env:
TARGET_BUILD_DIR_ARCHIVE: ${{ steps.archive.outputs.target-build-dir-archive }}
TARGET_BUILD_DIR_GCS_ARTIFACT: ${{ env.GCS_DIR }}/${{ steps.archive.outputs.target-build-dir-archive }}
run: |
gcloud storage cp "${TARGET_BUILD_DIR_ARCHIVE}" "${TARGET_BUILD_DIR_GCS_ARTIFACT}"
echo "target-build-dir-gcs-artifact=${TARGET_BUILD_DIR_GCS_ARTIFACT}" >> "${GITHUB_OUTPUT}"
test:
# These physical devices are not scalable. Only run on postsubmit for now.
if: (! inputs.is-pr)
needs: cross_compile
strategy:
matrix:
# TODO(#9855): Add Pixel-6-Pro and XT2201-2
target:
- device-name: Pixel-4
label-exclude: vulkan
name: test_on_${{ matrix.target.device-name }}
runs-on:
- self-hosted # must come first
- runner-group=${{ inputs.runner-group }}
- environment=${{ inputs.runner-env }}
- machine-type=${{ matrix.target.device-name }}
env:
TARGET_BUILD_DIR: ${{ needs.cross_compile.outputs.target-build-dir }}
TARGET_BUILD_DIR_ARCHIVE: ${{ needs.cross_compile.outputs.target-build-dir-archive }}
TARGET_BUILD_DIR_GCS_ARTIFACT: ${{ needs.cross_compile.outputs.target-build-dir-gcs-artifact }}
steps:
- name: "Checking out repository"
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
- name: "Downloading target build archive"
run: |
gcloud storage cp "${TARGET_BUILD_DIR_GCS_ARTIFACT}" "${TARGET_BUILD_DIR_ARCHIVE}"
- name: "Extracting target build dir archive"
run: tar -xf "${TARGET_BUILD_DIR_ARCHIVE}" "${TARGET_BUILD_DIR}"
- name: "Running tests"
env:
LABEL_EXCLUDE: ${{ matrix.target.label-exclude }}
run: |
ctest -j 4 \
--test-dir "${TARGET_BUILD_DIR}" \
--timeout=900 \
--output-on-failure \
--no-tests=error \
--label-exclude "${LABEL_EXCLUDE}"
26 changes: 20 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -861,12 +861,6 @@ jobs:
strategy:
matrix:
target:
- platform: android
arch: armv8.2-a
abi: arm64-v8a
docker_image: "gcr.io/iree-oss/android@sha256:3f641d25786b1e5e430ee4cacb8bfe57540fda5ecaa7ca2802c179c26e77ce09"
build_script: "./build_tools/cmake/build_android.sh"
# No test_script
- platform: linux
arch: riscv_64
abi: lp64d
Expand Down Expand Up @@ -938,6 +932,25 @@ jobs:
"${DOCKER_IMAGE}" \
"${TEST_SCRIPT}"
# Android cross-compilation and test is separated from cross_compile_and_test
# because some tests need to run on physical devices instead of emulators. And
# we need a fine-control on which tests only run on postsubmit as some devices
# are not scalable (while we want to test with Android emulator on ARM VMs on
# presubmit), which requires dynamic matrix generation (because "if" condition
# can't access matrix variable to skip certain matrix jobs for presubmit).
build_and_test_android:
needs: [setup, build_all]
if: fromJson(needs.setup.outputs.should-run)
uses: ./.github/workflows/build_and_test_android.yml
with:
runner-group: ${{ needs.setup.outputs.runner-group }}
runner-env: ${{ needs.setup.outputs.runner-env }}
write-caches: ${{ needs.setup.outputs.write-caches }}
is-pr: ${{ fromJson(needs.setup.outputs.is-pr) }}
build-dir: ${{ needs.build_all.outputs.build-dir }}
build-dir-archive: ${{ needs.build_all.outputs.build-dir-archive }}
build-dir-gcs-artifact: ${{ needs.build_all.outputs.build-dir-gcs-artifact }}

test_benchmark_suites:
needs: [setup, build_all, build_e2e_test_artifacts]
if: fromJson(needs.setup.outputs.should-run)
Expand Down Expand Up @@ -1051,6 +1064,7 @@ jobs:

# Crosscompilation
- cross_compile_and_test
- build_and_test_android

# Artifacts for e2e testing and benchmarking
- build_benchmark_tools
Expand Down
14 changes: 9 additions & 5 deletions build_tools/cmake/build_android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,26 @@
# Cross-compile the runtime using CMake targeting Android
#
# The required IREE_HOST_BIN_DIR environment variable indicates the location
# of the precompiled IREE binaries. Also requires that IREE_TARGET_ABI and
# ANDROID_NDK variables be set. The BUILD_PRESET environment variable indicates
# how the project should be configured: "test", "benchmark",
# "benchmark-with-tracing", or "benchmark-suite-test". Defaults to "test".
# of the precompiled IREE binaries. Also requires that ANDROID_NDK variables be
# set. The BUILD_PRESET environment variable indicates how the project should be
# configured: "test", "benchmark", "benchmark-with-tracing", or
# "benchmark-suite-test". Defaults to "test".
#
# The desired build directory can be passed as the first argument. Otherwise, it
# uses the environment variable IREE_TARGET_BUILD_DIR, defaulting to
# "build-android". Designed for CI, but can be run manually. It reuses the build
# directory if it already exists. Expects to be run from the root of the IREE
# repository.
#
# The default Android ABI is arm64-v8a, you can specify it with the variable
# IREE_ANDROID_ABI. See https://developer.android.com/ndk/guides/abis for the
# supported ABIs.


set -xeuo pipefail

BUILD_DIR="${1:-${IREE_TARGET_BUILD_DIR:-build-android}}"
ANDROID_ABI="${IREE_TARGET_ABI}"
ANDROID_ABI="${IREE_ANDROID_ABI:-arm64-v8a}"
IREE_HOST_BIN_DIR="$(realpath ${IREE_HOST_BIN_DIR})"
E2E_TEST_ARTIFACTS_DIR="${E2E_TEST_ARTIFACTS_DIR:-build-e2e-test-artifacts/e2e_test_artifacts}"
BUILD_PRESET="${BUILD_PRESET:-test}"
Expand Down

0 comments on commit e4e2398

Please sign in to comment.