diff mbox

[v2,05/19] gdb/testsuite: Add "get_endianness" convenience proc

Message ID 1494352015-10465-6-git-send-email-arnez@linux.vnet.ibm.com
State New
Headers show

Commit Message

Andreas Arnez May 9, 2017, 5:46 p.m. UTC
The test suite contains multiple instances of determining the target's
endianness with GDB's "show endian" command.  This patch replaces these by
an invocation of a new convenience proc 'get_endianness'.

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (get_endianness): New proc.
	* gdb.arch/aarch64-fp.exp: Use it.
	* gdb.arch/altivec-regs.exp: Likewise.
	* gdb.arch/e500-regs.exp: Likewise.
	* gdb.arch/vsx-regs.exp: Likewise.
	* gdb.base/dump.exp: Likewise.
	* gdb.base/funcargs.exp: Likewise.
	* gdb.base/gnu_vector.exp: Likewise.
	* gdb.dwarf2/formdata16.exp: Likewise.
	* gdb.dwarf2/implptrpiece.exp: Likewise.
	* gdb.dwarf2/nonvar-access.exp: Likewise.
	* gdb.python/py-inferior.exp: Likewise.
	* gdb.trace/unavailable-dwarf-piece.exp: Likewise.
---
 gdb/testsuite/gdb.arch/aarch64-fp.exp               |  9 +--------
 gdb/testsuite/gdb.arch/altivec-regs.exp             | 12 +-----------
 gdb/testsuite/gdb.arch/e500-regs.exp                | 12 +-----------
 gdb/testsuite/gdb.arch/vsx-regs.exp                 | 12 +-----------
 gdb/testsuite/gdb.base/dump.exp                     |  7 +------
 gdb/testsuite/gdb.base/funcargs.exp                 | 12 +++---------
 gdb/testsuite/gdb.base/gnu_vector.exp               |  7 +------
 gdb/testsuite/gdb.dwarf2/formdata16.exp             |  9 +--------
 gdb/testsuite/gdb.dwarf2/implptrpiece.exp           | 10 ++--------
 gdb/testsuite/gdb.dwarf2/nonvar-access.exp          | 10 ++--------
 gdb/testsuite/gdb.python/py-inferior.exp            | 12 +++---------
 gdb/testsuite/gdb.trace/unavailable-dwarf-piece.exp |  8 +-------
 gdb/testsuite/lib/gdb.exp                           | 13 +++++++++++++
 13 files changed, 31 insertions(+), 102 deletions(-)

Comments

Yao Qi May 11, 2017, 9:32 p.m. UTC | #1
On 17-05-09 19:46:01, Andreas Arnez wrote:
> The test suite contains multiple instances of determining the target's
> endianness with GDB's "show endian" command.  This patch replaces these by
> an invocation of a new convenience proc 'get_endianness'.
> 
> gdb/testsuite/ChangeLog:
> 
> 	* lib/gdb.exp (get_endianness): New proc.
> 	* gdb.arch/aarch64-fp.exp: Use it.
> 	* gdb.arch/altivec-regs.exp: Likewise.
> 	* gdb.arch/e500-regs.exp: Likewise.
> 	* gdb.arch/vsx-regs.exp: Likewise.
> 	* gdb.base/dump.exp: Likewise.
> 	* gdb.base/funcargs.exp: Likewise.
> 	* gdb.base/gnu_vector.exp: Likewise.
> 	* gdb.dwarf2/formdata16.exp: Likewise.
> 	* gdb.dwarf2/implptrpiece.exp: Likewise.
> 	* gdb.dwarf2/nonvar-access.exp: Likewise.
> 	* gdb.python/py-inferior.exp: Likewise.
> 	* gdb.trace/unavailable-dwarf-piece.exp: Likewise.

LGTM.
diff mbox

Patch

diff --git a/gdb/testsuite/gdb.arch/aarch64-fp.exp b/gdb/testsuite/gdb.arch/aarch64-fp.exp
index 2faf121..483c8f1 100644
--- a/gdb/testsuite/gdb.arch/aarch64-fp.exp
+++ b/gdb/testsuite/gdb.arch/aarch64-fp.exp
@@ -34,14 +34,7 @@  if ![runto_main] {
     return -1
 }
 
-set endianness "little"
-set test "show endian"
-gdb_test_multiple $test $test {
-    -re "(.* )(big|little)( endian.*)$gdb_prompt $" {
-        set endianness $expect_out(2,string)
-        pass "endianness"
-    }
-}
+set endianness [get_endianness]
 
 gdb_test "break ${srcfile}:[gdb_get_line_number "return"]" \
     "Breakpoint $decimal at 0x\[0-9a-fA-F\]+: file .*${srcfile}.*\\\." \
diff --git a/gdb/testsuite/gdb.arch/altivec-regs.exp b/gdb/testsuite/gdb.arch/altivec-regs.exp
index 680b512..3cf487b 100644
--- a/gdb/testsuite/gdb.arch/altivec-regs.exp
+++ b/gdb/testsuite/gdb.arch/altivec-regs.exp
@@ -77,17 +77,7 @@  gdb_test "set \$vrsave = 1" "" ""
 
 gdb_test "next" "" ""
 
