Skip to content

Commit

Permalink
Merge pull request #283 from Oscar-Pepper/multiple_api_integ_tests
Browse files Browse the repository at this point in the history
multiple apis for integ tests
  • Loading branch information
fluidvanadium authored Apr 13, 2023
2 parents 828cb7f + 20f0be8 commit e81923f
Showing 1 changed file with 86 additions and 49 deletions.
135 changes: 86 additions & 49 deletions scripts/integration_tests.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#!/bin/bash
set -Eeuo pipefail

set_abi=false
set_api_lvl=false
set_api_tgt=false
create_snapshot=false
apk_installed=false
install_attempts=0
valid_api_lvls=("23" "24" "25" "26" "27" "28" "29" "30" "31" "32" "33")
valid_api_tgts=("default" "google_apis" "google_apis_playstore" "google_atd" "google-tv" \
"aosp_atd" "android-tv" "android-desktop" "android-wear" "android-wear-cn")

function check_launch() {
emu_status=$(adb devices | grep "emulator-5554" | cut -f1)
Expand Down Expand Up @@ -31,63 +36,81 @@ function wait_for() {
timeout=$(( timeout - 1 ))
done
if [ $timeout -le 0 ]; then
echo -e "\nFailed due to timeout"
echo -e "\nError: Timeout" >&2
exit 1
fi
}

while getopts 'a:sh' OPTION; do
while getopts 'a:sl:t:h' OPTION; do
case "$OPTION" in
a)
abi="$OPTARG"
case "$abi" in
x86_64)
sdk="system-images;android-30;google_apis;x86_64"
api="android-30"
target="google_apis"
api_lvl_default="30"
api_tgt_default="google_apis"
arch="x86_64"
;;
x86)
sdk="system-images;android-30;google_apis;x86"
api="android-30"
target="google_apis"
api_lvl_default="30"
api_tgt_default="google_apis"
arch="x86"
;;
arm64-v8a)
sdk="system-images;android-30;google_apis;x86_64"
api="android-30"
target="google_apis"
api_lvl_default="30"
api_tgt_default="google_apis"
arch="x86_64"
;;
# armeabi-v7a)
# sdk="system-images;android-30;google_apis;x86"
# api="android-30"
# target="google_apis"
# arch="x86"
# ;;
armeabi-v7a)
api_lvl_default="30"
api_tgt_default="google_apis"
arch="x86"
;;
*)
echo "Invalid ABI" >&2
echo "Error: Invalid ABI" >&2
echo "Try '$(basename $0) -h' for more information." >&2
exit 1
;;
esac
set_abi=true
;;
l)
api_lvl="$OPTARG"

# Check API level is valid
if [[ $(echo ${valid_api_lvls[@]} | grep -ow "${api_lvl}" | wc -w) != 1 ]]; then
echo "Error: Invalid API level" >&2
echo "Try '$(basename $0) -h' for more information." >&2
exit 1
fi

set_api_lvl=true
;;
t)
api_tgt="$OPTARG"

# Check API target is valid
if [[ $(echo ${valid_api_tgts[@]} | tr -d '-' | grep -ow "$(echo ${api_tgt} | tr -d '-')" | wc -w) != 1 ]]; then
echo "Error: Invalid API target" >&2
echo "Try '$(basename $0) -h' for more information." >&2
exit 1
fi

set_api_tgt=true
;;
s)
create_snapshot=true
shift 1
;;
h)
echo "Run integration tests"
echo -e "\n -a\t\tSelect target ABI (required)"
echo -e "\n -a\t\tSelect ABI (required)"
echo -e " \t\tOptions:"
echo -e " \t\t x86_64"
echo -e " \t\t x86"
echo -e " \t\t arm64-v8a"
# echo -e " \t\t armeabi-v7a"
echo -e "\n -s\t\tCreate an AVD and snapshot for quick-boot"
echo -e " \t\t 'x86_64'"
echo -e " \t\t 'x86'"
echo -e " \t\t 'arm64-v8a' - uses x86_64 AVDs"
echo -e " \t\t 'armeabi-v7a' - still in development"
echo -e "\n -s\t\tCreate an AVD and snapshot for quick-boot (optional)"
echo -e " \t\tDoes not run integration tests"
echo -e " \t\tarm64-v8a ABIs use x86_64 AVDs"
# echo -e " \t\tarmeabi-v7a ABIs use x86 AVDs"
echo -e "\nExamples:"
echo -e " $(basename $0) -a x86_64 -s\tCreates an AVD and quick-boot snapshot for x86_64 ABI"
echo -e " $(basename $0) -a x86_64 \tRuns integration tests for x86_64 ABI from snapshot"
Expand All @@ -99,16 +122,24 @@ while getopts 'a:sh' OPTION; do
;;
esac
done
if [ $OPTIND -eq 1 ]; then
echo "Error: Required options missing" >&2
if [[ $set_abi == false ]]; then
echo "Error: ABI not specified" >&2
echo "Try '$(basename $0) -h' for more information." >&2
exit 1
fi

