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 TestSourceStep.''' 16dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 17a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummondfrom __future__ import absolute_import 18a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 19dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leoimport os 20dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leofrom harness.test_base_remote import TestBaseRemote 21a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummondfrom harness.decorators import ( 22a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond ordered_test, 23a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond cpp_only_test, 24a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond) 25dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 26dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 27dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leoclass TestSourceStep(TestBaseRemote): 28dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo '''Test stepping through the source using step-in, -over and -out.''' 29dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 30a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond bundle_target = { 31a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 'java': 'BranchingFunCalls', 32a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 'jni': 'JNIBranchingFunCalls', 33a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 'cpp': 'CppBranchingFunCalls' 34a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 35a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond } 36a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 37a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond def script_dir(self): 38a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond file_dir = os.path.dirname(os.path.realpath(__file__)) 39a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond app_root = os.path.join(file_dir, '..', '..') 40dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 41a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond return { 42a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 'java': os.path.join(app_root, 'java', 'BranchingFunCalls', 'src', 'rs'), 43a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 'cpp': os.path.join(app_root, 'cpp', 'BranchingFunCalls'), 44a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 'jni': os.path.join(app_root, 'jni', 'BranchingFunCalls', 'jnibranchingfuncalls') 45a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond }[self.app_type] 46dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 47a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond def setup(self, android): 48dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo '''This test requires to be run on one thread.''' 49dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo android.push_prop('debug.rs.max-threads', 1) 50dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 51a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond def teardown(self, android): 52dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo '''Reset the number of RS threads to the previous value.''' 53dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo android.pop_prop('debug.rs.max-threads') 54dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 55a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond def test_source_thread_step_in_out(self): 56dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('language renderscript status', 57dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['Runtime Library discovered', 58dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'Runtime Driver discovered']) 59dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 60506520732420b196f4f17d67596fd81004faf009Luke Drummond self.try_command('b -f scalars.rs -l 63', 61dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['(pending)']) 62dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 63dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('process continue', 64dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['stopped', 65dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'stop reason = breakpoint', 66506520732420b196f4f17d67596fd81004faf009Luke Drummond 'scalars.rs:63']) 67dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 68dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo # set the source mapping 69a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond self.set_src_map('scalars.rs', self.script_dir()) 70dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 71dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('process status', 72506520732420b196f4f17d67596fd81004faf009Luke Drummond ['-> 63', 73dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 'int i = in;']) 74dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo 75506520732420b196f4f17d67596fd81004faf009Luke Drummond #63 int i = in; 76dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('thread step-in', 77506520732420b196f4f17d67596fd81004faf009Luke Drummond ['-> 64']) 78506520732420b196f4f17d67596fd81004faf009Luke Drummond #64 float f = (float) i; 79dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('thread step-in', 80506520732420b196f4f17d67596fd81004faf009Luke Drummond ['-> 65']) 81dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo #49 modify_f(&f); 82dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('thread step-over', 83506520732420b196f4f17d67596fd81004faf009Luke Drummond ['-> 66']) 84dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo #50 modify_i(&i); 85dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('thread step-in', 86506520732420b196f4f17d67596fd81004faf009Luke Drummond ['-> 49']) 87506520732420b196f4f17d67596fd81004faf009Luke Drummond #49 int j = *i; 88506520732420b196f4f17d67596fd81004faf009Luke Drummond self.try_command('b -f scalars.rs -l 54', 89dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['librs.scalars.so`modify_i', 90506520732420b196f4f17d67596fd81004faf009Luke Drummond 'scalars.rs:54']) 91dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('c', 92dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo ['stop reason = breakpoint', 93506520732420b196f4f17d67596fd81004faf009Luke Drummond 'scalars.rs:54', 94506520732420b196f4f17d67596fd81004faf009Luke Drummond '-> 54']) 95506520732420b196f4f17d67596fd81004faf009Luke Drummond #54 set_i(i, 0); 96506520732420b196f4f17d67596fd81004faf009Luke Drummond # For the line number anything between #37 and #38 is fine 97dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('thread step-in', 98dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo [], 99506520732420b196f4f17d67596fd81004faf009Luke Drummond [r'-> 3[678]']) 100506520732420b196f4f17d67596fd81004faf009Luke Drummond #38 int tmp = b; 101dcecc0c8d22e894525e25a122ce25129b51338f2Dean De Leo self.try_command('thread step-out', 102506520732420b196f4f17d67596fd81004faf009Luke Drummond ['-> 54']) 103a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 104a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond @cpp_only_test() 105a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond @ordered_test('last') 106a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond def test_cpp_cleanup(self): 107a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond self.try_command('breakpoint delete 1', ['1 breakpoints deleted']) 108a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 109a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond self.try_command('breakpoint delete 2', ['1 breakpoints deleted']) 110a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 111a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond self.try_command('process continue', 112a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond ['exited with status = 0']) 113a3c6f62775506c95afd556e617f14d7a28839f01Luke Drummond 114