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 TestWriteGlobalElement.''' 16 17from __future__ import absolute_import 18 19from harness.test_base_remote import TestBaseRemote 20from harness.decorators import ( 21 ordered_test, 22 wimpy, 23 cpp_only_test 24) 25 26 27class TestWriteGlobalElement(TestBaseRemote): 28 '''Tests modifying elements of global variables of all types.''' 29 30 bundle_target = { 31 'java': 'KernelVariables', 32 'jni': 'JNIKernelVariables', 33 'cpp': 'CppKernelVariables' 34 } 35 36 def _try_inspecting_global(self, global_name, expected_output): 37 '''Run the "expr" command on a given global and with a given output. 38 39 Args: 40 global_name: String which is the name of the global to inspect. 41 expected_output: List of strings that should be found in the output. 42 43 Raises: 44 TestFail: The lldb command did not provide the expected output. 45 ''' 46 self.try_command('expr ' + global_name, expected_output) 47 48 def _try_modifying_global(self, global_name, new_value, expected_output, 49 expected_output_regex=None): 50 '''Modify and then inspect a global and check for the output. 51 52 Run the "expr" command to set a given global to a new value and 53 check that it is set afterwards by running the "target variable" 54 command. 55 56 Args: 57 global_name: String which is the name of the global to modify. 58 new_value: A string that is the new value of the global. 59 expected_output: List of strings that should be found in the output 60 of both commands. 61 expected_output_regex: List of regular expressions that should be 62 found in the output of the target variable 63 command. 64 65 Raises: 66 TestFail: One of the lldb commands did not provide the expected 67 output. 68 ''' 69 self.try_command('expr %s = %s' % (global_name, new_value), 70 expected_output, 71 expected_output_regex) 72 self.try_command('target variable ' + global_name, 73 expected_output, 74 expected_output_regex) 75 76 @wimpy 77 @ordered_test(0) 78 def test_setup(self): 79 self.try_command('language renderscript status', 80 ['Runtime Library discovered', 81 'Runtime Driver discovered']) 82 83 self.try_command('b -f simple.rs -l 145', []) 84 85 self.try_command('process continue', 86 ['resuming', 87 'stopped', 88 'stop reason = breakpoint']) 89 90 @wimpy 91 def test_modify_global(self): 92 self._try_modifying_global('char2_global[0]', '2', 93 ['\'\\x02\''], 94 [r'\((signed )?char\)']) 95 self._try_inspecting_global('char2_global', ['(char2)', '(2, -22)']) 96 97 def test_vec2(self): 98 self._try_modifying_global('uchar2_global[1]', '3', 99 ['\'\\x03\''], 100 [r'\(u(nsigned )?char\)']) 101 self._try_inspecting_global('uchar2_global', 102 ['(uchar2)', '(0x21, 0x03)']) 103 104 self._try_modifying_global('short2_global[0]', '-44', 105 ['(short)', '-44']) 106 self._try_inspecting_global('short2_global', 107 ['(short2)', '(-44, 666)']) 108 109 self._try_modifying_global('ushort2_global[1]', '55', 110 ['55'], 111 [r'\(u(nsigned )?short\)']) 112 self._try_inspecting_global('ushort2_global', 113 ['(ushort2)', '(777, 55)']) 114 115 self._try_modifying_global('int2_global[0]', '666', 116 ['(int)', '666']) 117 self._try_inspecting_global('int2_global', 118 ['(int2)', '(666, -1111)']) 119 120 self._try_modifying_global('uint2_global[1]', '777', 121 ['777'], 122 [r'\(u(nsigned )?int\)']) 123 self._try_inspecting_global('uint2_global', 124 ['(uint2)', '(2222, 777)']) 125 126 self._try_modifying_global('float2_global[0]', '-8.5', 127 ['(float)', '-8.5']) 128 self._try_inspecting_global('float2_global', 129 ['(float2)', '(-8.5, -5)']) 130 131 self._try_modifying_global('long2_global[1]', '999999', 132 ['999999'], 133 [r'\((long )?long\)']) 134 self._try_inspecting_global('long2_global', 135 ['(long2)', '(-4444, 999999)']) 136 137 self._try_modifying_global('ulong2_global[0]', '10101010101', 138 ['10101010101'], 139 [r'\(u(nsigned )?(long )?long\)']) 140 self._try_inspecting_global('ulong2_global', 141 ['(ulong2)', '(10101010101, 7777)']) 142 143 self._try_modifying_global('double2_global[1]', '-11.000', 144 ['(double)', '-11']) 145 self._try_inspecting_global('double2_global', 146 ['(double2)', '(88.5, -11)']) 147 148 self._try_modifying_global('char3_global[0]', '12', 149 ['\'\\f\''], 150 [r'\((signed )?char\)']) 151 self._try_inspecting_global('char3_global', 152 ['(char3)', 153 '(12, -22, -33,']) 154 155 @wimpy 156 def test_uchar3(self): 157 self._try_modifying_global('uchar3_global[1]', '\'d\'', 158 ['\'d\''], 159 [r'\(u(nsigned )?char\)']) 160 self._try_inspecting_global('uchar3_global', 161 ['(uchar3)', 162 '(0x21, 0x64, 0x37,']) 163 164 def test_vec3(self): 165 self._try_modifying_global('short3_global[2]', '-131', 166 ['(short)', '-131']) 167 self._try_inspecting_global('short3_global', 168 ['(short3)', 169 '(-555, 666, -131,']) 170 171 self._try_modifying_global('ushort3_global[0]', '1414', 172 ['1414'], 173 [r'\(u(nsigned )?short\)']) 174 self._try_inspecting_global('ushort3_global', 175 ['(ushort3)', 176 '(1414, 888, 999,']) 177 178 self._try_modifying_global('int3_global[0]', '151515', 179 ['(int)', '151515']) 180 self._try_inspecting_global('int3_global', 181 ['(int3)', 182 '(151515, -1111, 2222,']) 183 184 self._try_modifying_global('uint3_global[1]', '161616', 185 ['161616'], 186 [r'\(u(nsigned )?int\)']) 187 self._try_inspecting_global('uint3_global', 188 ['(uint3)', 189 '(2222, 161616, 4444,']) 190 191 self._try_modifying_global('float3_global[2]', '17.5', 192 ['(float)', '17.5']) 193 self._try_inspecting_global('float3_global', 194 ['(float3)', 195 '(4.5, -5, 17.5,']) 196 197 self._try_modifying_global('long3_global[0]', '-181818181818', 198 ['-181818181818'], 199 [r'\((long )?long\)']) 200 self._try_inspecting_global('long3_global', 201 ['(long3)', 202 '(-181818181818, 5555, 6666,']) 203 204 self._try_modifying_global('ulong3_global[1]', '191919191919', 205 ['191919191919'], 206 [r'\(u(nsigned )?(long )?long\)']) 207 self._try_inspecting_global('ulong3_global', 208 ['(ulong3)', 209 '(6666, 191919191919, 8888,']) 210 211 self._try_modifying_global('double3_global[2]', '20.5', 212 ['(double)', '20.5']) 213 self._try_inspecting_global('double3_global', 214 ['(double3)', 215 '(88.5, -99, 20.5,']) 216 217 self._try_modifying_global('char4_global[0]', '-21', 218 ['\'\\xeb\''], 219 [r'\((signed )?char\)']) 220 self._try_inspecting_global('char4_global', 221 ['(char4)', 222 '(-21, 11, -22, -33)']) 223 224 self._try_modifying_global('uchar4_global[1]', '22', 225 ['\'\\x16\''], 226 [r'\(u(nsigned )?char\)']) 227 self._try_inspecting_global('uchar4_global', 228 ['(uchar4)', 229 '(0xde, 0x16, 0x2c, 0x37)']) 230 231 @wimpy 232 def test_short4(self): 233 self._try_modifying_global('short4_global[2]', '23', 234 ['(short)', '23']) 235 self._try_inspecting_global('short4_global', 236 ['(short4)', 237 '(-444, -555, 23, 777)']) 238 239 def test_vec4(self): 240 self._try_modifying_global('ushort4_global[3]', '24', 241 ['24'], 242 [r'\(u(nsigned )?short\)']) 243 self._try_inspecting_global('ushort4_global', 244 ['(ushort4)', 245 '(666, 777, 888, 24)']) 246 247 self._try_modifying_global('int4_global[0]', '-2525', 248 ['(int)', '-2525']) 249 self._try_inspecting_global('int4_global', 250 ['(int4)', 251 '(-2525, 999, -1111, 2222)']) 252 253 self._try_modifying_global('uint4_global[1]', '26262', 254 ['26262'], 255 [r'\(u(nsigned )?int\)']) 256 self._try_inspecting_global('uint4_global', 257 ['(uint4)', 258 '(1111, 26262, 3333, 4444)']) 259 260 self._try_modifying_global('float4_global[2]', '27.0f', 261 ['(float)', '27']) 262 self._try_inspecting_global('float4_global', 263 ['(float4)', 264 '(3, 4.5, 27, -6.5)']) 265 266 self._try_modifying_global('long4_global[3]', '-28282828282', 267 ['-28282828282'], 268 [r'\((long )?long\)']) 269 self._try_inspecting_global('long4_global', 270 ['(long4)', 271 '(-3333, -4444, 5555, -28282828282)']) 272 273 self._try_modifying_global('ulong4_global[0]', '2929292929', 274 ['2929292929'], 275 [r'\(u(nsigned )?(long )?long\)']) 276 self._try_inspecting_global('ulong4_global', 277 ['(ulong4)', 278 '(2929292929, 6666, 7777, 8888)']) 279 280 self._try_modifying_global('double4_global[1]', '30.5', 281 ['(double)', '30.5']) 282 self._try_inspecting_global('double4_global', 283 ['(double4)', 284 '(-77, 30.5, -99, 111.5)']) 285 286 @cpp_only_test() 287 @ordered_test('last') 288 def test_cpp_cleanup(self): 289 self.try_command('breakpoint delete 1', ['1 breakpoints deleted']) 290 291 self.try_command('process continue', 292 ['exited with status = 0']) 293