1. 程式人生 > >如何debug android cts

如何debug android cts

啟動和關閉ADB服務(adb start-server和adbkill-server)

經作者測試,模擬器在執行一段時間後,adb服務有可能(在Windows程序中可以找到這個服務,該服務用來為模擬器或通過USB資料線連線的真機服務)會出現異常。這時需要重新對adb服務關閉和重啟。當然,重啟Eclipse可能會解決問題,但那比較麻煩。如果想手工關閉adb服務,可以使用如下命令:

1. adb kill-server 

在關閉adb服務後,要使用如下命令啟動adb服務:

1. adb start-server 


連結DLNA網路的命令:

ifconfig eth0 down; ifconfig eth0 hw ether 00:00:00:00:fd:87; ifconfig eth0 up; udhcpc



下面的方法是更適合RD debug CTS issuects執行方式, 這樣解決了一個大問題: 如果用android傳統方式去執行cts的話,必然已經被cts 執行環境佔用了adb,eclipsedebug就無法在另外一臺機器上進行(例如RDPC, eclipse debug也需要adb ),  唯一的方式, 就是把androidsource code搬到cts 執行的ubuntu機器上

,  由於size特別大,非常不便.

 

下面介紹的執行方式, 直接用adb 去模擬 cts環境的執行方式, 唯一的缺點是, 一個test一個test 的執行 但是RD來說,這反而是優點! 方便快捷.

 

這個方法概括一下就是: 在我們的branch 上就有cts sourcecode, 我們可以修改其中某個test case所對應的 apk  source, 之後,build apk,  然後安裝到板子上去run. 如果我們修改的testcase apk,

就是添加了一些message/log之類的, 就立即可以在執行過程中體現出來同時,我們可以利用eclipse/ddms相結合 debug android framework部分, 當然, 由於我們也有apksourcecode, 也可以debug test case apk本身.

 

請參考:

剛做完實驗 , 寫下 SOP 給各位參考…

之後若有 RD 需要, 也可以參考這份….

 

Steps:

1)cmd> cd android/ics-4.x (到 android 目錄)

2)cmd>make cts

 

Q)  如何知道0801cts 版本 ?

A)cmd> catandroid/ics-4.x/tools/tradefed-host/src/com/android/cts/tradefed/build/CtsBuildProvider.java|  grepCTS_BUILD_VERSION

      Result:public static final String CTS_BUILD_VERSION = "4.0.3_r2"; 

 

3)cmd>cd out/host/linux-x86/cts/android-cts/repository/testcases

4)找到需要測試的apk 並copy 到PC端file folder

 Ex: CtsTestStubs.apk, CtsOsTestCases.apk, android.core.tests.runner.apk, CtsMyExampleTestCases.apk

 

5)確定PC 可用adb 連到target

6)

cmd>adbinstall CtsMyExampleTestCases.apk (安裝需要測試的 apk)

cmd>adb install CtsTestStubs.apk (這是google大多原生testapk 需要用到的 stub)

cmd>adbinstall CtsOsTestCases.apk

cmd>adbinstall android.core.tests.runner.apk

7)cmd>adb shell pm list instrumentation   (用來檢視已經安裝的instrumentation, 每個 CTS 用測的 apk 都是用instrumentation)

Result:

Instrumentation:com.android.cts.myexample/android.test.InstrumentationTestRunner (target=com.android.cts.myexample)

8)

整個 package 測試

cmd>adbshell am instrument –w –r com.android.cts.myexample/android.test.InstrumentationTest(執行該 test package)

此時可檢視 failed (如下:Step8 test result example),也可透過 logcat log來看 fail (如下:[test result from logcat])

 

單一class測試

   cmd> adb shellam instrument e classandroid.myexample.cts.MySampleCalculatorTestw rcom.android.cts.myexample/android.test.InstrumentationTestRunner

   cmd> adb shellam instrument e classandroid.os.cts.MyHelloTestw rcom.android.cts.os/android.test.InstrumentationCtsTestRunner

單一function測試

   cmd> adbshell am instrument e classandroid.myexample.cts.MySampleCalculatorTest#testAddw rcom.android.cts.myexample/android.test.InstrumentationTestRunner

 

9) 移除測試用 apk (cmd: adb uninstall<app_name> à <app_name>可從 target 端查詢: ls /data/app )

cmd> adb uninstall com.android.cts.os

cmd> adb uninstall com.android.cts.stub

cmd> adb uninstall com.android.cts.myexample

 

=== [Step8: test result example] ===

INSTRUMENTATION_STATUS:id=InstrumentationTestRunner

INSTRUMENTATION_STATUS: current=1

INSTRUMENTATION_STATUS:class=android.myexample.cts.MySampleCalculatorTest

INSTRUMENTATION_STATUS: stream=

android.myexample.cts.MySampleCalculatorTest:

INSTRUMENTATION_STATUS: numtests=2

INSTRUMENTATION_STATUS: test=testAdd

INSTRUMENTATION_STATUS_CODE: 1

INSTRUMENTATION_STATUS:id=InstrumentationTestRunner

INSTRUMENTATION_STATUS: current=1

INSTRUMENTATION_STATUS:class=android.myexample.cts.MySampleCalculatorTest