# Set defaults
if [[ $set_api_lvl == false ]]; then
api_lvl=$api_lvl_default
fi
if [[ $set_api_tgt == false ]]; then
api_tgt=$api_tgt_default
fi

# Setup working directory
if [ ! -d "./android/app" ]; then
echo "Error: Incorrect working directory"
echo "Try './scripts/$(basename $0)' from zingo-mobile root directory."
echo "Error: Incorrect working directory" >&2
echo "Try './scripts/$(basename $0)' from zingo-mobile root directory." >&2
exit 1
fi
cd android
Expand All @@ -120,18 +151,20 @@ echo "Installing latest emulator..."
sdkmanager --install emulator --channel=0

echo "Installing system image..."
sdkmanager --install $sdk
avd_name="android-${api_lvl}_${api_tgt}_${arch}"
sdk="system-images;android-${api_lvl};${api_tgt};${arch}"
sdkmanager --install "${sdk}"
sdkmanager --licenses

# Kill all emulators
../scripts/kill_emulators.sh

if [ "$create_snapshot" = true ]; then
if [[ $create_snapshot == true ]]; then
echo -e "\nCreating AVD..."
echo no | avdmanager create avd --force --name "${api}_${target}_${arch}" --package $sdk --abi "${target}/${arch}"
echo no | avdmanager create avd --force --name "${avd_name}" --package "${sdk}"

echo -e "\n\nWaiting for emulator to launch..."
emulator -avd "${api}_${target}_${arch}" -netdelay none -netspeed full -no-window -no-audio -gpu swiftshader_indirect -no-boot-anim \
emulator -avd "${avd_name}" -netdelay none -netspeed full -no-window -no-audio -gpu swiftshader_indirect -no-boot-anim \
-no-snapshot-load -port 5554 &> /dev/null &
wait_for 1800 check_launch
echo "$(adb devices | grep "emulator-5554" | cut -f1) launch successful"
Expand All @@ -143,24 +176,26 @@ if [ "$create_snapshot" = true ]; then
echo -e "\nSnapshot saved"
else
echo -e "\nChecking for AVD..."
if emulator -list-avds | grep -q "${api}_${target}_${arch}"; then
echo "AVD found: ${api}_${target}_${arch}"
if [[ $(emulator -list-avds | grep -ow "${avd_name}" | wc -w) != 1 ]]; then
echo "AVD not found"
echo -e "\nCreating AVD..."
echo no | avdmanager create avd --force --name "${avd_name}" --package "${sdk}"
echo -e "\n\nTo to create a quick-boot snapshot for faster integration tests use the '-s' flag"
echo "Try '$(basename $0) -h' for more information."
else
echo "Error: AVD not found"
echo "Try '$(basename $0) -a ${abi} -s' to create an AVD and quick-boot snapshot."
exit 1
echo "AVD found: ${avd_name}"
fi

echo -e "\nBuilding APKs..."
./gradlew assembleDebug assembleAndroidTest -Psplitapk=true

# Create integration test report directory
test_report_dir="app/build/outputs/integration_test_reports/${abi}"
rm -rf $test_report_dir
mkdir -p $test_report_dir
rm -rf "${test_report_dir}"
mkdir -p "${test_report_dir}"

echo -e "\n\nWaiting for emulator to launch..."
emulator -avd "${api}_${target}_${arch}" -netdelay none -netspeed full -no-window -no-audio -gpu swiftshader_indirect -no-boot-anim \
emulator -avd "${avd_name}" -netdelay none -netspeed full -no-window -no-audio -gpu swiftshader_indirect -no-boot-anim \
-no-snapshot-save -read-only -port 5554 &> "${test_report_dir}/emulator.txt" &
wait_for 1800 check_launch
echo "$(adb devices | grep "emulator-5554" | cut -f1) launch successful"
Expand All @@ -177,19 +212,21 @@ else
adb shell settings put global animator_duration_scale 0.0

echo -e "\nInstalling APKs..."
i=0
until [[ $apk_installed == true ]]; do
if adb -s emulator-5554 install-multi-package -r -t -d --abi $abi \
if adb -s emulator-5554 install-multi-package -r -t -d --abi "${abi}" \
"app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk" \
"app/build/outputs/apk/debug/app-${abi}-debug.apk" &> "${test_report_dir}/apk_installation.txt"; then
apk_installed=true
echo "APK installation succeeded"
fi
if [[ $install_attempts -ge 10 ]]; then
echo "Error: APK installation failed"
echo "For more information see 'zingo-mobile/android/${test_report_dir}/apk_installation.txt'"
if [[ $i -ge 20 ]]; then
echo "Error: APK installation failed" >&2
echo "For more information see 'zingo-mobile/android/${test_report_dir}/apk_installation.txt'" >&2
exit 1
fi
install_attempts=$((install_attempts+1))
i=$((i+1))
sleep 1
done

# Store emulator info and start logging
Expand Down

0 comments on commit e81923f

Please sign in to comment.