Home | History | Annotate | Download | only in tests
      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.
     17 import sys
     18 import unittest
     19 sys.path.append('../..')
     20 
     21 from testrunner import am_instrument_parser
     22 
     23 
     24 class AmParserTest(unittest.TestCase):
     25 
     26   def testParseAmInstResult(self):
     27     result="""INSTRUMENTATION_RESULT: performance.java_size=4871
     28 INSTRUMENTATION_RESULT: stream=
     29 Error: Failed to generate emma coverage.
     30 INSTRUMENTATION_RESULT: performance.cpu_time=33846
     31 INSTRUMENTATION_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=
     43 INSTRUMENTATION_STATUS: test=testLaunchComplexActivity
     44 INSTRUMENTATION_STATUS: class=LaunchPerformanceTest
     45 INSTRUMENTATION_STATUS: current=1
     46 INSTRUMENTATION_STATUS: numtests=2
     47 INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
     48 INSTRUMENTATION_STATUS_CODE: 1"""
     49     segment2 = """INSTRUMENTATION_STATUS: stream=.
     50 INSTRUMENTATION_STATUS: test=testLaunchComplexActivity
     51 INSTRUMENTATION_STATUS: performance.cpu_time=866
     52 INSTRUMENTATION_STATUS: performance.execution_time=1242
     53 INSTRUMENTATION_STATUS: class=LaunchPerformanceTest
     54 INSTRUMENTATION_STATUS: current=1
     55 INSTRUMENTATION_STATUS: numtests=2
     56 INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
     57 INSTRUMENTATION_STATUS_CODE: 0"""
     58     # numtests after id
     59     segment3 = """INSTRUMENTATION_STATUS: stream=
     60 INSTRUMENTATION_STATUS: test=testLaunchSimpleActivity
     61 INSTRUMENTATION_STATUS: class=LaunchPerformanceTest
     62 INSTRUMENTATION_STATUS: current=2
     63 INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
     64 INSTRUMENTATION_STATUS: numtests=8
     65 INSTRUMENTATION_STATUS_CODE: 1"""
     66     segment4 = """INSTRUMENTATION_STATUS: stream=.
     67 INSTRUMENTATION_STATUS: test=testLaunchSimpleActivity
     68 INSTRUMENTATION_STATUS: performance.cpu_time=590
     69 INSTRUMENTATION_STATUS: performance.execution_time=1122
     70 INSTRUMENTATION_STATUS: class=LaunchPerformanceTest
     71 INSTRUMENTATION_STATUS: current=2
     72 INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
     73 INSTRUMENTATION_STATUS: numtests=8
     74 INSTRUMENTATION_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
    118 INSTRUMENTATION_STATUS: current=1
    119 INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
    120 INSTRUMENTATION_STATUS: numtests=2
    121 INSTRUMENTATION_STATUS: stream=
    122 LaunchPerformanceTestCase:
    123 INSTRUMENTATION_STATUS: test=testLaunchComplexActivity
    124 INSTRUMENTATION_STATUS_CODE: 1
    125 INSTRUMENTATION_STATUS: class=LaunchPerformanceTestCase
    126 INSTRUMENTATION_STATUS: current=1
    127 INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
    128 INSTRUMENTATION_STATUS: numtests=2
    129 INSTRUMENTATION_STATUS: performance.cpu_time=866
    130 INSTRUMENTATION_STATUS: performance.execution_time=1242
    131 INSTRUMENTATION_STATUS: stream=.
    132 INSTRUMENTATION_STATUS: test=testLaunchComplexActivity
    133 INSTRUMENTATION_STATUS_CODE: 0
    134 INSTRUMENTATION_STATUS: class=LaunchPerformanceTestCase
    135 INSTRUMENTATION_STATUS: current=2
    136 INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
    137 INSTRUMENTATION_STATUS: numtests=2
    138 INSTRUMENTATION_STATUS: stream=
    139 INSTRUMENTATION_STATUS: test=testLaunchSimpleActivity
    140 INSTRUMENTATION_STATUS_CODE: 1
    141 INSTRUMENTATION_STATUS: class=LaunchPerformanceTestCase
    142 INSTRUMENTATION_STATUS: current=2
    143 INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
    144 INSTRUMENTATION_STATUS: numtests=2
    145 INSTRUMENTATION_STATUS: performance.cpu_time=590
    146 INSTRUMENTATION_STATUS: performance.execution_time=1122
    147 INSTRUMENTATION_STATUS: stream=.
    148 INSTRUMENTATION_STATUS: test=testLaunchSimpleActivity
    149 INSTRUMENTATION_STATUS_CODE: 0
    150 INSTRUMENTATION_RESULT: performance.cpu_time=829
    151 INSTRUMENTATION_RESULT: performance.execution_time=1708
    152 INSTRUMENTATION_RESULT: performance.gc_invocation_count=0
    153 INSTRUMENTATION_RESULT: performance.global_alloc_count=2848
    154 INSTRUMENTATION_RESULT: performance.global_alloc_size=193079
    155 INSTRUMENTATION_RESULT: performance.global_freed_count=1207
    156 INSTRUMENTATION_RESULT: performance.global_freed_size=93040
    157 INSTRUMENTATION_RESULT: performance.java_allocated=2175
    158 INSTRUMENTATION_RESULT: performance.java_free=580
    159 INSTRUMENTATION_RESULT: performance.java_private_dirty=740
    160 INSTRUMENTATION_RESULT: performance.java_pss=1609
    161 INSTRUMENTATION_RESULT: performance.java_shared_dirty=3860
    162 INSTRUMENTATION_RESULT: performance.java_size=2755
    163 INSTRUMENTATION_RESULT: performance.native_allocated=2585
    164 INSTRUMENTATION_RESULT: performance.native_free=34
    165 INSTRUMENTATION_RESULT: performance.native_private_dirty=632
    166 INSTRUMENTATION_RESULT: performance.native_pss=701
    167 INSTRUMENTATION_RESULT: performance.native_shared_dirty=1164
    168 INSTRUMENTATION_RESULT: performance.native_size=2620
    169 INSTRUMENTATION_RESULT: performance.other_private_dirty=896
    170 INSTRUMENTATION_RESULT: performance.other_pss=1226
    171 INSTRUMENTATION_RESULT: performance.other_shared_dirty=804
    172 INSTRUMENTATION_RESULT: performance.pre_received_transactions=-1
    173 INSTRUMENTATION_RESULT: performance.pre_sent_transactions=-1
    174 INSTRUMENTATION_RESULT: performance.received_transactions=-1
    175 INSTRUMENTATION_RESULT: performance.sent_transactions=-1
    176 INSTRUMENTATION_RESULT: stream=
    177 Test results for InstrumentationTestRunner=..
    178 Time: 2.413
    179 
    180 OK (2 tests)
    181 
    182 
    183 INSTRUMENTATION_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 
    200 if __name__ == "__main__":
    201   unittest.main()
    202