• 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 TestReadGlobal.'''
16
17from __future__ import absolute_import
18
19from harness.test_base_remote import TestBaseRemote
20from harness.decorators import (
21    wimpy,
22    ordered_test,
23    cpp_only_test,
24)
25
26
27class TestReadGlobal(TestBaseRemote):
28    '''Tests inspecting 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                              expected_regex=None):
38        '''Inspect a global and check for the output.
39
40        Run the "expr" and "target variable" commands on a given global and
41        with a given output. (The commands should be equivalent.)
42
43        Args:
44            global_name: String which is the name of the global to inspect.
45            expected_output: List of strings that should be found in the output.
46            expected_regex: List of regular expressions that should match lldb's
47                            output.
48
49        Raises:
50            TestFail: One of the lldb commands did not provide the expected
51                      output.
52        '''
53        self.try_command('expr ' + global_name,
54                         expected_output,
55                         expected_regex)
56
57        self.try_command('target variable ' + global_name,
58                         expected_output,
59                         expected_regex)
60
61    @wimpy
62    @ordered_test(0)
63    def test_setup(self):
64        self.try_command('language renderscript status',
65                         ['Runtime Library discovered',
66                          'Runtime Driver discovered'])
67
68        self.try_command('b -f simple.rs -l 145', [])
69
70        self.try_command('process continue',
71                         ['resuming',
72                          'stopped',
73                          'stop reason = breakpoint'])
74
75    @wimpy
76    def test_list_script_globals(self):
77        # pylint: disable=line-too-long
78
79        self.try_command('target variable',
80                         ['Global variables for',
81                          'librs.simple.so',
82                          "(uchar) uchar_global = '\\xea'",
83                          '(short) short_global = -321',
84                          '(ushort) ushort_global = 432',
85                          '(int) int_global = 1234',
86                          '(uint) uint_global = 2345',
87                          '(float) float_global = 4.5',
88                          '(ulong) ulong_global = 8888',
89                          '(double) double_global = -456.5',
90                          '(char2) char2_global = (11, -22)',
91                          '(uchar2) uchar2_global = (0x21, 0x2c)',
92                          '(short2) short2_global = (-555, 666)',
93                          '(ushort2) ushort2_global = (777, 888)',
94                          '(int2) int2_global = (999, -1111)',
95                          '(uint2) uint2_global = (2222, 3333)',
96                          '(float2) float2_global = (4.5, -5)',
97                          '(long2) long2_global = (-4444, 5555)',
98                          '(ulong2) ulong2_global = (6666, 7777)',
99                          '(double2) double2_global = (88.5, -99)',
100                          '(char3) char3_global = (11, -22, -33,',
101                          '(uchar3) uchar3_global = (0x21, 0x2c, 0x37,',
102                          '(short3) short3_global = (-555, 666, 777,',
103                          '(ushort3) ushort3_global = (777, 888, 999,',
104                          '(int3) int3_global = (999, -1111, 2222,',
105                          '(uint3) uint3_global = (2222, 3333, 4444,',
106                          '(float3) float3_global = (4.5, -5, -6.5,',
107                          '(long3) long3_global = (-4444, 5555, 6666,',
108                          '(ulong3) ulong3_global = (6666, 7777, 8888,',
109                          '(double3) double3_global = (88.5, -99, 111.5,',
110                          '(char4) char4_global = (55, 11, -22, -33)',
111                          '(uchar4) uchar4_global = (0xde, 0x21, 0x2c, 0x37)',
112                          '(short4) short4_global = (-444, -555, 666, 777)',
113                          '(ushort4) ushort4_global = (666, 777, 888, 999)',
114                          '(int4) int4_global = (888, 999, -1111, 2222)',
115                          '(uint4) uint4_global = (1111, 2222, 3333, 4444)',
116                          '(float4) float4_global = (3, 4.5, -5, -6.5)',
117                          '(long4) long4_global = (-3333, -4444, 5555, 6666)',
118                          '(ulong4) ulong4_global = (5555, 6666, 7777, 8888)',
119                          '(double4) double4_global = (-77, 88.5, -99, 111.5)',
120                          '(rs_matrix2x2) matrix2x2_global = (m = (1, 2.5, 3, 4.5))',
121                          '(rs_matrix3x3) matrix3x3_global = {\n'
122                          '  m = ([0] = 5, [1] = 6.5, [2] = 7, [3] = 8.5, [4] = 9, [5] = 1.5, [6] = 2, [7] = 3.5, [8] = 4)',
123                          '(rs_matrix4x4) matrix4x4_global = {\n'
124                          '  m = {\n'
125                          '    [0] = 5.5\n'
126                          '    [1] = 6\n'
127                          '    [2] = 7.5\n'
128                          '    [3] = 8\n'
129                          '    [4] = 9\n'
130                          '    [5] = 1.5\n'
131                          '    [6] = 2\n'
132                          '    [7] = 3.5\n'
133                          '    [8] = 4.5\n'
134                          '    [9] = 5.5\n'
135                          '    [10] = 6.5\n'
136                          '    [11] = 7\n'
137                          '    [12] = 8\n'
138                          '    [13] = 9.5\n'
139                          '    [14] = 1.5\n'
140                          '    [15] = 2.5\n'
141                          '  }\n',
142                          '(rs_quaternion) quaternion_global = (4.5, 5.5, 6, 3)'],
143                         [r"\((signed )?char\) char_global = '\\f'",
144                          r'\((long )?long\) long_global = -77777'])
145
146    @wimpy
147    def test_read_char_global(self):
148        # Use expr to inspect locals
149        self._try_inspecting_global('char_global',
150                         ["'\\f'"],
151                         [r'\((signed )?char\)'])
152
153    def test_read_primitive_global(self):
154        self._try_inspecting_global('uchar_global',
155                         ['(uchar)', "'\\xea'"])
156
157        self._try_inspecting_global('short_global',
158                         ['(short)', '-321'])
159
160        self._try_inspecting_global('ushort_global',
161                         ['(ushort)', '432'])
162
163        self._try_inspecting_global('int_global',
164                         ['(int)', '1234'])
165
166        self._try_inspecting_global('uint_global',
167                         ['(uint)', '2345'])
168
169        self._try_inspecting_global('float_global',
170                         ['(float)', '4.5'])
171
172        self._try_inspecting_global('long_global',
173                         ['-77777'],
174                         [r'\((long )?long\)'])
175
176        self._try_inspecting_global('ulong_global',
177                         ['(ulong)', '8888'])
178
179        self._try_inspecting_global('double_global',
180                         ['(double)', '-456.5'])
181
182        self._try_inspecting_global('char2_global',
183                                   ['(char2)', '(11, -22)'])
184
185    @wimpy
186    def test_write_global2(self):
187        self._try_inspecting_global('uchar2_global',
188                               ['(uchar2)', '(0x21, 0x2c)'])
189
190    def test_write_global3(self):
191        self._try_inspecting_global('short2_global',
192                                   ['(short2)', '(-555, 666)'])
193
194        self._try_inspecting_global('ushort2_global',
195                                   ['(ushort2)', '(777, 888)'])
196
197        self._try_inspecting_global('int2_global',
198                                   ['(int2)', '(999, -1111)'])
199
200        self._try_inspecting_global('uint2_global',
201                                   ['(uint2)', '(2222, 3333)'])
202
203        self._try_inspecting_global('float2_global',
204                                   ['(float2)', '(4.5, -5)'])
205
206        self._try_inspecting_global('long2_global',
207                                   ['(long2)', '(-4444, 5555)'])
208
209        self._try_inspecting_global('ulong2_global',
210                                   ['(ulong2)', '(6666, 7777)'])
211
212        self._try_inspecting_global('double2_global',
213                                   ['(double2)', '(88.5, -99)'])
214
215        self._try_inspecting_global('char3_global',
216                                   ['(char3)',
217                                    '(11, -22, -33,'])
218
219        self._try_inspecting_global('uchar3_global',
220                                   ['(uchar3)',
221                                    '(0x21, 0x2c, 0x37,'])
222
223    @wimpy
224    def test_global_write_short3(self):
225        self._try_inspecting_global('short3_global',
226                                   ['(short3)',
227                                   '(-555, 666, 777,'])
228
229    def test_read_vec3(self):
230        self._try_inspecting_global('ushort3_global',
231                                   ['(ushort3)',
232                                    '(777, 888, 999,'])
233
234        self._try_inspecting_global('int3_global',
235                                   ['(int3)',
236                                    '(999, -1111, 2222,'])
237
238        self._try_inspecting_global('uint3_global',
239                                   ['(uint3)',
240                                    '(2222, 3333, 4444,'])
241
242        self._try_inspecting_global('float3_global',
243                                   ['(float3)',
244                                    '(4.5, -5, -6.5,'])
245
246        self._try_inspecting_global('long3_global',
247                                   ['(long3)',
248                                    '(-4444, 5555, 6666,'])
249
250        self._try_inspecting_global('ulong3_global',
251                                   ['(ulong3)',
252                                    '(6666, 7777, 8888,'])
253
254        self._try_inspecting_global('double3_global',
255                                   ['(double3)',
256                                    '(88.5, -99, 111.5,'])
257
258        self._try_inspecting_global('char4_global',
259                                   ['(char4)',
260                                    '(55, 11, -22, -33)'])
261
262        self._try_inspecting_global('uchar4_global',
263                                   ['(uchar4)',
264                                    '(0xde, 0x21, 0x2c, 0x37)'])
265
266        self._try_inspecting_global('short4_global',
267                                   ['(short4)',
268                                    '(-444, -555, 666, 777)'])
269
270    @wimpy
271    def test_read_ushort4(self):
272        self._try_inspecting_global('ushort4_global',
273                                   ['(ushort4)',
274                                    '(666, 777, 888, 999)'])
275
276    def test_read_vec4(self):
277        self._try_inspecting_global('int4_global',
278                                   ['(int4)',
279                                    '(888, 999, -1111, 2222)'])
280
281        self._try_inspecting_global('uint4_global',
282                                   ['(uint4)',
283                                    '(1111, 2222, 3333, 4444)'])
284
285        self._try_inspecting_global('float4_global',
286                                   ['(float4)',
287                                    '(3, 4.5, -5, -6.5)'])
288
289        self._try_inspecting_global('long4_global',
290                                   ['(long4)',
291                                    '(-3333, -4444, 5555, 6666)'])
292
293        self._try_inspecting_global('ulong4_global',
294                                   ['(ulong4)',
295                                    '(5555, 6666, 7777, 8888)'])
296
297        self._try_inspecting_global('double4_global',
298                                   ['(double4)',
299                                    '(-77, 88.5, -99, 111.5)'])
300
301        self._try_inspecting_global('matrix2x2_global',
302                                   ['(rs_matrix2x2)',
303                                    '= (m = (1, 2.5, 3, 4.5))'])
304
305        self._try_inspecting_global('matrix3x3_global',
306                                       ['(rs_matrix3x3)',
307                                        '= {\n'
308                                        '  m = ([0] = 5, [1] = 6.5, [2] = 7, [3] = 8.5, [4] = 9, [5] = 1.5, [6] = 2, [7] = 3.5, [8] = 4)'])
309    @wimpy
310    def test_read_matrix(self):
311        self._try_inspecting_global('matrix4x4_global',
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_read_quaternion(self):
335        self._try_inspecting_global('quaternion_global',
336                                   ['(rs_quaternion)',
337                                    '(4.5, 5.5, 6, 3)'])
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