-set endianness ""
-set msg "detect endianness"
-gdb_test_multiple "show endian" "$msg" {
-    -re "(The target endianness is set automatically .currently )(big|little)( endian.*)$gdb_prompt $" {
-        pass "$msg"
-        set endianness $expect_out(2,string)
-    }
-    -re ".*$gdb_prompt $" {
-        fail "$msg"
-    }
-}
+set endianness [get_endianness]
 
 # And then read the AltiVec registers back, to see that
 # a) the register write above worked, and
diff --git a/gdb/testsuite/gdb.arch/e500-regs.exp b/gdb/testsuite/gdb.arch/e500-regs.exp
index 8bf405a..bab6e7d 100644
--- a/gdb/testsuite/gdb.arch/e500-regs.exp
+++ b/gdb/testsuite/gdb.arch/e500-regs.exp
@@ -59,17 +59,7 @@  for {set i 0} {$i < 32} {incr i 1} {
 
 #gdb_test "next" "" ""
 
-send_gdb "show endian\n"
-gdb_expect {
-    -re "(The target endianness is set automatically .currently )(big|little)( endian.*)$gdb_prompt $" {
-        pass "endianness"
-	set endianness $expect_out(2,string)
-    }
-    -re ".*$gdb_prompt $" {
-	fail "couldn't get endianness"
-    }
-    timeout		{ fail "(timeout) endianness" }
-}
+set endianness [get_endianness]
 
 # And then read the E500 registers back, to see that
 # a) the register write above worked, and
diff --git a/gdb/testsuite/gdb.arch/vsx-regs.exp b/gdb/testsuite/gdb.arch/vsx-regs.exp
index bedbcaa..ab01c67 100644
--- a/gdb/testsuite/gdb.arch/vsx-regs.exp
+++ b/gdb/testsuite/gdb.arch/vsx-regs.exp
@@ -56,17 +56,7 @@  if ![runto_main] then {
     gdb_suppress_tests
 }
 
-set endianness ""
-set msg "detect endianness"
-gdb_test_multiple "show endian" "$msg" {
-    -re "(The target endianness is set automatically .currently )(big|little)( endian.*)$gdb_prompt $" {
-        pass "$msg"
-        set endianness $expect_out(2,string)
-    }
-    -re ".*$gdb_prompt $" {
-        fail "$msg"
-    }
-}
+set endianness [get_endianness]
 
 # Data sets used throughout the test
 
diff --git a/gdb/testsuite/gdb.base/dump.exp b/gdb/testsuite/gdb.base/dump.exp
index e67e1aa..a9625d7 100644
--- a/gdb/testsuite/gdb.base/dump.exp
+++ b/gdb/testsuite/gdb.base/dump.exp
@@ -101,12 +101,7 @@  if { ! [ runto checkpoint1 ] } then {
 
 # Get the endianness for the later use with endianless formats.
 
-gdb_test_multiple "show endian" "show endian" {
-    -re ".* (big|little) endian.*$gdb_prompt $" { 
-	set endian $expect_out(1,string) 
-	pass "endianness: $endian"
-    }
-}
+set endian [get_endianness]
 
 # Now generate some dump files.
 
diff --git a/gdb/testsuite/gdb.base/funcargs.exp b/gdb/testsuite/gdb.base/funcargs.exp
index 5852f12..c48b882 100644
--- a/gdb/testsuite/gdb.base/funcargs.exp
+++ b/gdb/testsuite/gdb.base/funcargs.exp
@@ -1139,15 +1139,9 @@  gdb_test_multiple "print sizeof (int)" "getting sizeof int" {
     }
 }
 
-gdb_test_multiple "show endian" "getting target endian" {
-    -re ".*little endian.*$gdb_prompt $" {
-	set target_bigendian_p 0
-	# pass silently
-    }
-    -re ".*big endian.*$gdb_prompt $" {
-	set target_bigendian_p 1
-	# pass silently
-    }
+switch [get_endianness] {
+    little { set target_bigendian_p 0 }
+    big { set target_bigendian_p 1 }
 }
 
 # Perform tests
diff --git a/gdb/testsuite/gdb.base/gnu_vector.exp b/gdb/testsuite/gdb.base/gnu_vector.exp
index 1e0e46c..44b1405 100644
--- a/gdb/testsuite/gdb.base/gnu_vector.exp
+++ b/gdb/testsuite/gdb.base/gnu_vector.exp
@@ -48,12 +48,7 @@  if { ![runto main] } {
 }
 
 # Get endianess for the scalar->vector casts
-gdb_test_multiple "show endian" "show endian" {
-    -re ".* (big|little) endian.*$gdb_prompt $" { 
-	set endian $expect_out(1,string) 
-	pass "endianness: $endian"
-    }
-}
+set endian [get_endianness]
 
 # Test printing of character vector types
 gdb_test "print c4" "\\\$$decimal = \\{1, 2, 3, 4\\}"
diff --git a/gdb/testsuite/gdb.dwarf2/formdata16.exp b/gdb/testsuite/gdb.dwarf2/formdata16.exp
index bba2015..036bf25 100644
--- a/gdb/testsuite/gdb.dwarf2/formdata16.exp
+++ b/gdb/testsuite/gdb.dwarf2/formdata16.exp
@@ -28,14 +28,7 @@  if [prepare_for_testing "failed to prepare for endianness test" ${testfile} ${sr
     return -1
 }
 
-set endianness "little"
-set test "show endian"
-gdb_test_multiple $test $test {
-    -re "(.* )(big|little)( endian.*)\r\n$gdb_prompt $" {
-	set endianness $expect_out(2,string)
-	pass "endianness"
-    }
-}
+set endianness [get_endianness]
 
 set high "0x123456789abcdef0"
 set low "0x0fedcba987654321"
diff --git a/gdb/testsuite/gdb.dwarf2/implptrpiece.exp b/gdb/testsuite/gdb.dwarf2/implptrpiece.exp
index ef483c0..ac3ee78 100644
--- a/gdb/testsuite/gdb.dwarf2/implptrpiece.exp
+++ b/gdb/testsuite/gdb.dwarf2/implptrpiece.exp
@@ -119,14 +119,8 @@  if ![runto_main] {
     return -1
 }
 
-# Determine endianness.
-set endian "little"
-gdb_test_multiple "show endian" "determine endianness" {
-    -re ".* (big|little) endian.*$gdb_prompt $" {
-	set endian $expect_out(1,string)
-	pass "endianness: $endian"
-    }
-}
+# Determine byte order.
+set endian [get_endianness]
 
 # Access the second byte of s through an implicit pointer to the third
 # byte of s, using a negative offset.  Compare that to the second byte of
diff --git a/gdb/testsuite/gdb.dwarf2/nonvar-access.exp b/gdb/testsuite/gdb.dwarf2/nonvar-access.exp
index 5406029..b7d952a 100644
--- a/gdb/testsuite/gdb.dwarf2/nonvar-access.exp
+++ b/gdb/testsuite/gdb.dwarf2/nonvar-access.exp
@@ -205,14 +205,8 @@  if ![runto_main] {
     return -1
 }
 
-# Determine endianness.
-set endian "little"
-gdb_test_multiple "show endian" "determine endianness" {
-    -re ".* (big|little) endian.*$gdb_prompt $" {
-	set endian $expect_out(1,string)
-	pass "endianness: $endian"
-    }
-}
+# Determine byte order.
+set endian [get_endianness]
 
 # Byte-aligned objects with simple location descriptions.
 switch $endian { big {set val 0x345678} little {set val 0x785634} }
diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp
index adb5df3..c2ea2c2 100644
--- a/gdb/testsuite/gdb.python/py-inferior.exp
+++ b/gdb/testsuite/gdb.python/py-inferior.exp
@@ -30,15 +30,9 @@  clean_restart ${testfile}
 # Skip all tests if Python scripting is not enabled.
 if { [skip_python_tests] } { continue }
 
-gdb_test_multiple "show endian" "getting target endian" {
-    -re ".*little endian.*$gdb_prompt $" {
-        set python_pack_char "<"
-	# pass silently
-    }
-    -re ".*big endian.*$gdb_prompt $" {
-        set python_pack_char ">"
-	# pass silently
-    }
+switch [get_endianness] {
+    little { set python_pack_char "<" }
+    big { set python_pack_char ">" }
 }
 
 # The following tests require execution.
diff --git a/gdb/testsuite/gdb.trace/unavailable-dwarf-piece.exp b/gdb/testsuite/gdb.trace/unavailable-dwarf-piece.exp
index 3b14bea..d8a75d4 100644
--- a/gdb/testsuite/gdb.trace/unavailable-dwarf-piece.exp
+++ b/gdb/testsuite/gdb.trace/unavailable-dwarf-piece.exp
@@ -325,13 +325,7 @@  with_test_prefix "tracing bar" {
     gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*"
     gdb_test_no_output "tstop"
 
-    set endian ""
-    gdb_test_multiple "show endian" "show endian" {
-	-re ".* (big|little) endian.*$gdb_prompt $" {
-	    set endian $expect_out(1,string)
-	    pass "endianness: $endian"
-	}
-    }
+    set endian [get_endianness]
 
     gdb_test "tfind 0" "Found trace frame 0, tracepoint .*"
     if { $endian == "little" } {
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 6633d24..a74f974 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5671,6 +5671,19 @@  proc set_remotetimeout { timeout } {
     }
 }
 
+# Get the target's current endianness and return it.
+proc get_endianness { } {
+    global gdb_prompt
+
+    gdb_test_multiple "show endian" "determine endianness" {
+	-re ".* (little|big) endian.*\r\n$gdb_prompt $" {
+	    # Pass silently.
+	    return $expect_out(1,string)
+	}
+    }
+    return "little"
+}
+
 # ROOT and FULL are file names.  Returns the relative path from ROOT
 # to FULL.  Note that FULL must be in a subdirectory of ROOT.
 # For example, given ROOT = /usr/bin and FULL = /usr/bin/ls, this