Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 2018-2020 Free Software Foundation, Inc. |
64d27cfc TV |
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 | ||
16 | # When caching a proc using gdb_caching_proc, it will become less likely to | |
17 | # be executed, and consequently it's going to be harder to detect that the | |
18 | # proc is racy. OTOH, in general the proc is easy to rerun. So, run all | |
19 | # uncached gdb_caching_procs a number of times and detect inconsistent results. | |
20 | # The purpose of caching is to reduce runtime, so rerunning is somewhat | |
21 | # counter-productive in that aspect, but it's better than uncached, because the | |
22 | # number of reruns is constant-bounded, and the increase in runtime is bound to | |
23 | # this test-case, and could be disabled on slow targets. | |
24 | ||
25 | # Test gdb_caching_proc NAME | |
26 | proc test_proc { name } { | |
27 | set real_name gdb_real__$name | |
28 | ||
29 | set resultlist [list] | |
30 | ||
4cd9f3d5 | 31 | with_test_prefix initial { |
1d727695 TV |
32 | set first [gdb_do_cache_wrap $real_name] |
33 | } | |
64d27cfc TV |
34 | lappend resultlist $first |
35 | ||
36 | # Ten repetitions was enough to trigger target_supports_scheduler_locking, | |
37 | # and costs about 20 seconds on an i7-6600U. | |
38 | set repeat 10 | |
39 | ||
40 | set racy 0 | |
41 | for {set i 0} {$i < $repeat} {incr i} { | |
1d727695 TV |
42 | with_test_prefix $i { |
43 | set rerun [gdb_do_cache_wrap $real_name] | |
44 | } | |
64d27cfc TV |
45 | lappend resultlist $rerun |
46 | if { $rerun != $first } { | |
47 | set racy 1 | |
48 | } | |
49 | } | |
50 | ||
51 | if { $racy == 0 } { | |
1d727695 | 52 | pass "consistency" |
64d27cfc | 53 | } else { |
1d727695 | 54 | fail "consistency" |
64d27cfc TV |
55 | verbose -log "$name: $resultlist" |
56 | } | |
57 | } | |
58 | ||
59 | # Test gdb_caching_procs in FILE | |
60 | proc test_file { file } { | |
61 | upvar obj obj | |
62 | set procnames [list] | |
63 | ||
64 | set fp [open $file] | |
65 | while { [gets $fp line] >= 0 } { | |
66 | if [regexp -- "^gdb_caching_proc \[ \t\]*(\[^ \t\]*)" $line \ | |
67 | match procname] { | |
68 | lappend procnames $procname | |
69 | } | |
70 | } | |
71 | close $fp | |
72 | ||
73 | if { [llength $procnames] == 0 } { | |
74 | return | |
75 | } | |
76 | ||
77 | if { [file tail $file] == "gdb.exp" } { | |
78 | # Already loaded | |
79 | } else { | |
80 | load_lib [file tail $file] | |
81 | } | |
82 | ||
83 | foreach procname $procnames { | |
1d727695 TV |
84 | with_test_prefix $procname { |
85 | switch $procname { | |
86 | "is_address_zero_readable" { set setup_gdb 1 } | |
87 | "target_is_gdbserver" { set setup_gdb 1 } | |
88 | default {set setup_gdb 0 } | |
89 | } | |
90 | ||
91 | if { $setup_gdb } { | |
92 | clean_restart $obj | |
93 | } | |
94 | ||
95 | test_proc $procname | |
96 | ||
97 | if { $setup_gdb } { | |
98 | gdb_exit | |
99 | } | |
64d27cfc TV |
100 | } |
101 | } | |
102 | } | |
103 | ||
104 | # Init | |
105 | set me "gdb_caching_proc" | |
106 | set src { int main() { return 0; } } | |
107 | if { ![gdb_simple_compile $me $src executable] } { | |
108 | return 0 | |
109 | } | |
110 | ||
111 | # Test gdb_caching_procs in gdb/testsuite/lib/*.exp | |
112 | set files [eval glob -types f $srcdir/lib/*.exp] | |
61f80d5d | 113 | set files [lsort $files] |
64d27cfc TV |
114 | foreach file $files { |
115 | test_file $file | |
116 | } | |
117 | ||
118 | # Cleanup | |
119 | remote_file build delete $obj |