• 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 TestWriteLocal.'''
16
17from __future__ import absolute_import
18
19from harness.test_base_remote import TestBaseRemote
20from harness.decorators import (
21    ordered_test,
22    wimpy
23)
24
25
26class TestWriteLocal(TestBaseRemote):
27    '''Tests modifying local variables of all types.'''
28
29    bundle_target = {
30        'java': 'KernelVariables',
31        'jni': 'JNIKernelVariables',
32        'cpp': 'CppKernelVariables'
33    }
34
35    def _try_modifying_local(self, local_name, new_value, data_type_in,
36                             expected_output, expected_output_regex=None):
37        '''Try getting lldb to modify a local and check the output.
38
39        Run the "expr" command to set a given local to a new value and
40        check that it is set afterwards by running the "target variable"
41        command.
42
43        Args:
44            local_name: String which is the name of the local to modify.
45            new_value: A string that is the new value of the local.
46            data_type_in: A string containing a c-style parenthesised data type
47                          representing the type of the local.
48            expected_output: List of strings that should be found in the output
49                             of both commands.
50            expected_output_regex: List of regular expressions that should be
51                                   found in the output of the target variable
52                                   command.
53
54        Raises:
55            TestFail: One of the lldb commands did not provide the expected
56                      output.
57        '''
58        # pylint: disable=too-many-arguments
59        self.try_command('expr %s = %s%s'
60                         % (local_name, data_type_in, new_value),
61                         expected_output,
62                         expected_output_regex)
63        self.try_command('frame variable ' + local_name,
64                         expected_output,
65                         expected_output_regex)
66
67    @wimpy
68    @ordered_test(0)
69    def test_setup(self):
70        self.try_command('language renderscript status',
71                         ['Runtime Library discovered',
72                          'Runtime Driver discovered'])
73
74        self.try_command('b -f simple.rs -l 145', [])
75
76        self.try_command('process continue',
77                         ['resuming',
78                          'stopped',
79                          'stop reason = breakpoint'])
80
81    @wimpy
82    def test_modify_char(self):
83        self._try_modifying_local('char_local', '-2',
84                                 '(signed char)', ['\'\\xfe\''],
85                                 [r'\((signed )?char\)'])
86
87    def test_modify_primitive(self):
88        self._try_modifying_local('uchar_local', '22',
89                                 '(uchar)', ['(uchar)', '\'\\x16\''])
90
91        self._try_modifying_local('short_local', '-33',
92                                 '(short)', ['(short)', '-33'])
93
94        self._try_modifying_local('ushort_local', '44',
95                                 '(ushort)', ['(ushort)', '44'])
96
97        self._try_modifying_local('int_local', '-55',
98                                 '(int)', ['(int)', '-55'])
99
100        self._try_modifying_local('uint_local', '66',
101                                 '(uint)', ['(uint)', '66'])
102
103        self._try_modifying_local('float_local', '-7.5',
104                                 '(float)', ['(float)', '-7.5'])
105
106        self._try_modifying_local('long_local', '-888888',
107                                 '(long long)', ['-888888'],
108                                 [r'\((long )?long\)'])
109
110        self._try_modifying_local('ulong_local', '99999999',
111                                 '(ulong)', ['(ulong)', '99999999'])
112
113        self._try_modifying_local('double_local', '-10101.5',
114                                 '(double)', ['(double)', '-10101.5'])
115
116        self._try_modifying_local('char2_local', '{22, 4}',
117                                 '(char2)', ['(char2)', '(22, 4)'])
118
119    @wimpy
120    def test_modify_uchar2(self):
121        self._try_modifying_local('uchar2_local', '{44, 55}',
122                             '(uchar2)', ['(uchar2)', '(0x2c, 0x37)'])
123
124    def test_modify_vec2(self):
125        self._try_modifying_local('short2_local', '{-66, 77}',
126                                 '(short2)', ['(short2)', '(-66, 77)'])
127
128        self._try_modifying_local('ushort2_local', '{88, 99}',
129                                 '(ushort2)', ['(ushort2)', '(88, 99)'])
130
131        self._try_modifying_local('int2_local', '{111, -222}',
132                                 '(int2)', ['(int2)', '(111, -222)'])
133
134        self._try_modifying_local('uint2_local', '{333, 444}',
135                                 '(uint2)', ['(uint2)', '(333, 444)'])
136
137        self._try_modifying_local('float2_local', '{-55.5f, 6.0}',
138                                 '(float2)', ['(float2)', '(-55.5, 6)'])
139
140        self._try_modifying_local('long2_local', '{666666, -777777}',
141                                 '(long2)', ['(long2)', '(666666, -777777)'])
142
143        self._try_modifying_local('ulong2_local', '{888888, 999999}',
144                                 '(ulong2)', ['(ulong2)', '(888888, 999999)'])
145
146        self._try_modifying_local('double2_local', '{11.0000000, -0.0l}',
147                                 '(double2)', ['(double2)', '(11, -0)'])
148
149        self._try_modifying_local('char3_local', '{2, -3, 4}',
150                                 '(char3)', ['(char3)', '(2, -3, 4,'])
151
152        self._try_modifying_local('uchar3_local', '{\'a\', \'b\', \'c\'}',
153                                 '(uchar3)', ['(uchar3)', '(0x61, 0x62, 0x63,'])
154
155    @wimpy
156    def test_modify_short3(self):
157        self._try_modifying_local('short3_local', '{44, -55, 66}',
158                             '(short3)', ['(short3)', '(44, -55, 66,'])
159
160    def test_modify_vec3(self):
161        self._try_modifying_local('ushort3_local', '{88, 99, 111}',
162                                 '(ushort3)', ['(ushort3)', '(88, 99, 111,'])
163
164        self._try_modifying_local('int3_local', '{-111, 222, -333}',
165                                 '(int3)', ['(int3)', '(-111, 222, -333,'])
166
167        self._try_modifying_local('uint3_local', '{444, 555, 666}',
168                                 '(uint3)', ['(uint3)', '(444, 555, 666,'])
169
170        self._try_modifying_local('float3_local', '{7.5F, 0008.000, 9}',
171                                 '(float3)', ['(float3)', '(7.5, 8, 9,'])
172
173        self._try_modifying_local('long3_local', '{111111, -22222222, 3333333}',
174                                 '(long3)', ['(long3)', '(111111, -22222222, 3333333,'])
175
176        self._try_modifying_local('ulong3_local', '{4444444, 5555555, 66666666}',
177                                 '(ulong3)', ['(ulong3)', '(4444444, 5555555, 66666666,'])
178
179        self._try_modifying_local('double3_local', '{7.5L, -0, 8.9e1}',
180                                 '(double3)', ['(double3)', '(7.5, 0, 89,'])
181
182        self._try_modifying_local('char4_local', '{0x1, 0x2, 0x3, 0x4}',
183                                 '(char4)',
184                                 ['(char4)', '(1, 2, 3, 4)'])
185
186        self._try_modifying_local('uchar4_local', '{0x5, 0x6, 0x7, 0x8}',
187                                 '(uchar4)',
188                                 ['(uchar4)', '(0x05, 0x06, 0x07, 0x08)'])
189
190        self._try_modifying_local('short4_local', '{0x9, 0xa, 0xb, 0xc}',
191                                 '(short4)',
192                                 ['(short4)', '(9, 10, 11, 12)'])
193
194    @wimpy
195    def test_modify_ushort4(self):
196        self._try_modifying_local('ushort4_local', '{0xd, 0xe, 0xf, 0x10}',
197                             '(ushort4)',
198                             ['(ushort4)', '(13, 14, 15, 16)'])
199
200    def test_modify_vec4(self):
201        self._try_modifying_local('int4_local', '{0x11, 0x12, 0x13, 0x14}',
202                                 '(int4)',
203                                 ['(int4)', '(17, 18, 19, 20)'])
204
205        self._try_modifying_local('uint4_local', '{0x15, 0x16, 0x17, 0x18}',
206                                 '(uint4)',
207                                 ['(uint4)', '(21, 22, 23, 24)'])
208
209        self._try_modifying_local('float4_local', '{19.0, 20.5, -21, -22.5}',
210                                 '(float4)',
211                                 ['(float4)', '(19, 20.5, -21, -22.5)'])
212
213        self._try_modifying_local('long4_local', '{0x1d, 0x1e, 0x1f, 0x20}',
214                                 '(long4)',
215                                 ['(long4)', '(29, 30, 31, 32)'])
216
217        self._try_modifying_local('ulong4_local', '{0x21, 0x22, 0x23, 0x24}',
218                                 '(ulong4)',
219                                 ['(ulong4)', '(33, 34, 35, 36)'])
220
221        self._try_modifying_local('double4_local', '{25.000, -26, -27.5, 28.0}',
222                                 '(double4)',
223                                 ['(double4)', '(25, -26, -27.5, 28)'])
224