[02/46] Change 'require' to accept a list of predicates

Message ID 20221217000818.3729389-3-tom@tromey.com
State Committed
Headers
Series Rewrite "require" test procedure and use it more often |

Commit Message

Tom Tromey Dec. 17, 2022, 12:07 a.m. UTC
  This changes 'require' to accept a list of simple predicates.  For
now, each predicate is just the name of a proc, optionally prefixed
with "!" to indicate that the result should be inverted.

It's possible to make this fancier, but so far I haven't done so.  One
idea I had is to allow a predicate to have associated text to display
on failure.  Another is to convert the predicates that need a running
gdb (e.g., skip_python_tests) to start their own gdb, and then
'require' could enforce the rule that gdb not be running when it is
called.
---
 gdb/testsuite/gdb.base/valgrind-bt.exp        |  2 +-
 gdb/testsuite/gdb.base/valgrind-disp-step.exp |  2 +-
 gdb/testsuite/gdb.base/valgrind-infcall-2.exp |  2 +-
 gdb/testsuite/gdb.base/valgrind-infcall.exp   |  2 +-
 gdb/testsuite/gdb.dwarf2/dw2-lines.exp        |  2 +-
 .../gdb.dwarf2/dw2-symtab-includes-lookup.exp |  2 +-
 .../frame-inlined-in-outer-frame.exp          |  2 +-
 gdb/testsuite/gdb.mi/mi-async.exp             |  2 +-
 gdb/testsuite/gdb.reverse/insn-reverse.exp    |  2 +-
 gdb/testsuite/gdb.tui/tui-missing-src.exp     |  2 +-
 gdb/testsuite/lib/gdb.exp                     | 51 ++++++++-----------
 11 files changed, 30 insertions(+), 41 deletions(-)
  

Patch

diff --git a/gdb/testsuite/gdb.base/valgrind-bt.exp b/gdb/testsuite/gdb.base/valgrind-bt.exp
index 5dba34e2348..e3399dfc767 100644
--- a/gdb/testsuite/gdb.base/valgrind-bt.exp
+++ b/gdb/testsuite/gdb.base/valgrind-bt.exp
@@ -14,7 +14,7 @@ 
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # Valgrind gdbserver requires gdb with xml support.
-require gdb_skip_xml_test 0
+require !gdb_skip_xml_test
 
 load_lib valgrind.exp
 
diff --git a/gdb/testsuite/gdb.base/valgrind-disp-step.exp b/gdb/testsuite/gdb.base/valgrind-disp-step.exp
index ee0ed660565..896ea2875b9 100644
--- a/gdb/testsuite/gdb.base/valgrind-disp-step.exp
+++ b/gdb/testsuite/gdb.base/valgrind-disp-step.exp
@@ -19,7 +19,7 @@ 
 # automatically instead of getting stuck or crashing.
 
 # Valgrind gdbserver requires gdb with xml support.
-require gdb_skip_xml_test 0
+require !gdb_skip_xml_test
 
 load_lib valgrind.exp
 
diff --git a/gdb/testsuite/gdb.base/valgrind-infcall-2.exp b/gdb/testsuite/gdb.base/valgrind-infcall-2.exp
index a001561aed3..b59d8b14c01 100644
--- a/gdb/testsuite/gdb.base/valgrind-infcall-2.exp
+++ b/gdb/testsuite/gdb.base/valgrind-infcall-2.exp
@@ -30,7 +30,7 @@ 
 # Aborted (core dumped)
 
 # Valgrind gdbserver requires gdb with xml support.
-require gdb_skip_xml_test 0
+require !gdb_skip_xml_test
 
 load_lib valgrind.exp
 
diff --git a/gdb/testsuite/gdb.base/valgrind-infcall.exp b/gdb/testsuite/gdb.base/valgrind-infcall.exp
index 87d7c6b8a50..389cdaa9bc0 100644
--- a/gdb/testsuite/gdb.base/valgrind-infcall.exp
+++ b/gdb/testsuite/gdb.base/valgrind-infcall.exp
@@ -14,7 +14,7 @@ 
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # Valgrind gdbserver requires gdb with xml support.
-require gdb_skip_xml_test 0
+require !gdb_skip_xml_test
 
 load_lib valgrind.exp
 
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-lines.exp b/gdb/testsuite/gdb.dwarf2/dw2-lines.exp
index b24eec0c8d2..b3e0aff446e 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-lines.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-lines.exp
@@ -18,7 +18,7 @@ 
 load_lib dwarf.exp
 
 # This test can only be run on targets which support DWARF-2 and use gas.
-require dwarf2_support 1
+require dwarf2_support
 
 standard_testfile .c
 
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-symtab-includes-lookup.exp b/gdb/testsuite/gdb.dwarf2/dw2-symtab-includes-lookup.exp
index 0390d36f74e..c8df4b46477 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-symtab-includes-lookup.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-symtab-includes-lookup.exp
@@ -40,7 +40,7 @@ 
 load_lib dwarf.exp
 
 # This test can only be run on targets which support DWARF-2 and use gas.
