RFC: refactor gcore checking in test suite

Tom Tromey tromey@redhat.com
Tue Oct 30 17:11:00 GMT 2012


I noticed that many tests copy-and-paste the same code to see if "gcore"
works.

This patch unifies all such instances into a new proc.

Built and regtested on x86-64 Fedora 16.
However, this does not actually exercise every change, so I would
appreciate some extra review.

Tom

2012-10-30  Tom Tromey  <tromey@redhat.com>

	* gdb.threads/gcore-thread.exp: Use gdb_gcore_cmd.
	* gdb.python/py-strfns.exp (test_strfns_core_file): Use
	gdb_gcore_cmd.
	* gdb.cell/gcore.exp: Use gdb_gcore_cmd.
	* gdb.base/gcore.exp: Use gdb_gcore_cmd.
	* gdb.base/gcore-relro.exp: Use gdb_gcore_cmd.
	* gdb.base/gcore-buffer-overflow.exp: Use gdb_gcore_cmd.
	* gdb.base/auxv.exp: Use gdb_gcore_cmd.
	* gdb.arch/vsx-regs.exp: Use gdb_gcore_cmd.
	* gdb.arch/system-gcore.exp: Use gdb_gcore_cmd.
	* gdb.arch/pa-nullify.exp (test_core_bt): Use gdb_gcore_cmd.
	* lib/gdb.exp (gdb_gcore_cmd): New proc.

---
 gdb/testsuite/ChangeLog                          |   15 +++++++++
 gdb/testsuite/gdb.arch/pa-nullify.exp            |   20 +------------
 gdb/testsuite/gdb.arch/system-gcore.exp          |   19 +----------
 gdb/testsuite/gdb.arch/vsx-regs.exp              |   20 +-----------
 gdb/testsuite/gdb.base/auxv.exp                  |   15 +---------
 gdb/testsuite/gdb.base/gcore-buffer-overflow.exp |   15 +---------
 gdb/testsuite/gdb.base/gcore-relro.exp           |   13 +-------
 gdb/testsuite/gdb.base/gcore.exp                 |   20 +-----------
 gdb/testsuite/gdb.cell/gcore.exp                 |   14 +-------
 gdb/testsuite/gdb.python/py-strfns.exp           |   17 ++--------
 gdb/testsuite/gdb.threads/gcore-thread.exp       |   14 +--------
 gdb/testsuite/lib/gdb.exp                        |   35 ++++++++++++++++++++++
 12 files changed, 68 insertions(+), 149 deletions(-)

diff --git a/gdb/testsuite/gdb.arch/pa-nullify.exp b/gdb/testsuite/gdb.arch/pa-nullify.exp
index e3223d9..2ad3af6 100644
--- a/gdb/testsuite/gdb.arch/pa-nullify.exp
+++ b/gdb/testsuite/gdb.arch/pa-nullify.exp
@@ -107,26 +107,8 @@ gdb_test "stepi" "in main.*" "stepi to main"
 
 proc gen_core { test } {
   global gcorefile
-  global gdb_prompt
-  set gcore_works 0
-  set escapedfilename [string_to_regexp $gcorefile]
-
-  # gcore is not yet implemented for HPUX
-  setup_xfail hppa*-*-hpux*
-
-  gdb_test_multiple "gcore $gcorefile" "$test: gcore" {
-    -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
-      pass "$test: gcore"
-      set gcore_works 1
-    }
-    -re "Undefined command.*$gdb_prompt $" {
-      fail "$test: gcore (undefined command)"
-    }
-    -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
-      fail "$test: gcore (can't create corefile)"
-    }
-  }
 
+  set gcore_works [gdb_gcore_cmd $gcorefile "$test: gcore"]
   return $gcore_works
 }
 
diff --git a/gdb/testsuite/gdb.arch/system-gcore.exp b/gdb/testsuite/gdb.arch/system-gcore.exp
index ab97f69..f631b45 100644
--- a/gdb/testsuite/gdb.arch/system-gcore.exp
+++ b/gdb/testsuite/gdb.arch/system-gcore.exp
@@ -95,23 +95,8 @@ set pre_corefile_local_array \
 set pre_corefile_extern_array \
 	[capture_command_output "print extern_array" "$print_prefix"]
 
