1# Copyright (C) 2012-2019 Free Software Foundation, Inc. 2 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 3 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16standard_testfile 17 18# Run the tests. We run the tests two different ways: once with a 19# plain probe, and once with a probe that has an associated semaphore. 20# This returns -1 on failure to compile or start, 0 otherwise. 21proc stap_test {exec_name {arg ""}} { 22 global testfile hex srcfile 23 24 if {[prepare_for_testing "failed to prepare" ${exec_name} $srcfile \ 25 [concat $arg debug]]} { 26 return -1 27 } 28 29 if ![runto_main] { 30 return -1 31 } 32 33 gdb_test "print \$_probe_argc" "No probe at PC $hex" \ 34 "check argument not at probe point" 35 36 gdb_test "info probes stap" \ 37 "test *user *$hex .*" \ 38 "info probes stap" 39 40 if {[runto "-pstap test:user"]} { 41 pass "run to -pstap test:user" 42 } else { 43 fail "run to -pstap test:user" 44 } 45 46 # Test probe arguments. 47 gdb_test "print \$_probe_argc" " = 1" \ 48 "print \$_probe_argc for probe user" 49 gdb_test "print \$_probe_arg0 == x" " = 1" \ 50 "check \$_probe_arg0 for probe user" 51 gdb_test "print \$_probe_arg1" \ 52 "Invalid probe argument 1 -- probe has 1 arguments available" \ 53 "check \$_probe_arg1 for probe user" 54 55 # Set a breakpoint with multiple probe locations. 56 gdb_test "break -pstap test:two" \ 57 "Breakpoint \[0-9\]+ at $hex.*2 locations.*" \ 58 "set multi-location probe breakpoint (probe two)" 59 60 # Reinit GDB, set a breakpoint on probe m4. 61 delete_breakpoints 62 if {[runto "-pstap test:m4"]} { 63 pass "run to -pstap test:m4" 64 } else { 65 fail "run to -pstap test:m4" 66 } 67 68 # Testing probe arguments. 69 gdb_test "print \$_probe_argc" " = 3" \ 70 "print \$_probe_argc for probe m4" 71 gdb_test "print \$_probe_arg0" " = 42" \ 72 "check \$_probe_arg0 for probe m4" 73 gdb_test "print (const char *) \$_probe_arg1" \ 74 " = $hex .This is a test message.*" \ 75 "check \$_probe_arg1 for probe m4" 76 gdb_test "print \$_probe_arg2 == v" " = 1" \ 77 "check \$_probe_arg2 for probe m4" 78 79 # Reinit GDB, set a breakpoint on probe ps. 80 delete_breakpoints 81 if {[runto "-pstap test:ps"]} { 82 pass "run to -pstap test:m4" 83 } else { 84 fail "run to -pstap test:m4" 85 } 86 87 gdb_test "print \$_probe_argc" " = 3" \ 88 "print \$_probe_argc for probe ps" 89 gdb_test "print (const char *) \$_probe_arg1" \ 90 " = $hex .This is another test message.*" \ 91 "print \$_probe_arg1 for probe ps" 92 93 return 0 94} 95 96proc stap_test_no_debuginfo {exec_name {arg ""}} { 97 global testfile hex 98 99 if {[prepare_for_testing "failed to prepare" ${exec_name} ${testfile}.c \ 100 {$arg nodebug optimize=-O2}]} { 101 return -1 102 } 103 104 if {[runto "-pstap test:user"]} { 105 pass "run to -pstap test:user" 106 } else { 107 fail "run to -pstap test:user" 108 } 109 110 # Test probe arguments. 111 gdb_test "print \$_probe_argc" " = 1" \ 112 "print \$_probe_argc for probe user" 113 gdb_test "print \$_probe_arg0 == 23" " = 1" \ 114 "check \$_probe_arg0 for probe user" 115 gdb_test "print \$_probe_arg1" \ 116 "Invalid probe argument 1 -- probe has 1 arguments available" \ 117 "check \$_probe_arg1 for probe user" 118 119 # Set a breakpoint with multiple probe locations. 120 # In this scenario, we may expect more than 2 locations because of 121 # the optimizations (inlining, loop unrolling, etc). 122 gdb_test "break -pstap test:two" \ 123 "Breakpoint .* at $hex.*\[0-9\]+ locations.*" \ 124 "set multi-location probe breakpoint (probe two)" 125 126 # Reinit GDB, set a breakpoint on probe m4. 127 delete_breakpoints 128 if {[runto "-pstap test:m4"]} { 129 pass "run to -pstap test:m4" 130 } else { 131 fail "run to -pstap test:m4" 132 } 133 134 # Testing probe arguments. 135 gdb_test "print \$_probe_argc" " = 3" \ 136 "print \$_probe_argc for probe m4" 137 gdb_test "print \$_probe_arg0" " = 42" \ 138 "check \$_probe_arg0 for probe m4" 139 gdb_test "print (const char *) \$_probe_arg1" \ 140 " = $hex .This is a test message.*" \ 141 "check \$_probe_arg1 for probe m4" 142 gdb_test "print \$_probe_arg2 == 0" " = 1" \ 143 "check \$_probe_arg2 for probe m4" 144 145 # Reinit GDB, set a breakpoint on probe ps. 146 delete_breakpoints 147 if {[runto "-pstap test:ps"]} { 148 pass "run to -pstap test:m4" 149 } else { 150 fail "run to -pstap test:m4" 151 } 152 153 gdb_test "print \$_probe_argc" " = 3" \ 154 "print \$_probe_argc for probe ps" 155 gdb_test "print (const char *) \$_probe_arg1" \ 156 " = $hex .This is another test message.*" \ 157 "print \$_probe_arg1 for probe ps" 158 159 return 0 160} 161 162with_test_prefix "without semaphore, not optimized" { 163 if {[stap_test "stap-probe-nosem-noopt"] == -1} { 164 untested "stap probe test failed" 165 return -1 166 } 167} 168 169with_test_prefix "with semaphore, not optimized" { 170 stap_test "stap-probe-sem-noopt" "-DUSE_PROBES" 171} 172 173with_test_prefix "without semaphore, optimized" { 174 stap_test_no_debuginfo "stap-probe-nosem-opt" 175} 176 177with_test_prefix "with semaphore, optimized" { 178 stap_test_no_debuginfo "stap-probe-sem-opt" "-DUSE_PROBES" 179} 180