15bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond# Copyright (C) 2016 The Android Open Source Project 25bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond# 35bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond# Licensed under the Apache License, Version 2.0 (the "License"); 45bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond# you may not use this file except in compliance with the License. 55bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond# You may obtain a copy of the License at 65bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond# 75bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond# http://www.apache.org/licenses/LICENSE-2.0 85bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond# 95bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond# Unless required by applicable law or agreed to in writing, software 105bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond# distributed under the License is distributed on an "AS IS" BASIS, 115bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 125bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond# See the License for the specific language governing permissions and 135bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond# limitations under the License. 145bbcc3861c44435f89481f80946ef5c9c49968f2Luke Drummond 15dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo'''Module that contains the test TestLanguageSubcmds.''' 16dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 17a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummondfrom __future__ import absolute_import 18a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 19dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leoimport os 20dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 21dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leofrom harness.test_base_remote import TestBaseRemote 22a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummondfrom harness.decorators import ( 23a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond cpp_only_test, 24a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond ordered_test, 25a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond) 26dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 27dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 28dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leoclass TestLanguageSubcmds(TestBaseRemote): 29dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo '''Tests the 'language renderscript' subcommands.''' 30dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 31a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond bundle_target = { 32a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 'java': 'JavaDebugWaitAttach', 33a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 'jni': 'JNIDebugWaitAttach', 34a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 'cpp': 'CppDebugWaitAttach' 35a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond } 36dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 37a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond def setup(self, android): 38dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo '''This test requires to be run on one thread.''' 39dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo android.push_prop('debug.rs.max-threads', 1) 40dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 41a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond def teardown(self, android): 42dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo '''Reset the number of RS threads to the previous value.''' 43dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo android.pop_prop('debug.rs.max-threads') 44dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 45a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond def _pkg_name(self): 46a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond return { 47a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 'java': 'com.android.rs.waitattachdebug', 48a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 'jni': 'com.android.rs.jnidebugwaitattach', 49a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 'cpp': 'com.android.rs.cppwaitattach' 50a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond }[self.app_type] 51a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 52a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond def test_language_subcommands(self): 53dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language', 54dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo []) 55dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 56dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language renderscript status', 57dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['Runtime Library discovered', 58dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'Runtime Driver discovered', 59dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'Runtime functions hooked', 60dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'rsdAllocationInit', 61dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'rsdAllocationRead2D', 62dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'rsdScriptInit', 63dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'rsdScriptInvokeForEach', 64dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'rsdScriptInvokeForEachMulti', 65dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'rsdScriptSetGlobalVar']) 66dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 67a8b6960a8815bb1fff74c1d9dcf4c572a7a831d9Luke Drummond self.try_command('breakpoint set --file simple.rs --line 28', 68dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['(pending)']) 69dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 70dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('process continue', 71dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo []) 72dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 73dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language renderscript kernel', 74dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['breakpoint', 75dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'coordinate', 76dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'list']) 77dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 78dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language renderscript kernel breakpoint', 79dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['all', 80dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'set']) 81dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 82dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language renderscript kernel list', 83dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['RenderScript Kernels', 84dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo "Resource 'simple'", 85dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'root', 86dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'simple_kernel']) 87dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 88dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language renderscript kernel coordinate', 89dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['Coordinate: (0, 0, 0)']) 90dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 91dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language renderscript context', 92dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['dump']) 93dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 94dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language renderscript context dump', 95dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['Inferred RenderScript Contexts', 96dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo '1 script instances']) 97dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 98dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language renderscript allocation', 99dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['list', 100dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'load', 101dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'save', 102dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'dump', 103dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'refresh']) 104dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 105dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language renderscript allocation list', 106dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['RenderScript Allocations:']) 107dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 108dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language renderscript allocation list -i 0', 109dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['RenderScript Allocations:']) 110dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 111dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language renderscript allocation list --id 0', 112dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['RenderScript Allocations:']) 113dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 114dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language renderscript allocation dump 1', 115dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['Data (X, Y, Z):']) 116dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 117dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo output_file = self.get_tmp_file_path() 118dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language renderscript allocation dump 1 -f ' + 119dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo output_file, 120dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ["Results written to '%s'" % output_file]) 121dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 122dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo if os.path.isfile(output_file): 123dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo os.remove(output_file) 124dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 125dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language renderscript allocation dump 1 --file ' + 126dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo output_file, 127dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ["Results written to '%s'" % output_file]) 128dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 129dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language renderscript allocation save 1 ' + 130dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo output_file, 131dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ["Allocation written to file '%s'" % output_file]) 132dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 133dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language renderscript allocation load 1 ' + 134dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo output_file, 135dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ["Contents of file '%s' read into allocation 1" % 136dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo output_file]) 137dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 138dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language renderscript allocation refresh', 139dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['All allocations successfully recomputed']) 140dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 141dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language renderscript module', 142dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['dump']) 143dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 144dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language renderscript module dump', 145dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['RenderScript Modules:', 146dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'librs.simple.so', 147dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'Debug info loaded', 148dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'Globals: 1', 149dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'gColor - float4', 150dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'Kernels: 3', 151dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'root', 152dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'simple_kernel', 153dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'other_kernel', 154a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 'java_package_name: %s' % self._pkg_name(), 155dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'version:']) 156a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 157a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond @ordered_test('last') 158a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond @cpp_only_test() 159a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond def test_cpp_cleanup(self): 160a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond self.try_command('breakpoint delete 1', ['1 breakpoints deleted']) 161a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 162a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond self.try_command('process continue', ['exited with status = 0']) 163