• 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 TestAllocationFile.'''
16
17from __future__ import absolute_import
18
19import os
20
21from harness.test_base_remote import TestBaseRemote
22from harness.decorators import (
23    cpp_only_test,
24    ordered_test
25)
26
27
28class TestAllocationFile(TestBaseRemote):
29    '''Tests saving the contents of allocations to disk and reloading them.'''
30
31    bundle_target = {
32        'java': 'Allocations',
33        'cpp': 'CppAllocations',
34        'jni': 'JNIAllocations'
35    }
36
37    @ordered_test(0)
38    def test_allocation_file_roundtrip(self):
39        self.try_command('language renderscript kernel breakpoint all enable',
40                         ['Breakpoints will be set on all kernels'])
41
42        self.try_command('process continue',
43                         ['resuming',
44                          'stopped',
45                          'stop reason = breakpoint'])
46
47        # Binary file of int2 allocation
48        file_int2 = self.get_tmp_file_path()
49
50        self.try_command('language renderscript allocation save 12 ' +
51                         file_int2,
52                         ["Allocation written to file '%s'" % file_int2])
53
54        # Check file was created
55        self.assert_true(os.path.isfile(file_int2))
56
57        # Load the file we just created, to assert the allocation contents are
58        # the same
59        self.try_command('language renderscript allocation load 12 ' +
60                         file_int2,
61                         ["Contents of file '%s' read into allocation 12" %
62                          file_int2])
63        os.remove(file_int2)
64
65        self.try_command('language renderscript allocation dump 12',
66                         ['(0, 0, 0) = {0 1}',
67                          '(1, 0, 0) = {2 3}',
68                          '(2, 0, 0) = {4 5}',
69                          '(3, 0, 0) = {6 7}',
70                          '(4, 0, 0) = {8 9}',
71                          '(5, 0, 0) = {10 11}',
72                          '(6, 0, 0) = {12 13}',
73                          '(7, 0, 0) = {14 15}',
74                          '(8, 0, 0) = {16 17}',
75                          '(9, 0, 0) = {18 19}',
76                          '(10, 0, 0) = {20 21}',
77                          '(11, 0, 0) = {22 23}'])
78
79        self.try_command('breakpoint del 1',
80                         ['1 breakpoints deleted'])
81
82        # Hit second kernel
83        self.try_command('process continue',
84                         ['resuming',
85                          'stopped',
86                          'stop reason = breakpoint'])
87
88        # Binary file of uint allocation
89        file_uint = self.get_tmp_file_path()
90
91        self.try_command('language renderscript allocation save 28 ' +
92                         file_uint,
93                         ["Allocation written to file '%s'" % file_uint])
94
95        # Check file was created
96        self.assert_true(os.path.isfile(file_uint))
97
98        # Test loading file into allocation with an incompatible type 'short'
99        self.try_command('language renderscript allocation load 7 ' + file_uint,
100                         ["Contents of file '%s' read into allocation 7" %
101                          file_uint,
102                          "Warning: Mismatched Element sizes",
103                          "Warning: Mismatched Types",
104                          "Warning: Mismatched allocation sizes"])
105
106        # Check result of size inconsistency, mapping 4-byte unsigned to 2-byte
107        # int
108        self.try_command('language renderscript allocation dump 7',
109                         ['(0, 0, 0) = 0',
110                          '(1, 0, 0) = 0',
111                          '(2, 0, 0) = 1',
112                          '(3, 0, 0) = 0',
113                          '(4, 0, 0) = 2',
114                          '(5, 0, 0) = 0',
115                          '(6, 0, 0) = 3',
116                          '(7, 0, 0) = 0',
117                          '(8, 0, 0) = 4',
118                          '(9, 0, 0) = 0',
119                          '(10, 0, 0) = 5',
120                          '(11, 0, 0) = 0',
121                          '(12, 0, 0) = 6',
122                          '(13, 0, 0) = 0',
123                          '(14, 0, 0) = 7',
124                          '(15, 0, 0) = 0',
125                          '(16, 0, 0) = 8',
126                          '(17, 0, 0) = 0',
127                          '(18, 0, 0) = 9',
128                          '(19, 0, 0) = 0',
129                          '(20, 0, 0) = 10',
130                          '(21, 0, 0) = 0',
131                          '(22, 0, 0) = 11',
132                          '(23, 0, 0) = 0'])
133
134        self.try_command('breakpoint del 2',
135                         ['1 breakpoints deleted'])
136
137        # Hit third kernel
138        self.try_command('process continue',
139                         ['resuming',
140                          'stopped',
141                          'stop reason = breakpoint'])
142
143        # Test that uint allocation has been squared by square_kernel
144        self.try_command('language renderscript allocation dump 28',
145                         ['(0, 0, 0) = 0',
146                          '(1, 0, 0) = 1',
147                          '(2, 0, 0) = 4',
148                          '(3, 0, 0) = 9',
149                          '(4, 0, 0) = 16',
150                          '(5, 0, 0) = 25',
151                          '(6, 0, 0) = 36',
152                          '(7, 0, 0) = 49',
153                          '(8, 0, 0) = 64',
154                          '(9, 0, 0) = 81',
155                          '(10, 0, 0) = 100',
156                          '(11, 0, 0) = 121',
157                          '(12, 0, 0) = 144',
158                          '(13, 0, 0) = 169',
159                          '(14, 0, 0) = 196',
160                          '(15, 0, 0) = 225',
161                          '(16, 0, 0) = 256',
162                          '(17, 0, 0) = 289',
163                          '(18, 0, 0) = 324',
164                          '(19, 0, 0) = 361',
165                          '(20, 0, 0) = 400',
166                          '(21, 0, 0) = 441',
167                          '(22, 0, 0) = 484',
168                          '(23, 0, 0) = 529'])
169
170        # Load uint allocation from save before square_kernel had been run
171        self.try_command('language renderscript allocation load 28 ' +
172                         file_uint,
173                         ["Contents of file '%s' read into allocation 28" %
174                          file_uint])
175        os.remove(file_uint)
176
177        # Check contents are back to original
178        self.try_command('language renderscript allocation dump 28',
179                         ['(0, 0, 0) = 0',
180                          '(1, 0, 0) = 1',
181                          '(2, 0, 0) = 2',
182                          '(3, 0, 0) = 3',
183                          '(4, 0, 0) = 4',
184                          '(5, 0, 0) = 5',
185                          '(6, 0, 0) = 6',
186                          '(7, 0, 0) = 7',
187                          '(8, 0, 0) = 8',
188                          '(9, 0, 0) = 9',
189                          '(10, 0, 0) = 10',
190                          '(11, 0, 0) = 11',
191                          '(12, 0, 0) = 12',
192                          '(13, 0, 0) = 13',
193                          '(14, 0, 0) = 14',
194                          '(15, 0, 0) = 15',
195                          '(16, 0, 0) = 16',
196                          '(17, 0, 0) = 17',
197                          '(18, 0, 0) = 18',
198                          '(19, 0, 0) = 19',
199                          '(20, 0, 0) = 20',
200                          '(21, 0, 0) = 21',
201                          '(22, 0, 0) = 22',
202                          '(23, 0, 0) = 23'])
203
204    @ordered_test('last')
205    @cpp_only_test()
206    def test_cpp_cleanup(self):
207        self.try_command('breakpoint delete 3', ['1 breakpoints deleted'])
208
209        self.try_command('process continue',
210                         ['exited with status = 0'])
211