Android CTS V2 under windows

不知道為什麼CTS在網路上找到的資訊總是停留在Android 4.4。偶有幾篇2016的卻也僅只於5.1的lollipop。雖然其實Google在官方上的說明其實也已經很清楚。但是卻缺少了Windows版本的說明.只好自己照unix script來試試瞜!

由於Android過個季也會因為Security patch的關係升級TestPlan,快速的疊代也是追的蠻辛苦的,實際跑玩一Run才發現總是要結關前就能趕的及測過也是挺不容易的呢。

這邊的Setup guide裡面就只提到Linux與Mac…

https://source.android.com/compatibility/cts/setup

好吧~ 廢話完了開始進入正題,這邊我拿的是這個時間點最新的CTS 7.1 r5

Android 7.1 R5 Compatibility Test Suite (CTS)

解開後的路徑”android-cts\tools\cts-tradefed”也就是在UNIX下要執行的腳本

首先開頭就是對於環境的檢查,最少就是要有adb, aapt, java。
Java這邊我的電腦本來就已經裝好JRE 1.8,而adb和aapt都可以透過android-sdk來取得。
記得要Update到最新的API level,當前是25.0.3

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# launcher script for cts-tradefed harness
# can be used from an Android build environment, or a standalone cts zip
 
checkFile() {
    if [ ! -f "$1" ]; then
        echo "Unable to locate $1"
        exit
    fi;
}
 
checkPath() {
    if ! type -P $1 &> /dev/null; then
        echo "Unable to find $1 in path."
        exit
    fi;
}
 
checkPath aapt
checkPath adb
checkPath java

接續環境的檢查,諸如確定Java版本,Android的Build env detect 看來作用是取得CTS_ROOT.
debug_flag這段和os我們則是都用不到可以略過的

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# check java version
JAVA_VERSION=$(java -version 2>&1 | head -n 2 | grep '[ "]1\.[678][\. "$$]')
if [ "${JAVA_VERSION}" == "" ]; then
    echo "Wrong java version. 1.6, 1.7 or 1.8 is required."
    exit
fi
 
# check debug flag and set up remote debugging
if [ -n "${TF_DEBUG}" ]; then
  if [ -z "${TF_DEBUG_PORT}" ]; then
    TF_DEBUG_PORT=10088
  fi
  RDBG_FLAG=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=${TF_DEBUG_PORT}
fi
 
# get OS
HOST=`uname`
if [ "$HOST" == "Linux" ]; then
    OS="linux-x86"
elif [ "$HOST" == "Darwin" ]; then
    OS="darwin-x86"
else
    echo "Unrecognized OS"
    exit
fi
 
# check if in Android build env
if [ ! -z "${ANDROID_BUILD_TOP}" ]; then
    if [ ! -z "${ANDROID_HOST_OUT}" ]; then
      CTS_ROOT=${ANDROID_HOST_OUT}/cts
    else
      CTS_ROOT=${ANDROID_BUILD_TOP}/${OUT_DIR:-out}/host/${OS}/cts
    fi
    if [ ! -d ${CTS_ROOT} ]; then
        echo "Could not find $CTS_ROOT in Android build environment. Try 'make cts'"
        exit
    fi;
fi;
 
if [ -z ${CTS_ROOT} ]; then
    # assume we're in an extracted cts install
    CTS_ROOT="$(dirname $0)/../.."
fi;

