diff options
Diffstat (limited to 'en/devices/tech/test_infra/tradefed')
4 files changed, 142 insertions, 81 deletions
diff --git a/en/devices/tech/test_infra/tradefed/full_example.html b/en/devices/tech/test_infra/tradefed/full_example.html index c8f44f93..f2bbb704 100644 --- a/en/devices/tech/test_infra/tradefed/full_example.html +++ b/en/devices/tech/test_infra/tradefed/full_example.html @@ -58,7 +58,8 @@ your modules against that JAR.</p> tradefed test generally implements the <a href="/reference/com/android/tradefed/testtype/IRemoteTest.html">IRemoteTest</a> interface. Here's an implementation for the HelloWorldTest:</p> -<pre><code>package com.android.tradefed.example; +<pre class="prettyprint"> +package com.android.tradefed.example; import com.android.tradefed.device.DeviceNotAvailableException; import com.android.tradefed.result.ITestInvocationListener; @@ -70,12 +71,14 @@ public class HelloWorldTest implements IRemoteTest { System.out.println("Hello, TF World!"); } } -</code></pre> +</pre> <p>Save this sample code to <code><tree>/tools/tradefederation/core/prod-tests/src/com/android/tradefed/example/HelloWorldTest.java</code> and rebuild tradefed from your shell:</p> -<pre><code>m -jN</code></pre> +<pre class="devsite-terminal devsite-click-to-copy"> +m -jN +</pre> <p>Note that <code>System.out</code> in the example above may not actually direct output to the console. While this is acceptable for this test example, @@ -94,9 +97,10 @@ order.</p> <p>Lets create a new Configuration for our HelloWorldTest (note the full class name of the HelloWorldTest):</p> -<pre><code><configuration description="Runs the hello world test"> +<pre class="prettyprint"> +<configuration description="Runs the hello world test"> <test class="com.android.tradefed.example.HelloWorldTest" /> -</configuration></code></pre> +</configuration></pre> <p>Save this data to a <code>helloworld.xml</code> file anywhere on your local filesystem (e.g. <code>/tmp/helloworld.xml</code>). TF will parse the @@ -106,21 +110,24 @@ reflection, instantiate it, cast it to a <code>IRemoteTest</code>, and call its <h2 id="runconfig">Running the config (R)</h2> <p>From your shell, launch the tradefed console:</p> -<pre><code>$ tradefed.sh -</code></pre> +<pre class="devsite-terminal devsite-click-to-copy"> +tradefed.sh +</pre> <p>Ensure a device is connected to the host machine and is visible to tradefed:</p> -<pre><code>tf >list devices +<pre class="devsite-click-to-copy"> +tf> list devices Serial State Product Variant Build Battery 004ad9880810a548 Available mako mako JDQ39 100 -</code></pre> +</pre> <p>Configurations can be executed using the <code>run <config></code> console command. Try:</p> -<pre><code>tf> run /tmp/helloworld.xml +<pre class="devsite-click-to-copy"> +tf> run /tmp/helloworld.xml 05-12 13:19:36 I/TestInvocation: Starting invocation for target stub on build 0 on device 004ad9880810a548 Hello, TF World! -</code></pre> +</pre> <p>You should see "Hello, TF World!" output on the terminal.</p> <h2 id="addconfig">Adding the config to the Classpath (D, I, R)</h2> @@ -133,13 +140,15 @@ core library (<code><tree>/tools/tradefederation/core/prod-tests/res/config/example/helloworld.xml</code>). Rebuild tradefed, restart the tradefed console, then ask tradefed to display the list of configurations from the classpath:</p> -<pre><code>tf> list configs +<pre class="devsite-click-to-copy"> +tf> list configs […] example/helloworld: Runs the hello world test -</code></pre> +</pre> <p>You can now run the helloworld config using:</p> -<pre><code>tf >run example/helloworld +<pre class="devsite-click-to-copy"> +tf> run example/helloworld 05-12 13:21:21 I/TestInvocation: Starting invocation for target stub on build 0 on device 004ad9880810a548 Hello, TF World! </code></pre> @@ -152,7 +161,8 @@ to the test.</p> <p>Tests can get a reference to an Android device by implementing the <a href="/reference/com/android/tradefed/testtype/IDeviceTest.html">IDeviceTest</a> interface. Here's a sample implementation of what this looks like:</p> -<pre><code>public class HelloWorldTest implements IRemoteTest, IDeviceTest { +<pre class="prettyprint"> +public class HelloWorldTest implements IRemoteTest, IDeviceTest { private ITestDevice mDevice; @Override public void setDevice(ITestDevice device) { @@ -165,7 +175,7 @@ interface. Here's a sample implementation of what this looks like:</p> } … } -</code></pre> +</pre> <p>The Trade Federation framework will inject the <code>ITestDevice</code> reference into your test via the <code>IDeviceTest#setDevice</code> method, @@ -173,25 +183,30 @@ before the <code>IRemoteTest#run</code> method is called.</p> <p>Let's modify the HelloWorldTest print message to display the serial number of the device:</p> -<pre><code>@Override +<pre class="prettyprint"> +@Override public void run(ITestInvocationListener listener) throws DeviceNotAvailableException { System.out.println("Hello, TF World! I have device " + getDevice().getSerialNumber()); } -</code></pre> +</pre> <p>Now rebuild tradefed and check the list of devices:</p> -<pre><code>$ tradefed.sh -tf >list devices +<pre class="devsite-terminal devsite-click-to-copy"> +tradefed.sh +</pre> +<pre class="devsite-click-to-copy"> +tf> list devices Serial State Product Variant Build Battery 004ad9880810a548 Available mako mako JDQ39 100 -</code></pre> +</pre> <p>Take note of the serial number listed as <strong>Available</strong>; that is the device that should be allocated to HelloWorld:</p> -<pre><code>tf >run example/helloworld +<pre class="devsite-click-to-copy"> +tf> run example/helloworld 05-12 13:26:18 I/TestInvocation: Starting invocation for target stub on build 0 on device 004ad9880810a548 Hello, TF World! I have device 004ad9880810a548 -</code></pre> +</pre> <p>You should see the new print message displaying the serial number of the device.</p> @@ -213,7 +228,8 @@ the start and end of each test, and the end of the test run.</p> <p>Here's what the HelloWorldTest implementation might look like with a single failed test result.</p> -<pre><code>@Override +<pre class="prettyprint"> +@Override public void run(ITestInvocationListener listener) throws DeviceNotAvailableException { System.out.println("Hello, TF World! I have device " + getDevice().getSerialNumber()); @@ -223,7 +239,8 @@ public void run(ITestInvocationListener listener) throws DeviceNotAvailableExcep listener.testFailed(testId, "oh noes, test failed"); listener.testEnded(testId, Collections.emptyMap()); listener.testRunEnded(0, Collections.emptyMap()); -}</code></pre> +} +</pre> <p>TF includes several <code>IRemoteTest</code> implementations you can reuse instead of writing your own from scratch. For example, @@ -239,15 +256,18 @@ Types</a>.</p> <a href="/reference/com/android/tradefed/result/TextResultReporter.html">TextResultReporter</a>, which dumps the results of an invocation to stdout. To illustrate, run the HelloWorldTest config from the previous section:</p> -<pre><code>$ ./tradefed.sh -tf >run example/helloworld +<pre class="devsite-terminal devsite-click-to-copy"> +./tradefed.sh +</pre> +<pre class="devsite-click-to-copy"> +tf> run example/helloworld 05-16 20:03:15 I/TestInvocation: Starting invocation for target stub on build 0 on device 004ad9880810a548 Hello, TF World! I have device 004ad9880810a548 05-16 20:03:15 I/InvocationToJUnitResultForwarder: run helloworldrun started: 1 tests Test FAILURE: com.example.TestClassName#sampleTest stack: oh noes, test failed 05-16 20:03:15 I/InvocationToJUnitResultForwarder: run ended 0 ms -</code></pre> +</pre> <p>To store the results of an invocation elsewhere, such as in a file, specify a custom <code>ITestInvocationListener</code> implementation using the @@ -259,14 +279,16 @@ listener, which writes test results to an XML file in a format similar to that used by the <em>ant</em> JUnit XML writer. To specify the result_reporter in the configuration, edit the <code>…/res/config/example/helloworld.xml</code> config:</p> -<pre><code><configuration description="Runs the hello world test"> +<pre class="prettyprint"> +<configuration description="Runs the hello world test"> <test class="com.android.tradefed.example.HelloWorldTest" /> <result_reporter class="com.android.tradefed.result.XmlResultReporter" /> </configuration> -</code></pre> +</pre> <p>Now rebuild tradefed and re-run the hello world sample:</p> -<pre><code>tf >run example/helloworld +<pre class="devsite-click-to-copy"> +tf> run example/helloworld 05-16 21:07:07 I/TestInvocation: Starting invocation for target stub on build 0 on device 004ad9880810a548 Hello, TF World! I have device 004ad9880810a548 05-16 21:07:07 I/XmlResultReporter: Saved device_logcat log to /tmp/0/inv_2991649128735283633/device_logcat_6999997036887173857.txt @@ -276,7 +298,8 @@ Hello, TF World! I have device 004ad9880810a548 <p>Notice the log message stating that an XML file has been generated; the generated file should look like this:</p> -<pre><code><?xml version='1.0' encoding='UTF-8' ?> +<pre class="prettyprint"> +<?xml version='1.0' encoding='UTF-8' ?> <testsuite name="stub" tests="1" failures="1" errors="0" time="9" timestamp="2011-05-17T04:07:07" hostname="localhost"> <properties /> <testcase name="sampleTest" classname="com.example.TestClassName" time="0"> @@ -284,7 +307,7 @@ generated file should look like this:</p> </failure> </testcase> </testsuite> -</code></pre> +</pre> <p>You can also write your own custom invocation listeners—they simply need to implement the @@ -313,19 +336,21 @@ and sends it to the invocation listener for processing. for the ddmlib Log class. Let's convert the previous <code>System.out.println</code> call in HelloWorldTest to a <code>CLog</code> call:</p> -<pre><code>@Override +<pre class="prettyprint"> +@Override public void run(ITestInvocationListener listener) throws DeviceNotAvailableException { CLog.i("Hello, TF World! I have device %s", getDevice().getSerialNumber()); -</code></pre> +</pre> <p><code>CLog</code> handles string interpolation directly, similar to <code>String.format</code>. When you rebuild and rerun TF, you should see the log message on stdout:</p> -<pre><code>tf> run example/helloworld +<pre class="devsite-click-to-copy"> +tf> run example/helloworld … 05-16 21:30:46 I/HelloWorldTest: Hello, TF World! I have device 004ad9880810a548 … -</code></pre> +</pre> <p>By default, tradefed <a href"/reference/com/android/tradefed/log/StdoutLogger.html">outputs host log @@ -334,7 +359,8 @@ messages to a file: <a href="/reference/com/android/tradefed/log/FileLogger.html">FileLogger</a>. To add file logging, add a <code>logger</code> tag to the config, specifying the full class name of <code>FileLogger</code>:</p> -<pre><code><configuration description="Runs the hello world test"> +<pre class="prettyprint"> +<configuration description="Runs the hello world test"> <test class="com.android.tradefed.example.HelloWorldTest" /> <result_reporter class="com.android.tradefed.result.XmlResultReporter" /> <logger class="com.android.tradefed.log.FileLogger" /> @@ -342,7 +368,8 @@ full class name of <code>FileLogger</code>:</p> </code></pre> <p>Now, rebuild and run the helloworld example again:</p> -<pre><code>tf >run example/helloworld +<pre class="devsite-click-to-copy"> +tf >run example/helloworld … 05-16 21:38:21 I/XmlResultReporter: Saved device_logcat log to /tmp/0/inv_6390011618174565918/device_logcat_1302097394309452308.txt 05-16 21:38:21 I/XmlResultReporter: Saved host_log log to /tmp/0/inv_6390011618174565918/host_log_4255420317120216614.txt @@ -350,10 +377,13 @@ full class name of <code>FileLogger</code>:</p> </code></pre> <p>The log message indicates the path of the host log, which, when viewed, should contain your HelloWorldTest log message:</p> -<pre><code>$ more /tmp/0/inv_6390011618174565918/host_log_4255420317120216614.txt +<pre class="devsite-terminal devsite-click-to-copy"> +more /tmp/0/inv_6390011618174565918/host_log_4255420317120216614.txt</pre> +<p>Example output:</p> +<pre class="devsite-click-to-copy"> … 05-16 21:38:21 I/HelloWorldTest: Hello, TF World! I have device 004ad9880810a548 -</code></pre> +</pre> <h2 id="optionhandling">Handling options (D, I, R)</h2> <p>Objects loaded from a TF Configuration (aka <b>Configuration objects</b>) @@ -371,41 +401,46 @@ description of supported types, see </p> <p>Let's add an <code>@Option</code> to HelloWorldTest:</p> -<pre><code>@Option(name="my_option", +<pre class="prettyprint"> +@Option(name="my_option", shortName='m', description="this is the option's help text", // always display this option in the default help text importance=Importance.ALWAYS) private String mMyOption = "thisisthedefault"; -</code></pre> +</pre> <p>Next, let's add a log message to display the value of the option in HelloWorldTest so we can demonstrate it was received correctly:</p> -<pre><code>@Override +<pre class="prettyprint"> +@Override public void run(ITestInvocationListener listener) throws DeviceNotAvailableException { … CLog.logAndDisplay(LogLevel.INFO, "I received option '%s'", mMyOption); -</code></pre> +</pre> <p>Finally, rebuild TF and run helloworld; you should see a log message with the <code>my_option</code> default value:</p> -<pre><code>tf> run example/helloworld +<pre class="devsite-click-to-copy"> +tf> run example/helloworld … 05-24 18:30:05 I/HelloWorldTest: I received option 'thisisthedefault' -</code></pre> +</pre> <h3 id="passclivalues">Passing values from the command line</h3> <p>Pass in a value for <code>my_option</code>; you should see <code>my_option</code> populated with that value:</p> -<pre><code>tf> run example/helloworld --my_option foo +<pre class="devsite-click-to-copy"> +tf> run example/helloworld --my_option foo … 05-24 18:33:44 I/HelloWorldTest: I received option 'foo' -</code></pre> +</pre> <p>TF configurations also include a help system, which automatically displays help text for <code>@Option</code> fields. Try it now, and you should see the help text for <code>my_option</code>:</p> -<pre><code>tf> run example/helloworld --help +<pre class="devsite-click-to-copy"> +tf> run example/helloworld --help Printing help for only the important options. To see help for all options, use the --help-all flag cmd_options options: @@ -432,21 +467,24 @@ all <code>@Option</code> fields, regardless of importance. For details, see <p>You can also specify an Option value within the config by adding a <code><option name="" value=""></code> element. Test it using <code>helloworld.xml</code>:</p> -<pre><code><test class="com.android.tradefed.example.HelloWorldTest" > +<pre class="prettyprint"> +<test class="com.android.tradefed.example.HelloWorldTest" > <option name="my_option" value="fromxml" /> </test> -</code></pre> +</pre> <p>Re-building and running helloworld should now produce this output:</p> -<pre><code>05-24 20:38:25 I/HelloWorldTest: I received option 'fromxml' -</code></pre> +<pre class="devsite-click-to-copy"> +05-24 20:38:25 I/HelloWorldTest: I received option 'fromxml' +</pre> <p>The configuration help should also update to indicate the default value of <code>my_option</code>:</p> -<pre><code>tf> run example/helloworld --help +<pre class="devsite-click-to-copy"> +tf> run example/helloworld --help test options: -m, --my_option this is the option's help text Default: fromxml. -</code></pre> +</pre> <p>Other configuration objects included in the helloworld config, such as <code>FileLogger</code>, also accept options. The option @@ -458,7 +496,8 @@ logging to stdout by passing in the <code>--log-level-display</code> arg.</p> <p>Try this now, and you should see the 'I have device' log message reappear on stdout, in addition to being logged to a file:</p> -<pre><code>tf >run example/helloworld --log-level-display info +<pre class="devsite-click-to-copy"> +tf> run example/helloworld --log-level-display info … 05-24 18:53:50 I/HelloWorldTest: Hello, TF World! I have device 004ad9880810a548 </code></pre> diff --git a/en/devices/tech/test_infra/tradefed/fundamentals/machine_setup.html b/en/devices/tech/test_infra/tradefed/fundamentals/machine_setup.html index 71dcf5c9..47b99bde 100644 --- a/en/devices/tech/test_infra/tradefed/fundamentals/machine_setup.html +++ b/en/devices/tech/test_infra/tradefed/fundamentals/machine_setup.html @@ -33,7 +33,7 @@ <p> From the root directory of the Android source tree: </p> -<pre> +<pre class="devsite-click-to-copy"> <code class="devsite-terminal">source ./build/make/envsetup.sh</code> <code class="devsite-terminal">lunch <device-target></code> <code class="devsite-terminal">make tradefed-all -j8</code> @@ -44,7 +44,7 @@ <p> TradeFed requires the <code>adb</code> utility in your <code>$PATH</code>: </p> -<pre class="devsite-terminal"> +<pre class="devsite-terminal devsite-click-to-copy"> export PATH=$PATH:<path/to/adb> </pre> @@ -52,7 +52,7 @@ export PATH=$PATH:<path/to/adb> Once TradeFed is built, the <code>tradefed.sh</code> launcher script is accessible from your path. To launch the Trade Federation console: </p> -<pre class="devsite-terminal"> +<pre class="devsite-terminal devsite-click-to-copy"> tradefed.sh </pre> <p> diff --git a/en/devices/tech/test_infra/tradefed/fundamentals/options.html b/en/devices/tech/test_infra/tradefed/fundamentals/options.html index fc494f34..bb891b79 100644 --- a/en/devices/tech/test_infra/tradefed/fundamentals/options.html +++ b/en/devices/tech/test_infra/tradefed/fundamentals/options.html @@ -46,7 +46,8 @@ the TF console when the command is run with <code>--help</code> or <code>--help- <p>As an example, let's say we want to build a functional phone test which will dial a variety of phone numbers, and will expect to receive a sequence of DTMF tones from each number after it connects.</p> -<code><pre>public class PhoneCallFuncTest extends IRemoteTest { +<pre class="prettyprint"> +public class PhoneCallFuncTest extends IRemoteTest { @Option(name = "timeout", description = "How long to wait for connection, in millis") private long mWaitTime = 30 * 1000; // 30 seconds @@ -56,7 +57,8 @@ connects.</p> public PhoneCallFuncTest() { mCalls.add("123-456-7890", "01134"); // default - }</pre></code> + } +</pre> <p>That's all that's required for the Developer to set up two points of configuration for that test. They could then go off and use <code>mWaitTime</code> and <code>mCalls</code> as normal, @@ -73,21 +75,24 @@ suppose the Integrator wanted to define a lower-latency test that calls the defa as a long-running test that calls a variety of numbers. They could create a pair of configurations that might look like the following:</p> -<code><pre><?xml version="1.0" encoding="utf-8"?> +<pre class="prettyprint"> +<?xml version="1.0" encoding="utf-8"?> <configuration description="low-latency default test; low-latency.xml"> <test class="com.example.PhoneCallFuncTest"> <option name="timeout" value="5000" /> </test> -</configuration></pre></code> +</configuration></pre> -<code><pre><?xml version="1.0" encoding="utf-8"?> +<pre class="prettyprint"> +<?xml version="1.0" encoding="utf-8"?> <configuration description="call a bunch of numbers; many-numbers.xml"> <test class="com.example.PhoneCallFuncTest"> <option name="call" key="111-111-1111" value="#*#*TEST1*#*#" /> <option name="call" key="222-222-2222" value="#*#*TEST2*#*#" /> <!-- ... --> </test> -</configuration></pre></code> +</configuration> +</pre> <h2 id="testrunner">Test Runner</h2> <p>The Test Runner also has access to these configuration points via the Trade Federation console. @@ -98,11 +103,14 @@ append to fields specified by Lifecycle Objects within each config.</p> <p>To run the low-latency test with the <code>many-numbers</code> phone numbers, the Test Runner could execute:</p> -<code><pre>tf >run low-latency.xml --call 111-111-1111 #*#*TEST1*#*# --call 222-222-2222 #*#*TEST2*#*#</pre></code> +<pre class="devsite-click-to-copy"> +tf> run low-latency.xml --call 111-111-1111 #*#*TEST1*#*# --call 222-222-2222 #*#*TEST2*#*# +</pre> <p>Or, to get a similar effect from the opposite direction, the Test Runner could reduce the wait time for the <code>many-numbers</code> test:</p> -<code><pre>tf >run many-numbers.xml --timeout 5000</code></pre> +<pre class="devsite-click-to-copy"> +tf> run many-numbers.xml --timeout 5000</pre> </body> </html> diff --git a/en/devices/tech/test_infra/tradefed/fundamentals/vts.html b/en/devices/tech/test_infra/tradefed/fundamentals/vts.html index 473db22f..8ba912d8 100644 --- a/en/devices/tech/test_infra/tradefed/fundamentals/vts.html +++ b/en/devices/tech/test_infra/tradefed/fundamentals/vts.html @@ -31,27 +31,41 @@ then test a patch using a VTS plan.</p> <p>To set up a testing environment:</p> <ol> <li>Install Python development kit: -<pre><code>$ sudo apt-get install python-dev</code></pre></li> +<pre class="devsite-terminal devsite-click-to-copy"> +sudo apt-get install python-dev +</pre> +</li> <li>Install Protocol Buffer tools (for Python): -<pre><code>$ sudo apt-get install python-protobuf<br> -$ sudo apt-get install protobuf-compiler -</code></pre></li> +<pre class="devsite-click-to-copy"> +<code class="devsite-terminal">sudo apt-get install python-protobuf</code> +<code class="devsite-terminal">sudo apt-get install protobuf-compiler</code> +</pre> +</li> <li>Install Python virtual environment-related tools: -<pre><code>$ sudo apt-get install python-virtualenv<br> -$ sudo apt-get install python-pip -</code></pre></li></ol> +<pre class="devsite-click-to-copy"> +<code class="devsite-terminal">sudo apt-get install python-virtualenv</code> +<code class="devsite-terminal">sudo apt-get install python-pip</code> +</pre> +</li> +</ol> <h2 id="test">Testing a patch</h2> <p>To test a patch:</p> <ol> <li>Build a VTS host-side package: -<pre><code>$ . build/envsetup.sh -$ lunch aosp_arm64-userdebug -$ make vts -j</code></pre></li> +<pre class="devsite-click-to-copy"> +<code class="devsite-terminal">. build/envsetup.sh</code> +<code class="devsite-terminal">lunch aosp_arm64-userdebug</code> +<code class="devsite-terminal">make vts -j</code> +</pre> +</li> <li>Run the default VTS tests: -<pre><code>$ vts-tradefed<br> -> run vts // where vts is the test plan name -</pre></code></li></ol> +<pre class="devsite-click-to-copy"> +<code class="devsite-terminal">vts-tradefed</code> +tf> run vts // where vts is the test plan name +</pre> +</li> +</ol> <h2 id="plans">VTS plans</h2> <p>Available VTS test plans include:</p> |