This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] Introduce test setup helpers.


Presently, most tests in GDB testsuite have quite a bunch of boilerplate
code to compile the test case and load it into GDB. This patch introduces
some helper functions, and as a proof of concept converts some tests to use
those. 

OK?

- Volodya

	* lib/gdb.exp (build_executable, clean_restart)
	(prepare_for_testing): New.
	* gdb.base/break.exp: Use prepare_for_testing, and clean_restart.
	* gdb.base/return.exp: Likewise.
	* gdb.base/ending-run.exp: Likewise.
---
 gdb/testsuite/gdb.base/break.exp      |   82 ++-------------------------------
 gdb/testsuite/gdb.base/ending-run.exp |   23 +--------
 gdb/testsuite/gdb.base/return.exp     |   23 +--------
 gdb/testsuite/lib/gdb.exp             |   71 ++++++++++++++++++++++++++++
 4 files changed, 80 insertions(+), 119 deletions(-)

diff --git a/gdb/testsuite/gdb.base/break.exp b/gdb/testsuite/gdb.base/break.exp
index 2e042dd..387396c 100644
--- a/gdb/testsuite/gdb.base/break.exp
+++ b/gdb/testsuite/gdb.base/break.exp
@@ -19,49 +19,11 @@
 
 # This file was written by Rob Savoye. (rob@cygnus.com)
 
-if $tracelevel then {
-    strace $tracelevel
-}
-
-
-#
-# test running programs
-#
-set prms_id 0
-set bug_id 0
-
-set testfile "break"
-set srcfile ${testfile}.c
-set srcfile1 ${testfile}1.c
-set binfile ${objdir}/${subdir}/${testfile}
-
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
-     untested break.exp
-     return -1
-}
-
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
-     untested break.exp
-     return -1
-}
-
-if  { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
-     untested break.exp
-     return -1
-}
-
-if [get_compiler_info ${binfile}] {
+if { [prepare_for_testing break.exp "break" {break.c break1.c} {debug nowarnings}] } {
     return -1
 }
-
-gdb_exit
-gdb_start
-gdb_reinitialize_dir $srcdir/$subdir
-gdb_load ${binfile}
-
-if [target_info exists gdb_stub] {
-    gdb_step_for_stub;
-}
+set srcfile break.c
+set srcfile1 break1.c
 #
 # test simple breakpoint setting commands
 #
@@ -845,36 +807,10 @@ test_next_with_recursion
 # build a new file with optimization enabled so that we can try breakpoints
 # on targets with optimized prologues
 
-set binfileo2 ${objdir}/${subdir}/${testfile}o2
-
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}O0.o" object {debug nowarnings optimize=-O2}] != "" } {
-     untested break.exp
-     return -1
-}
-
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}O1.o" object {debug nowarnings optimize=-O2}] != "" } {
-     untested break.exp
-     return -1
-}
-
-if  { [gdb_compile "${binfile}O0.o ${binfile}O1.o" "${binfileo2}" executable {debug nowarnings}] != "" } {
-     untested break.exp
-     return -1
-}
-
-if [get_compiler_info ${binfileo2}] {
+if { [prepare_for_testing break.exp "breako2" {break.c break1.c} {debug nowarnings optimize=-O2}] } {
     return -1
 }
 
-gdb_exit
-gdb_start
-gdb_reinitialize_dir $srcdir/$subdir
-gdb_load ${binfileo2}
-
-if [target_info exists gdb_stub] {
-    gdb_step_for_stub;
-}
-
 #
 # test break at function
 #
@@ -943,15 +879,7 @@ gdb_expect {
     }
 }
 
-
-gdb_exit
-gdb_start
-gdb_reinitialize_dir $srcdir/$subdir
-gdb_load ${binfile}
-
-if [target_info exists gdb_stub] {
-    gdb_step_for_stub;
-}
+clean_restart breako2
 
 #
 # test that 'rbreak' on a symbol that may be from a shared library doesn't
diff --git a/gdb/testsuite/gdb.base/ending-run.exp b/gdb/testsuite/gdb.base/ending-run.exp
index 75c16b2..c8a5712 100644
--- a/gdb/testsuite/gdb.base/ending-run.exp
+++ b/gdb/testsuite/gdb.base/ending-run.exp
@@ -22,30 +22,11 @@
 
 # ending-run.exp -- Expect script to test ending a test run in gdb
 