-set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore.test]
-
-set core_supported 0
-gdb_test_multiple "gcore ${objdir}/${subdir}/gcore.test" \
-	"save a corefile" \
-{
-  -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
-    pass "save a corefile"
-    global core_supported
-    set core_supported 1
-  }
-  -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
-    unsupported "save a corefile"
-    global core_supported
-    set core_supported 0
-  }
-}
+set core_supported [gdb_gcore_cmd "${objdir}/${subdir}/gcore.test" \
+			"save a corefile"]
 
 if {!$core_supported} {
   return -1
diff --git a/gdb/testsuite/gdb.arch/vsx-regs.exp b/gdb/testsuite/gdb.arch/vsx-regs.exp
index d015787..5f23444 100644
--- a/gdb/testsuite/gdb.arch/vsx-regs.exp
+++ b/gdb/testsuite/gdb.arch/vsx-regs.exp
@@ -128,24 +128,8 @@ for {set i 0} {$i < 32} {incr i 1} {
 # later when loading the core file (i.e., different register values for different
 # vector register banks).
 
-set escapedfilename [string_to_regexp ${objdir}/${subdir}/vsx-core.test]
-
-set core_supported 0
-
-gdb_test_multiple "gcore ${objdir}/${subdir}/vsx-core.test" \
-        "Save a VSX-enabled corefile" \
-{
-  -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
-    pass "Save a VSX-enabled corefile"
-    global core_supported
-    set core_supported 1
-  }
-  -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
-    unsupported "Save a VSX-enabled corefile"
-    global core_supported
-    set core_supported 0
-  }
-}
+set core_supported [gdb_gcore_cmd "${objdir}/${subdir}/vsx-core.test" \
+			"Save a VSX-enabled corefile"]
 
 # Now run the F32~F63/VR0~VR31 tests.
 
diff --git a/gdb/testsuite/gdb.base/auxv.exp b/gdb/testsuite/gdb.base/auxv.exp
index 16f12c7..0c7bac4 100644
--- a/gdb/testsuite/gdb.base/auxv.exp
+++ b/gdb/testsuite/gdb.base/auxv.exp
@@ -127,20 +127,7 @@ proc fetch_auxv {test} {
 set live_data [fetch_auxv "info auxv on live process"]
 
 # Now try gcore.
-set gcore_works 0
-set escapedfilename [string_to_regexp $gcorefile]
-gdb_test_multiple "gcore $gcorefile" "gcore" {
-    -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
-	pass "gcore"
-	set gcore_works 1
-    }
-    -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
-	unsupported "gcore"
-    }
-    -re "Undefined command: .*\[\r\n\]+$gdb_prompt $" {
-	unsupported "gcore"
-    }
-}
+set gcore_works [gdb_gcore_cmd "$gcorefile" "gcore"]
 
 # Let the program continue and die.
 gdb_test continue ".*Program received signal.*"
diff --git a/gdb/testsuite/gdb.base/gcore-buffer-overflow.exp b/gdb/testsuite/gdb.base/gcore-buffer-overflow.exp
index 7736bb8..13c3e75 100644
--- a/gdb/testsuite/gdb.base/gcore-buffer-overflow.exp
+++ b/gdb/testsuite/gdb.base/gcore-buffer-overflow.exp
@@ -55,17 +55,4 @@ if { ! [ runto_main ] } then {
     return -1
 }
 
-set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore-buffer-overflow.test]
-
-set test "save a corefile"
-gdb_test_multiple "gcore ${objdir}/${subdir}/gcore-buffer-overflow.test" $test {
-    -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
-	pass $test
-    }
-    -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
-	unsupported $test
-    }
-    eof {
-	fail $test
-    }
-}
+gdb_gcore_cmd "${objdir}/${subdir}/gcore-buffer-overflow.test" "save a corefile"
diff --git a/gdb/testsuite/gdb.base/gcore-relro.exp b/gdb/testsuite/gdb.base/gcore-relro.exp
index 5b8d6c7..b35126d 100644
--- a/gdb/testsuite/gdb.base/gcore-relro.exp
+++ b/gdb/testsuite/gdb.base/gcore-relro.exp
@@ -55,17 +55,8 @@ if ![runto lib] {
     return -1
 }
 
-set escapedfilename [string_to_regexp ${gcorefile}]
-
-set test "save a corefile"
-gdb_test_multiple "gcore ${gcorefile}" $test {
-    -re "Saved corefile ${escapedfilename}\r\n$gdb_prompt $" {
-	pass $test
-    }
-    -re "Can't create a corefile\r\n$gdb_prompt $" {
-	unsupported $test
-	return -1
-    }
+if {![gdb_gcore_cmd $gcorefile "save a corefile"]} {
+    return -1
 }
 
 # Now restart gdb and load the corefile.
diff --git a/gdb/testsuite/gdb.base/gcore.exp b/gdb/testsuite/gdb.base/gcore.exp
index faa8fa7..a6db867 100644
--- a/gdb/testsuite/gdb.base/gcore.exp
+++ b/gdb/testsuite/gdb.base/gcore.exp
@@ -85,24 +85,8 @@ set pre_corefile_local_array \
 set pre_corefile_extern_array \
 	[capture_command_output "print extern_array" "$print_prefix"]
 
-set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore.test]
-
-set core_supported 0
-gdb_test_multiple "gcore ${objdir}/${subdir}/gcore.test" \
-	"save a corefile" \
-{
-  -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
-    pass "save a corefile"
-    global core_supported
-    set core_supported 1
-  }
-  -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
-    unsupported "save a corefile"
-    global core_supported
-    set core_supported 0
-  }
-}
-
+set core_supported [gdb_gcore_cmd "${objdir}/${subdir}/gcore.test" \
+			"save a corefile"]
 if {!$core_supported} {
   return -1
 }
