标签:
近期接触到CTS,据传不懂CTS就不算一个合格的android开发者,我之前一直没见周边谁用过。作为一个产品开发的android人员,我还是太年轻~
撰写不易,转载请注明出处:http://blog.csdn.net/jscese/article/details/40650001#t11
Compatibility Test Suite (CTS) 兼容性測试组。是由google提供的一套測试框架。含有非常多測试用例,
框架用于管理測试用例在真机设备或者模拟器上的执行,那些用例全是用java写的apk,通过执行这些apk得到的结果来測试系统平台的兼容性与稳定性.
Compatibility Definition Document (CDD) 一个定义标准,系统须要符合软件以及硬件相关參数.
你能够把測试结果发送给cts@android.com。当你提交了一个CTS报告时。你还能够要求訪问Android Market。
有android源代码的能够直接在源代码下 make cts ,最后会生成 /out/host/linux-x86/cts/android-cts
还能够去 http://source.android.com/compatibility/downloads.html 上面下载google提供的各个版本号的 CTS组件。解压出来android-cts文件夹须要版本号相应!
文件夹结构例如以下:
当中docs为空,
repository文件夹下有plans . testcases
tools 文件夹下就是启动 cts console 的工具包。由 cts-tradefed 脚本启动。当中有个README
网上的配置五花八门。直接看这个简单明了:
Configuring cts-tradefed ------------------------ 1. Ensure 'adb' is in your current PATH. adb can be found in the Android SDK available from http://developer.android.com Example: PATH=$PATH:/home/myuser/android-sdk-linux_x86/platform-tools 2. Follow the 'Setting up your device' steps documented in the CTS User Manual. The CTS User Manual can be downloaded at http://source.android.com/compatibility/downloads.html 3. Connect the device to the host machine. 4. Ensure device is visible via 'adb devices' Using cts-tradefed ------------------- To run a test plan on a single device: 1. Make sure you have at least one device connected 2. Launch the cts-tradefed console by running the 'cts-tradefed' script at android-cts/tools/cts-tradefed 3. Type: 'run cts --plan CTS' to run the default CTS plan Some other useful commands are To run a test package: 'run cts --package <packagename>' To run a test class: 'run cts --class <full test class name>' To shard a plan test run on multiple devices 'run cts --plan CTS --shards <number of shards> note: all connected devices must be running the same build For more options: 'run cts --help' CTS Tradefed Development ------------------------ See http://source.android.com for instructions on obtaining the Android platform source code and setting up a build environment. The source for the CTS extensions for tradefed can be found at <android source root>/cts/tools/tradefed-host The source for the tradefed framework can be found on the 'tradefed' branch. Perform these steps to build and run cts-tradefed from the development environment: cd <path to android source root> make cts cts-tradefed
能够看下cts-tradefed 这个脚本:
checkPath adb checkPath java # check java version JAVA_VERSION=$(java -version 2>&1 | head -n 1 | grep '[ "]1\.6[\. "$$]') if [ "${JAVA_VERSION}" == "" ]; then echo "Wrong java version. 1.6 is required." exit fi
android源代码下的 cts 可能不是最新的。所以最好是去上面提到的google官网去下载相应的 cts 组件!
首先打开TV的adb调试开关。ubuntu通过adb connect TV_IP 连接。android-cts下运行cts-tradefed脚本进入cts控制台:
能够看到在cts-tf下使用 l d 命令查看到了 设备的相关信息.
使用help查看:
能够看到支持的命令集!
当中版本号为4.2_r4,定义在/cts/tools/tradefed-host/src/com/android/cts/tradefed/build/CtsBuildProvider.java 中
使用 l p 查看可測试的计划:
cts-tf > l p CTS-TF CTS VM-TF AppSecurity PDK Java Android Signature
一个plan中包括多个package 。每一次运行 run cts 都会分配一个 Session 号。从 0開始..
l d 显示连接的设备。 l packages 显示可測试的包 , l r 显示记录结果
run cts -p package_name 单独測试package_name包
run cts --continue-session sessionID --disable-reboot
依据sessionID 继续进行測试,不重新启动 。由于重新启动 adb就断掉了!
run cts -c com.class_name -m methmod_name 单独測试某个类的方法 -c 后面跟类名全路径 –m 后面跟方法名
其他命令能够看凝视,不多做解释。
假设须要測试media相关的包,可在google官网下载 CTS Media 1.0 放到sdcard的test文件夹.
另外须要做的准备有:
安装cts測试须要的apk到目标板:CtsDelegatingAccessibilityService.apk,CtsDeviceAdmin.apk
(这两个APK能够在cts源代码文件夹的testcase中找到)
系统setting的配置
(假设项目删除了默认的setting或者深度改动了,能够用google的原生setting替代原有的setting来进行设置)
进入settings打开Wi-Fi并连接AP (AP须要连外网)
进入settings->Security->Screenlock设为None
进入settings->Security->Deviceadministrators->Enable两个选项
进入Language&input->language设为English(UnitedStates)
进入settings->Display->Sleep设为30minutes或None
进入settings->Accessibility->EnableDelegating Accessibility Service
进入settings->Developeroptions->Enable USB debugging、Stay awake、Allowmock locations
手动设置时间,并将时区调为北京。设置国家为china
这样就能够执行 run cts * 进行測试啦!
測试完之后的结果保存在 /android-cts/repository/results/2014.10.31_11.53.42/testResult.xml 中
能够看到结果就四种:[pass/fail/notExecuted/timeout]
假设我们的硬件上并不支持某个功能模块的时候。我们能够在testResult.xml中改动 result="fail" 为 result="notExecuted"
假设是fail的肯定还有这种附加信息:
<Test name="testPlay00" result="fail" starttime="星期五 十月 31 12:01:24 CST 2014" endtime="星期五 十月 31 12:01:26 CST 2014"> <FailedScene message="junit.framework.AssertionFailedError: playback /mnt/sdcard/test/bbb_short/176x144/3gp_h263_libfaac/bbb_short.ffmpeg.176x144.3gp.h263_300kbps_12fps.libfaac_mono_24kbps_11025Hz.3gp at android.mediastress.cts.MediaPlayerStressTest.doTestVideoPlayback(MediaPlayerStressTest.java:161) "> <StackTrace>junit.framework.AssertionFailedError: playback /mnt/sdcard/test/bbb_short/176x144/3gp_h263_libfaac/bbb_short.ffmpeg.176x144.3gp.h263_300kbps_12fps.libfaac_mono_24kbps_11025Hz.3gp at android.mediastress.cts.MediaPlayerStressTest.doTestVideoPlayback(MediaPlayerStressTest.java:161) at android.mediastress.cts.MediaPlayerStressTest.doTestVideoPlaybackShort(MediaPlayerStressTest.java:165) at android.mediastress.cts.H263QcifShortPlayerTest.testPlay00(H263QcifShortPlayerTest.java:49) at java.lang.reflect.Method.invokeNative(Native Method) at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214) at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661) </StackTrace> </FailedScene> </Test>
我们能够在源代码/cts/tests/tests/以下看到全部的testcase
网上的方法。这里借用记录例如以下:
<manifestxmlns:android="http://schemas.android.com/apk/res/android" package="com.android.cts.XXX"> <uses-permissionandroid:name="android.permission.DISABLE_KEYGUARD" /> <application> <uses-libraryandroid:name="android.test.runner" /> </application> <instrumentationandroid:name="android.test.InstrumentationCtsTestRunner" android:targetPackage="com.android.cts.stub" android:label="CTStests of android.XXX"/> </manifest>
>
标签:
原文地址:http://www.cnblogs.com/gcczhongduan/p/5080039.html