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 TestScriptGroup.'''
16
17from __future__ import absolute_import
18
19from harness.test_base_remote import TestBaseRemote
20from harness.decorators import wimpy
21
22
23class TestScriptGroup(TestBaseRemote):
24    bundle_target = {
25        'java': 'ScriptGroup'
26    }
27
28    def setup(self, android):
29        '''This test requires to be run on one thread.'''
30        android.push_prop('debug.rs.max-threads', 1)
31
32    def teardown(self, android):
33        '''Reset the number of RS threads to the previous value.'''
34        android.pop_prop('debug.rs.max-threads')
35
36    @wimpy
37    def test_kernel_backtrace(self):
38        # number of allocation elements
39        array_size = 8
40
41        self.try_command('language renderscript status',
42                         ['Runtime Library discovered',
43                          'Runtime Driver discovered',
44                          'rsdDebugHintScriptGroup2'])
45
46        self.try_command('language renderscript scriptgroup breakpoint set scriptgroup_test',
47                         ['Breakpoint 1: no locations (pending)'])
48
49        self.try_command('language renderscript scriptgroup list',
50                         ['0 script groups'])
51
52        self.try_command('process continue',
53                         ['resuming',
54                          'stopped',
55                          'stop reason = breakpoint',
56                          'librs.scriptgroup.so`foo',
57                          'scriptgroup.rs'])
58
59        self.try_command('breakpoint list',
60                         ['scriptgroup_test',
61                          'locations = 1'])
62
63        self.try_command('language renderscript scriptgroup list',
64                         ['1 script group',
65                          'scriptgroup_test',
66                          'foo',
67                          'goo'])
68
69        self.try_command('language renderscript scriptgroup breakpoint set --stop-on-all scriptgroup_test',
70                         ['Breakpoint 2: 2 locations'])
71
72        self.try_command('breakpoint list',
73                         ['scriptgroup_test',
74                          'librs.scriptgroup.so`foo',
75                          'librs.scriptgroup.so`goo'])
76
77        # iterate over foo kernels
78        self.try_command('bt',
79                         ['scriptgroup.rs:',
80                          'frame #0', 'librs.scriptgroup.so`foo',
81                          'frame #1', 'librs.scriptgroup.so`foo.expand'])
82
83        for x in range(array_size):
84            self.try_command('frame var',
85                             ['(int) a = {0}'.format(x)])
86            self.try_command('process continue',
87                             ['resuming',
88                              'stopped',
89                              'stop reason = breakpoint',
90                              'librs.scriptgroup.so`{0}'.format(
91                                  'foo' if x < 7 else 'goo')])
92
93        # iterate over goo kernels
94        self.try_command('bt',
95                         ['stop reason = breakpoint',
96                          'scriptgroup.rs:',
97                          'frame #0', 'librs.scriptgroup.so`goo',
98                          'frame #1', 'librs.scriptgroup.so`goo.expand'])
99
100        for x in range(array_size):
101            self.try_command('frame var',
102                             ['(int) a = {0}'.format(x * x)])
103
104            if x < 7:
105                self.try_command('process continue',
106                                 ['resuming',
107                                  'stopped',
108                                  'stop reason = breakpoint',
109                                  'librs.scriptgroup.so`goo'])
110