diff --git a/gdb/testsuite/gdb.cell/gcore.exp b/gdb/testsuite/gdb.cell/gcore.exp
index c05bc4a..c6c8d8c 100644
--- a/gdb/testsuite/gdb.cell/gcore.exp
+++ b/gdb/testsuite/gdb.cell/gcore.exp
@@ -69,21 +69,11 @@ delete_breakpoints
 
 gdb_test "continue" ".*Aborted.*"
 
-set escapedfilename [string_to_regexp ${objdir}/${subdir}/gcore.test]
-
-gdb_test_multiple "gcore ${objdir}/${subdir}/gcore.test" \
-        "save a corefile" \
-{
-  -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
-    pass "save a corefile"
-  }
-  -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
-    unsupported "save a corefile"
+if {![gdb_gcore_cmd "${objdir}/${subdir}/gcore.test" \
+	  "save a corefile"]} {
     return -1
-  }
 }
 
-
 # Now restart gdb and load the corefile.
 gdb_exit
 gdb_start
diff --git a/gdb/testsuite/gdb.python/py-strfns.exp b/gdb/testsuite/gdb.python/py-strfns.exp
index 88d6cdf..ddc384f 100644
--- a/gdb/testsuite/gdb.python/py-strfns.exp
+++ b/gdb/testsuite/gdb.python/py-strfns.exp
@@ -67,20 +67,11 @@ proc test_strfns_core_file { } {
     global objdir subdir gdb_prompt testfile
 
     set filename "${objdir}/${subdir}/py-strfns.core"
-    set escapedfilename [string_to_regexp $filename]
 
-    gdb_test_multiple "gcore $filename" \
-	"save a corefile" \
-	{
-	    -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
-		pass "save a corefile"
-	    }
-	    -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
-		unsupported "save a corefile"
-		# No use proceeding from here.
-		return
-	    }
-	}
+    if {![gdb_gcore_cmd "$filename" "save a corefile"]} {
+	# No use proceeding from here.
+	return
+    }
 
     clean_restart $testfile
 
diff --git a/gdb/testsuite/gdb.threads/gcore-thread.exp b/gdb/testsuite/gdb.threads/gcore-thread.exp
index 37eadd3..97189b9 100644
--- a/gdb/testsuite/gdb.threads/gcore-thread.exp
+++ b/gdb/testsuite/gdb.threads/gcore-thread.exp
@@ -91,20 +91,8 @@ delete_breakpoints
 gdb_breakpoint "thread2"
 gdb_test "continue" "Continuing.*Breakpoint.* thread2 .*" "thread 2 is running"
 
-set escapedfilename [string_to_regexp $corefile]
 # Drop corefile
-set core_supported 0
-gdb_test_multiple "gcore $corefile" "save a corefile" \
-{
-  -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
-    pass "save a corefile"
-    global core_supported
-    set core_supported 1
-  }
-  -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
-    unsupported "save a corefile"
-  }
-}
+set core_supported [gdb_gcore_cmd "$corefile" "save a corefile"]
 
 if {!$core_supported} {
   return -1
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index a972045..0851df0 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3026,6 +3026,41 @@ proc gdb_load_cmd { args } {
     return -1
 }
 
+# Invoke "gcore".  CORE is the name of the core file to write.  TEST
+# is the name of the test case.  This will return 1 if the core file
+# was created, 0 otherwise.  If this fails to make a core file due to
+# some error, it will call "unsupported", not "fail".  However, if
+# this fails to make a core file due to an EOF from gdb, then it will
+# call "fail".
+
+proc gdb_gcore_cmd {core test} {
+    global gdb_prompt
+
+    set result 0
+    gdb_test_multiple "gcore $core" $test {
+	-re "Saved corefile .*\[\r\n\]+$gdb_prompt $" {
+	    pass $test
+	    set result 1
+	}
+
+	-re "Undefined command.*$gdb_prompt $" {
+	    unsupported $test
+	    verbose -log "'gcore' command undefined in gdb_gcore_cmd"
+	}
+
+	-re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
+	    unsupported $test
+	}
+
+	eof {
+	    # Catastrophe.
+	    fail $test
+	}
+    }
+
+    return $result
+}
+
 # Return the filename to download to the target and load on the target
 # for this shared library.  Normally just LIBNAME, unless shared libraries
 # for this target have separate link and load images.
-- 
1.7.7.6



More information about the Gdb-patches mailing list