到這邊開始把要跑的jar檔一起收進JAR_PATH這個環境變數裡.
最主要就是由上一段code定義好的CTS_ROOT基礎去撈 android-cts/tools 底下
tradefed-prebuilt, hosttestlib, compatibility-host-util, cts-tradefed這四個執行模組.
然後中段的部分視環境情況載入google指定模組和Libary.
但是這些我們載下來的檔案裡頭都是沒有的.
所以就只剩下最後的東西 android-cts/testcases/*.jar 所有的test module.

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
JAR_DIR=${CTS_ROOT}/android-cts/tools
JARS="tradefed-prebuilt
  hosttestlib
  compatibility-host-util
  cts-tradefed"
 
for JAR in $JARS; do
    checkFile ${JAR_DIR}/${JAR}.jar
    JAR_PATH=${JAR_PATH}:${JAR_DIR}/${JAR}.jar
done
 
OPTIONAL_JARS="
  google-tradefed
  google-tradefed-tests
  google-tf-prod-tests"
 
for JAR in $OPTIONAL_JARS; do
    if [ -f "$JAR.jar" ]; then
        JAR_PATH=${JAR_PATH}:${JAR_DIR}/${JAR}.jar
    fi;
done
 
# load any shared libraries for host-side executables
LIB_DIR=${CTS_ROOT}/android-cts/lib
if [ "$HOST" == "Linux" ]; then
    LD_LIBRARY_PATH=${LIB_DIR}:${LIB_DIR}64:${LD_LIBRARY_PATH}
    export LD_LIBRARY_PATH
elif [ "$HOST" == "Darwin" ]; then
    DYLD_LIBRARY_PATH=${LIB_DIR}:${LIB_DIR}64:${DYLD_LIBRARY_PATH}
    export DYLD_LIBRARY_PATH
fi
 
# include any host-side test jars
for j in ${CTS_ROOT}/android-cts/testcases/*.jar; do
    JAR_PATH=${JAR_PATH}:$j
done

當然最後的最後就是把這些環境變數都代入JAVA machine run啦.

119
java $RDBG_FLAG -cp ${JAR_PATH} -DCTS_ROOT=${CTS_ROOT} com.android.compatibility.common.tradefed.command.CompatibilityConsole "$@"

我們分析完整個腳本後,需要的是確保DOS shell裡面adb, aapt, java
已經是可以直接執行的.所以要修改的是進入腳本時windows PATH環境變數.

其二是要處理兩個放進JAVA執行時的變數CTS_ROOT和JAR_PATH.
CTS_ROOT是去指定當下存放的路徑,然後再把這些JAR file都能疊代進JAR_PATH裡頭.

依據結論,下列即是代換成Windows下可以跑的Batch腳本.
SDK_ROOT指向系統上安裝android-sdk的路徑
CTS_ROOT則填入存放CTS的目錄

@echo off
set SDK_ROOT=%ANDROID_HOME%
set CTS_ROOT=D:\CTS
set "RUN_PATH="
set "JAR_PATH="
set PATH=%PATH%;%SDK_ROOT%\platform-tools\;%SDK_ROOT%\tools\;%SDK_ROOT%\build-tools\25.0.3\
:: set RDBG_FLAG=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y
SETLOCAL ENABLEDELAYEDEXPANSION 
 
:: include \android-cts\tools
for %%f in (%CTS_ROOT%\android-cts\tools\*.jar) do set RUN_PATH=%%f;!RUN_PATH!
 
:: include any host-side test jars
for %%f in (%CTS_ROOT%\android-cts\testcases\*.jar) do set JAR_PATH=%%f;!JAR_PATH!
 
java -Xmx512M -cp %RUN_PATH%%JAR_PATH% -DCTS_ROOT=%CTS_ROOT% com.android.compatibility.common.tradefed.command.CompatibilityConsole

最後放到CTS目錄底下存成cts.bat直接點兩下就可以快樂執行他瞜.

最後的最後
run cts是跑整份testplan這是沒有變的,但是v2的版本取消了class與method的方式指定部分測試.
而是改成由test module的方式如下鍵入module test:

run cts -m Gesture –test android.gesture.cts.GestureTest#testGetStrokes
run cts -m CtsGestureTestCases –test android.gesture.cts.GestureTest#testGetStrokes

如果不知道要測試的module可以用”list m”來查詢.詳細請參閱官網瞜

CTS V2 Console

Refers:

喜熊多的研究室 Run CTS on WIndows

Android CTS Test 環境

http://cloudlife2013.blogspot.tw/2015/04/jrejdk.html

https://discuss.appium.io/t/error-aapt-not-found-when-running-test/7321

Facebook Comments
Scottj Written by:

Be First to Comment

發表迴響