]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.threads/wp-replication.exp
Fix test names starting with uppercase output by basic functions
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / wp-replication.exp
CommitLineData
aacbb8a5
LM
1# This testcase is part of GDB, the GNU debugger.
2
618f726f 3# Copyright 2009-2016 Free Software Foundation, Inc.
aacbb8a5
LM
4
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18# Check that hardware watchpoints get correctly replicated to all
19# existing threads when hardware watchpoints are created. This test
20# creates one hardware watchpoint per thread until a maximum is
21# reached. It originally addresses a deficiency seen on embedded
22# powerpc targets with slotted hardware *point designs.
23
24set NR_THREADS 10
25set NR_TRIGGERS_PER_THREAD 2
26
27# This test verifies that a hardware watchpoint gets replicated to
28# every existing thread and is detected properly. This test is
29# only meaningful on a target with hardware watchpoint support.
30if {[skip_hw_watchpoint_tests]} {
31 return 0
32}
33
34standard_testfile
35if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "additional_flags=-DNR_THREADS=$NR_THREADS -DNR_TRIGGERS_PER_THREAD=$NR_TRIGGERS_PER_THREAD"]] != "" } {
36 return -1
37}
38
39clean_restart ${binfile}
40
41# Force hardware watchpoints to be used.
42gdb_test_no_output "set can-use-hw-watchpoints 1" ""
43
44# Run to `main' where we begin our tests.
45if ![runto_main] then {
bc6c7af4 46 fail "failed to run to main"
aacbb8a5
LM
47 return 0
48}
49
aacbb8a5
LM
50# Set some default values.
51set hwatch_count 0
4081c0f1 52set count 0
aacbb8a5
LM
53
54# Count the number of hardware watchpoints available on
55# this target.
4081c0f1
YQ
56
57# So we get an immediate warning/error if the target doesn't support a
58# hardware watchpoint or run out of hardware resource.
59gdb_test_no_output "set breakpoint always-inserted on"
60
61while { $count < $NR_THREADS } {
62 # Some targets do resource counting as we insert watchpoints.
63 # Such targets won't cause a watchpoint insertion failure, but
64 # will switch to software watchpoints silently. We check for
65 # both cases here.
66 gdb_test_multiple "watch watched_data\[$hwatch_count\]" \
67 "watch watched_data\[$hwatch_count\]" {
68 -re ".*Could not insert hardware watchpoint.*$gdb_prompt $" {
69 # End the loop.
70 set count $NR_THREADS
71 }
72 -re "Hardware watchpoint .*$gdb_prompt $" {
73 incr hwatch_count
74 }
75 -re "Watchpoint .*$gdb_prompt $" {
76 # End the loop.
77 set count $NR_THREADS
78 }
79 }
80 incr count
aacbb8a5
LM
81}
82
4081c0f1
YQ
83gdb_test_no_output "set breakpoint always-inserted off"
84
aacbb8a5
LM
85# Target cannot insert hardware watchpoints. It should have reported
86# (through board settings) that it did not support them in the first place.
87# Just exit.
88if { $hwatch_count == 0} {
bc6c7af4 89 fail "no hardware watchpoints available"
aacbb8a5
LM
90 return 0
91}
92
93# Set the testcase's internal variable indicating the number of
94# hardware watchpoints the target supports.
95gdb_test_no_output "set var hw_watch_count=${hwatch_count}" \
96 "set var hw_watch_count=${hwatch_count}"
97
98# At this point, we know how many hardware watchpoints
99# the target supports. Use that to do further testing.
100delete_breakpoints
101
aacbb8a5
LM
102# Prepare to create all the threads.
103gdb_test "break thread_started" \
104 "Breakpoint \[0-9\]+ at .*: file .*${srcfile}, line .*" \
105 "Breakpoint on thread_started"
106
107# Move all threads to where they're supposed to be for testing.
108for { set i 0 } { $i < $NR_THREADS } { incr i } {
109
110 # We want to set the maximum number of hardware watchpoints
111 # and make sure the target can handle that without an error.
112 # That will show us the watchpoints got replicated to all the
113 # threads correctly, and that no new watchpoints got created
114 # in the background for a specific thread.
115 if {$i < $hwatch_count} {
116 gdb_test "watch watched_data\[$i\]" \
117 "Hardware watchpoint .*" \
118 "watch watched_data\[$i\]"
119 } else {
120 verbose -log "Not setting watchpoint for watched_data\[$i\]\n"
121 }
122
123 gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, thread_started \\(\\) at .*$srcfile.*" \
124 "Thread $i hit breakpoint at thread_started"
125}
126
127# Let the threads run and change the watched data, leading
128# to watchpoint triggers.
129gdb_test_no_output "set var test_ready=1" \
130 "set var test_ready=1"
131
132# Set the number of expected watchpoint triggers.
133set TRIGGERS [expr "$NR_THREADS * $hwatch_count * $NR_TRIGGERS_PER_THREAD"]
134
135# Move the threads and hit the watchpoints TRIGGERS times.
136for { set i 1 } { $i <= $TRIGGERS } { incr i } {
137 gdb_test continue "Continuing\\..*Hardware watchpoint \[0-9\]+: watched_data\[\[0-9\]+\].*Old value = \[0-9\]+.*New value = \[0-9\]+.*thread_function \\(arg=$hex\\) at .*$srcfile.*" \
138 "Continue to watchpoint trigger $i out of ${TRIGGERS} on watched_data"
139}