shithub: openh264

Download patch

ref: a22d976b4e823d3f3cb26f1b8dd433116c156700
parent: a8286234bba2d693dbf39350b342137aaa2831ea
author: syureyi <[email protected]>
date: Fri Jul 25 10:05:21 EDT 2014

checking the scripits for unittest automatically on mobile

--- /dev/null
+++ b/autotest/unitTest/.gitignore
@@ -1,0 +1,4 @@
+.DS_Store
+./ios/report/
+./android/report/
+
--- /dev/null
+++ b/autotest/unitTest/android/run_AutoTest_android.sh
@@ -1,0 +1,106 @@
+#!/bin/bash
+
+AUTO_TEST_ANDROID_PATH=`pwd`
+AUTO_TEST_SRC_PATH="../../../"
+AUTO_TEST_RES_PATH="${AUTO_TEST_ANDROID_PATH}/report"
+mkdir -p ${AUTO_TEST_RES_PATH}
+#Prepare android build enviroment
+echo please set the enviroment variable as: 
+echo export ANDROID_HOME="path of android sdk" 
+echo export ANDROID_NDK_HOME="path of android ndk"
+ANDROID_SDK_PATH=${ANDROID_HOME}
+ANDROID_NDK_PATH=${ANDROID_NDK_HOME}
+ANDROID_MAKE_PARAMS="OS=android NDKROOT=${ANDROID_NDK_PATH} TARGET=android-19"
+
+if [ "#${ANDROID_SDK_PATH}" = "#" ]
+then  
+echo Please set ANDROID_HOME with the path of Android SDK 
+exit 1
+fi
+if [ "#${ANDROID_NDK_PATH}" = "#" ]
+then
+echo Please set ANDROID_NDK_HOME with the path of Android NDK 
+exit 1
+fi
+#make build
+cd ${AUTO_TEST_SRC_PATH}
+find ./ -name *.o -exec rm -f {} \;
+find ./ -name *.d -exec rm -f {} \;
+make clean
+make $ANDROID_MAKE_PARAMS test
+
+if [ $? -ne 0 ]
+then 
+   echo Build error,check with the trace of make
+   exit 1
+fi
+
+#find apk
+echo Start to find unittest apk
+apk_name=`find ./ -name MainActivity-debug.apk`
+if [ "#${apk_name}" = "#" ]
+then
+  echo Fail to find encoder APK.
+  exit 1
+fi
+
+#prepare devices
+ADB=${ANDROID_SDK_PATH}/platform-tools/adb
+
+#get devices
+devices=`$ADB devices | awk -F" " '/\tdevice/{print $1}'`                                         
+if [ "#$devices" = "#" ];then                                                                     
+   echo "Have not any android devices."                                        
+   exit 1                                                                                        
+fi 
+              
+#run apk                                                                          
+run_apk() {
+local apk=$1;
+local rand=` date +%s`
+apk_id="com.cisco.codec.unittest"
+apk_main="com.cisco.codec.unittest/.MainActivity"
+test_path="/sdcard/welsenc"
+log_grep_params="welsenc"
+test_res=./res
+xml_file="sdcard/codec_unittest.xml"
+for dev in $devices; do  
+    #dev_info_file=${AUTO_TEST_RES_PATH}/${dev}.log
+    report_file=${AUTO_TEST_RES_PATH}/codec_unittest_${dev}_${rand}.xml                                                                  
+    $ADB -s $dev uninstall ${apk_id}                                            
+    $ADB -s $dev install -r ${apk}
+    #TODO: output more info about android device such as name,cpu,memory,and also power comsumption.
+    echo `$ADB -s $dev shell cat /system/build.prop |grep ro.product.model | awk -F"=" '{print $2}'`>${dev_info_file}
+    $ADB -s $dev push ${test_res} /sdcard/res
+    $ADB -s $dev shell am start --es path "$xml_file" -n ${apk_main}
+    # check whetehr the app is finished every 2 sec
+    for (( ; ; )); do
+        $ADB -s $dev shell ps | grep ${apk_id}
+        if [ $? -ne 0 ]; then
+            sleep 2
+            $ADB -s $dev shell ps | grep ${apk_id}
+            [ $? -ne 0 ] && break
+        fi
+        sleep 2
+    done
+
+    # kill logcat
+    $ADB -s $dev pull ${xml_file} ${report_file}
+    #delete the res
+    $ADB -s $dev shell rm -rf ${xml_file}
+    $ADB -s $dev shell rm -rf /sdcard/res
+done      
+}
+for apk in ${apk_name};do
+   run_apk $apk;
+   if [ $? -ne 0 ]
+   then
+     echo There is something wrong happened when run ${apk_name}
+     exit 1
+   else
+     echo Finished unit test on android
+     echo The test result is at ./android/report/xxx.xml
+     echo xxxxxxxxxxxxxxxAndroid unittest Endxxxxxxxxxxxxxxxx
+   fi
+done
+
--- /dev/null
+++ b/autotest/unitTest/ios/run_AutoTest_ios.sh
@@ -1,0 +1,163 @@
+#!/bin/bash
+
+##############################################################
+#Build ios test ref app
+
+#set the default configuration
+CODEC_TEST_IOS_ARCH="armv7"
+CODEC_TEST_IOS_PLATFORM="iphoneos"
+CODEC_TEST_IOS_DEBUG_RELEASE="Release"
+CODEC_TEST_IOS_REPORT_SUBFOLDER="release"
+
+
+buildXcodeProject()
+{
+ xcodebuild ARCHS="${CODEC_TEST_IOS_ARCH}" VALID_ARCHS="${CODEC_TEST_IOS_ARCH}" ONLY_ACTIVE_ARCH=NO -project $1 -target $2 -configuration $3 -sdk ${CODEC_TEST_IOS_PLATFORM} clean build
+ 
+if [ $? -eq 0 ]; then                                                                              
+ echo "build $1 $3 successfully"                                                                                                                                                         
+ else                                                                                              
+ echo "build $1 $3  fail"                                                                        
+ exit 1                                                                                         
+ fi            
+}
+
+
+
+iosUnitTest()
+{
+
+if [ $# -gt 2 ]; then
+echo "Please use command $0 [armv7/armv7s/arm64] [release/debug]"
+exit 1
+fi
+
+     CODEC_TEST_XCODE_PROJECT_NAME="${AUTO_TEST_SRC_PATH}/test/build/ios/codec_unittest/codec_unittest.xcodeproj/"
+     CODEC_TEST_IOS_PROJECT_NAME="codec_unittest"
+     CODEC_TEST_IOS_PROJECT_PATH="${AUTO_TEST_SRC_PATH}/test/build/ios/codec_unittest/build"
+     CODEC_TEST_IOS_APP=${CODEC_TEST_IOS_PROJECT_PATH}/${CODEC_TEST_IOS_DEBUG_RELEASE}-iphoneos/${CODEC_TEST_IOS_PROJECT_NAME}.app
+     CODEC_TEST_IOS_APP_ID="com.cisco.codec-unittest"
+     CODEC_TEST_RES=${AUTO_TEST_SRC_PATH}/res
+     CODEC_TEST_LOG="codec_unittest"
+for PARAM in $*; do  
+   if [ "release" = "${PARAM}" ]; then
+     CODEC_TEST_IOS_DEBUG_RELEASE="Release"                                                      
+     CODEC_TEST_IOS_REPORT_SUBFOLDER="release"                                                   
+ elif [ "debug" = "${PARAM}" ]; then                                                             
+     CODEC_TEST_IOS_DEBUG_RELEASE="Debug"                                                        
+     CODEC_TEST_IOS_REPORT_SUBFOLDER="debug"   
+ elif [ "armv7" = "${PARAM}" ];then
+      CODEC_TEST_IOS_ARCH="armv7"
+ elif [ "armv7s" = "${PARAM}" ];then
+     CODEC_TEST_IOS_ARCH="armv7s"
+ elif [ "arm64" = "${PARAM}" ];then
+    CODEC_TEST_IOS_ARCH="arm64"                                                  
+ else                                                                                          
+    echo parameters are illegal!!!, please have a check.                                        
+    exit 1                                                                                      
+ fi                                                                                            
+ done     
+cd ${AUTO_TEST_SRC_PATH}
+IOS_MAKE_PARAMS="OS=ios ARCH=${CODEC_TEST_IOS_ARCH}"
+############make build 
+find ./ -name *.o -exec rm -rf {} \;
+find ./ -name *.d -exec rm -rf {} \;
+make clean
+make ${IOS_MAKE_PARAMS} test
+echo "Codec test will run on ${CODEC_TEST_IOS_PLATFORM} with ${CODEC_TEST_IOS_DEBUG_RELEASE}"
+cd ${AUTO_TEST_IOS_PATH}
+buildXcodeProject ${CODEC_TEST_XCODE_PROJECT_NAME} ${CODEC_TEST_IOS_PROJECT_NAME} ${CODEC_TEST_IOS_DEBUG_RELEASE} ${CODEC_TEST_IOS_PLATFORM}
+
+
+ 
+
+##############run on ios devices#########################
+# for real device
+if [ ! -d ${CODEC_TEST_IOS_APP} ] ; then
+echo "${CODEC_TEST_IOS_APP} is not found"
+exit 1
+else
+echo "Find app ${CODEC_TEST_IOS_APP}"
+fi
+
+ #ensure instruments not runing
+echo "Try to kill the runing instruments"
+pids_str=`ps x -o pid,command | grep -v grep | grep "instruments" | awk '{printf "%s,", $1}'`
+instruments_pids="${pids_str//,/ }"
+for pid in ${instruments_pids}; do
+echo "Found instruments ${pid}. Killing..."                                                      
+kill -9 ${pid} && wait ${pid} &> /dev/null                                                       
+done                                                                                             
+
+
+
+DEVICES=`system_profiler SPUSBDataType | sed -n -e '/iPad/,/Serial/p' -e '/iPhone/,/Serial/p' | grep "Serial Number:" | awk -F ": " '{print $2}'`
+if [ "${DEVICES}#" == "#" ]
+then  
+echo "Can not find any connected device! please check device is connected to MAC!"
+exit 1
+else
+rand=`date +%s`
+for DEVICE_ID in ${DEVICES}
+do
+echo "Try to run on device:${DEVICE_ID}"
+
+#uninstall the application from device to remove the last result
+${AUTO_TEST_IOS_SCRIPT_PATH}/fruitstrap uninstall --bundle ${CODEC_TEST_IOS_APP_ID} --id ${DEVICE_ID}
+if [ $? -ne 0 ]; then
+echo uninstall application: ${CODEC_TEST_IOS_APP} from device: ${DEVICE_ID} is failed!
+fi
+#install the application
+${AUTO_TEST_IOS_SCRIPT_PATH}/fruitstrap install --bundle ${CODEC_TEST_IOS_APP} --id ${DEVICE_ID}
+if [ $? -ne 0 ]; then
+echo install application: ${CODEC_TEST_IOS_APP} to device: ${DEVICE_ID} is failed!
+exit 1
+fi
+
+${AUTO_TEST_IOS_SCRIPT_PATH}/iFileTransfer -o copy -id ${DEVICE_ID} -app ${CODEC_TEST_IOS_APP_ID} -from ${CODEC_TEST_RES}
+instruments -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 ${AUTO_TEST_IOS_SCRIPT_PATH}/uiascript.js -e UIARRESULTPATH /tmp/
+#copy to report folder
+${AUTO_TEST_IOS_SCRIPT_PATH}/iFileTransfer -o download -id ${DEVICE_ID} -app ${CODEC_TEST_IOS_APP_ID} -from /Documents/${CODEC_TEST_LOG}.xml -to ${CODEC_TEST_IOS_REPORT_PATH}/${CODEC_TEST_LOG}_${DEVICE_ID}_${rand}_${CODEC_TEST_IOS_ARCH}.xml
+if [ $? -ne 0 ]; then
+echo "download file: ${CODEC_TEST_LOG}.xml from ${CODEC_TEST_IOS_APP_ID} is failed!"
+exit 1
+fi
+
+done
+fi
+}
+
+AUTO_TEST_IOS_PATH=`pwd`
+AUTO_TEST_SRC_PATH="../../.."
+AUTO_TEST_IOS_SCRIPT_PATH="../../performanceTest/ios"
+CODEC_TEST_IOS_REPORT_PATH="${AUTO_TEST_IOS_PATH}/report"
+if [ ! -d ${CODEC_TEST_IOS_REPORT_PATH} ]
+then
+ mkdir -p ${CODEC_TEST_IOS_REPORT_PATH}
+fi
+
+#start to run unittest,default run the xcode at arch armv7 with release
+iosUnitTest armv7 release
+
+if [ $? -ne 0 ]; then                                                                                              
+echo "Running Unittest demo with armv7 is failed!"                          
+exit 1
+else 
+echo Finished unittest with armv7 on ios devices
+echo the test result is generated at ./ios/report/xx.xml
+fi
+#start to run unittest,run the xcode at arch arm64 with release
+iosUnitTest arm64 release
+if [ $? -ne 0 ]; then                                    
+echo "Running Unittest demo with arm64 is failed!"                  
+exit 1                                                   
+else                                                     
+echo Finished unittest with arm64 on ios devices         
+echo the test result is generated at ./ios/report/xx.xml 
+fi
+
+echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxIOS unittest  Endxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+
+#TODO:according to the trace of instruments to do some analysis                            
+#find ${AUTO_TEST_IOS_SCRIPT_PATH} -name *.trace -exec rm -rf {} \;
+rm -rf *.trace
--- /dev/null
+++ b/autotest/unitTest/run_ParseUTxml.sh
@@ -1,0 +1,44 @@
+if [ $# -ne 1 ];then
+	echo Please input $0 [report dir]
+	exit 1
+fi
+
+REPORT=$1
+if [ ! -e ${REPORT} ];then
+	echo "The directory of ${REPORT} dose't not exit,please check the test log"
+    exit 1
+fi
+
+UT_Failed_Num=0
+parse_unittest() {
+	res=$1
+	echo Start to parse unittest results of $res
+	if [ -e $res ];then
+    tests=`cat $res | grep "<testsuites" | awk -F " " '{print $2;}' | awk -F "\"" '{print $2;}'`
+	fails=`cat $res | grep "<testsuites" | awk -F " " '{print $3;}' | awk -F "\"" '{print $2;}'`
+	times=`cat $res | grep "<testsuites" | awk -F " " '{print $6;}' | awk -F "\"" '{print $2;}'`
+	waste=`cat $res | grep "<testsuites" | awk -F " " '{print $7;}' | awk -F "\"" '{print $2;}'`
+	msg="Total testcases: $tests, failed: $fails,time:$waste seconds, at$times,xml:$res"
+    echo $msg
+    UT_Failed_Num=$[${UT_Failed_Num}+${fails}]
+	fi
+		
+}
+
+xmlcount=`ls $REPORT | wc -l`
+xmlfiles=`ls $REPORT`
+if [ ${xmlcount} -eq 0 ];
+then echo There is nothing xml files generated at $REPORT
+     exit 1
+fi
+for file in $xmlfiles;do
+	parse_unittest $REPORT/$file
+done
+
+if [ ${UT_Failed_Num} = "0" ];then
+echo Total $xmlcount files at $REPORT,all sucessful
+exit 0
+else
+echo Total $xmlcount files at $REPORT,${UT_Failed_Num} error cases
+exit 2
+fi
--- /dev/null
+++ b/autotest/unitTest/run_unitTest.sh
@@ -1,0 +1,84 @@
+#!/bin/bash
+
+AUTO_TEST_PATH=`pwd`
+#Prepare GTEST
+AUTO_TEST_SRC_PATH="../../"
+cd ${AUTO_TEST_SRC_PATH}
+if [ ! -d "./gtest" ]
+then
+   make gtest-bootstrap
+fi
+cd ${AUTO_TEST_PATH}
+#To find whether have android devices
+echo please set the enviroment variable as: 
+echo export ANDROID_HOME="path of android sdk" 
+echo export ANDROID_NDK_HOME="path of android ndk"
+ANDROID_SDK_PATH=${ANDROID_HOME}
+ANDROID_NDK_PATH=${ANDROID_NDK_HOME}
+if [ "#${ANDROID_SDK_PATH}" = "#" ]
+then
+echo Please set ANDROID_HOME with the path of Android SDK 
+exit 1
+fi
+if [ "#${ANDROID_NDK_PATH}" = "#" ]
+then
+echo Please set ANDROID_NDK_HOME with the path of Android NDK 
+exit 1
+fi
+#prepare devices                                              
+ADB=${ANDROID_SDK_PATH}/platform-tools/adb                    
+                                                              
+#get devices                                                  
+devices=`$ADB devices | awk -F" " '/\tdevice/{print $1}'`     
+if [ "#$devices" = "#" ];then                                 
+   echo "Can not find any android devices!"                       
+else
+   echo Start to run the unittest on android devices
+   ANDROID=1  
+   cd ./android
+   bash run_AutoTest_android.sh
+   cd ${AUTO_TEST_PATH}
+   if [ $? -ne 0 ];then
+   echo There is something wrong happened when runing unittest on android devices,please to check
+   fi                                                     
+fi 
+
+#To find whether have ios devices
+ DEVICES=`system_profiler SPUSBDataType | sed -n -e '/iPad/,/Serial/p' -e '/iPhone/,/Serial/p' | grep "Serial Number:" | awk -F ": " '{print $2}'`
+ if [ "${DEVICES}#" == "#" ]                                                                       
+ then                                                                                              
+ echo "Can not find any connected device! please check device is connected to MAC!"
+else
+  echo Start to run the unittest on ios devices
+  IOS=1
+  cd ./ios
+  bash run_AutoTest_ios.sh
+  cd ${AUTO_TEST_PATH}
+ if [ $? -ne 0 ];then
+ echo There is something wrong happened when runing unittest on ios devices,please to check
+ fi
+fi
+                
+#To parse the unit test result file to find whether have failures                                                            
+if [ ${ANDROID} = "1" ];then
+bash run_ParseUTxml.sh ./android/report
+ret=$?
+if [ ${ret} -eq 0 ];then
+echo Unit test run on the android devices have not any failure case
+elif [ ${ret} -eq 2 ];then                                                                                                                                    
+echo Unit test have cases failed,please check                                                                                                             
+elif [ ${ret} -eq 1 ];then                                                                                                                                    
+echo Unit test run failed 
+fi
+fi
+if [ $IOS = "1" ];then
+bash run_ParseUTxml.sh ./ios/report
+ret=$?                       
+if [ $ret -eq 0 ];then                                          
+echo Unit test run on the ios devices have not any failure case
+elif [ $ret -eq 2 ];then                                                          
+echo Unit test have cases failed,please check
+elif [ $ret -eq 1 ];then
+echo Unit test run failed
+fi
+fi