INSTRUMENTATION_STATUS: stream=.

INSTRUMENTATION_STATUS: numtests=2

INSTRUMENTATION_STATUS: test=testAdd

INSTRUMENTATION_STATUS_CODE: 0

INSTRUMENTATION_STATUS:id=InstrumentationTestRunner

INSTRUMENTATION_STATUS: current=2

INSTRUMENTATION_STATUS: class=android.myexample.cts.MySampleCalculatorTest

INSTRUMENTATION_STATUS: stream=

INSTRUMENTATION_STATUS: numtests=2

INSTRUMENTATION_STATUS:test=testSubtration

INSTRUMENTATION_STATUS_CODE: 1

INSTRUMENTATION_STATUS:id=InstrumentationTestRunner

INSTRUMENTATION_STATUS: current=2

INSTRUMENTATION_STATUS:class=android.myexample.cts.MySampleCalculatorTest

INSTRUMENTATION_STATUS: stream=

Failure in testSubtration:

junit.framework.AssertionFailedError:expected:<20> but was:<30>

                               atandroid.myexample.cts.MySampleCalculatorTest.testSubtration(MySampleCalculatorTest.java:63)

                               at java.lang.reflect.Method.invokeNative(Native Method)

                               at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)

                               at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)

                               at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:545)

                               at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1551)

 

INSTRUMENTATION_STATUS:numtests=2           

INSTRUMENTATION_STATUS:stack=junit.framework.AssertionFailedError: expected:<20> but was:<30>

                               at android.myexample.cts.MySampleCalculatorTest.testSubtration(MySampleCalculatorTest.java:63)

                               at java.lang.reflect.Method.invokeNative(Native Method)

                               at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)

                               at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)

                               at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:545)

                               at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1551)

 

INSTRUMENTATION_STATUS:test=testSubtration

INSTRUMENTATION_STATUS_CODE: -2

INSTRUMENTATION_RESULT: stream=

Test results forInstrumentationTestRunner=..F

Time: 0.079

 

FAILURES!!!

Tests run: 2,  Failures: 1, Errors: 0

 

INSTRUMENTATION_CODE: -1

 

===[test result from logcat] ====

 

/ethernet(6210): Loading ethernet jni class

D/AndroidRuntime(6210): Calling main entry com.android.commands.am.Am

I/ActivityManager(1143): Force stopping package com.android.cts.myexample uid=10036

I/ActivityManager(1143): Start proc com.android.cts.myexample for added applicationcom.android.cts.myexample: pid=6220 uid=10036 gids={}

I/TestRunner(6220): started: testAdd(android.myexample.cts.MySampleCalculatorTest)

I/TestRunner(6220): finished: testAdd(android.myexample.cts.MySampleCalculatorTest)

I/TestRunner(6220): passed: testAdd(android.myexample.cts.MySampleCalculatorTest)

I/TestRunner(6220): started: testSubtration(android.myexample.cts.MySampleCalculatorTest)

I/TestRunner(6220): failed: testSubtration(android.myexample.cts.MySampleCalculatorTest)

I/TestRunner(6220): ----- begin exception -----

I/TestRunner(6220):

I/TestRunner(6220): junit.framework.AssertionFailedError: expected:<20> butwas:<30>

I/TestRunner(6220):    at junit.framework.Assert.fail(Assert.java:47)

I/TestRunner(6220):    atjunit.framework.Assert.failNotEquals(Assert.java:282)

I/TestRunner(6220):    at junit.framework.Assert.assertEquals(Assert.java:64)

I/TestRunner(6220):    atjunit.framework.Assert.assertEquals(Assert.java:201)

I/TestRunner(6220):    atjunit.framework.Assert.assertEquals(Assert.java:207)

I/TestRunner(6220):    at android.myexample.cts.MySampleCalculatorTest.testSubtration(MySampleCalculatorTest.java:63)

I/TestRunner(6220):    at java.lang.reflect.Method.invokeNative(NativeMethod)

I/TestRunner(6220):    at java.lang.reflect.Method.invoke(Method.java:511)

I/TestRunner(6220):    at junit.framework.TestCase.runTest(TestCase.java:154)

I/TestRunner(6220):    at junit.framework.TestCase.runBare(TestCase.java:127)

I/TestRunner(6220):    atjunit.framework.TestResult$1.protect(TestResult.java:106)

I/TestRunner(6220):    at junit.framework.TestResult.runProtected(TestResult.java:124)

I/TestRunner(6220):    at junit.framework.TestResult.run(TestResult.java:109)

I/TestRunner(6220):    at junit.framework.TestCase.run(TestCase.java:118)

I/TestRunner(6220):    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)

I/TestRunner(6220):    atandroid.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)

I/TestRunner(6220):    atandroid.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:545)

I/TestRunner(6220):    atandroid.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1551)

I/TestRunner(6220): ----- end exception -----

I/TestRunner(6220): finished: testSubtration(android.myexample.cts.MySampleCalculatorTest)

I/ActivityManager(1143): Force stopping package com.android.cts.myexample uid=10036

I/ActivityManager(1143): Killing proc 6220:com.android.cts.myexample/10036: force stop

D/AndroidRuntime(6210): Shutting down VM