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 TestInvokeFun.''' 16 17from __future__ import absolute_import 18 19from harness.test_base_remote import TestBaseRemote 20from harness.decorators import (ordered_test, wimpy) 21from harness.exception import TestSuiteException 22 23 24class TestSingleSource(TestBaseRemote): 25 '''Tests debugging a function executed from Java using invoke_*.''' 26 27 bundle_target = { 28 'java': "SingleSource" 29 } 30 31 def setup(self, android): 32 33 '''This test requires to be run on one thread.''' 34 android.push_prop('debug.rs.max-threads', 1) 35 36 def teardown(self, android): 37 38 '''Reset the number of RS threads to the previous value.''' 39 android.pop_prop('debug.rs.max-threads') 40 41 @ordered_test(-1) 42 @wimpy 43 def test_startup(self): 44 45 # pylint: disable=line-too-long 46 self.try_command('language renderscript status', 47 ['Runtime Library discovered', 48 'Runtime Driver discovered']) 49 50 self.try_command('breakpoint set --name check_in', 51 ['(pending)']) 52 53 @ordered_test(0) 54 @wimpy 55 def test_invoke_1(self): 56 57 # enter script_invoke_1 58 self.try_command('breakpoint set --name script_invoke_1', 59 ['(pending)']) 60 61 self.try_command('process continue', 62 ['stopped', 63 'stop reason = breakpoint'], 64 [r'librs.rs_single_source.so`script_invoke_1']) 65 66 self.try_command( 67 'language renderscript allocation dump 1', 68 ['(0, 0, 0) = 1', 69 '(1, 0, 0) = 2', 70 '(2, 0, 0) = 3', 71 '(3, 0, 0) = 4']) 72 73 self.try_command( 74 'language renderscript allocation dump 2', 75 ['(0, 0, 0) = 5', 76 '(1, 0, 0) = 6', 77 '(2, 0, 0) = 7', 78 '(3, 0, 0) = 8']) 79 80 self.try_command('breakpoint set --name `kernel_1', 81 ['address']) 82 83 self.try_command('breakpoint set --name `kernel_2', 84 ['address']) 85 86 # check our global allocation is visible 87 self.try_command('p global_alloc', 88 ['(rs_allocation)', 89 'p = 0x']) 90 91 # test kernel_1 92 for _ in range(10): 93 # continue as long as there are threads hitting kernel_1 94 out = self.do_command('process continue') 95 if 'librs.rs_single_source.so`kernel_1' in out: 96 continue 97 # if we hit check_in we have finished with kernel_1 98 if 'librs.rs_single_source.so`check_in' in out: 99 self.try_command( 100 'language renderscript allocation dump 1', 101 ['(0, 0, 0) = 25', 102 '(1, 0, 0) = 36', 103 '(2, 0, 0) = 49', 104 '(3, 0, 0) = 64']) 105 break 106 TestSuiteException('unexpected breakpoint') 107 else: 108 TestSuiteException('loop quota exceeded') 109 110 # test kernel_2 111 for _ in range(10): 112 # continue as long as there are threads hitting kernel_2 113 out = self.do_command('process continue') 114 if 'librs.rs_single_source.so`kernel_2' in out: 115 continue 116 # if we hit check_in we have finished with kernel_2 117 if 'librs.rs_single_source.so`check_in' in out: 118 self.try_command( 119 'language renderscript allocation dump 2', 120 ['(0, 0, 0) = 125', 121 '(1, 0, 0) = 216', 122 '(2, 0, 0) = 343', 123 '(3, 0, 0) = 512']) 124 break 125 TestSuiteException('unexpected breakpoint') 126 else: 127 TestSuiteException('loop quota exceeded') 128 129 @ordered_test(1) 130 @wimpy 131 def test_invoke_2(self): 132 133 # enter script_invoke_2 134 self.try_command('breakpoint set --name script_invoke_2', 135 ['address']) 136 137 self.try_command('process continue', 138 ['stopped', 139 'stop reason = breakpoint'], 140 [r'librs.rs_single_source.so`script_invoke_2']) 141 142 # test void_kernel_1 143 self.try_command('breakpoint set --name void_kernel_1', 144 ['address']) 145 146 for _ in range(10): 147 out = self.do_command('process continue') 148 149 # continue as long as there are threads hitting void_kernel_1 150 if 'librs.rs_single_source.so`void_kernel_1' in out: 151 continue 152 153 # if we hit check_in we have finished with void_kernel_1 154 if 'librs.rs_single_source.so`check_in' in out: 155 self.try_command( 156 'language renderscript allocation dump 4', 157 ['(0, 0, 0) = 0', 158 '(1, 0, 0) = 1', 159 '(2, 0, 0) = 2', 160 '(3, 0, 0) = 3']) 161 break 162 163 TestSuiteException('unexpected breakpoint') 164 else: 165 TestSuiteException('loop quota exceeded') 166