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]

FYI: introduce procs for test suite cleanup


I'm checking this in.

This is the first of a rather large series to start cleaning up the test
suite.

The first sub-series just does some minor cleanups to transform things
like:

    set testfile "jprint"
    set srcfile ${srcdir}/$subdir/${testfile}.java
    set binfile ${objdir}/${subdir}/${testfile}

to

    standard_testfile .java

The idea here is to eliminate boilerplate and the possibilities for bugs
of the sort discussed in another thread -- for example the way that
multiple tests in gdb.base use the same executable name.

standard_testfile is just a convenience proc that sets up various
globals that are typically used in tests.  The values are based on the
.exp file's name, and in particular the executable's name is chosen this
way.

This approach can't be used everywhere, but it does work for the vast
majority of files.

This patch also introduces standard_output_file, which computes the
appropriate name of some output file.  The idea here is that,
eventually, tests should not refer to $objdir themselves; in the long
term what I would like to do is run each .exp file in its own subdir, to
ensure as much test isolation as possible.

This series also makes some incidental cleanups; for example using
prepare_for_testing in more places.

Tom

2012-06-22  Tom Tromey  <tromey@redhat.com>

	* lib/gdb.exp (default_gdb_init): Set gdb_test_file_name.
	(standard_output_file, standard_testfile): New procs.
	(build_executable, clean_restart): Use standard_output_file.

Index: lib/gdb.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/lib/gdb.exp,v
retrieving revision 1.207
diff -u -r1.207 gdb.exp
--- lib/gdb.exp	21 Jun 2012 20:46:25 -0000	1.207
+++ lib/gdb.exp	22 Jun 2012 16:25:44 -0000
@@ -3024,12 +3024,15 @@
 proc default_gdb_init { args } {
     global gdb_wrapper_initialized
     global gdb_wrapper_target
+    global gdb_test_file_name
     global cleanfiles
     
     set cleanfiles {}
 
     gdb_clear_suppressed;
 
+    set gdb_test_file_name [file rootname [file tail [lindex $args 0]]]
+
     # Make sure that the wrapper is rebuilt
     # with the appropriate multilib option.
     if { $gdb_wrapper_target != [current_target_name] } {
@@ -3063,6 +3066,70 @@
     }
 }
 
+# Turn BASENAME into a full file name in the standard output
+# directory.
+
+proc standard_output_file {basename} {
+    global objdir subdir
+
+    return $objdir/$subdir/$basename
+}
+
+# Set 'testfile', 'srcfile', and 'binfile'.
+#
+# ARGS is a list of source file specifications.
+# Without any arguments, the .exp file's base name is used to
+# compute the source file name.  The ".c" extension is added in this case.
+# If ARGS is not empty, each entry is a source file specification.
+# If the specification starts with a ".", it is treated as a suffix
+# to append to the .exp file's base name.
+# If the specification is the empty string, it is treated as if it
+# were ".c".
+# Otherwise it is a file name.
+# The first file in the list is used to set the 'srcfile' global.
+# Each subsequent name is used to set 'srcfile2', 'srcfile3', etc.
+#
+# Most tests should call this without arguments.
+#
+# If a completely different binary file name is needed, then it
+# should be handled in the .exp file with a suitable comment.
+
+proc standard_testfile {args} {
+    global gdb_test_file_name
+    global objdir subdir
+
+    # Outputs.
+    global testfile binfile
+
+    set testfile $gdb_test_file_name
+    set binfile [standard_output_file ${testfile}]
+
+    if {[llength $args] == 0} {
+	set args .c
+    }
+
+    set suffix ""
+    foreach arg $args {
+	set varname srcfile$suffix
+	global $varname
+
+	# Handle an extension.
+	if {$arg == ""} {
+	    set arg $testfile.c
+	} elseif {[string range $arg 0 0] == "."} {
+	    set arg $testfile$arg
+	}
+
+	set $varname $arg
+
+	if {$suffix == ""} {
+	    set suffix 2
+	} else {
+	    incr suffix
+	}
+    }
+}
+
 # The default timeout used when testing GDB commands.  We want to use
 # the same timeout as the default dejagnu timeout, unless the user has
 # already provided a specific value (probably through a site.exp file).
@@ -3666,7 +3733,7 @@
         set sources ${executable}.c
     }
 
-    set binfile ${objdir}/${subdir}/${executable}
+    set binfile [standard_output_file $executable]
 
     set objects {}
     for {set i 0} "\$i<[llength $sources]" {incr i} {
@@ -3694,12 +3761,12 @@
 }
 
 # Starts fresh GDB binary and loads EXECUTABLE into GDB. EXECUTABLE is
-# the name of binary in ${objdir}/${subdir}.
+# the basename of the binary.
 proc clean_restart { executable } {
     global srcdir
     global objdir
     global subdir
-    set binfile ${objdir}/${subdir}/${executable}
+    set binfile [standard_output_file ${executable}]
 
     gdb_exit
     gdb_start


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