1#!/bin/bash 2# Copyright (c) Meta Platforms, Inc. and affiliates. 3# All rights reserved. 4# 5# This source code is licensed under the BSD-style license found in the 6# LICENSE file in the root directory of this source tree. 7 8set -e 9 10APP_PATH="examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo" 11MODEL_NAME="mv3" 12SIMULATOR_NAME="executorch" 13 14# If this is set, copy the build artifacts to this directory 15ARTIFACTS_DIR_NAME="$1" 16 17finish() { 18 EXIT_STATUS=$? 19 if xcrun simctl list | grep -q "$SIMULATOR_NAME"; then 20 say "Deleting Simulator" 21 xcrun simctl delete "$SIMULATOR_NAME" 22 fi 23 if [ $EXIT_STATUS -eq 0 ]; then 24 say "SUCCEEDED" 25 else 26 say "FAILED" 27 fi 28 exit $EXIT_STATUS 29} 30 31trap finish EXIT 32 33say() { 34 echo -e "\033[1m\n\t** $1 **\n\033[0m" 35} 36 37say "Installing CoreML Backend Requirements" 38 39./backends/apple/coreml/scripts/install_requirements.sh 40 41say "Installing MPS Backend Requirements" 42 43./backends/apple/mps/install_requirements.sh 44 45say "Exporting Models" 46 47python3 -m examples.portable.scripts.export --model_name="$MODEL_NAME" --segment_alignment=0x4000 48python3 -m examples.apple.coreml.scripts.export --model_name="$MODEL_NAME" 49python3 -m examples.apple.mps.scripts.mps_example --model_name="$MODEL_NAME" 50python3 -m examples.xnnpack.aot_compiler --model_name="$MODEL_NAME" --delegate 51 52mkdir -p "$APP_PATH/Resources/Models/MobileNet/" 53mv $MODEL_NAME*.pte "$APP_PATH/Resources/Models/MobileNet/" 54 55say "Downloading Labels" 56 57curl https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt \ 58 -o "$APP_PATH/Resources/Models/MobileNet/imagenet_classes.txt" 59 60say "Creating Simulator" 61 62xcrun simctl create "$SIMULATOR_NAME" "iPhone 15" 63 64say "Running Tests" 65 66xcodebuild test \ 67 -project "$APP_PATH.xcodeproj" \ 68 -scheme MobileNetClassifierTest \ 69 -destination name="$SIMULATOR_NAME" 70 71# NB: https://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-ios-xctest-ui.html 72say "Package The Test Suite" 73 74xcodebuild build-for-testing \ 75 -project "$APP_PATH.xcodeproj" \ 76 -scheme MobileNetClassifierTest \ 77 -destination platform="iOS" \ 78 -allowProvisioningUpdates \ 79 DEVELOPMENT_TEAM=78E7V7QP35 \ 80 CODE_SIGN_STYLE=Manual \ 81 PROVISIONING_PROFILE_SPECIFIER=ExecuTorchDemo \ 82 CODE_SIGN_IDENTITY="iPhone Distribution" 83 84# The hack to figure out where the xctest package locates 85BUILD_DIR=$(xcodebuild -showBuildSettings -project "$APP_PATH.xcodeproj" -json | jq -r ".[0].buildSettings.BUILD_DIR") 86 87# Prepare the demo app 88MODE="Debug" 89PLATFORM="iphoneos" 90pushd "${BUILD_DIR}/${MODE}-${PLATFORM}" 91 92rm -rf Payload && mkdir Payload 93MOCK_APP_NAME=ExecuTorchDemo 94 95ls -lah 96cp -r "${MOCK_APP_NAME}.app" Payload && zip -vr "${MOCK_APP_NAME}.ipa" Payload 97 98popd 99 100# Prepare the test suite 101pushd "${BUILD_DIR}" 102 103ls -lah 104zip -vr "${MOCK_APP_NAME}.xctestrun.zip" *.xctestrun 105 106popd 107 108if [[ -n "${ARTIFACTS_DIR_NAME}" ]]; then 109 mkdir -p "${ARTIFACTS_DIR_NAME}" 110 # Prepare all the artifacts to upload 111 cp "${BUILD_DIR}/${MODE}-${PLATFORM}/${MOCK_APP_NAME}.ipa" "${ARTIFACTS_DIR_NAME}/" 112 cp "${BUILD_DIR}/${MOCK_APP_NAME}.xctestrun.zip" "${ARTIFACTS_DIR_NAME}/" 113 114 ls -lah "${ARTIFACTS_DIR_NAME}/" 115fi 116