diff --git a/.github/workflows/old/android-macos-integration-test.yaml b/.github/workflows/android-macos-integration-test.yaml similarity index 52% rename from .github/workflows/old/android-macos-integration-test.yaml rename to .github/workflows/android-macos-integration-test.yaml index ad9ceea93..69749b899 100644 --- a/.github/workflows/old/android-macos-integration-test.yaml +++ b/.github/workflows/android-macos-integration-test.yaml @@ -1,4 +1,4 @@ -name: Android Macos Integration tests +name: Android Integration test on: workflow_call: @@ -12,7 +12,7 @@ on: abi: required: true type: string - + env: CACHE-KEY: ${{ inputs.cache-key }} TIMESTAMP: ${{ inputs.timestamp }} @@ -21,8 +21,8 @@ env: RUSTFLAGS: -D warnings jobs: - android-macos-integration-avd-cache: - name: Android Macos integration AVD cache + android-build-test-artifacts: + name: Android Build test artifacts runs-on: macos-13 steps: - name: Set envs for zingolib CI @@ -34,82 +34,49 @@ jobs: with: repository: ${{ env.REPO-OWNER }}/zingo-mobile - - name: Set envs for x86_64 - if: ${{ env.ABI == 'x86_64' }} - run: echo "AVD-ARCH=x86_64" >> $GITHUB_ENV - - - name: Set envs for x86 - if: ${{ env.ABI == 'x86' }} - run: echo "AVD-ARCH=x86" >> $GITHUB_ENV - - - name: Set envs for arm64-v8a - if: ${{ env.ABI == 'arm64-v8a' }} - run: echo "AVD-ARCH=x86_64" >> $GITHUB_ENV - - - name: Set envs for armeabi-v7a - if: ${{ env.ABI == 'armeabi-v7a' }} - run: echo "AVD-ARCH=x86" >> $GITHUB_ENV + - name: Install protoc + run: brew install protobuf - - name: AVD cache - uses: actions/cache/restore@v4 - id: avd-cache + - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - path: | - ~/.android/avd/* - ~/.android/adb* - key: avd-${{ env.AVD-ARCH }}-integ-macos - lookup-only: true - - - name: Trying to free space in the runner - if: steps.avd-cache.outputs.cache-hit != 'true' - run: | - xcrun simctl delete all - sudo rm -rf ~/Library/Developer/CoreSimulator/Caches/* - - - name: Setup Android SDK - if: steps.avd-cache.outputs.cache-hit != 'true' - uses: android-actions/setup-android@v3 + toolchain: stable - - name: Add emulator to PATH - if: steps.avd-cache.outputs.cache-hit != 'true' - run: echo "${ANDROID_SDK_ROOT}/emulator" >> $GITHUB_PATH + - name: Install nextest + uses: taiki-e/install-action@nextest - - name: Create AVD and generate snapshot for caching - if: steps.avd-cache.outputs.cache-hit != 'true' - uses: nick-fields/retry@v3 + - name: Cargo cache + uses: Swatinem/rust-cache@v2 with: - timeout_minutes: 30 - max_attempts: 3 - command: ./scripts/integration_tests.sh -a ${{ env.AVD-ARCH }} -s + workspaces: rust - - name: AVD cache saving - if: steps.avd-cache.outputs.cache-hit != 'true' - uses: actions/cache/save@v4 - id: avd-cache-saving + - name: Build and archive tests + working-directory: ./rust + run: cargo nextest archive --verbose --features "regchest" --archive-file nextest-archive-${{ env.ABI }}.tar.zst + + - name: Upload archive + uses: actions/upload-artifact@v4 with: - path: | - ~/.android/avd/* - ~/.android/adb* - key: avd-${{ env.AVD-ARCH }}-integ-macos + name: nextest-archive-${{ env.ABI }} + path: ./rust/nextest-archive-${{ env.ABI }}.tar.zst - android-macos-integration-test: - needs: [android-macos-integration-avd-cache] - name: Android Macos Integration test + android-integration-test: + name: Android Integration test runs-on: macos-13 - + needs: android-build-test-artifacts strategy: + fail-fast: false matrix: - partition: [1, 2, 3, 4, 5] + partition: [1, 2, 3, 4, 5, 6] steps: - name: Set envs for zingolib CI if: ${{ contains(github.repository, 'zingolib') }} run: echo "REPO-OWNER=zingolabs" >> $GITHUB_ENV - + - name: Checkout repository uses: actions/checkout@v4 with: repository: ${{ env.REPO-OWNER }}/zingo-mobile - + - name: Set envs for x86_64 if: ${{ env.ABI == 'x86_64' }} run: | @@ -134,48 +101,24 @@ jobs: echo "AVD-ARCH=x86" >> $GITHUB_ENV echo "NEXTEST-ABI=arm32" >> $GITHUB_ENV - - name: Trying to free space in the runner - run: | - xcrun simctl delete all - sudo rm -rf ~/Library/Developer/CoreSimulator/Caches/* - - - name: Setup Docker 1 try - uses: douglascamata/setup-docker-macos-action@v1-alpha - id: dockerTry1 - continue-on-error: true - - - name: checking outcome 1 - run: echo ${{ steps.dockerTry1.outcome }} - - - name: Setup Docker 2 try - if: steps.dockerTry1.outcome != 'success' - uses: douglascamata/setup-docker-macos-action@v1-alpha - id: dockerTry2 - continue-on-error: true - - - name: checking outcome 2 - if: steps.dockerTry1.outcome != 'success' - run: echo ${{ steps.dockerTry2.outcome }} - - - name: Setup Docker Manually - if: steps.dockerTry1.outcome != 'success' && steps.dockerTry2.outcome != 'success' + - name: Install docker run: | brew install --head colima brew install --formula docker - colima start --vm-type qemu --arch x86_64 + colima start + + - name: Colima status + run: colima status - name: Pull regchest docker image run: docker pull zingodevops/regchest:008 - - name: Rust toolchain stable - uses: actions-rust-lang/setup-rust-toolchain@v1 + - uses: actions-rust-lang/setup-rust-toolchain@v1 with: toolchain: stable - name: Install nextest - uses: taiki-e/install-action@v2 - with: - tool: nextest + uses: taiki-e/install-action@nextest - name: Cargo cache uses: Swatinem/rust-cache@v2 @@ -189,58 +132,65 @@ jobs: key: native-android-uniffi-${{ env.ABI }}-${{ env.CACHE-KEY }} fail-on-cache-miss: true + - name: Kotlin uniffi cache + uses: actions/cache/restore@v4 + with: + path: android/app/build/generated/source/uniffi/debug/java/uniffi/zingo + key: kotlin-android-uniffi-${{ env.ABI }}-${{ env.CACHE-KEY }} + fail-on-cache-miss: true + - name: Setup Java uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '17' - + - name: Setup Android SDK uses: android-actions/setup-android@v3 - with: - cmdline-tools-version: 11.0 - + - name: Add emulator to PATH run: echo "${ANDROID_SDK_ROOT}/emulator" >> $GITHUB_PATH - + - name: Gradle cache - uses: gradle/actions/setup-gradle@v4 + uses: gradle/actions/setup-gradle@v3 with: gradle-version: 8.2 + build-root-directory: ./android cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/dev' }} - + - name: AVD cache - uses: actions/cache/restore@v4 + uses: actions/cache@v4 id: avd-cache - with: + with: path: | ~/.android/avd/* ~/.android/adb* - key: avd-${{ env.AVD-ARCH }}-integ-macos - - - name: Kotlin uniffi cache - uses: actions/cache/restore@v4 + key: avd-${{ env.AVD-ARCH }}-integ + + - name: Create AVD and generate snapshot for caching + if: steps.avd-cache.outputs.cache-hit != 'true' + uses: nick-fields/retry@v2 with: - path: android/app/build/generated/source/uniffi/debug/java/uniffi/zingo - key: kotlin-android-uniffi-${{ env.ABI }}-${{ env.CACHE-KEY }} - fail-on-cache-miss: true + timeout_minutes: 60 + max_attempts: 3 + command: ./scripts/integration_tests.sh -a ${{ env.AVD-ARCH }} -s - name: Download archive uses: actions/download-artifact@v4 with: - name: nextest-archive + name: nextest-archive-${{ env.ABI }} path: ./rust - - name: Run Android integration tests + - name: Run integration tests working-directory: ./rust run: | - cargo nextest run ${{ env.NEXTEST-ABI }} --verbose --profile ci \ - --archive-file nextest-archive.tar.zst \ - --partition count:${{ matrix.partition}}/5 + cargo nextest run integration::${{ env.NEXTEST-ABI }} --verbose --profile ci \ + --archive-file nextest-archive-${{ env.ABI }}.tar.zst \ + --partition count:${{ matrix.partition}}/6 - name: Upload test reports if: ${{ ! cancelled() }} uses: actions/upload-artifact@v4 with: - name: test-integration-reports-${{ env.ABI }}-${{ matrix.partition}}-${{ env.TIMESTAMP }} - path: android/app/build/outputs/integration_test_reports + name: test-reports-${{ env.ABI }}-${{ matrix.partition}}-${{ env.TIMESTAMP }} + path: android/app/build/outputs/integration_test_reports \ No newline at end of file diff --git a/.github/workflows/android-ubuntu-e2e-test-ci.yaml b/.github/workflows/android-ubuntu-e2e-test-ci.yaml index 1c1ee5099..a67a0f00a 100644 --- a/.github/workflows/android-ubuntu-e2e-test-ci.yaml +++ b/.github/workflows/android-ubuntu-e2e-test-ci.yaml @@ -15,11 +15,15 @@ on: api-level: required: true type: string + target: + required: true + type: string env: REPO-OWNER: ${{ github.repository_owner }} ABI: ${{ inputs.abi }} API-LEVEL: ${{ inputs.api-level }} + TARGET: ${{ inputs.target }} TIMESTAMP: ${{ inputs.timestamp }} jobs: @@ -86,6 +90,7 @@ jobs: with: api-level: ${{ env.API-LEVEL }} arch: ${{ env.AVD-ARCH }} + target: ${{ env.TARGET }} force-avd-creation: true emulator-options: -no-snapshot-load -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none disable-animations: false @@ -278,6 +283,7 @@ jobs: with: api-level: ${{ env.API-LEVEL }} arch: ${{ env.AVD-ARCH }} + target: ${{ env.TARGET }} force-avd-creation: true emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none disable-animations: true diff --git a/.github/workflows/android-ubuntu-integration-test-ci.yaml b/.github/workflows/android-ubuntu-integration-test-ci.yaml index 56b66535c..3df1e2875 100644 --- a/.github/workflows/android-ubuntu-integration-test-ci.yaml +++ b/.github/workflows/android-ubuntu-integration-test-ci.yaml @@ -15,11 +15,15 @@ on: api-level: required: true type: string + target: + required: true + type: string env: REPO-OWNER: ${{ github.repository_owner }} ABI: ${{ inputs.abi }} API-LEVEL: ${{ inputs.api-level }} + TARGET: ${{ inputs.target }} TIMESTAMP: ${{ inputs.timestamp }} jobs: @@ -80,6 +84,7 @@ jobs: with: api-level: ${{ env.API-LEVEL }} arch: ${{ env.AVD-ARCH }} + target: ${{ env.TARGET }} force-avd-creation: true emulator-options: -no-snapshot-load -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none disable-animations: false @@ -253,6 +258,7 @@ jobs: with: api-level: ${{ env.API-LEVEL }} arch: ${{ env.AVD-ARCH }} + target: ${{ env.TARGET }} force-avd-creation: true emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none disable-animations: true diff --git a/.github/workflows/ci-nightly.yaml b/.github/workflows/ci-nightly.yaml index 7631cabf7..140d74f76 100644 --- a/.github/workflows/ci-nightly.yaml +++ b/.github/workflows/ci-nightly.yaml @@ -26,18 +26,32 @@ jobs: cache-key: ${{ needs.create-cache-key.outputs.cache-key }} arch: ${{ matrix.arch }} + android-macos-integration-test: + strategy: + matrix: + arch: [arm64-v8a, armeabi-v7a] + uses: ./.github/workflows/android-macos-integration-test.yaml + needs: [ create-timestamp, create-cache-key, android-build ] + with: + timestamp: ${{ needs.create-timestamp.outputs.timestamp }} + cache-key: ${{ needs.create-cache-key.outputs.cache-key }} + abi: ${{ matrix.arch }} + android-ubuntu-integration-test-ci: strategy: matrix: - abi: [ x86_64, x86 ] + config: + - { abi: x86_64, api-level: 34, target: default } + - { abi: x86, api-level: 29, target: default } fail-fast: false uses: ./.github/workflows/android-ubuntu-integration-test-ci.yaml needs: [create-timestamp, android-build] with: timestamp: ${{ needs.create-timestamp.outputs.timestamp }} cache-key: ${{ needs.create-cache-key.outputs.cache-key }} - abi: ${{ matrix.abi }} - api-level: 29 + abi: ${{ matrix.config.abi }} + api-level: ${{ matrix.config['api-level'] }} + target: ${{ matrix.config.target }} ios-build: strategy: diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1a811ddd9..b437c085a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -19,19 +19,30 @@ jobs: android-build: strategy: matrix: - arch: [x86_64, x86] + arch: [ x86_64, x86, arm64-v8a, armeabi-v7a ] uses: ./.github/workflows/android-build.yaml needs: create-cache-key with: cache-key: ${{ needs.create-cache-key.outputs.cache-key }} arch: ${{ matrix.arch }} + android-macos-integration-test: + strategy: + matrix: + arch: [arm64-v8a, armeabi-v7a] + uses: ./.github/workflows/android-macos-integration-test.yaml + needs: [ create-timestamp, create-cache-key, android-build ] + with: + timestamp: ${{ needs.create-timestamp.outputs.timestamp }} + cache-key: ${{ needs.create-cache-key.outputs.cache-key }} + abi: ${{ matrix.arch }} + android-ubuntu-integration-test-ci: strategy: matrix: config: - - { abi: x86_64, api-level: 34 } - - { abi: x86, api-level: 29 } + - { abi: x86_64, api-level: 34, target: default } + - { abi: x86, api-level: 29, target: default } uses: ./.github/workflows/android-ubuntu-integration-test-ci.yaml needs: [create-timestamp, android-build] with: @@ -39,13 +50,14 @@ jobs: cache-key: ${{ needs.create-cache-key.outputs.cache-key }} abi: ${{ matrix.config.abi }} api-level: ${{ matrix.config['api-level'] }} + target: ${{ matrix.config.target }} android-ubuntu-e2e-test-ci: strategy: matrix: config: - - { abi: x86_64, api-level: 30 } - - { abi: x86, api-level: 28 } + - { abi: x86_64, api-level: 30, target: default } + - { abi: x86, api-level: 28, target: default } uses: ./.github/workflows/android-ubuntu-e2e-test-ci.yaml needs: [create-timestamp, android-build] with: @@ -53,6 +65,7 @@ jobs: cache-key: ${{ needs.create-cache-key.outputs.cache-key }} abi: ${{ matrix.config.abi }} api-level: ${{ matrix.config['api-level'] }} + target: ${{ matrix.config.target }} ios-build: uses: ./.github/workflows/ios-build.yaml @@ -67,7 +80,7 @@ jobs: timestamp: ${{ needs.create-timestamp.outputs.timestamp }} cache-key: ${{ needs.create-cache-key.outputs.cache-key }} - # deactivating these for now, until we fix how + # deactivating these for now, until we know how to fix # detox run in MACOS. #ios-e2e-test: # uses: ./.github/workflows/ios-e2e-test.yaml diff --git a/rust/android/tests/integration_tests.rs b/rust/android/tests/integration_tests.rs index 0eaa0b6c7..631ed81a7 100644 --- a/rust/android/tests/integration_tests.rs +++ b/rust/android/tests/integration_tests.rs @@ -4,10 +4,12 @@ use zingolib::testutils::scenarios; // ubuntu ci runner #[cfg(feature = "ci")] const UNIX_SOCKET: Option<&str> = Some("/var/run/docker.sock"); + // macos ci runner -//const UNIX_SOCKET: Option<&str> = Some("`/Users/runner/.colima/default/docker.sock`"); +#[cfg(target_os = "macos")] +const UNIX_SOCKET: Option<&str> = Some("unix:///Users/runner/.colima/default/docker.sock"); -#[cfg(all(not(feature = "ci"), feature = "regchest"))] +#[cfg(all(not(feature = "ci"), feature = "regchest", not(target_os = "macos")))] const UNIX_SOCKET: Option<&str> = None; async fn offline_testsuite(abi: &str) { diff --git a/scripts/e2e_tests.sh b/scripts/e2e_tests.sh index fb35e97f7..fa7186064 100755 --- a/scripts/e2e_tests.sh +++ b/scripts/e2e_tests.sh @@ -1,61 +1,58 @@ #!/bin/bash set -Eeuo pipefail -set_abi=false set_test_name=false -set_api_level=false -set_api_target=false -intel_host_os=true -create_snapshot=false -test_name_default="new_wallet" -valid_api_levels=("23" "24" "25" "26" "27" "28" "29" "30" "31" "32" "33" "34" "35") -valid_api_targets=("default" "google_apis" "google_apis_playstore" "google_atd" "google-tv" \ - "aosp_atd" "android-tv" "android-desktop" "android-wear" "android-wear-cn") timeout_seconds=1800 # default timeout set to 30 minutes +api_level="30" +api_target="google_apis_playstore" +arch="x86_64" device="pixel_7" -while getopts 'a:Al:e:t:sx:h' OPTION; do +function check_launch() { + emulator_status=$(adb devices | grep "emulator-5554" | cut -f1) + if [ "${emulator_status}" = "emulator-5554" ]; then + return 0; + else + return 1; + fi +} + +function check_boot() { + boot_status=$(adb -s emulator-5554 shell getprop sys.boot_completed) + if [ "${boot_status}" = "1" ]; then + return 0; + else + return 1; + fi +} + +function check_device_online() { + device_status=$(adb devices | grep emulator-5554 | cut -f2) + if [ "${device_status}" = "offline" ]; then + return 1; + fi + return 0; +} + +function wait_for() { + timeout_seconds=$1 + shift 1 + until [ $timeout_seconds -le 0 ] || ("$@" &> /dev/null); do + sleep 1 + timeout_seconds=$(( timeout_seconds - 1 )) + done + if [ $timeout_seconds -le 0 ]; then + echo -e "\nError: Timeout" >&2 + exit 1 + fi +} + +while getopts 'e:sx:h' OPTION; do case "$OPTION" in - a) - abi="$OPTARG" - set_abi=true - ;; - A) - intel_host_os=false - ;; e) test_name="$OPTARG" set_test_name=true ;; - l) - api_level="$OPTARG" - - # Check API level is valid - # tr -d '-' is used to remove all hyphons as they count as word boundaries for grep - if [[ $(echo ${valid_api_levels[@]} | tr -d '-' | grep -ow "$(echo ${api_level} | tr -d '-')" | wc -w) != 1 ]]; then - echo "Error: Invalid API level" >&2 - echo "Try '$(basename $0) -h' for more information." >&2 - exit 1 - fi - - set_api_level=true - ;; - t) - api_target="$OPTARG" - - # Check API target is valid - # tr -d '-' is used to remove all hyphons as they count as word boundaries for grep - if [[ $(echo ${valid_api_targets[@]} | tr -d '-' | grep -ow "$(echo ${api_target} | 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_target=true - ;; - s) - create_snapshot=true - ;; x) timeout_seconds="$OPTARG" @@ -65,38 +62,11 @@ while getopts 'a:Al:e:t:sx:h' OPTION; do fi ;; h) - echo -e "\nRun e2e tests. Requires Android SDK Command-line Tools." - echo -e "\n -a\t\tSelect ABI (required)" - echo -e " \t\t Options:" - echo -e " \t\t 'x86_64' - default system image: API 30 google_apis_playstore x86_64" - echo -e " \t\t 'x86' - default system image: API 30 google_apis_playstore x86" - echo -e " \t\t 'arm64-v8a' - default system image: API 30 google_apis_playstore x86_64" - echo -e " \t\t 'armeabi-v7a' - default system image: API 30 google_apis_playstore x86" - echo -e "\n -A\t\tSets default system image of arm abis to arm instead of x86 (optional)" - echo -e " \t\t Use this option if the host OS is arm" - echo -e "\n -e\t\tSelect test name or test suite (optional)" - echo -e " \t\t Default: OfflineTestSuite" - echo -e "\n -l\t\tSelect API level (optional)" - echo -e " \t\t Minimum API level: 23" - echo -e "\n -t\t\tSelect API target (optional)" - echo -e " \t\t See examples on selecting system images below" - echo -e "\n -s\t\tCreate an AVD and snapshot for quick-boot (optional)" - echo -e " \t\t Does not run e2e tests" + echo -e "\nRun end-to-end tests. Requires Android SDK Command-line Tools." + echo -e "\n -e\t\tSelect test name" echo -e "\n -x\t\tSet timeout in seconds for emulator launch and AVD boot-up (optional)" echo -e " \t\t Default: 1800" echo -e " \t\t Must be an integer" - 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 e2e tests for x86_64 ABI from snapshot" - echo -e " '$(basename $0) -a x86 -l 29 -t google_apis'" - echo -e " \t\tSelect system image \"system-images;android-29;google_apis;x86\"" - echo -e "\nRecommended system images for testing ARM ABIs:" - echo -e " armeabi-v7a:" - echo -e " \"system-images;android-30;google_apis_playstore;x86\" - default" - echo -e " \"system-images;android-30;google-tv;x86\"" - # TODO: add list of supported images for arm64-v8a - echo -e "\nFor a full list of system images run 'sdkmanager --list'" - exit 1 ;; ?) echo "Try '$(basename $0) -h' for more information." >&2 @@ -104,230 +74,120 @@ while getopts 'a:Al:e:t:sx:h' OPTION; do ;; esac done -if [[ $set_abi == false ]]; then - echo "Error: ABI not specified" >&2 +if [[ $set_test_name == false ]]; then + echo "Error: Test not specified" >&2 echo "Try '$(basename $0) -h' for more information." >&2 exit 1 fi -case "$abi" in - x86_64) - api_level_default="30" - api_target_default="aosp_atd" - if [ $intel_host_os == true ]; then - arch="x86_64" - else - arch="arm64-v8a" - fi - ;; - x86) - api_level_default="30" - api_target_default="aosp_atd" - if [ $intel_host_os == true ]; then - arch="x86" - else - arch="arm64-v8a" - fi - ;; - arm64-v8a) - api_level_default="30" - api_target_default="aosp_atd" - if [ $intel_host_os == true ]; then - arch="x86_64" - else - arch="arm64-v8a" - fi - ;; - armeabi-v7a) - api_level_default="30" - api_target_default="aosp_atd" - if [ $intel_host_os == true ]; then - arch="x86" - else - arch="arm64-v8a" - fi - ;; - *) - echo "Error: Invalid ABI" >&2 - echo "Try '$(basename $0) -h' for more information." >&2 - exit 1 - ;; -esac - -# Set defaults -if [[ $set_test_name == false ]]; then - test_name=$test_name_default -fi -if [[ $set_api_level == false ]]; then - api_level=$api_level_default -fi -if [[ $set_api_target == false ]]; then - api_target=$api_target_default -fi - # Setup working directory -if [ ! -d "./android/app" ]; then - echo "Error: Incorrect working directory" >&2 - echo "Try './scripts/$(basename $0)' from zingo-mobile root directory." >&2 - exit 1 -fi +cd $(git rev-parse --show-toplevel) -echo -e "\nRemoving node_modules before yarn..." -rm -rf ./node_modules - -echo -e "\nRunning yarn..." -yarn +echo -e "\nRunning yarn install..." +# yarn global add node-gyp +yarn install cd android -avd_name="${device}_api-${api_level}_${api_target}_${arch}" -sdk="system-images;android-${api_level};${api_target};${arch}" -platform="platforms;android-${api_level}" +echo -e "\nInstalling latest build tools, platform tools, and platform..." +sdkmanager --install 'build-tools;34.0.0' platform-tools -echo -e "\nInstalling platform tools..." -sdkmanager --install platform-tools +echo "Installing latest emulator..." +sdkmanager --install emulator --channel=0 echo "Installing system image..." +avd_name="${device}_api-${api_level}_${api_target}_${arch}" +sdk="system-images;android-${api_level};${api_target};${arch}" sdkmanager --install "${sdk}" - -echo "Installing android platform..." -sdkmanager --install "${platform}" - -echo -e "\nInstalling latest build tools..." -sdkmanager --install 'build-tools;34.0.0' - -echo "Installing latest emulator..." -sdkmanager --install emulator - echo y | sdkmanager --licenses # Kill all emulators ../scripts/kill_emulators.sh -if [[ $create_snapshot == true ]]; then +if [ $(emulator -list-avds | grep -ow "${avd_name}" | wc -w) -ne 1 ]; then echo -e "\nCreating AVD..." - echo no | avdmanager --verbose create avd --force --name "${avd_name}" --abi "${arch}" --package "${sdk}" --device "${device}" + echo no | avdmanager create avd --force --name "${avd_name}" --package "${sdk}" --device "${device}" - echo -e "\n\nWaiting for emulator to launch & boot..." - nohup emulator -avd "${avd_name}" -no-window -no-audio -gpu swiftshader_indirect -no-boot-anim -port 5554 & - echo -e "\n\nWaiting more..." - adb wait-for-device + echo -e "\n\nWaiting for emulator to launch..." + nohup emulator -avd "${avd_name}" -netdelay none -netspeed full -gpu swiftshader_indirect -no-boot-anim \ + -no-snapshot-load -port 5554 &> /dev/null & + wait_for $timeout_seconds check_launch + wait_for $timeout_seconds check_device_online echo "$(adb devices | grep "emulator-5554" | cut -f1) launch successful" + echo -e "\nWaiting for AVD to boot..." + wait_for $timeout_seconds check_boot echo $(adb -s emulator-5554 emu avd name | head -1) echo "Boot completed" - sleep 5 + sleep 1 echo -e "\nSnapshot saved" -else - echo -e "\nChecking for AVD..." - if [ $(emulator -list-avds | grep -ow "${avd_name}" | wc -w) -ne 1 ]; then - echo "AVD not found" - echo -e "\nCreating AVD..." - echo no | avdmanager --verbose create avd --force --name "${avd_name}" --abi "${arch}" --package "${sdk}" --device "${device}" - - echo -e "\n\nTo create a quick-boot snapshot for faster e2e tests use the '-s' flag" - echo "Try '$(basename $0) -h' for more information." - else - echo "AVD found: ${avd_name}" - fi - - echo -e "\nBuilding APKs..." - ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug -PsplitApk=true - - # Create e2e test report directory - test_report_dir="app/build/outputs/e2e_test_reports/${abi}" - rm -rf "${test_report_dir}" - mkdir -p "${test_report_dir}" - - echo -e "\n\nWaiting for emulator to launch & boot..." - nohup emulator -avd "${avd_name}" -no-window -no-audio -gpu swiftshader_indirect -no-boot-anim -port 5554 &> "${test_report_dir}/emulator.txt" & - adb wait-for-device \ - shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done; input keyevent 82' - #echo "$(adb devices | grep "emulator-5554" | cut -f1) launch successful" - - #echo $(adb -s emulator-5554 emu avd name | head -1) - echo "Device online" - sleep 5 - - # restart adb in root mode - #adb root - - # Disable animations - #adb shell input keyevent 82 - #adb shell settings put global window_animation_scale 0.0 - #adb shell settings put global transition_animation_scale 0.0 - #adb shell settings put global animator_duration_scale 0.0 - - echo -e "\nInstalling Test APK..." - i=0 - step_complete=false - until [[ $step_complete == true ]]; do - if adb -s emulator-5554 install -r -t -d \ - "app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk" &> "${test_report_dir}/apk_installation.txt"; then - step_complete=true - echo "Successfully installed Test APK" - fi - if [[ $i -ge 100 ]]; then - echo "Error: Failed to install Test APK" >&2 - echo "For more information see 'android/${test_report_dir}/apk_installation.txt'" >&2 - exit 1 - fi - i=$((i+1)) - sleep 1 - done - - echo -e "\nInstalling ABI APK..." - i=0 - step_complete=false - until [[ $step_complete == true ]]; do - if adb -s emulator-5554 install -r -t -d --abi "${abi}" \ - "app/build/outputs/apk/debug/app-${abi}-debug.apk" &> "${test_report_dir}/apk_installation.txt"; then - step_complete=true - echo "Successfully installed ABI APK" - fi - if [[ $i -ge 100 ]]; then - echo "Error: Failed to install ABI APK" >&2 - echo "For more information see 'android/${test_report_dir}/apk_installation.txt'" >&2 - exit 1 - fi - i=$((i+1)) - sleep 1 - done - - # Store emulator info and start logging - adb -s emulator-5554 shell getprop &> "${test_report_dir}/getprop.txt" - adb -s emulator-5554 shell cat /proc/meminfo &> "${test_report_dir}/meminfo.txt" - adb -s emulator-5554 shell cat /proc/cpuinfo &> "${test_report_dir}/cpuinfo.txt" - nohup adb -s emulator-5554 shell logcat -v threadtime -b main &> "${test_report_dir}/logcat.txt" & - - # Create additional test output directory - #adb -s emulator-5554 shell rm -rf "/sdcard/Android/media/org.ZingoLabs.Zingo/additional_e2e_test_output" - #adb -s emulator-5554 shell mkdir -p "/sdcard/Android/media/org.ZingoLabs.Zingo/additional_e2e_test_output" - echo -e "\nRunning end-to-end tests..." - nohup npx react-native start --sourceExts mock.ts,js,json,ts,tsx &> "${test_report_dir}/metro.txt" & - yarn detox test -c android.att.debug.${abi} ${test_name}.test.js --reuse - success_status=$? + # Kill all emulators + ../scripts/kill_emulators.sh +fi - # Store additional test outputs - #if [ -n "$(adb -s emulator-5554 shell ls -A /sdcard/Android/media/org.ZingoLabs.Zingo/additional_e2e_test_output 2>/dev/null)" ]; then - # adb -s emulator-5554 shell cat /sdcard/Android/media/org.ZingoLabs.Zingo/additional_e2e_test_output/* \ - # &> "${test_report_dir}/additional_e2e_test_output.txt" - #fi +# Create integration test report directory +test_report_dir="app/build/outputs/e2e_test_reports/${avd_name}" +rm -rf "${test_report_dir}" +mkdir -p "${test_report_dir}" + +echo -e "\n\nWaiting for emulator to launch..." +nohup emulator -avd "${avd_name}" -netdelay none -netspeed full -gpu swiftshader_indirect -no-boot-anim \ + -no-snapshot-save -read-only -port 5554 &> "${test_report_dir}/emulator.txt" & +wait_for $timeout_seconds check_launch +echo "$(adb devices | grep "emulator-5554" | cut -f1) launch successful" + +echo -e "\nWaiting for AVD to boot..." +wait_for $timeout_seconds check_boot +wait_for $timeout_seconds check_device_online +echo $(adb -s emulator-5554 emu avd name | head -1) +echo "Device online" +sleep 1 + +# # Disable animations +# adb shell input keyevent 82 +# adb shell settings put global window_animation_scale 0.0 +# adb shell settings put global transition_animation_scale 0.0 +# adb shell settings put global animator_duration_scale 0.0 + +# Store emulator info and start logging +adb -s emulator-5554 shell getprop &> "${test_report_dir}/getprop.txt" +adb -s emulator-5554 shell cat /proc/meminfo &> "${test_report_dir}/meminfo.txt" +adb -s emulator-5554 shell cat /proc/cpuinfo &> "${test_report_dir}/cpuinfo.txt" +nohup adb -s emulator-5554 shell logcat -v threadtime -b main &> "${test_report_dir}/logcat.txt" & + +# Create additional test output directory +adb -s emulator-5554 shell rm -rf "/sdcard/Android/media/org.ZingoLabs.Zingo/additional_test_output" +adb -s emulator-5554 shell mkdir -p "/sdcard/Android/media/org.ZingoLabs.Zingo/additional_test_output" + +echo -e "\nRunning end-to-end tests..." +nohup yarn start &> "${test_report_dir}/metro.txt" & +yarn detox build -c android.att.debug +yarn detox test -c android.att.debug ${test_name}.test.js +success_status=$? + +# Store additional test outputs +if [ -n "$(adb -s emulator-5554 shell ls -A /sdcard/Android/media/org.ZingoLabs.Zingo/additional_test_output 2>/dev/null)" ]; then + adb -s emulator-5554 shell cat /sdcard/Android/media/org.ZingoLabs.Zingo/additional_test_output/* \ + &> "${test_report_dir}/additional_test_output.txt" +fi - echo -e "\nTest reports saved: android/${test_report_dir}" - - if [ $success_status -ne 0 ]; then - echo -e "\nEnd-to-end tests FAILED" +echo -e "\nTest reports saved: android/${test_report_dir}" + +if [ $success_status -ne 0 ]; then + echo -e "\nEnd-to-end tests FAILED" - # Kill all emulators - ../scripts/kill_emulators.sh + # Kill all emulators + ../scripts/kill_emulators.sh - exit 1 - fi + killall node - echo -e "\ne2e tests PASSED" + exit 1 fi +echo -e "\nEnd-to-end tests PASSED" + # Kill all emulators ../scripts/kill_emulators.sh + +killall node \ No newline at end of file diff --git a/scripts/integration_tests.sh b/scripts/integration_tests.sh index 4f745537a..0ae41f876 100755 --- a/scripts/integration_tests.sh +++ b/scripts/integration_tests.sh @@ -8,11 +8,49 @@ set_api_target=false intel_host_os=true create_snapshot=false test_name_default="OfflineTestSuite" -valid_api_levels=("23" "24" "25" "26" "27" "28" "29" "30" "31" "32" "33" "34" "35") +valid_api_levels=("23" "24" "25" "26" "27" "28" "29" "30" "31" "32" "33" "34") valid_api_targets=("default" "google_apis" "google_apis_playstore" "google_atd" "google-tv" \ "aosp_atd" "android-tv" "android-desktop" "android-wear" "android-wear-cn") timeout_seconds=1800 # default timeout set to 30 minutes -device="pixel_7" + +function check_launch() { + emulator_status=$(adb devices | grep "emulator-5554" | cut -f1) + if [ "${emulator_status}" = "emulator-5554" ]; then + return 0; + else + return 1; + fi +} + +function check_boot() { + boot_status=$(adb -s emulator-5554 shell getprop sys.boot_completed) + if [ "${boot_status}" = "1" ]; then + return 0; + else + return 1; + fi +} + +function check_device_online() { + device_status=$(adb devices | grep emulator-5554 | cut -f2) + if [ "${device_status}" = "offline" ]; then + return 1; + fi + return 0; +} + +function wait_for() { + timeout_seconds=$1 + shift 1 + until [ $timeout_seconds -le 0 ] || ("$@" &> /dev/null); do + sleep 1 + timeout_seconds=$(( timeout_seconds - 1 )) + done + if [ $timeout_seconds -le 0 ]; then + echo -e "\nError: Timeout" >&2 + exit 1 + fi +} while getopts 'a:Al:e:t:sx:h' OPTION; do case "$OPTION" in @@ -172,11 +210,12 @@ if [ ! -d "./android/app" ]; then exit 1 fi -echo -e "\nRemoving node_modules before yarn..." +echo -e "\nYarn install directory removed..." rm -rf ./node_modules -echo -e "\nRunning yarn..." -yarn +echo -e "\nRunning yarn install..." +yarn global add node-gyp +yarn install cd android @@ -199,19 +238,18 @@ if [[ $create_snapshot == true ]]; then echo -e "\nCreating AVD..." echo no | avdmanager create avd --force --name "${avd_name}" --package "${sdk}" - echo -e "\n\nWaiting for emulator to launch & boot..." + echo -e "\n\nWaiting for emulator to launch..." nohup 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 & - - echo -e "\n\nWaiting more..." - adb wait-for-device \ - shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done' - + wait_for $timeout_seconds check_launch + wait_for $timeout_seconds check_device_online echo "$(adb devices | grep "emulator-5554" | cut -f1) launch successful" + echo -e "\nWaiting for AVD to boot..." + wait_for $timeout_seconds check_boot echo $(adb -s emulator-5554 emu avd name | head -1) echo "Boot completed" - sleep 5 + sleep 1 echo -e "\nSnapshot saved" else echo -e "\nChecking for AVD..." @@ -226,26 +264,28 @@ else fi echo -e "\nBuilding APKs..." - ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug -PsplitApk=true + ./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}" - echo -e "\n\nWaiting for emulator to launch & boot..." + echo -e "\n\nWaiting for emulator to launch..." nohup 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" & - adb wait-for-device \ - shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done; input keyevent 82' - #echo "$(adb devices | grep "emulator-5554" | cut -f1) launch successful" + wait_for $timeout_seconds check_launch + echo "$(adb devices | grep "emulator-5554" | cut -f1) launch successful" - #echo $(adb -s emulator-5554 emu avd name | head -1) + echo -e "\nWaiting for AVD to boot..." + wait_for $timeout_seconds check_boot + wait_for $timeout_seconds check_device_online + echo $(adb -s emulator-5554 emu avd name | head -1) echo "Device online" - sleep 5 + sleep 1 # Disable animations - #adb shell input keyevent 82 + adb shell input keyevent 82 adb shell settings put global window_animation_scale 0.0 adb shell settings put global transition_animation_scale 0.0 adb shell settings put global animator_duration_scale 0.0 @@ -276,19 +316,19 @@ else nohup adb -s emulator-5554 shell logcat -v threadtime -b main &> "${test_report_dir}/logcat.txt" & # Create additional test output directory - adb -s emulator-5554 shell rm -rf "/sdcard/Android/media/org.ZingoLabs.Zingo/additional_integration_test_output" - adb -s emulator-5554 shell mkdir -p "/sdcard/Android/media/org.ZingoLabs.Zingo/additional_integration_test_output" + adb -s emulator-5554 shell rm -rf "/sdcard/Android/media/org.ZingoLabs.Zingo/additional_test_output" + adb -s emulator-5554 shell mkdir -p "/sdcard/Android/media/org.ZingoLabs.Zingo/additional_test_output" echo -e "\nRunning integration tests..." adb -s emulator-5554 shell am instrument -w -r -e class org.ZingoLabs.Zingo.$test_name \ - -e additionalTestOutputDir /sdcard/Android/media/org.ZingoLabs.Zingo/additional_integration_test_output \ + -e additionalTestOutputDir /sdcard/Android/media/org.ZingoLabs.Zingo/additional_test_output \ -e testTimeoutSeconds 31536000 org.ZingoLabs.Zingo.test/androidx.test.runner.AndroidJUnitRunner \ | tee "${test_report_dir}/test_results.txt" # Store additional test outputs - if [ -n "$(adb -s emulator-5554 shell ls -A /sdcard/Android/media/org.ZingoLabs.Zingo/additional_integration_test_output 2>/dev/null)" ]; then - adb -s emulator-5554 shell cat /sdcard/Android/media/org.ZingoLabs.Zingo/additional_integration_test_output/* \ - &> "${test_report_dir}/additional_integration_test_output.txt" + if [ -n "$(adb -s emulator-5554 shell ls -A /sdcard/Android/media/org.ZingoLabs.Zingo/additional_test_output 2>/dev/null)" ]; then + adb -s emulator-5554 shell cat /sdcard/Android/media/org.ZingoLabs.Zingo/additional_test_output/* \ + &> "${test_report_dir}/additional_test_output.txt" fi echo -e "\nTest reports saved: android/${test_report_dir}" @@ -307,4 +347,4 @@ else fi # Kill all emulators -../scripts/kill_emulators.sh +../scripts/kill_emulators.sh \ No newline at end of file