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