Merge lp:~liuyq0307/lava-android-test/document2 into lp:lava-android-test
- document2
- Merge into trunk
Proposed by
Yongqin Liu
Status: | Merged |
---|---|
Merged at revision: | 151 |
Proposed branch: | lp:~liuyq0307/lava-android-test/document2 |
Merge into: | lp:lava-android-test |
Diff against target: |
346 lines (+256/-22) 3 files modified
doc/changes.rst (+1/-2) doc/usage.rst (+254/-18) lava_android_test/commands.py (+1/-2) |
To merge this branch: | bzr merge lp:~liuyq0307/lava-android-test/document2 |
Related bugs: | |
Related blueprints: |
Improve LAVA Documentation
(High)
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Andy Doan (community) | Approve | ||
Review via email: mp+104352@code.launchpad.net |
Commit message
Description of the change
Add description about how to integrate a android test into lava
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'doc/changes.rst' |
2 | --- doc/changes.rst 2012-04-26 03:20:30 +0000 |
3 | +++ doc/changes.rst 2012-05-02 09:27:20 +0000 |
4 | @@ -15,8 +15,7 @@ |
5 | =========== |
6 | * new gator test |
7 | * update mmtest script |
8 | -* Bug #962094: error occurred when no parser specified for run-custom |
9 | -command |
10 | +* Bug #962094: error occurred when no parser specified for run-custom command |
11 | * Bug #962096: the test_id generated is longer than 64 |
12 | |
13 | .. _version_0_0.10: |
14 | |
15 | === modified file 'doc/usage.rst' |
16 | --- doc/usage.rst 2012-02-16 10:58:03 +0000 |
17 | +++ doc/usage.rst 2012-05-02 09:27:20 +0000 |
18 | @@ -15,9 +15,9 @@ |
19 | ^^^^^^^^^^^^^^^^ |
20 | |
21 | In standalone mode a human operator installs LAVA Android Test on some device |
22 | -(development board, laptop or other computer or a virtual machine), installs |
23 | -the tests that are to be executed and then executes them manually (by manually |
24 | -running LAVA Android test, the actual tests are non-interactive). |
25 | +(laptop or computer or a virtual machine), installs the tests that are to be |
26 | +executed and then executes them manually (by manually running LAVA Android test, |
27 | +the actual tests are non-interactive). |
28 | |
29 | Using LAVA to develop and run new tests |
30 | +++++++++++++++++++++++++++++++++++++++ |
31 | @@ -45,22 +45,22 @@ |
32 | This part has to be implemented in python (unlike the test program that can be |
33 | implemented in any language and technology). Here the developer is focusing on |
34 | refining the parser to see if the outcome is as indented. Assuming that earlier |
35 | -the developer ran the test at least once and wrote down the result identifier |
36 | -the set of commands one might use is:: |
37 | +the developer ran the test at least once and wrote down the result identifier. |
38 | +The set of commands one might use is:: |
39 | |
40 | - $ lava-android-test parse my-custom-test |
41 | + $ lava-android-test parse result-id |
42 | |
43 | The result id is used to locate leftovers from running that specific test |
44 | at some previous point in time. |
45 | |
46 | By default parse will print the bundle to standard output for inspection. |
47 | -It should be redirected to a pager for easier verification. |
48 | +It should be redirected to a page for easier verification. |
49 | |
50 | .. note:: |
51 | |
52 | - While the syntax of the bundle created with `lava-test parse` is always |
53 | + While the syntax of the bundle created with `lava-android-test parse` is always |
54 | correct (or, if the parser does something really, really strange, a |
55 | - detailed error is reported) the actual contents may not be what you |
56 | + detailed error is reported), the actual contents may not be what you |
57 | intended it to be. Parsers are ultimately fragile as they mostly deal with |
58 | unstructured or semi-structured free-form text that most test programs seem |
59 | to produce. The ultimate goal of a developer should be to produce |
60 | @@ -71,7 +71,7 @@ |
61 | Usage with the dispatcher |
62 | ^^^^^^^^^^^^^^^^^^^^^^^^^ |
63 | |
64 | -The dispatcher is useful for automating LAVA Test environment setup, describing |
65 | +The dispatcher is useful for automating LAVA Android Test environment setup, describing |
66 | test scenarios (the list of tests to invoke) and finally storing the results in |
67 | the LAVA dashboard. |
68 | |
69 | @@ -100,9 +100,9 @@ |
70 | Technically all tests are hidden behind a set of abstract interfaces that tell |
71 | LAVA Android Test what to do in response to operator or dispatcher actions. The primary |
72 | interface is :class:`~lava_android_test.api.ITest` and the three principal |
73 | -methods: :meth:`~lava_android_test.api.ITest`, |
74 | -:meth:`~lava_android_test.api.ITest`, |
75 | -:meth:`~lava_android_test.api.ITest`. |
76 | +methods: :meth:`~lava_android_test.api.ITest.install`, |
77 | +:meth:`~lava_android_test.api.ITest.run`, |
78 | +:meth:`~lava_android_test.api.ITest.parse`. |
79 | |
80 | In practice it is usually much easier to instantiate our pluggable delegate |
81 | test (:class:`lava_android_test.testdef.Test`) and define the three delegates that |
82 | @@ -129,9 +129,245 @@ |
83 | tests need to follow Linaro development work flow, get reviewed and finally |
84 | merged. Depending on your situation this may be undesired. |
85 | |
86 | -.. todo:: |
87 | - |
88 | - Describe how tests are discovered, loaded and used. It would be |
89 | - nice to have a tutorial that walks the user through wrapping a |
90 | - simple pass/fail test. |
91 | +Steps to integrate an Android test to LAVA |
92 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
93 | + |
94 | +1. Checkout the lava-android-test |
95 | + |
96 | +With the following command:: |
97 | + |
98 | + bzr branch lp:lava-android-test |
99 | + |
100 | +2. About wrapper script |
101 | + |
102 | +If the test tools are just command that can be run on android system, |
103 | +and the output is well formatted, then congratulations, you can go |
104 | +directly to step 6. You don't need to wrap script again. |
105 | + |
106 | +3. About test scripts/tools |
107 | + |
108 | +If the test tools has already been build into the android image or |
109 | +in the host image(normal Ubuntu image), then you won't need to define any |
110 | +scripts for organizing the test tools, you can skip this step. |
111 | + |
112 | +Otherwise, put the actual test tools in some place, normally they are |
113 | +in a sub directory of test_definitions, like the busybox test, i.e. |
114 | +the actual test tool is busybox_test.sh, and it is put in the |
115 | +lava_android_test/test_definitions/busybox directory. |
116 | + |
117 | +.. note:: |
118 | + In this case, we should modify the MANIFEST.in file in the root source directory. |
119 | + Otherwise the contents in that directory won’t be installed into the system python library. |
120 | + Like: |
121 | + |
122 | + include lava_android_test/test_definitions/busybox/ |
123 | + |
124 | +4. Add a test wrapper script for your test into the test_definitions directory. |
125 | + |
126 | +The content of the wrapper script should be something like below, |
127 | +Normally, you just need to redefine the red and bold part in the above:: |
128 | + |
129 | + import os |
130 | + import lava_android_test.testdef |
131 | + |
132 | + test_name = 'test_sample' |
133 | + |
134 | + #linux commands that will be run on the host before INSTALL_STEPS_ADB_PRE" |
135 | + INSTALL_STEPS_HOST_PRE = [] |
136 | + #adb commands that will be run before install apk file into android |
137 | + INSTALL_STEPS_ADB_PRE = [] |
138 | + #APK file path list that will be intalled into android |
139 | + APKS= [] |
140 | + #adb commands that will be run before install apk file into android |
141 | + INSTALL_STEPS_ADB_POST = [] |
142 | + #linux commands that will be run on the host after INSTALL_STEPS_ADB_POST |
143 | + INSTALL_STEPS_HOST_POST = [] |
144 | + |
145 | + #linux commands that will be run on the host before RUN_STEPS_ADB_PRE |
146 | + RUN_STEPS_HOST_PRE = [] |
147 | + #adb commands that will be run before install apk file into android |
148 | + RUN_STEPS_ADB_PRE = [] |
149 | + #commands that will be run on android |
150 | + ADB_SHELL_STEPS = [] |
151 | + #adb commands that will be run before install apk file into android |
152 | + RUN_STEPS_ADB_POST = [] |
153 | + #linux commands that will be run on the host after RUN_STEPS_ADB_POST |
154 | + RUN_STEPS_HOST_POST = [] |
155 | + |
156 | + #pattern to parse the command output to generate the test result. |
157 | + PATTERN = "^\s*(?P<test_case_id>\w+)=(?P<result>\w+)\s*$" |
158 | + |
159 | + inst = lava_android_test.testdef.AndroidTestInstaller(steps_host_pre=INSTALL_STEPS_HOST_PRE, |
160 | + steps_adb_pre=INSTALL_STEPS_ADB_PRE, |
161 | + apks=APKS, |
162 | + steps_adb_post=INSTALL_STEPS_ADB_POST, |
163 | + steps_host_post=INSTALL_STEPS_HOST_POST) |
164 | + run = lava_android_test.testdef.AndroidTestRunner(steps_host_pre=RUN_STEPS_HOST_PRE, |
165 | + steps_adb_pre=RUN_STEPS_ADB_PRE, |
166 | + adbshell_steps=ADB_SHELL_STEPS, |
167 | + steps_adb_post=RUN_STEPS_ADB_POST, |
168 | + steps_host_post=RUN_STEPS_HOST_POST) |
169 | + parser = lava_android_test.testdef.AndroidTestParser(PATTERN) |
170 | + testobj = lava_android_test.testdef.AndroidTest(testname=test_name, |
171 | + installer=inst, |
172 | + runner=run, |
173 | + parser=parser) |
174 | + |
175 | + |
176 | +And in the command part, you can use "$(SERIAL)" to represent the device serial number, like:: |
177 | + |
178 | + RUN_STEPS_HOST_POST = [ 'python %s/android-0xbenchmark/android_0xbenchmark_wait.py $(SERIAL)' % curdir] |
179 | + |
180 | +and "$(OPTIONS)" to represent the option string passed from command line, like:: |
181 | + |
182 | + INSTALL_STEPS_HOST_PRE = [ 'echo $(OPTION)'] |
183 | + RUN_STEPS_HOST_PRE = [ 'echo $(OPTION)'] |
184 | + |
185 | +then you can run lava-android-test install -o "install options string" or lava-android-test run -O "run options string" |
186 | + |
187 | +.. note:: |
188 | + |
189 | + Because lava-android-test will be run on lava-lab, and there will be multiple devices connected simultaneously, |
190 | + So we should consider to pass the device serial number for each test tools. |
191 | + If the test tools is defined for steps_adb_pre/adbshell_steps/steps_adb_post, |
192 | + then there is no need to pass the device serial number, lava-android-test will do this for you. |
193 | + |
194 | + |
195 | +5. you can: |
196 | + |
197 | +* use "lava-android-test list-tests" to check if the test wrapper created can be recognized, |
198 | +* use "lava-android-test install ${test_name}" to install the test, |
199 | +* use "lava-android-test run ${test_name}" to execute the test, |
200 | +* use "lava-android-test show ${result_id}" to show the output the test executed, |
201 | +* use "lava-android-test parse ${result_id}" to to generate the result bundle for the test executed. |
202 | + |
203 | +Here is a blog about install/test lava-android-test that you can reference:: |
204 | + |
205 | + http://www.linaro.org/linaro-blog/2011/12/01/local-lava-testing-of-android-ics/ |
206 | + |
207 | +6. Integrate Into Lava |
208 | + |
209 | +When you have done the above steps and verified your test that works well, |
210 | +then you can integrate it in LAVA with the android-build. Here is a description about that:: |
211 | + |
212 | + https://wiki.linaro.org/Platform/Android/AndroidBuild-LavaIntegration |
213 | + |
214 | +7. Add Document |
215 | + |
216 | +At last don’t forget to add an entry and some document in the doc/tests.rst file. Like:: |
217 | + |
218 | + busybox |
219 | + +++++++ |
220 | + .. automodule:: lava_android_test.test_definitions.busybox |
221 | + |
222 | +Then the information will be listed in the below url: |
223 | + http://lava-android-test.readthedocs.org/en/latest/tests.html |
224 | + |
225 | +8. Commit Modification |
226 | + |
227 | +In lava-android-test directory, run the following commands:: |
228 | + |
229 | + bzr launchpad-login ${your-lauchpad-id} |
230 | + bzr commit -m '${commit msg} |
231 | + bzr push lp:~${your-launchpad-id}/lava-android-test/${branch-name} |
232 | + |
233 | +Then you can see your branch in the following page: |
234 | + https://code.launchpad.net/lava-android-test |
235 | + |
236 | +Click your branch, and click the “Propose for merging” link in your branch page to submit a merge proposal. |
237 | +In the proposal page, please set Reviewer: to linaro-validation. |
238 | + |
239 | +Adding Results Parsing |
240 | +++++++++++++++++++++++ |
241 | + |
242 | +Because every test has its own way of displaying results, there is no common, |
243 | +enforced way of interpreting the results from any given test. That means that |
244 | +every test definition also has to define a parser so that LAVA Android Test can |
245 | +understand how to pick out the most useful bits of information from the output. |
246 | +What we've tried to do, is make this as simple as possible for the most common |
247 | +cases, while providing the tools necessary to handle more complex output. |
248 | + |
249 | +To start off, there are some fields you are always going to want to either pull |
250 | +from the results, or define. For all tests: |
251 | + |
252 | +* test_case_id - This is just a field that uniquely identifies the test. |
253 | + This can contain letters, numbers, underscores, dashes, or periods. |
254 | + If you use any illegal characters, they will automatically be dropped |
255 | + by the TestParser base class before parsing the results. Spaces will be |
256 | + automatically converted to underscores. If you wish to change this behaviour, |
257 | + make sure that you either handle fixing the test_case_id in your parser, |
258 | + or override the TestParser.fixids() method. |
259 | +* result - result is simply the result of the test. This applies to both qualitative |
260 | + as well as quantitative tests, and the meaning is specific to the test itself. |
261 | + The valid values for result are: "pass", "fail", "skip", or "unknown". |
262 | + |
263 | +For performance tests, you will also want to have the following two fields: |
264 | + |
265 | +* measurement - the "score" or resulting measurement from the benchmark. |
266 | +* units - a string defining the units represented by the measurement in some way |
267 | + that will be meaningful to someone looking at the results later. |
268 | + |
269 | +For results parsing, it's probably easier to look at some examples. Several |
270 | +tests have already been defined in the lava-android-test test_definitions directory |
271 | +that serve as useful examples. |
272 | + |
273 | +Defining a simple test |
274 | +++++++++++++++++++++++ |
275 | + |
276 | +**Example 1** The tjunittest example might look something like this:: |
277 | + |
278 | + import os |
279 | + import lava_android_test.testdef |
280 | + |
281 | + test_name = 'tjunittest' |
282 | + |
283 | + #linux commands that will be run on the host before INSTALL_STEPS_ADB_PRE" |
284 | + INSTALL_STEPS_HOST_PRE = [] |
285 | + #adb commands that will be run before install apk file into android |
286 | + INSTALL_STEPS_ADB_PRE = [] |
287 | + #APK file path list that will be intalled into android |
288 | + APKS= [] |
289 | + #adb commands that will be run before install apk file into android |
290 | + INSTALL_STEPS_ADB_POST = [] |
291 | + #linux commands that will be run on the host after INSTALL_STEPS_ADB_POST |
292 | + INSTALL_STEPS_HOST_POST = [] |
293 | + |
294 | + #linux commands that will be run on the host before RUN_STEPS_ADB_PRE |
295 | + RUN_STEPS_HOST_PRE = [] |
296 | + #adb commands that will be run before install apk file into android |
297 | + RUN_STEPS_ADB_PRE = [] |
298 | + #commands that will be run on android |
299 | + ADB_SHELL_STEPS = ['tjunittest'] |
300 | + #adb commands that will be run before install apk file into android |
301 | + RUN_STEPS_ADB_POST = [] |
302 | + #linux commands that will be run on the host after RUN_STEPS_ADB_POST |
303 | + RUN_STEPS_HOST_POST = [] |
304 | + |
305 | + #pattern to parse the command output to generate the test result. |
306 | + PATTERN = "^\s*(?P<test_case_id>.+)\s+\.\.\.\s+(?P<result>\w+)\.\s+(?P<measurement>[\d\.]+)\s+(?P<units>\w+)\s*$" |
307 | + |
308 | + inst = lava_android_test.testdef.AndroidTestInstaller(steps_host_pre=INSTALL_STEPS_HOST_PRE, |
309 | + steps_adb_pre=INSTALL_STEPS_ADB_PRE, |
310 | + apks=APKS, |
311 | + steps_adb_post=INSTALL_STEPS_ADB_POST, |
312 | + steps_host_post=INSTALL_STEPS_HOST_POST) |
313 | + run = lava_android_test.testdef.AndroidTestRunner(steps_host_pre=RUN_STEPS_HOST_PRE, |
314 | + steps_adb_pre=RUN_STEPS_ADB_PRE, |
315 | + adbshell_steps=ADB_SHELL_STEPS, |
316 | + steps_adb_post=RUN_STEPS_ADB_POST, |
317 | + steps_host_post=RUN_STEPS_HOST_POST) |
318 | + parser = lava_android_test.testdef.AndroidTestParser(PATTERN) |
319 | + testobj = lava_android_test.testdef.AndroidTest(testname=test_name, |
320 | + installer=inst, |
321 | + runner=run, |
322 | + parser=parser) |
323 | + |
324 | +In this example, we just simply defined the tjunittest command in ADB_SHELL_STEPS variable, |
325 | +and defined the PATTERN variable used by AndroidTestParser. |
326 | + |
327 | +If you were to save this under the test_definitions directory as 'tjunittest.py', |
328 | +then run 'lava-android-test install tjunittest' and 'lava-android-test run tjunittest', |
329 | +you would have a test result with the result id shown to you. |
330 | +And you can also run 'lava-android-test parse ${result_id}' to get the test result in the json format, |
331 | +which you can submit to lava. |
332 | |
333 | |
334 | === modified file 'lava_android_test/commands.py' |
335 | --- lava_android_test/commands.py 2012-04-11 05:58:13 +0000 |
336 | +++ lava_android_test/commands.py 2012-05-02 09:27:20 +0000 |
337 | @@ -324,8 +324,7 @@ |
338 | class run_custom(AndroidCommand): |
339 | """ |
340 | Run the command(s) that specified by the -c option in the command line |
341 | |
342 | - program:: lava-android-test run-custom -c 'command1' -c 'command2' |
343 | - -p 'parse-regex1' |
344 | + program:: lava-android-test run-custom -c 'command1' -c 'command2' -p 'parse-regex1' |
345 | program:: lava-android-test run test-id -s device_serial |
346 | program:: lava-android-test run test-id -s device_serial -o outputfile |
347 | """ |
looks good