• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python2.4
2#
3#
4# Copyright 2009, The Android Open Source Project
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17import sys
18import unittest
19sys.path.append('../..')
20
21from testrunner import am_instrument_parser
22
23
24class AmParserTest(unittest.TestCase):
25
26  def testParseAmInstResult(self):
27    result="""INSTRUMENTATION_RESULT: performance.java_size=4871
28INSTRUMENTATION_RESULT: stream=
29Error: Failed to generate emma coverage.
30INSTRUMENTATION_RESULT: performance.cpu_time=33846
31INSTRUMENTATION_CODE: -1
32"""
33    bundle_dict = \
34        am_instrument_parser._ParseInstrumentationFinishedBundle(result)
35    self.assertEquals(4871, bundle_dict['java_size'])
36    self.assertEquals(33846, bundle_dict['cpu_time'])
37    self.assertEquals("\nError: Failed to generate emma coverage.",
38        bundle_dict['stream'])
39
40  def testParseAmInstStatus(self):
41    # numtests before id
42    segment1 = """INSTRUMENTATION_STATUS: stream=
43INSTRUMENTATION_STATUS: test=testLaunchComplexActivity
44INSTRUMENTATION_STATUS: class=LaunchPerformanceTest
45INSTRUMENTATION_STATUS: current=1
46INSTRUMENTATION_STATUS: numtests=2
47INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
48INSTRUMENTATION_STATUS_CODE: 1"""
49    segment2 = """INSTRUMENTATION_STATUS: stream=.
50INSTRUMENTATION_STATUS: test=testLaunchComplexActivity
51INSTRUMENTATION_STATUS: performance.cpu_time=866
52INSTRUMENTATION_STATUS: performance.execution_time=1242
53INSTRUMENTATION_STATUS: class=LaunchPerformanceTest
54INSTRUMENTATION_STATUS: current=1
55INSTRUMENTATION_STATUS: numtests=2
56INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
57INSTRUMENTATION_STATUS_CODE: 0"""
58    # numtests after id
59    segment3 = """INSTRUMENTATION_STATUS: stream=
60INSTRUMENTATION_STATUS: test=testLaunchSimpleActivity
61INSTRUMENTATION_STATUS: class=LaunchPerformanceTest
62INSTRUMENTATION_STATUS: current=2
63INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
64INSTRUMENTATION_STATUS: numtests=8
65INSTRUMENTATION_STATUS_CODE: 1"""
66    segment4 = """INSTRUMENTATION_STATUS: stream=.
67INSTRUMENTATION_STATUS: test=testLaunchSimpleActivity
68INSTRUMENTATION_STATUS: performance.cpu_time=590
69INSTRUMENTATION_STATUS: performance.execution_time=1122
70INSTRUMENTATION_STATUS: class=LaunchPerformanceTest
71INSTRUMENTATION_STATUS: current=2
72INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
73INSTRUMENTATION_STATUS: numtests=8
74INSTRUMENTATION_STATUS_CODE: 0"""
75
76    result = am_instrument_parser.TestResult(segment1)
77    map = result.GetResultFields()
78    self.assertEquals('testLaunchComplexActivity', map['test'])
79    self.assertEquals('LaunchPerformanceTest', map['class'])
80    self.assertEquals('1', map['current'])
81    self.assertEquals('2', map['numtests'])
82    self.assertEquals('InstrumentationTestRunner', map['id'])
83    self.assertEquals(1, result.GetStatusCode())
84
85    result = am_instrument_parser.TestResult(segment2)
86    map = result.GetResultFields()
87    self.assertEquals('testLaunchComplexActivity', map['test'])
88    self.assertEquals('866', map['cpu_time'])
89    self.assertEquals('1242', map['execution_time'])
90    self.assertEquals('LaunchPerformanceTest', map['class'])
91    self.assertEquals('1', map['current'])
92    self.assertEquals('2', map['numtests'])
93    self.assertEquals('InstrumentationTestRunner', map['id'])
94    self.assertEquals(0, result.GetStatusCode())
95
96    result = am_instrument_parser.TestResult(segment3)
97    map = result.GetResultFields()
98    self.assertEquals('testLaunchSimpleActivity', map['test'])
99    self.assertEquals('LaunchPerformanceTest', map['class'])
100    self.assertEquals('2', map['current'])
101    self.assertEquals('8', map['numtests'])
102    self.assertEquals('InstrumentationTestRunner', map['id'])
103    self.assertEquals(1, result.GetStatusCode())
104
105    result = am_instrument_parser.TestResult(segment4)
106    map = result.GetResultFields()
107    self.assertEquals('testLaunchSimpleActivity', map['test'])
108    self.assertEquals('590', map['cpu_time'])
109    self.assertEquals('1122', map['execution_time'])
110    self.assertEquals('LaunchPerformanceTest', map['class'])
111    self.assertEquals('2', map['current'])
112    self.assertEquals('8', map['numtests'])
113    self.assertEquals('InstrumentationTestRunner', map['id'])
114    self.assertEquals(0, result.GetStatusCode())
115
116  def testParseAmInstOutput(self):
117    result = """INSTRUMENTATION_STATUS: class=LaunchPerformanceTestCase
118INSTRUMENTATION_STATUS: current=1
119INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
120INSTRUMENTATION_STATUS: numtests=2
121INSTRUMENTATION_STATUS: stream=
122LaunchPerformanceTestCase:
123INSTRUMENTATION_STATUS: test=testLaunchComplexActivity
124INSTRUMENTATION_STATUS_CODE: 1
125INSTRUMENTATION_STATUS: class=LaunchPerformanceTestCase
126INSTRUMENTATION_STATUS: current=1
127INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
128INSTRUMENTATION_STATUS: numtests=2
129INSTRUMENTATION_STATUS: performance.cpu_time=866
130INSTRUMENTATION_STATUS: performance.execution_time=1242
131INSTRUMENTATION_STATUS: stream=.
132INSTRUMENTATION_STATUS: test=testLaunchComplexActivity
133INSTRUMENTATION_STATUS_CODE: 0
134INSTRUMENTATION_STATUS: class=LaunchPerformanceTestCase
135INSTRUMENTATION_STATUS: current=2
136INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
137INSTRUMENTATION_STATUS: numtests=2
138INSTRUMENTATION_STATUS: stream=
139INSTRUMENTATION_STATUS: test=testLaunchSimpleActivity
140INSTRUMENTATION_STATUS_CODE: 1
141INSTRUMENTATION_STATUS: class=LaunchPerformanceTestCase
142INSTRUMENTATION_STATUS: current=2
143INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
144INSTRUMENTATION_STATUS: numtests=2
145INSTRUMENTATION_STATUS: performance.cpu_time=590
146INSTRUMENTATION_STATUS: performance.execution_time=1122
147INSTRUMENTATION_STATUS: stream=.
148INSTRUMENTATION_STATUS: test=testLaunchSimpleActivity
149INSTRUMENTATION_STATUS_CODE: 0
150INSTRUMENTATION_RESULT: performance.cpu_time=829
151INSTRUMENTATION_RESULT: performance.execution_time=1708
152INSTRUMENTATION_RESULT: performance.gc_invocation_count=0
153INSTRUMENTATION_RESULT: performance.global_alloc_count=2848
154INSTRUMENTATION_RESULT: performance.global_alloc_size=193079
155INSTRUMENTATION_RESULT: performance.global_freed_count=1207
156INSTRUMENTATION_RESULT: performance.global_freed_size=93040
157INSTRUMENTATION_RESULT: performance.java_allocated=2175
158INSTRUMENTATION_RESULT: performance.java_free=580
159INSTRUMENTATION_RESULT: performance.java_private_dirty=740
160INSTRUMENTATION_RESULT: performance.java_pss=1609
161INSTRUMENTATION_RESULT: performance.java_shared_dirty=3860
162INSTRUMENTATION_RESULT: performance.java_size=2755
163INSTRUMENTATION_RESULT: performance.native_allocated=2585
164INSTRUMENTATION_RESULT: performance.native_free=34
165INSTRUMENTATION_RESULT: performance.native_private_dirty=632
166INSTRUMENTATION_RESULT: performance.native_pss=701
167INSTRUMENTATION_RESULT: performance.native_shared_dirty=1164
168INSTRUMENTATION_RESULT: performance.native_size=2620
169INSTRUMENTATION_RESULT: performance.other_private_dirty=896
170INSTRUMENTATION_RESULT: performance.other_pss=1226
171INSTRUMENTATION_RESULT: performance.other_shared_dirty=804
172INSTRUMENTATION_RESULT: performance.pre_received_transactions=-1
173INSTRUMENTATION_RESULT: performance.pre_sent_transactions=-1
174INSTRUMENTATION_RESULT: performance.received_transactions=-1
175INSTRUMENTATION_RESULT: performance.sent_transactions=-1
176INSTRUMENTATION_RESULT: stream=
177Test results for InstrumentationTestRunner=..
178Time: 2.413
179
180OK (2 tests)
181
182
183INSTRUMENTATION_CODE: -1
184"""
185    (results_list, perf_dict) = \
186        am_instrument_parser.ParseAmInstrumentOutput(result)
187    self.assertEquals(829, perf_dict['cpu_time'])
188    self.assertEquals(2848, perf_dict['global_alloc_count'])
189    self.assertEquals(93040, perf_dict['global_freed_size'])
190    self.assertEquals(740, perf_dict['java_private_dirty'])
191    self.assertEquals(2755, perf_dict['java_size'])
192    self.assertEquals(632, perf_dict['native_private_dirty'])
193    self.assertEquals(2620, perf_dict['native_size'])
194    self.assertEquals(804, perf_dict['other_shared_dirty'])
195    self.assertEquals(-1, perf_dict['received_transactions'])
196    self.assertTrue(len(perf_dict['stream']) > 50)
197    self.assertEquals('-1', perf_dict['code'])
198
199
200if __name__ == "__main__":
201  unittest.main()
202