[PATCH v2 01/12] testsuite: Factor out target feature test template

"Maciej W. Rozycki" <[email protected]>
Newsgroups gmane.comp.gdb.patches
Message-ID <[email protected]>
From: Maciej W. Rozycki <[email protected]>

Implement `allow_target_tests' generic target feature test procedure, 
factoring out duplicate code from tests such as `allow_altivec_tests', 
`allow_power_isa_3_1_tests', `allow_vsx_tests', etc.
---
No change from v1 (1/7),
<https://inbox.sourceware.org/gdb-patches/[email protected]/>.
---
 gdb/testsuite/lib/gdb.exp |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

gdb-test-target-allow.diff
Index: binutils-gdb/gdb/testsuite/lib/gdb.exp
===================================================================
--- binutils-gdb.orig/gdb/testsuite/lib/gdb.exp
+++ binutils-gdb/gdb/testsuite/lib/gdb.exp
@@ -4291,6 +4291,50 @@ gdb_caching_proc libc_has_debug_info {}
     }
 }
 
+# Using name ME for reporting, check for target feature FEATURE, the
+# absence of which is supposed to get message MESSAGE produced by GDB.
+# Use source SRC and optional list of additional compiler flags FLAGS
+# for the check.  Make sure the source provided builds and then that
+# target hardware runs it.
+proc allow_target_tests { me feature message src { flags {} } } {
+    global srcdir subdir gdb_prompt inferior_exited_re
+
+    set compile_flags {}
+    foreach flag $flags {
+	require {have_compile_flag $flag}
+	lappend compile_flags "additional_flags=$flag"
+    }
+
+    if {![gdb_simple_compile $me $src executable $compile_flags]} {
+	return 0
+    }
+
+    gdb_exit
+    gdb_start
+    gdb_reinitialize_dir $srcdir/$subdir
+    gdb_load "$obj"
+    gdb_run_cmd
+    gdb_expect {
+	-re ".*${message}.*${gdb_prompt} $" {
+	    verbose -log "\n$me $feature not detected"
+	    set allow_target_tests 0
+	}
+	-re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
+	    verbose -log "\n$me: $feature detected"
+	    set allow_target_tests 1
+	}
+	default {
+	    warning "\n$me: default case taken"
+	    set allow_target_tests 0
+	}
+    }
+    gdb_exit
+    remote_file build delete $obj
+
+    verbose "$me: returning $allow_target_tests" 2
+    return $allow_target_tests
+}
+
 # Run a test on the target to see if it supports vmx hardware.  Return 1 if so,
 # 0 if it does not.  Based on 'check_vmx_hw_available' from the GCC testsuite.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.