-
Notifications
You must be signed in to change notification settings - Fork 33
Add enable_android_sdk_checks option for Android emulator testing #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
marcprux
wants to merge
84
commits into
swiftlang:main
Choose a base branch
from
swift-android-sdk:android-testing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+174
−25
Open
Changes from all commits
Commits
Show all changes
84 commits
Select commit
Hold shift + click to select a range
d8ce023
Add enable_android_sdk_checks option for Android emulator testing
marcprux b7d0a75
Update build flags
marcprux 51883a5
Pull request enable_android_sdk_checks: true
marcprux 427b18b
Fix script location
marcprux c082391
Fix script permissions
marcprux 1d76ea7
Download the Android SDK
marcprux b7e9a5d
Update the Android SDK
marcprux 1e9bf25
Install Android SDK using package manager
marcprux b19a2f9
Update the Android SDK
marcprux 4312ece
Install Java
marcprux 728894a
Install Java
marcprux cb08f99
Install commandline tools in correct directory
marcprux 4d8249c
Update Android SDK
marcprux bad3c64
Update Android SDK
marcprux 06d6ff7
Update Android SDK
marcprux 3c29f25
Use different Android emulator device
marcprux 988484d
Update path to Android emulator
marcprux cbf8812
Update path to Android emulator
marcprux 3620be4
Update path to Android emulator
marcprux 97923bd
Fix check for JAVA_HOME
marcprux 0c52793
Install sudo
marcprux 8b7cdf5
Better JAVA_HOME check
marcprux b363415
Try not enabling KVM
marcprux 9c38d01
Try not enabling KVM
marcprux 4031eee
Fix install path for Android AVD
marcprux 560f60a
Try to install KVM
marcprux b09c11b
Try to install KVM
marcprux 1ef5eb5
Just run tests on a single config
marcprux 8362509
Try installing KVM
marcprux f0a2e91
Try installing KVM
marcprux c97c292
Try installing KVM
marcprux 6932225
Try running emulator with -no-accel
marcprux 88e55ce
Try running tests
marcprux dedd2a8
Try running tests
marcprux 67efdb9
Try running tests
marcprux 1889eba
Try freeing disk space
marcprux 5c112a8
Try freeing disk space
marcprux 8551570
Try freeing disk space
marcprux a714374
Try freeing disk space
marcprux 1c088a2
Use x86_64-linux-android for test cases
marcprux 345a468
Use x86_64-linux-android for test cases
marcprux c299a2d
Fix AVD partition size
marcprux 8204a10
Fix AVD partition size
marcprux 5b015d8
Fix AVD partition size
marcprux d0d4b4c
Fix location of libc++_shared.so
marcprux bf04475
Fix location of libc++_shared.so
marcprux b0b4595
Fix location of libc++_shared.so
marcprux b0fc274
Fix location of libc++_shared.so
marcprux 6433df2
Fix location of libc++_shared.so
marcprux bbc4a12
Fix location of libc++_shared.so
marcprux 4f6703e
Fix location of Swift SDK for Android
marcprux 707adbd
Fix location of Swift SDK for Android
marcprux 6cab1f3
Fix location of Swift SDK for Android
marcprux e910952
Fix location of Swift SDK for Android
marcprux 6563fe6
Fix location of Swift SDK for Android
marcprux 7d58ee6
Fix location of Swift SDK for Android
marcprux c705e86
Fix location of Swift SDK for Android
marcprux e56b090
Set AVD partition size
marcprux 25c305b
Set AVD partition size
marcprux 4a197ee
Set AVD partition size
marcprux 6841907
Set AVD partition size
marcprux 4a2a9c7
Set AVD partition size
marcprux a86bcba
Set AVD partition size
marcprux ca5f01d
Set AVD partition size
marcprux 1add73b
Set AVD partition size
marcprux 1ecdca9
Set AVD partition size
marcprux ea1eb0a
Run without a docker container
marcprux 4411d7e
Run without a docker container
marcprux a0c6393
Run without a docker container
marcprux a5a207b
Run without a docker container
marcprux edb1240
Fix ANDROID_SDK_TRIPLE
marcprux 77fd5d6
Fix ANDROID_AVD_HOME
marcprux 4f63ef2
Fix ANDROID_AVD_HOME
marcprux fe29bf4
Cleanup copy of test resources and executables
marcprux 0cc3112
Cleanup copy of test resources and executables
marcprux c09530d
Cleanup copy of test resources and executables
marcprux 2f1c57f
Break up build and test run into two separate steps
marcprux 614fb27
Add explicit --testing-library arg
marcprux 5adabf6
Check with ANDROID_SDK_TRIPLES
marcprux 4413049
Check with ANDROID_SDK_TRIPLES
marcprux 89d7535
Cleanup
marcprux c0e37d7
Quote ANDROID_EMULATOR_TIMEOUT for shellcheck
marcprux 15a740d
Add log message about which triple is under test
marcprux 5f4d9bf
Add warning when Package.swift contains macros
marcprux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
.github/workflows/scripts/android/android-emulator-tests.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| #!/bin/bash | ||
| ##===----------------------------------------------------------------------===## | ||
| ## | ||
| ## This source file is part of the Swift.org open source project | ||
| ## | ||
| ## Copyright (c) 2025 Apple Inc. and the Swift project authors | ||
| ## Licensed under Apache License v2.0 with Runtime Library Exception | ||
| ## | ||
| ## See https://swift.org/LICENSE.txt for license information | ||
| ## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
| ## | ||
| ##===----------------------------------------------------------------------===## | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| log() { printf -- "** %s\n" "$*" >&2; } | ||
| error() { printf -- "** ERROR: %s\n" "$*" >&2; } | ||
| fatal() { error "$@"; exit 1; } | ||
|
|
||
| ANDROID_PROFILE="Nexus 10" | ||
| ANDROID_EMULATOR_TIMEOUT=300 | ||
|
|
||
| SWIFTPM_HOME="${XDG_CONFIG_HOME}"/swiftpm | ||
| # e.g., "${SWIFTPM_HOME}"/swift-sdks/swift-DEVELOPMENT-SNAPSHOT-2025-12-11-a_android.artifactbundle/ | ||
| SWIFT_ANDROID_SDK_HOME=$(find "${SWIFTPM_HOME}"/swift-sdks -maxdepth 1 -name 'swift-*android.artifactbundle' | tail -n 1) | ||
|
|
||
| ANDROID_SDK_TRIPLE="x86_64-unknown-linux-android28" | ||
|
|
||
| while [[ $# -gt 0 ]]; do | ||
| case $1 in | ||
| --android-sdk-triple=*) | ||
| ANDROID_SDK_TRIPLE="${1#*=}" | ||
| shift | ||
| ;; | ||
| --android-profile=*) | ||
| ANDROID_PROFILE="${1#*=}" | ||
| shift | ||
| ;; | ||
| --android-emulator-timeout=*) | ||
| ANDROID_EMULATOR_TIMEOUT="${1#*=}" | ||
| shift | ||
| ;; | ||
| -*) | ||
| fatal "Unknown option: $1" | ||
| ;; | ||
| *) | ||
| if [[ -z "$SWIFT_VERSION_INPUT" ]]; then | ||
| SWIFT_VERSION_INPUT="$1" | ||
| else | ||
| fatal "Multiple Swift versions specified: $SWIFT_VERSION_INPUT and $1" | ||
| fi | ||
| shift | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| # extract the API level from the end of the triple | ||
| ANDROID_API="${ANDROID_SDK_TRIPLE/*-unknown-linux-android/}" | ||
|
|
||
| # extract the build arch from the beginning of the triple | ||
| ANDROID_EMULATOR_ARCH="${ANDROID_SDK_TRIPLE/-unknown-linux-android*/}" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If multiple triples are passed in, what does this do, just grab the arch of the first one? If we only support x86_64 right now, may be better to just hard-code this until we support testing on other arches, or it may fail if it attempts those. |
||
|
|
||
| # x86_64=x86_64, armv7=arm | ||
| ANDROID_EMULATOR_ARCH_TRIPLE="${ANDROID_EMULATOR_ARCH}" | ||
|
|
||
marcprux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| log "Running tests for ${ANDROID_SDK_TRIPLE}" | ||
|
|
||
| EMULATOR_SPEC="system-images;android-${ANDROID_API};default;${ANDROID_EMULATOR_ARCH}" | ||
|
|
||
| log "SWIFT_ANDROID_SDK_HOME=${SWIFT_ANDROID_SDK_HOME}" | ||
|
|
||
| # install and start an Android emulator | ||
| log "Listing installed Android SDKs" | ||
| export PATH="${PATH}:$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/build-tools/latest:$ANDROID_HOME/platform-tools:$ANDROID_HOME/cmdline-tools/latest/bin" | ||
| sdkmanager --list_installed | ||
|
|
||
| log "Updating Android SDK licenses" | ||
| yes | sdkmanager --licenses > /dev/null || true | ||
|
|
||
| log "Installing Android emulator" | ||
| sdkmanager --install "emulator" "platform-tools" "platforms;android-${ANDROID_API}" "${EMULATOR_SPEC}" | ||
|
|
||
| log "Creating Android emulator" | ||
| export ANDROID_AVD_HOME=${XDG_CONFIG_HOME:-$HOME}/.android/avd | ||
| ANDROID_EMULATOR_NAME="swiftemu" | ||
| avdmanager create avd --force -n "${ANDROID_EMULATOR_NAME}" --package "${EMULATOR_SPEC}" --device "${ANDROID_PROFILE}" | ||
|
|
||
| log "Configuring Android emulators" | ||
| emulator -list-avds | ||
|
|
||
| log "Check Hardware Acceleration (KVM)" | ||
| emulator -accel-check | ||
|
|
||
| log "Starting Android emulator" | ||
| # launch the emulator in the background | ||
| nohup emulator -no-metrics -partition-size 1024 -memory 4096 -wipe-data -no-window -no-snapshot -noaudio -no-boot-anim -avd "${ANDROID_EMULATOR_NAME}" & | ||
|
|
||
| log "Waiting for Android emulator startup" | ||
| timeout "${ANDROID_EMULATOR_TIMEOUT}" adb wait-for-any-device | ||
|
|
||
| log "Prepare Swift test package" | ||
| # create a staging folder where we copy the test executable | ||
| # and all the dependent libraries to copy over to the emulator | ||
| STAGING_DIR="swift-android-test" | ||
| rm -rf "${STAGING_DIR}" | ||
| mkdir "${STAGING_DIR}" | ||
|
|
||
| BUILD_DIR=.build/"${ANDROID_SDK_TRIPLE}"/debug | ||
|
|
||
| find "${BUILD_DIR}" -name '*.xctest' -exec cp -av {} "${STAGING_DIR}" \; | ||
| find "${BUILD_DIR}" -name '*.resources' -exec cp -av {} "${STAGING_DIR}" \; | ||
|
|
||
| # copy over the required library dependencies | ||
| cp -av "${SWIFT_ANDROID_SDK_HOME}"/swift-android/swift-resources/usr/lib/swift-"${ANDROID_EMULATOR_ARCH_TRIPLE}"/android/*.so "${STAGING_DIR}" | ||
| cp -av "${SWIFT_ANDROID_SDK_HOME}"/swift-android/ndk-sysroot/usr/lib/"${ANDROID_EMULATOR_ARCH_TRIPLE}"-linux-android/libc++_shared.so "${STAGING_DIR}" | ||
|
|
||
| # for the common case of tests referencing | ||
| # their own files as hardwired paths instead of resources | ||
| if [[ -d Tests ]]; then | ||
| cp -a Tests "${STAGING_DIR}" | ||
| fi | ||
|
|
||
| # warn about macros in packages, as per | ||
| # https://github.com/swiftlang/github-workflows/pull/215#discussion_r2621335245 | ||
| grep -q '\.macro(' Package.swift && log "WARNING: Packages with macros are known to have issues with cross-compilation: https://github.com/swiftlang/swift-package-manager/issues/8094" || true | ||
|
|
||
| log "Copy Swift test package to emulator" | ||
|
|
||
| ANDROID_TMP_FOLDER="/data/local/tmp/${STAGING_DIR}" | ||
| adb push "${STAGING_DIR}" "${ANDROID_TMP_FOLDER}" | ||
|
|
||
| TEST_CMD="./*.xctest" | ||
| TEST_SHELL="cd ${ANDROID_TMP_FOLDER}" | ||
| TEST_SHELL="${TEST_SHELL} && ${TEST_CMD} --testing-library xctest" | ||
|
|
||
| # Run test cases a second time with the Swift Testing library | ||
| # We additionally need to handle the special exit code | ||
| # EXIT_NO_TESTS_FOUND (69 on Android), which can happen | ||
| # when the tests link to Testing, but no tests are executed | ||
| # see: https://github.com/swiftlang/swift-package-manager/blob/main/Sources/Commands/SwiftTestCommand.swift#L1571 | ||
| TEST_SHELL="${TEST_SHELL} && ${TEST_CMD} --testing-library swift-testing && [ \$? -eq 0 ] || [ \$? -eq 69 ]" | ||
marcprux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| log "Run Swift package tests" | ||
|
|
||
| # run the test executable | ||
| adb shell "${TEST_SHELL}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If multiple triples are passed in, what does this do, just grab the API level of the first one?