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'''Module that contains the test TestCoordinates.''' 16 17from __future__ import absolute_import 18 19from harness.test_base_remote import TestBaseRemote 20from harness.decorators import ( 21 ordered_test, 22 cpp_only_test 23) 24 25 26class TestCoordinates(TestBaseRemote): 27 '''Tests the inspection of coordinates. 28 29 Tests the inspection of the range and dimension of coordinates as well 30 as the current coordinates.''' 31 32 bundle_target = { 33 'java': 'JavaDebugWaitAttach', 34 'jni': 'JNIDebugWaitAttach', 35 'cpp': 'CppDebugWaitAttach' 36 } 37 38 def setup(self, android): 39 '''This test requires to be run on one thread. 40 41 Args: 42 android: The android_util module. 43 ''' 44 android.push_prop('debug.rs.max-threads', 1) 45 46 def teardown(self, android): 47 '''Reset the number of RS threads to the previous value. 48 49 Args: 50 android: The android_util module. 51 ''' 52 android.pop_prop('debug.rs.max-threads') 53 54 @ordered_test(0) 55 def test_inspect_coordinates(self): 56 # pylint: disable=line-too-long 57 self.try_command('language renderscript status', 58 ['Runtime Library discovered', 59 'Runtime Driver discovered']) 60 61 self.try_command('language renderscript kernel breakpoint set simple_kernel', 62 ['Breakpoint(s) created', 63 '(pending)']) 64 65 # Check the initial conditions. 66 self._lldb_continue() 67 self._inspect_coordinates(0, 0, 0) 68 69 # Check two more steps. 70 self._lldb_continue() 71 self._inspect_coordinates(1, 0, 0) 72 self._lldb_continue() 73 self._inspect_coordinates(2, 0, 0) 74 75 # After eight more steps we should have advanced one step in the y dimension. 76 for _ in range(8): 77 self._lldb_continue() 78 self._inspect_coordinates(2, 1, 0) 79 80 @ordered_test('last') 81 @cpp_only_test() 82 def test_cpp_cleanup(self): 83 self.try_command('breakpoint delete 1', ['1 breakpoints deleted']) 84 85 self.try_command('process continue', 86 ['exited with status = 0']) 87 88 def _lldb_continue(self): 89 '''Try 'continue' lldb command. Expect to hit a breakpoint.''' 90 self.try_command('process continue', 91 ['resuming', 92 'stopped', 93 'stop reason = breakpoint']) 94 95 def _inspect_coordinates(self, x_coord, y_coord, z_coord): 96 '''Run lldb commands to inspect kernel size and coordinates 97 and match against expected values. 98 99 Args: 100 (x_coord, y_coord, z_coord): The expected coordinates (int triple) 101 102 Raises: 103 TestFail: One of the lldb commands did not provide the expected 104 output. 105 ''' 106 self.try_command('language renderscript kernel coordinate', 107 ['Coordinate: (%d, %d, %d)' 108 % (x_coord, y_coord, z_coord)]) 109 110 self.try_command('frame select 1', 111 ['librs.simple.so`simple_kernel.expand', 112 'at generated.rs:1']) 113 114 # Inspect the invocation length, should be the same every time. 115 self.try_command('expr p->dim', 116 ['x = 8', 117 'y = 8', 118 'z = 0']) 119 120 # The X coordinate is in the rsIndex variable. 121 self.try_command('expr rsIndex', 122 ['= ' + str(x_coord)]) 123 124 # Inspect the Y and Z coordinates. 125 self.try_command('expr p->current', 126 ['x = ' + str(0), 127 'y = ' + str(y_coord), 128 'z = ' + str(z_coord)]) 129