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 TestReadLocal.''' 16 17from __future__ import absolute_import 18 19from harness.test_base_remote import TestBaseRemote 20from harness.decorators import ( 21 wimpy, 22 ordered_test, 23 skip_conditional, 24 cpp_only_test 25) 26 27 28class TestReadLocal(TestBaseRemote): 29 '''Tests inspecting local variables of all types.''' 30 31 bundle_target = { 32 'java': 'KernelVariables', 33 'jni': 'JNIKernelVariables', 34 'cpp': 'CppKernelVariables' 35 } 36 37 def _try_inspecting_local(self, local_name, expected_output, 38 expected_regex=None): 39 '''Inspect a local and check for the output. 40 41 Run the "expr" and "frame variable" commands on a given local and 42 with a given output. (The commands should be equivalent.) 43 44 Args: 45 local_name: String which is the name of the global to inspect. 46 expected_output: List of strings that should be found in the output. 47 expected_regex: List of regular expressions that should match lldb's 48 output. 49 50 Raises: 51 TestFail: One of the lldb commands did not provide the expected 52 output. 53 ''' 54 self.try_command('expr ' + local_name, 55 expected_output, 56 expected_regex) 57 58 self.try_command('frame variable ' + local_name, 59 expected_output, 60 expected_regex) 61 62 @wimpy 63 @ordered_test(0) 64 def test_setup(self): 65 self.try_command('language renderscript status', 66 ['Runtime Library discovered', 67 'Runtime Driver discovered']) 68 69 self.try_command('breakpoint set --file simple.rs --line 145', []) 70 71 self.try_command('process continue', 72 ['resuming', 73 'stopped', 74 'stop reason = breakpoint']) 75 76 @wimpy 77 def test_list_rs_kernel_frame_variables(self): 78 # pylint: disable=line-too-long 79 80 self.try_command('frame variable', 81 ["(uchar) uchar_local = 'b'", 82 '(short) short_local = -321', 83 '(ushort) ushort_local = 432', 84 '(int) int_local = 1234', 85 '(uint) uint_local = 2345', 86 '(float) float_local = 4.5', 87 '(ulong) ulong_local = 8888', 88 '(double) double_local = -456.5', 89 '(char2) char2_local = (-11, -22)', 90 '(uchar2) uchar2_local = (0x21, 0x2c)', 91 '(short2) short2_local = (-555, 666)', 92 '(ushort2) ushort2_local = (777, 888)', 93 '(int2) int2_local = (999, -1111)', 94 '(uint2) uint2_local = (2222, 3333)', 95 '(float2) float2_local = (4.5, -5)', 96 '(long2) long2_local = (-4444, 5555)', 97 '(ulong2) ulong2_local = (6666, 7777)', 98 '(double2) double2_local = (88.5, -99)', 99 '(char3) char3_local = (11, -22, -33,', 100 '(uchar3) uchar3_local = (0x21, 0x2c, 0x37,', 101 '(short3) short3_local = (-555, 666, 777,', 102 '(ushort3) ushort3_local = (777, 888, 999,', 103 '(int3) int3_local = (999, -1111, 2222,', 104 '(uint3) uint3_local = (2222, 3333, 4444,', 105 '(float3) float3_local = (4.5, -5, -6.5,', 106 '(long3) long3_local = (-4444, 5555, 6666,', 107 '(ulong3) ulong3_local = (6666, 7777, 8888,', 108 '(double3) double3_local = (88.5, -99, 111.5,', 109 '(char4) char4_local = (55, 11, -22, -33)', 110 '(uchar4) uchar4_local = (0x16, 0x21, 0x2c, 0x37)', 111 '(short4) short4_local = (-444, -555, 666, 777)', 112 '(ushort4) ushort4_local = (666, 777, 888, 999)', 113 '(int4) int4_local = (888, 999, -1111, 2222)', 114 '(uint4) uint4_local = (1111, 2222, 3333, 4444)', 115 '(float4) float4_local = (3, 4.5, -5, -6.5)', 116 '(long4) long4_local = (-3333, -4444, 5555, 6666)', 117 '(ulong4) ulong4_local = (5555, 6666, 7777, 8888)', 118 '(double4) double4_local = (-77, 88.5, -99, 111.5)', 119 '(rs_matrix2x2) matrix2x2_local = (m = (1, 2.5, 3, 4.5))', 120 '(rs_matrix3x3) matrix3x3_local = {\n' 121 ' m = ([0] = 5, [1] = 6.5, [2] = 7, [3] = 8.5, [4] = 9, [5] = 1.5, [6] = 2, [7] = 3.5, [8] = 4)', 122 '(rs_matrix4x4) matrix4x4_local = {\n' 123 ' m = {\n' 124 ' [0] = 5.5\n' 125 ' [1] = 6\n' 126 ' [2] = 7.5\n' 127 ' [3] = 8\n' 128 ' [4] = 9\n' 129 ' [5] = 1.5\n' 130 ' [6] = 2\n' 131 ' [7] = 3.5\n' 132 ' [8] = 4.5\n' 133 ' [9] = 5.5\n' 134 ' [10] = 6.5\n' 135 ' [11] = 7\n' 136 ' [12] = 8\n' 137 ' [13] = 9.5\n' 138 ' [14] = 1.5\n' 139 ' [15] = 2.5\n' 140 ' }\n', 141 '(rs_quaternion) quaternion_local = (8, 9, 0.5, 7.5)'], 142 [r"\((signed )?char\) char_local = 'a'", 143 r'\((long )?long\) long_local = -77777']) 144 145 146 @wimpy 147 def test_inspect_primitive_types(self): 148 # Use expr to inspect locals 149 self._try_inspecting_local('char_local', 150 ["'a'"], 151 [r'\((signed )?char\)']) 152 153 self._try_inspecting_local('uchar_local', 154 ['(uchar)', "'b'"]) 155 156 self._try_inspecting_local('short_local', 157 ['(short)', '-321']) 158 159 self._try_inspecting_local('ushort_local', 160 ['(ushort)', '432']) 161 162 self._try_inspecting_local('int_local', 163 ['(int)', '1234']) 164 165 self._try_inspecting_local('uint_local', 166 ['(uint)', '2345']) 167 168 self._try_inspecting_local('float_local', 169 ['(float)', '4.5']) 170 171 self._try_inspecting_local('long_local', 172 ['-77777'], [r'\((long )?long\)']) 173 174 self._try_inspecting_local('ulong_local', 175 ['(ulong)', '8888']) 176 177 self._try_inspecting_local('double_local', 178 ['(double)', '-456.5']) 179 180 181 @wimpy 182 def test_inspect_uchar2(self): 183 self._try_inspecting_local('uchar2_local', 184 ['(uchar2)', '(0x21, 0x2c)']) 185 186 def test_inspect_vec2_types(self): 187 self._try_inspecting_local('char2_local', 188 ['(char2)', '(-11, -22)']) 189 190 self._try_inspecting_local('short2_local', 191 ['(short2)', '(-555, 666)']) 192 193 self._try_inspecting_local('ushort2_local', 194 ['(ushort2)', '(777, 888)']) 195 196 self._try_inspecting_local('int2_local', 197 ['(int2)', '(999, -1111)']) 198 199 self._try_inspecting_local('uint2_local', 200 ['(uint2)', '(2222, 3333)']) 201 202 self._try_inspecting_local('float2_local', 203 ['(float2)', '(4.5, -5)']) 204 205 self._try_inspecting_local('long2_local', 206 ['(long2)', '(-4444, 5555)']) 207 208 self._try_inspecting_local('ulong2_local', 209 ['(ulong2)', '(6666, 7777)']) 210 211 self._try_inspecting_local('double2_local', 212 ['(double2)', '(88.5, -99)']) 213 214 self._try_inspecting_local('char3_local', 215 ['(char3)', 216 '(11, -22, -33,']) 217 218 self._try_inspecting_local('uchar3_local', 219 ['(uchar3)', 220 '(0x21, 0x2c, 0x37,']) 221 222 @wimpy 223 def test_inspect_short3(self): 224 self._try_inspecting_local('short3_local', 225 ['(short3)', 226 '(-555, 666, 777,']) 227 228 def test_inspect_vec3_types(self): 229 self._try_inspecting_local('ushort3_local', 230 ['(ushort3)', 231 '(777, 888, 999,']) 232 233 self._try_inspecting_local('int3_local', 234 ['(int3)', 235 '(999, -1111, 2222,']) 236 237 self._try_inspecting_local('uint3_local', 238 ['(uint3)', 239 '(2222, 3333, 4444,']) 240 241 self._try_inspecting_local('float3_local', 242 ['(float3)', 243 '(4.5, -5, -6.5,']) 244 245 self._try_inspecting_local('long3_local', 246 ['(long3)', 247 '(-4444, 5555, 6666,']) 248 249 self._try_inspecting_local('ulong3_local', 250 ['(ulong3)', 251 '(6666, 7777, 8888,']) 252 253 self._try_inspecting_local('double3_local', 254 ['(double3)', 255 '(88.5, -99, 111.5,']) 256 257 self._try_inspecting_local('char4_local', 258 ['(char4)', 259 '(55, 11, -22, -33)']) 260 261 self._try_inspecting_local('uchar4_local', 262 ['(uchar4)', 263 '(0x16, 0x21, 0x2c, 0x37)']) 264 265 self._try_inspecting_local('short4_local', 266 ['(short4)', 267 '(-444, -555, 666, 777)']) 268 269 @wimpy 270 def test_inspect_ushort4(self): 271 self._try_inspecting_local('ushort4_local', 272 ['(ushort4)', 273 '(666, 777, 888, 999)']) 274 275 def test_inspect_vec4_types(self): 276 self._try_inspecting_local('int4_local', 277 ['(int4)', 278 '(888, 999, -1111, 2222)']) 279 280 self._try_inspecting_local('uint4_local', 281 ['(uint4)', 282 '(1111, 2222, 3333, 4444)']) 283 284 self._try_inspecting_local('float4_local', 285 ['(float4)', 286 '(3, 4.5, -5, -6.5)']) 287 288 self._try_inspecting_local('long4_local', 289 ['(long4)', 290 '(-3333, -4444, 5555, 6666)']) 291 292 self._try_inspecting_local('ulong4_local', 293 ['(ulong4)', 294 '(5555, 6666, 7777, 8888)']) 295 296 self._try_inspecting_local('double4_local', 297 ['(double4)', 298 '(-77, 88.5, -99, 111.5)']) 299 def test_inspect_matrix_types(self): 300 self._try_inspecting_local('matrix2x2_local', 301 ['(rs_matrix2x2)', 302 '= (m = (1, 2.5, 3, 4.5))']) 303 304 self._try_inspecting_local('matrix3x3_local', 305 ['(rs_matrix3x3)', 306 '= {\n' 307 ' m = ([0] = 5, [1] = 6.5, [2] = 7, [3] = 8.5, [4] = 9, [5] = 1.5, [6] = 2, [7] = 3.5, [8] = 4)']) 308 309 @wimpy 310 def test_inspect_matrix_4x4_local(self): 311 self._try_inspecting_local('matrix4x4_local', 312 ['(rs_matrix4x4)', 313 '= {\n' 314 ' m = {\n' 315 ' [0] = 5.5\n' 316 ' [1] = 6\n' 317 ' [2] = 7.5\n' 318 ' [3] = 8\n' 319 ' [4] = 9\n' 320 ' [5] = 1.5\n' 321 ' [6] = 2\n' 322 ' [7] = 3.5\n' 323 ' [8] = 4.5\n' 324 ' [9] = 5.5\n' 325 ' [10] = 6.5\n' 326 ' [11] = 7\n' 327 ' [12] = 8\n' 328 ' [13] = 9.5\n' 329 ' [14] = 1.5\n' 330 ' [15] = 2.5\n' 331 ' }\n']) 332 333 @wimpy 334 def test_inspect_quaternion_local(self): 335 self._try_inspecting_local('quaternion_local', 336 ['(rs_quaternion)', 337 '(8, 9, 0.5, 7.5)']) 338 339 @ordered_test('last') 340 @cpp_only_test() 341 def test_cpp_cleanup(self): 342 self.try_command('breakpoint delete 1', ['1 breakpoints deleted']) 343 344 self.try_command('process continue', ['exited with status = 0']) 345