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 TestLanguageSubcmds.''' 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 TestLanguageSubcmds(TestBaseRemote): 29 '''Tests the 'language renderscript' subcommands.''' 30 31 bundle_target = { 32 'java': 'JavaDebugWaitAttach', 33 'jni': 'JNIDebugWaitAttach', 34 'cpp': 'CppDebugWaitAttach' 35 } 36 37 def setup(self, android): 38 '''This test requires to be run on one thread.''' 39 android.push_prop('debug.rs.max-threads', 1) 40 41 def teardown(self, android): 42 '''Reset the number of RS threads to the previous value.''' 43 android.pop_prop('debug.rs.max-threads') 44 45 def _pkg_name(self): 46 return { 47 'java': 'com.android.rs.waitattachdebug', 48 'jni': 'com.android.rs.jnidebugwaitattach', 49 'cpp': 'com.android.rs.cppwaitattach' 50 }[self.app_type] 51 52 def test_language_subcommands(self): 53 self.try_command('language', 54 []) 55 56 self.try_command('language renderscript status', 57 ['Runtime Library discovered', 58 'Runtime Driver discovered', 59 'Runtime functions hooked', 60 'rsdAllocationInit', 61 'rsdAllocationRead2D', 62 'rsdScriptInit', 63 'rsdScriptInvokeForEach', 64 'rsdScriptInvokeForEachMulti', 65 'rsdScriptSetGlobalVar']) 66 67 self.try_command('breakpoint set --file simple.rs --line 28', 68 ['(pending)']) 69 70 self.try_command('process continue', 71 []) 72 73 self.try_command('language renderscript kernel', 74 ['breakpoint', 75 'coordinate', 76 'list']) 77 78 self.try_command('language renderscript kernel breakpoint', 79 ['all', 80 'set']) 81 82 self.try_command('language renderscript kernel list', 83 ['RenderScript Kernels', 84 "Resource 'simple'", 85 'root', 86 'simple_kernel']) 87 88 self.try_command('language renderscript kernel coordinate', 89 ['Coordinate: (0, 0, 0)']) 90 91 self.try_command('language renderscript context', 92 ['dump']) 93 94 self.try_command('language renderscript context dump', 95 ['Inferred RenderScript Contexts', 96 '1 script instances']) 97 98 self.try_command('language renderscript allocation', 99 ['list', 100 'load', 101 'save', 102 'dump', 103 'refresh']) 104 105 self.try_command('language renderscript allocation list', 106 ['RenderScript Allocations:']) 107 108 self.try_command('language renderscript allocation list -i 0', 109 ['RenderScript Allocations:']) 110 111 self.try_command('language renderscript allocation list --id 0', 112 ['RenderScript Allocations:']) 113 114 self.try_command('language renderscript allocation dump 1', 115 ['Data (X, Y, Z):']) 116 117 output_file = self.get_tmp_file_path() 118 self.try_command('language renderscript allocation dump 1 -f ' + 119 output_file, 120 ["Results written to '%s'" % output_file]) 121 122 if os.path.isfile(output_file): 123 os.remove(output_file) 124 125 self.try_command('language renderscript allocation dump 1 --file ' + 126 output_file, 127 ["Results written to '%s'" % output_file]) 128 129 self.try_command('language renderscript allocation save 1 ' + 130 output_file, 131 ["Allocation written to file '%s'" % output_file]) 132 133 self.try_command('language renderscript allocation load 1 ' + 134 output_file, 135 ["Contents of file '%s' read into allocation 1" % 136 output_file]) 137 138 self.try_command('language renderscript allocation refresh', 139 ['All allocations successfully recomputed']) 140 141 self.try_command('language renderscript module', 142 ['dump']) 143 144 self.try_command('language renderscript module dump', 145 ['RenderScript Modules:', 146 'librs.simple.so', 147 'Debug info loaded', 148 'Globals: 1', 149 'gColor - float4', 150 'Kernels: 3', 151 'root', 152 'simple_kernel', 153 'other_kernel', 154 'java_package_name: %s' % self._pkg_name(), 155 'version:']) 156 157 @ordered_test('last') 158 @cpp_only_test() 159 def test_cpp_cleanup(self): 160 self.try_command('breakpoint delete 1', ['1 breakpoints deleted']) 161 162 self.try_command('process continue', ['exited with status = 0']) 163