-require dwarf2_support 1
+require dwarf2_support
 
 standard_testfile main.c .S
 
diff --git a/gdb/testsuite/gdb.dwarf2/frame-inlined-in-outer-frame.exp b/gdb/testsuite/gdb.dwarf2/frame-inlined-in-outer-frame.exp
index 02f9d13af77..cb208c430db 100644
--- a/gdb/testsuite/gdb.dwarf2/frame-inlined-in-outer-frame.exp
+++ b/gdb/testsuite/gdb.dwarf2/frame-inlined-in-outer-frame.exp
@@ -26,7 +26,7 @@ 
 # directives.
 
 # Check if starti command is supported.
-require use_gdb_stub 0
+require !use_gdb_stub
 
 load_lib dwarf.exp
 
diff --git a/gdb/testsuite/gdb.mi/mi-async.exp b/gdb/testsuite/gdb.mi/mi-async.exp
index 756ca112820..5687c9ac335 100644
--- a/gdb/testsuite/gdb.mi/mi-async.exp
+++ b/gdb/testsuite/gdb.mi/mi-async.exp
@@ -26,7 +26,7 @@  if {!([isnative] && [istarget *-linux*])} {
 }
 
 # Check if start command is supported.
-require use_gdb_stub 0
+require !use_gdb_stub
 
 # The plan is for async mode to become the default but toggle for now.
 set saved_gdbflags $GDBFLAGS
diff --git a/gdb/testsuite/gdb.reverse/insn-reverse.exp b/gdb/testsuite/gdb.reverse/insn-reverse.exp
index 82ae39f9cd9..e16866e1433 100644
--- a/gdb/testsuite/gdb.reverse/insn-reverse.exp
+++ b/gdb/testsuite/gdb.reverse/insn-reverse.exp
@@ -18,7 +18,7 @@  if ![supports_reverse] {
 }
 
 # Check if start command is supported.
-require use_gdb_stub 0
+require !use_gdb_stub
 
 standard_testfile
 
diff --git a/gdb/testsuite/gdb.tui/tui-missing-src.exp b/gdb/testsuite/gdb.tui/tui-missing-src.exp
index d1fac0b5811..1cb1bb1fbad 100644
--- a/gdb/testsuite/gdb.tui/tui-missing-src.exp
+++ b/gdb/testsuite/gdb.tui/tui-missing-src.exp
@@ -26,7 +26,7 @@ 
 # 7. Going back to main() shall result in no contents again.
 
 # Check if start command is supported.
-require use_gdb_stub 0
+require !use_gdb_stub
 
 tuiterm_env
 
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 132d538957c..62e519a3cb7 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -9022,41 +9022,30 @@  gdb_caching_proc have_avx {
     return $status
 }
 
-# Called as either:
-# - require EXPR VAL
-# - require EXPR OP VAL
-# In the first case, OP is ==.
-#
-# Require EXPR OP VAL, where EXPR is evaluated in caller context.  If not,
-# return in the caller's context.
-
-proc require { fn arg1 {arg2 ""} } {
-    if { $arg2 == "" } {
-	set op ==
-	set val $arg1
-    } else {
-	set op $arg1
-	set val $arg2
-    }
-    set res [uplevel 1 $fn]
-    if { [expr $res $op $val] } {
-	return
-    }
+# Called as
+# - require ARG...
+#
+# ARG can either be a name, or of the form !NAME.
+#
+# Each name is a proc to evaluate in the caller's context.  It returns
+# a boolean, and a "!" means to invert the result.  If this is
+# nonzero, all is well.  If it is zero, an "untested" is emitted and
+# this proc causes the caller to return.
 
-    switch "$fn $op $val" {
-	"gdb_skip_xml_test == 0" { set msg "missing xml support" }
-	"ensure_gdb_index $binfile != -1" -
-	"ensure_gdb_index $binfile -dwarf-5 != -1" {
-	    set msg "Couldn't ensure index in binfile"
+proc require { args } {
+    foreach arg $args {
+	if {[string index $arg 0] == "!"} {
+	    set ok 0
+	    set fn [string range $arg 1 end]
+	} else {
+	    set ok 1
+	    set fn $arg
 	}
-	"use_gdb_stub == 0" {
-	    set msg "Remote stub used"
+	if {$ok != !![uplevel 1 $fn]} {
+	    untested "require failed: $arg"
+	    return -code return 0
 	}
-	default { set msg "$fn != $val" }
     }
-
-    untested $msg
-    return -code return 0
 }
 
 # Wait up to ::TIMEOUT seconds for file PATH to exist on the target system.