Home | History | Annotate | Download | only in harness
      1 # Copyright (C) 2016 The Android Open Source Project
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License");
      4 # you may not use this file except in compliance with the License.
      5 # You may obtain a copy of the License at
      6 #
      7 #      http://www.apache.org/licenses/LICENSE-2.0
      8 #
      9 # Unless required by applicable law or agreed to in writing, software
     10 # distributed under the License is distributed on an "AS IS" BASIS,
     11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
     14 
     15 """
     16 Set of mixins for asserting common RenderScript lldb interactions
     17 That should cut down boilerplate
     18 To use these assertions simply inherit from them along with your
     19 `TestBase`:
     20 
     21     >>> class MyLLDBRenderScriptTest(TestBaseRemote, CoordinateAssertionsMixin):
     22     >>>     pass
     23 
     24 This will give you access to the useful assertion methods related to Coordinates
     25 
     26 NOTE: These are strictly clean mixins for `TestBase`. All classes here should
     27 strictly inherit only from `object`
     28 """
     29 
     30 
     31 class CoordinateAssertionsMixin(object):
     32     def assert_coord_bp_set(
     33             self, breakpoint_expr, x, y=None, z=None, kernel_type='kernel'
     34         ):
     35         '''
     36         Assert that a breakpoint conditional on a given coordinate is confirmed
     37         by the renderscript breakpoint resolver.
     38         This does not assert test the breakpoint is hit, only registered.
     39             breakpoint_expr: the expression (e.g. the name of a function, or a
     40             file and line).
     41             kernel_type: The breakpoint resolver to use:
     42                 (reduction|kernel|scriptgroup)
     43                 default='kernel'
     44             x: x coordinate: required
     45             y, z: optional y, and z coordinates
     46         '''
     47 
     48         y = 0 if z is not None and y is None else y
     49         coord_text = ','.join(map(str, filter(lambda p: p is not None, (x, y, z))))
     50         self.try_command(
     51             'language renderscript %s breakpoint set %s -c %s' % (
     52                 kernel_type, breakpoint_expr, coord_text
     53             ),
     54             [r'Breakpoint(s) created'],
     55             expected_regex=[
     56                 r'Conditional kernel breakpoint on coordinate.+%d,\s*%d,\s*%d' % (
     57                     x or 0, y or 0, z or 0
     58                 )
     59             ]
     60         )
     61 
     62     def assert_coord_stop(
     63             self, soname, func_name, x, y=None, z=None, stopped=True
     64         ):
     65         '''Run lldb commands to check that coordinates match expected values.
     66 
     67         Args:
     68             (x, y, z): The expected coordinates.
     69             soname: The name of the renderscript script module e.g. 'allocs'
     70             for librs.allocs.so
     71             func_name: String that is the name of the kernel function
     72 
     73         Raises:
     74             TestFail: One of the lldb commands did not provide the expected
     75                       output.
     76         '''
     77 
     78         if stopped:
     79             self.try_command(
     80                 'process continue',
     81                 expected_regex=[
     82                     r'resuming',
     83                     r'Process \d+ stopped',
     84                     r'stop reason = breakpoint',
     85                     r'frame #0: (0x[0-9a-fA-F]+ )?librs.%s.so`%s' % (
     86                         soname, func_name)
     87                 ]
     88             )
     89         else:
     90             self.try_command(
     91                 'bt',
     92                 expected_regex=[
     93                     'stop reason = breakpoint',
     94                     'frame #0:',
     95                     'librs.*\.so`%s' % kernel
     96                 ]
     97             )
     98 
     99         self.try_command(
    100             'language renderscript kernel coordinate',
    101             '(%d, %d, %d)' % (x, y or 0, z or 0)
    102         )
    103