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