1#!/bin/bash 2 3############################################################## 4#Build ios test ref app 5 6#set the default configuration 7CODEC_TEST_IOS_ARCH="armv7 armv7s arm64" 8CODEC_TEST_IOS_PLATFORM="iphoneos" 9CODEC_TEST_IOS_DEBUG_RELEASE="Release" 10CODEC_TEST_IOS_REPORT_SUBFOLDER="release" 11 12 13buildXcodeProject() 14{ 15 xcodebuild ARCHS="${CODEC_TEST_IOS_ARCH}" VALID_ARCHS="${CODEC_TEST_IOS_ARCH}" ONLY_ACTIVE_ARCH=YES -project $1 -target $2 -configuration $3 -sdk ${CODEC_TEST_IOS_PLATFORM} clean build 16 17if [ $? -eq 0 ]; then 18 echo "build $1 $3 successfully" 19 else 20 echo "build $1 $3 fail" 21 exit 1 22 fi 23} 24 25 26 27iosPerformanceTest() 28{ 29 30if [ $# -gt 2 ]; then 31echo "Please use command $0 [enc/dec] [release/debug]" 32exit 1 33fi 34 35for PARAM in $*; do 36 if [ "enc" = "${PARAM}" ]; then 37 CODEC_TEST_XCODE_PROJECT_NAME="${AUTO_TEST_SRC_PATH}/codec/build/iOS/enc/encDemo/encDemo.xcodeproj" 38 CODEC_TEST_IOS_PROJECT_NAME="encDemo" 39 CODEC_TEST_IOS_PROJECT_PATH="${AUTO_TEST_SRC_PATH}/codec/build/iOS/enc/encDemo/build" 40 CODEC_TEST_IOS_APP=${CODEC_TEST_IOS_PROJECT_PATH}/${CODEC_TEST_IOS_DEBUG_RELEASE}-iphoneos/${CODEC_TEST_IOS_PROJECT_NAME}.app 41 CODEC_TEST_IOS_APP_ID="cisco.encDemo" 42 CODEC_TEST_RES=${AUTO_TEST_IOS_PATH}/../EncoderPerfTestRes 43 CODEC_TEST_LOG="encPerf" 44 elif [ "dec" = "${PARAM}" ]; then 45 CODEC_TEST_XCODE_PROJECT_NAME="${AUTO_TEST_SRC_PATH}/codec/build/iOS/dec/demo/demo.xcodeproj/" 46 CODEC_TEST_IOS_PROJECT_NAME="demo" 47 CODEC_TEST_IOS_PROJECT_PATH="${AUTO_TEST_SRC_PATH}/codec/build/iOS/dec/demo/build" 48 CODEC_TEST_IOS_APP=${CODEC_TEST_IOS_PROJECT_PATH}/${CODEC_TEST_IOS_DEBUG_RELEASE}-iphoneos/${CODEC_TEST_IOS_PROJECT_NAME}.app 49 CODEC_TEST_IOS_APP_ID="hf.cisco.demo" 50 CODEC_TEST_RES=${AUTO_TEST_IOS_PATH}/../DecoderPerfTestRes 51 CODEC_TEST_LOG="decPerf" 52 elif [ "release" = "${PARAM}" ]; then 53 CODEC_TEST_IOS_DEBUG_RELEASE="Release" 54 CODEC_TEST_IOS_REPORT_SUBFOLDER="release" 55 elif [ "debug" = "${PARAM}" ]; then 56 CODEC_TEST_IOS_DEBUG_RELEASE="Debug" 57 CODEC_TEST_IOS_REPORT_SUBFOLDER="debug" 58 else 59 echo parameters are illegal!!!, please have a check. 60 exit 1 61 fi 62 done 63 64echo "Codec test will run on ${CODEC_TEST_IOS_PLATFORM} with ${CODEC_TEST_IOS_DEBUG_RELEASE}" 65buildXcodeProject ${CODEC_TEST_XCODE_PROJECT_NAME} ${CODEC_TEST_IOS_PROJECT_NAME} ${CODEC_TEST_IOS_DEBUG_RELEASE} ${CODEC_TEST_IOS_PLATFORM} 66 67 68 69 70##############run on ios devices######################### 71# for real device 72if [ ! -d ${CODEC_TEST_IOS_APP} ] ; then 73echo "${CODEC_TEST_IOS_APP} is not found" 74exit 1 75else 76echo "Find app ${CODEC_TEST_IOS_APP}" 77fi 78 79 #ensure instruments not runing 80echo "Try to kill the runing instruments" 81pids_str=`ps x -o pid,command | grep -v grep | grep "instruments" | awk '{printf "%s,", $1}'` 82instruments_pids="${pids_str//,/ }" 83for pid in ${instruments_pids}; do 84echo "Found instruments ${pid}. Killing..." 85kill -9 ${pid} && wait ${pid} &> /dev/null 86done 87 88 89 90DEVICES=`system_profiler SPUSBDataType | sed -n -e '/iPad/,/Serial/p' -e '/iPhone/,/Serial/p' | grep "Serial Number:" | awk -F ": " '{print $2}'` 91if [ "${DEVICES}#" == "#" ] 92then 93echo "Can not find any connected device! please check device is connected to MAC!" 94exit 1 95else 96rand=`date +%s` 97for DEVICE_ID in ${DEVICES} 98do 99echo "Try to run on device:${DEVICE_ID}" 100 101#Encoder YUV file too large 102if [ ${ENCDEC} = "enc" ] 103then 104#For limited devices space 105BAKRES=${CODEC_TEST_RES}_bak 106mv ${CODEC_TEST_RES} ${BAKRES} 107mkdir -p ${CODEC_TEST_RES} 108CODEC_CASE=`ls ${BAKRES}` 109echo ${CODEC_CASE} 110for CASE in ${CODEC_CASE} 111do 112echo ${CASE} 113cp -r ${BAKRES}/${CASE} ${CODEC_TEST_RES}/. 114 115 116#uninstall the application from device to remove the last result 117./fruitstrap uninstall --bundle ${CODEC_TEST_IOS_APP_ID} --id ${DEVICE_ID} 118if [ $? -ne 0 ]; then 119echo uninstall application: ${CODEC_TEST_IOS_APP} from device: ${DEVICE_ID} is failed! 120fi 121#install the application 122./fruitstrap install --bundle ${CODEC_TEST_IOS_APP} --id ${DEVICE_ID} 123if [ $? -ne 0 ]; then 124echo install application: ${CODEC_TEST_IOS_APP} to device: ${DEVICE_ID} is failed! 125exit 1 126fi 127 128./iFileTransfer -o copy -id ${DEVICE_ID} -app ${CODEC_TEST_IOS_APP_ID} -from ${CODEC_TEST_RES} 129instruments -w ${DEVICE_ID} -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate ${CODEC_TEST_IOS_APP} -e UIASCRIPT ./uiascript.js -e UIARRESULTPATH /tmp/ 130#copy to report folder 131./iFileTransfer -o download -id ${DEVICE_ID} -app ${CODEC_TEST_IOS_APP_ID} -from /Documents/${CODEC_TEST_LOG}.log -to ${CODEC_TEST_IOS_REPORT_PATH}/${CODEC_TEST_LOG}_${DEVICE_ID}_${rand}_${CASE}.log 132if [ $? -ne 0 ]; then 133echo "download file: ${CODEC_TEST_LOG}.log from ${CODEC_TEST_IOS_APP_ID} is failed!" 134exit 1 135fi 136cat ${CODEC_TEST_IOS_REPORT_PATH}/${CODEC_TEST_LOG}_${DEVICE_ID}_${rand}_${CASE}.log>>${CODEC_TEST_IOS_REPORT_PATH}/${CODEC_TEST_LOG}_${DEVICE_ID}_${rand}.log 137rm -f ${CODEC_TEST_IOS_REPORT_PATH}/${CODEC_TEST_LOG}_${DEVICE_ID}_${rand}_${CASE}.log 138rm -rf ${CODEC_TEST_RES}/${CASE} 139done 140rm -rf ${CODEC_TEST_RES} 141mv ${BAKRES} ${CODEC_TEST_RES} 142#Enough spaces 143else 144#uninstall the application from device to remove the last result 145./fruitstrap uninstall --bundle ${CODEC_TEST_IOS_APP_ID} --id ${DEVICE_ID} 146if [ $? -ne 0 ]; then 147echo uninstall application: ${CODEC_TEST_IOS_APP} from device: ${DEVICE_ID} is failed! 148fi 149#install the application 150./fruitstrap install --bundle ${CODEC_TEST_IOS_APP} --id ${DEVICE_ID} 151if [ $? -ne 0 ]; then 152echo install application: ${CODEC_TEST_IOS_APP} to device: ${DEVICE_ID} is failed! 153exit 1 154fi 155 156./iFileTransfer -o copy -id ${DEVICE_ID} -app ${CODEC_TEST_IOS_APP_ID} -from ${CODEC_TEST_RES} 157instruments -w ${DEVICE_ID} -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate ${CODEC_TEST_IOS_APP} -e UIASCRIPT ./uiascript.js -e UIARRESULTPATH /tmp/ 158#copy to report folder 159./iFileTransfer -o download -id ${DEVICE_ID} -app ${CODEC_TEST_IOS_APP_ID} -from /Documents/${CODEC_TEST_LOG}.log -to ${CODEC_TEST_IOS_REPORT_PATH}/${CODEC_TEST_LOG}_${DEVICE_ID}_${rand}_${CASE}.log 160if [ $? -ne 0 ]; then 161echo "download file: ${CODEC_TEST_LOG}.log from ${CODEC_TEST_IOS_APP_ID} is failed!" 162exit 1 163fi 164 165 166fi 167done 168 169fi 170} 171 172AUTO_TEST_IOS_PATH=`pwd` 173AUTO_TEST_SRC_PATH="../../.." 174CODEC_TEST_IOS_REPORT_PATH="${AUTO_TEST_IOS_PATH}/report" 175if [ ! -d ${CODEC_TEST_IOS_REPORT_PATH} ] 176then 177 mkdir -p ${CODEC_TEST_IOS_REPORT_PATH} 178fi 179 180ENCDEC=$1 181#start to get encoder/decoder performance data,default run the xcode with release 182iosPerformanceTest $ENCDEC release 183 184if [ $? -ne 0 ]; then 185echo "Running $ENCDEC demo to get encoder performance is failed!" 186exit 1 187else 188echo Finished $ENCDEC performance test on ios devices 189echo the test result is generated at ./ios/report/xx.loGbash parsePerfData.sh 190echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxIOS $ENCDEC Endxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 191fi 192#TODO:according to the trace of instruments to do some analysis 193#find ./ -name *.trace -exec rm -rf {} \; 194