* gdb.gdb/python-selftest.exp: New file.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.gdb / observer.exp
CommitLineData
8acc9f48 1# Copyright 2003-2013 Free Software Foundation, Inc.
5b2a3989
JB
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
5b2a3989 6# (at your option) any later version.
e22f8b7c 7#
5b2a3989
JB
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.
e22f8b7c 12#
5b2a3989 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
5b2a3989 15
5b2a3989
JB
16# This file was written by Joel Brobecker (brobecker@gnat.com), derived
17# from xfullpath.exp.
18
c95aea6b 19load_lib selftest-support.exp
5b2a3989
JB
20
21# are we on a target board
c1d88655 22if { [is_remote target] || ![isnative] } then {
5b2a3989
JB
23 return
24}
25
ab89363a 26proc attach_first_observer { message } {
019ebafc
MS
27 gdb_test_no_output "set \$first_obs = observer_attach_test_notification (&observer_test_first_notification_function)" \
28 "$message; attach first observer"
5b2a3989
JB
29}
30
ab89363a 31proc attach_second_observer { message } {
019ebafc
MS
32 gdb_test_no_output "set \$second_obs = observer_attach_test_notification (&observer_test_second_notification_function)" \
33 "$message; attach second observer"
5b2a3989
JB
34}
35
ab89363a 36proc attach_third_observer { message } {
019ebafc
MS
37 gdb_test_no_output "set \$third_obs = observer_attach_test_notification (&observer_test_third_notification_function)" \
38 "$message; attach third observer"
5b2a3989
JB
39}
40
ab89363a 41proc detach_first_observer { message } {
019ebafc
MS
42 gdb_test_no_output "call observer_detach_test_notification (\$first_obs)" \
43 "$message; detach first observer"
5b2a3989
JB
44}
45
ab89363a 46proc detach_second_observer { message } {
019ebafc
MS
47 gdb_test_no_output "call observer_detach_test_notification (\$second_obs)" \
48 "$message; detach second observer"
5b2a3989
JB
49}
50
ab89363a 51proc detach_third_observer { message } {
019ebafc
MS
52 gdb_test_no_output "call observer_detach_test_notification (\$third_obs)" \
53 "$message; detach third observer"
5b2a3989
JB
54}
55
56proc check_counters { first second third message } {
57 gdb_test "print observer_test_first_observer" \
ab89363a
AC
58 ".\[0-9\]+ =.*$first" \
59 "$message; check first observer counter value"
5b2a3989 60 gdb_test "print observer_test_second_observer" \
ab89363a
AC
61 ".\[0-9\]+ =.*$second" \
62 "$message; check second observer counter value"
5b2a3989 63 gdb_test "print observer_test_third_observer" \
ab89363a
AC
64 ".\[0-9\]+ =.*$third" \
65 "$message; check third observer counter value"
5b2a3989
JB
66}
67
ab89363a 68proc reset_counters { message } {
019ebafc 69 gdb_test_no_output "set variable observer_test_first_observer = 0" \
ab89363a 70 "$message; reset first observer counter"
019ebafc 71 gdb_test_no_output "set variable observer_test_second_observer = 0" \
ab89363a 72 "$message; reset second observer counter"
019ebafc 73 gdb_test_no_output "set variable observer_test_third_observer = 0" \
ab89363a 74 "$message; reset third observer counter"
5b2a3989
JB
75}
76
3ea85240 77proc test_notifications { first second third message args } {
ab89363a
AC
78 # Do any initialization
79 for {set i 0} {$i < [llength $args]} {incr i} {
80 [lindex $args $i] $message
81 }
82 reset_counters $message
3ea85240 83 # Call observer_notify_test_notification. Note that this procedure
90990674
JB
84 # takes one argument, but this argument is ignored by the observer
85 # callbacks we have installed. So we just pass an arbitrary value.
019ebafc 86 gdb_test_no_output "call observer_notify_test_notification (0)" \
ab89363a 87 "$message; sending notification"
5b2a3989
JB
88 check_counters $first $second $third $message
89}
90
c95aea6b 91proc test_observer {} {
5b2a3989 92 # First, try sending a notification without any observer attached.
3ea85240 93 test_notifications 0 0 0 "no observer attached"
5b2a3989
JB
94
95 # Now, attach one observer, and send a notification.
3ea85240 96 test_notifications 0 1 0 "second observer attached" \
ab89363a 97 attach_second_observer
5b2a3989
JB
98
99 # Remove the observer, and send a notification.
3ea85240 100 test_notifications 0 0 0 "second observer detached" \
ab89363a 101 detach_second_observer
5b2a3989
JB
102
103 # With a new observer.
3ea85240 104 test_notifications 1 0 0 "1st observer added" \
ab89363a 105 attach_first_observer
5b2a3989
JB
106
107 # With 2 observers.
3ea85240 108 test_notifications 1 1 0 "2nd observer added" \
ab89363a 109 attach_second_observer
5b2a3989
JB
110
111 # With 3 observers.
3ea85240 112 test_notifications 1 1 1 "3rd observer added" \
ab89363a 113 attach_third_observer
5b2a3989
JB
114
115 # Remove middle observer.
3ea85240 116 test_notifications 1 0 1 "2nd observer removed" \
ab89363a 117 detach_second_observer
5b2a3989
JB
118
119 # Remove first observer.
3ea85240 120 test_notifications 0 0 1 "1st observer removed" \
ab89363a 121 detach_first_observer
5b2a3989
JB
122
123 # Remove last observer.
3ea85240 124 test_notifications 0 0 0 "3rd observer removed" \
ab89363a 125 detach_third_observer
5b2a3989
JB
126
127 # Go back to 3 observers, and remove them in a different order...
3ea85240 128 test_notifications 1 1 1 "three observers added" \
ab89363a
AC
129 attach_first_observer \
130 attach_second_observer \
131 attach_third_observer
5b2a3989
JB
132
133 # Remove the third observer.
3ea85240 134 test_notifications 1 1 0 "third observer removed" \
ab89363a 135 detach_third_observer
5b2a3989
JB
136
137 # Remove the second observer.
3ea85240 138 test_notifications 1 0 0 "second observer removed" \
ab89363a 139 detach_second_observer
5b2a3989
JB
140
141 # Remove the first observer, no more observers.
3ea85240 142 test_notifications 0 0 0 "first observer removed" \
ab89363a 143 detach_first_observer
5b2a3989
JB
144
145 return 0
146}
147
c95aea6b 148do_self_tests captured_main test_observer
This page took 1.039184 seconds and 4 git commands to generate.