• 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 TestWriteGlobal.'''
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 TestWriteGlobal(TestBaseRemote):
28    '''Tests modifying global variables of all types.'''
29
30    bundle_target = {
31        'java': 'KernelVariables',
32        'jni': 'JNIKernelVariables',
33        'cpp': 'CppKernelVariables'
34    }
35
36    def _try_modifying_global(self, global_name, new_value, data_type_in,
37                             expected_output, expected_output_regex=None):
38        '''Modify and then inspect a global and check for the output.
39
40        Run the "expr" command to set a given global to a new value and
41        check that it is set afterwards by running the "target variable"
42        command.
43
44        Args:
45            global_name: String which is the name of the global to modify.
46            new_value: A string that is the new value of the global.
47            data_type_in: A string containing a c-style parenthesised data type
48                          representing the type of the global.
49            expected_output: List of strings that should be found in the output
50                             of both commands.
51            expected_output_regex: List of regular expressions that should be
52                                   found in the output of the target variable
53                                   command.
54
55        Raises:
56            TestFail: One of the lldb commands did not provide the expected
57                      output.
58        '''
59        self.try_command('expr %s = %s%s' %
60                         (global_name, data_type_in, new_value),
61                         expected_output,
62                         expected_output_regex)
63        self.try_command('target variable ' + global_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_char_global(self):
83        self._try_modifying_global('char_global', '-2',
84                                  '(signed char)', ['\'\\xfe\''],
85                                  [r'\((signed )?char\)'])
86
87    def test_write_primitive_types(self):
88        self._try_modifying_global('uchar_global', '22',
89                                  '(uchar)', ['(uchar)', '\'\\x16\''])
90
91        self._try_modifying_global('short_global', '-33',
92                                  '(short)', ['(short)', '-33'])
93
94        self._try_modifying_global('ushort_global', '44',
95                                  '(ushort)', ['(ushort)', '44'])
96
97        self._try_modifying_global('int_global', '-55',
98                                  '(int)', ['(int)', '-55'])
99
100        self._try_modifying_global('uint_global', '66',
101                                  '(uint)', ['(uint)', '66'])
102
103        self._try_modifying_global('float_global', '-7.5',
104                                  '(float)', ['(float)', '-7.5'])
105
106        self._try_modifying_global('long_global', '-888888',
107                                  '(long long)', ['-888888'],
108                                  [r'\((long )?long\)'])
109
110        self._try_modifying_global('ulong_global', '99999999',
111                                  '(ulong)', ['(ulong)', '99999999'])
112
113        self._try_modifying_global('double_global', '-10101.5',
114                                  '(double)', ['(double)', '-10101.5'])
115
116        self._try_modifying_global('char2_global', '{22, 4}',
117                                  '(char2)', ['(char2)', '(22, 4)'])
118
119    @wimpy
120    def test_write_uchar2(self):
121        self._try_modifying_global('uchar2_global', '{44, 55}',
122                                  '(uchar2)', ['(uchar2)', '(0x2c, 0x37)'])
123
124    def test_write_vec2(self):
125        self._try_modifying_global('short2_global', '{-66, 77}',
126                                  '(short2)', ['(short2)', '(-66, 77)'])
127
128        self._try_modifying_global('ushort2_global', '{88, 99}',
129                                  '(ushort2)', ['(ushort2)', '(88, 99)'])
130
131        self._try_modifying_global('int2_global', '{111, -222}',
132                                  '(int2)', ['(int2)', '(111, -222)'])
133
134        self._try_modifying_global('uint2_global', '{333, 444}',
135                                  '(uint2)', ['(uint2)', '(333, 444)'])
136
137        self._try_modifying_global('float2_global', '{-55.5f, 6.0}',
138                                  '(float2)', ['(float2)', '(-55.5, 6)'])
139
140        self._try_modifying_global('long2_global', '{666666, -777777}',
141                                  '(long2)', ['(long2)', '(666666, -777777)'])
142
143        self._try_modifying_global('ulong2_global', '{888888, 999999}',
144                                  '(ulong2)', ['(ulong2)', '(888888, 999999)'])
145
146        self._try_modifying_global('double2_global', '{11.0000000, -0.0l}',
147                                  '(double2)', ['(double2)', '(11, -0)'])
148
149        self._try_modifying_global('char3_global', '{2, -3, 4}',
150                                  '(char3)', ['(char3)', '(2, -3, 4,'])
151
152        self._try_modifying_global('uchar3_global', '{\'a\', \'b\', \'c\'}',
153                                  '(uchar3)', ['(uchar3)', '(0x61, 0x62, 0x63,'])
154
155    @wimpy
156    def test_write_short3(self):
157        self._try_modifying_global('short3_global', '{44, -55, 66}',
158                                  '(short3)', ['(short3)', '(44, -55, 66,'])
159
160    def test_write_vec3(self):
161        self._try_modifying_global('ushort3_global', '{88, 99, 111}',
162                                  '(ushort3)', ['(ushort3)', '(88, 99, 111,'])
163
164        self._try_modifying_global('int3_global', '{-111, 222, -333}',
165                                  '(int3)', ['(int3)', '(-111, 222, -333,'])
166
167        self._try_modifying_global('uint3_global', '{444, 555, 666}',
168                                  '(uint3)', ['(uint3)', '(444, 555, 666,'])
169
170        self._try_modifying_global('float3_global', '{7.5F, 0008.000, 9}',
171                                  '(float3)', ['(float3)', '(7.5, 8, 9,'])
172
173        self._try_modifying_global('long3_global', '{111111, -22222222, 3333333}',
174                                  '(long3)', ['(long3)', '(111111, -22222222, 3333333,'])
175
176        self._try_modifying_global('ulong3_global', '{4444444, 5555555, 66666666}',
177                                  '(ulong3)', ['(ulong3)', '(4444444, 5555555, 66666666,'])
178
179        self._try_modifying_global('double3_global', '{7.5L, -0, 8.9e1}',
180                                  '(double3)', ['(double3)', '(7.5, 0, 89,'])
181
182        self._try_modifying_global('char4_global', '{0x1, 0x2, 0x3, 0x4}',
183                                  '(char4)',
184                                  ['(char4)', '(1, 2, 3, 4)'])
185
186        self._try_modifying_global('uchar4_global', '{0x5, 0x6, 0x7, 0x8}',
187                                  '(uchar4)',
188                                  ['(uchar4)', '(0x05, 0x06, 0x07, 0x08)'])
189
190        self._try_modifying_global('short4_global', '{0x9, 0xa, 0xb, 0xc}',
191                                  '(short4)',
192                                  ['(short4)', '(9, 10, 11, 12)'])
193
194    @wimpy
195    def test_write_ushort4(self):
196        self._try_modifying_global('ushort4_global', '{0xd, 0xe, 0xf, 0x10}',
197                                  '(ushort4)',
198                                  ['(ushort4)', '(13, 14, 15, 16)'])
199
200    def test_write_vec4_global(self):
201        self._try_modifying_global('int4_global', '{0x11, 0x12, 0x13, 0x14}',
202                                  '(int4)',
203                                  ['(int4)', '(17, 18, 19, 20)'])
204
205        self._try_modifying_global('uint4_global', '{0x15, 0x16, 0x17, 0x18}',
206                                  '(uint4)',
207                                  ['(uint4)', '(21, 22, 23, 24)'])
208
209        self._try_modifying_global('float4_global', '{19.0, 20.5, -21, -22.5}',
210                                  '(float4)',
211                                  ['(float4)', '(19, 20.5, -21, -22.5)'])
212
213        self._try_modifying_global('long4_global', '{0x1d, 0x1e, 0x1f, 0x20}',
214                                  '(long4)',
215                                  ['(long4)', '(29, 30, 31, 32)'])
216
217        self._try_modifying_global('ulong4_global', '{0x21, 0x22, 0x23, 0x24}',
218                                  '(ulong4)',
219                                  ['(ulong4)', '(33, 34, 35, 36)'])
220
221        self._try_modifying_global('double4_global', '{25.000, -26, -27.5, 28.0}',
222                                  '(double4)',
223                                  ['(double4)', '(25, -26, -27.5, 28)'])
224
225    @ordered_test('last')
226    @cpp_only_test()
227    def test_cpp_cleanup(self):
228        self.try_command('breakpoint delete 1', ['1 breakpoints deleted'])
229
230        self.try_command('process continue', ['exited with status = 0'])
231