-if $tracelevel then {
-    strace $tracelevel
+if { [prepare_for_testing ending-run.exp ending-run] } {
+    return -1
 }
-
-set testfile ending-run
-set srcfile ${testfile}.c
-set binfile ${objdir}/${subdir}/${testfile}
-
-remote_exec build "rm -f ${binfile}"
 remote_exec build "rm -f core"
 
-
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
-     untested ending-run.exp
-     return -1
-}
-
-
-
-gdb_exit
-gdb_start
-gdb_reinitialize_dir $srcdir/$subdir
-gdb_load ${binfile}
-
 # CHFts23469: Test that you can "clear" a bp set at
 # a line _before_ the routine (which will default to the
 # first line in the routine, which turns out to correspond
diff --git a/gdb/testsuite/gdb.base/return.exp b/gdb/testsuite/gdb.base/return.exp
index accb1ca..d157026 100644
--- a/gdb/testsuite/gdb.base/return.exp
+++ b/gdb/testsuite/gdb.base/return.exp
@@ -18,19 +18,8 @@
 
 # This file was written by Jeff Law. (law@cs.utah.edu)
 
-if $tracelevel then {
-	strace $tracelevel
-}
-
-set prms_id 0
-set bug_id 0
-
-set testfile "return"
-set srcfile ${testfile}.c
-set binfile ${objdir}/${subdir}/${testfile}
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
-     untested return.exp
-     return -1
+if { [prepare_for_testing return.exp "return"] } {
+    return -1
 }
 
 proc return_tests { } {
@@ -104,13 +93,5 @@ proc return_tests { } {
     gdb_test "p tmp3" ".* = 5.*" "correct value returned double test (known problem with sparc solaris)"
 }
 
-
-# Start with a fresh gdb.
-
-gdb_exit
-gdb_start
-gdb_reinitialize_dir $srcdir/$subdir
-gdb_load ${binfile}
-
 set timeout 30
 return_tests
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 70ae6c9..8814e24 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -2653,3 +2653,74 @@ proc test_prefix_command_help { command_list expected_initial_lines args } {
         help_test_raw "help ${command}" $l_entire_body
     }
 }
+
+# Build executable named EXECUTABLE, from SOURCES.  If SOURCES are not
+# provided, uses $EXECUTABLE.c.  The TESTNAME paramer is the name of test
+# to pass to untested, if something is wrong.  OPTIONS are passed
+# to gdb_compile directly.
+proc build_executable { testname executable {sources ""} {options {debug}} } {
+
+    global objdir
+    global subdir
+    global srcdir
+    if {[llength $sources]==0} {
+        set sources ${executable}.c
+    }
+
+    set binfile ${objdir}/${subdir}/${executable}
+
+    set objects {}
+    for {set i 0} "\$i<[llength $sources]" {incr i} {
+        set s [lindex $sources $i]
+        if  { [gdb_compile "${srcdir}/${subdir}/${s}" "${binfile}${i}.o" object $options] != "" } {
+            untested $testname
+            return -1
+        }
+        lappend objects "${binfile}${i}.o"
+    }
+    
+    if  { [gdb_compile $objects "${binfile}" executable $options] != "" } {
+        untested $testname
+        return -1
+    }
+
+    if [get_compiler_info ${binfile}] {
+        return -1
+    }
+    return 0
+}
+
+# Starts fresh GDB binary and loads EXECUTABLE into GDB. EXECUTABLE is
+# the name of binary in ${objdir}/${subdir}.
+proc clean_restart { executable } {
+    global srcdir
+    global objdir
+    global subdir
+    set binfile ${objdir}/${subdir}/${executable}
+
+    gdb_exit
+    gdb_start
+    gdb_reinitialize_dir $srcdir/$subdir
+    gdb_load ${binfile}
+
+    if [target_info exists gdb_stub] {
+        gdb_step_for_stub;
+    }    
+}
+
+# Prepares for testing, by calling build_executable, and then clean_restart.
+# Please refer to build_executable for parameter description.
+proc prepare_for_testing { testname executable {sources ""} {options {debug}}} {
+
+    global tracelevel
+    if $tracelevel then {
+        strace $tracelevel
+    }
+
+    if {[build_executable $testname $executable $sources] == -1} {
+        return -1
+    }
+    clean_restart $executable
+
+    return 0
+}
-- 
1.5.3.5


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]