1 1.1 christos # Copyright 2018-2024 Free Software Foundation, Inc. 2 1.1 christos 3 1.1 christos # This program is free software; you can redistribute it and/or modify 4 1.1 christos # it under the terms of the GNU General Public License as published by 5 1.1 christos # the Free Software Foundation; either version 3 of the License, or 6 1.1 christos # (at your option) any later version. 7 1.1 christos # 8 1.1 christos # This program is distributed in the hope that it will be useful, 9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 1.1 christos # GNU General Public License for more details. 12 1.1 christos # 13 1.1 christos # You should have received a copy of the GNU General Public License 14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 1.1 christos 16 1.1 christos # When caching a proc using gdb_caching_proc, it will become less likely to 17 1.1 christos # be executed, and consequently it's going to be harder to detect that the 18 1.1 christos # proc is racy. OTOH, in general the proc is easy to rerun. So, run all 19 1.1 christos # uncached gdb_caching_procs a number of times and detect inconsistent results. 20 1.1 christos # The purpose of caching is to reduce runtime, so rerunning is somewhat 21 1.1 christos # counter-productive in that aspect, but it's better than uncached, because the 22 1.1 christos # number of reruns is constant-bounded, and the increase in runtime is bound to 23 1.1 christos # this test-case, and could be disabled on slow targets. 24 1.1 christos 25 1.1 christos # Test gdb_caching_proc NAME 26 1.1 christos proc test_proc { name } { 27 1.1 christos set real_name gdb_real__$name 28 1.1 christos 29 1.1 christos set resultlist [list] 30 1.1 christos 31 1.1 christos with_test_prefix initial { 32 1.1 christos set first [gdb_do_cache_wrap $real_name] 33 1.1 christos } 34 1.1 christos lappend resultlist $first 35 1.1 christos 36 1.1 christos # Ten repetitions was enough to trigger target_supports_scheduler_locking, 37 1.1 christos # and costs about 20 seconds on an i7-6600U. 38 1.1 christos set repeat 10 39 1.1 christos 40 1.1 christos set racy 0 41 1.1 christos for {set i 0} {$i < $repeat} {incr i} { 42 1.1 christos with_test_prefix $i { 43 1.1 christos set rerun [gdb_do_cache_wrap $real_name] 44 1.1 christos } 45 1.1 christos lappend resultlist $rerun 46 1.1 christos if { $rerun != $first } { 47 1.1 christos set racy 1 48 1.1 christos } 49 1.1 christos } 50 1.1 christos 51 1.1 christos if { $racy == 0 } { 52 1.1 christos pass "consistency" 53 1.1 christos } else { 54 1.1 christos fail "consistency" 55 1.1 christos verbose -log "$name: $resultlist" 56 1.1 christos } 57 1.1 christos } 58 1.1 christos 59 1.1 christos # Test gdb_caching_procs in FILE 60 1.1 christos proc test_file { file } { 61 1.1 christos upvar obj obj 62 1.1 christos set procnames [list] 63 1.1 christos 64 1.1 christos set fp [open $file] 65 1.1 christos while { [gets $fp line] >= 0 } { 66 1.1 christos if [regexp -- "^gdb_caching_proc \[ \t\]*(\[^ \t\]*)" $line \ 67 1.1 christos match procname] { 68 1.1 christos lappend procnames $procname 69 1.1 christos } 70 1.1 christos } 71 1.1 christos close $fp 72 1.1 christos 73 1.1 christos if { [llength $procnames] == 0 } { 74 1.1 christos return 75 1.1 christos } 76 1.1 christos 77 1.1 christos if { [file tail $file] == "gdb.exp" } { 78 1.1 christos # Already loaded 79 1.1 christos } else { 80 1.1 christos load_lib [file tail $file] 81 1.1 christos } 82 1.1 christos 83 1.1 christos foreach procname $procnames { 84 1.1 christos if { [info args $procname] != "" } { 85 1.1 christos # With args. 86 1.1 christos continue 87 1.1 christos } 88 1.1 christos with_test_prefix $procname { 89 1.1 christos switch $procname { 90 1.1 christos "is_address_zero_readable" { set setup_gdb 1 } 91 1.1 christos "target_is_gdbserver" { set setup_gdb 1 } 92 1.1 christos "supports_memtag" { set setup_gdb 1 } 93 1.1 christos "have_native_target" { set setup_gdb 1 } 94 1.1 christos default {set setup_gdb 0 } 95 1.1 christos } 96 1.1 christos 97 1.1 christos if { $setup_gdb } { 98 1.1 christos clean_restart $obj 99 1.1 christos } 100 1.1 christos 101 1.1 christos test_proc $procname 102 1.1 christos 103 1.1 christos gdb_exit 104 1.1 christos } 105 1.1 christos } 106 1.1 christos } 107 1.1 christos 108 1.1 christos # Init 109 1.1 christos set me "gdb_caching_proc" 110 1.1 christos set src { int main() { return 0; } } 111 1.1 christos if { ![gdb_simple_compile $me $src executable] } { 112 1.1 christos return 0 113 1.1 christos } 114 1.1 christos 115 1.1 christos # Test gdb_caching_procs in gdb/testsuite/lib/*.exp 116 1.1 christos set files [eval glob -types f $srcdir/lib/*.exp] 117 1.1 christos set files [lsort $files] 118 1.1 christos foreach file $files { 119 1.1 christos test_file $file 120 1.1 christos } 121 1.1 christos 122 1.1 christos # Cleanup 123 1.1 christos remote_file build delete $obj 124