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]

[PATCH] Remove symlinks created in argv0-symlink.exp and general cleanup


When running argv0-symlink.exp, symlinks are left in the test output
directory.  One of them is a recursive symlink.  This causes the same tests
to be found multiple times and disturbs subsequent test runs.

To witness it simply, just run

  $ make check RUNTESTFLAGS="argv0-symlink.exp"

twice in a row.  The second run will find and run argv0-symlink.exp
multiple times because of the recursive symlink left by the first run.  Note
that this only happens when building in tree.  The simple fix is to
remove the links when we are done.

At the same time, I did a general cleanup of the test:

  - Add and use a create_link proc.
  - Bail out early if target does not support argv[0].
  - Of course, remove created symlinks before returning.

gdb/testsuite/ChangeLog:

	* gdb.base/argv0-symlink.exp: Remove symlinks when done.
	General cleanup.
---
 gdb/testsuite/gdb.base/argv0-symlink.exp | 90 ++++++++++++++++++++------------
 1 file changed, 56 insertions(+), 34 deletions(-)

diff --git a/gdb/testsuite/gdb.base/argv0-symlink.exp b/gdb/testsuite/gdb.base/argv0-symlink.exp
index f030656..053f8c5 100644
--- a/gdb/testsuite/gdb.base/argv0-symlink.exp
+++ b/gdb/testsuite/gdb.base/argv0-symlink.exp
@@ -13,80 +13,102 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+
+# Delete files specified in ARGS.  The paths are relative to the standard
+# test output directory.
+
+proc cleanup {args} {
+    foreach file $args {
+        remote_exec host "rm -f [standard_output_file $file]"
+    }
+}
+
+
+# Create a symbolic link from LINK_NAME to TARGET.  Return 1 on success,
+# 0 otherwise.
+
+proc create_link {target link_name} {
+    set status [remote_exec host "ln -sf ${target} ${link_name}"]
+    if { [lindex $status 0] != 0 } {
+        return 0
+    }
+
+    return 1
+}
+
 standard_testfile
 
-set has_argv0 [gdb_has_argv0]
+if { ![gdb_has_argv0] } {
+    unsupported "target does not provide argv\[0\]"
+    return 0
+}
+
+set filelink "${testfile}-filelink"
+set dirlink "${testfile}-dirlink"
+
+# For a link named /PATH/TO/DIR/LINK, we want to check the output
+# against "/DIR/LINK", but computed in a way that doesn't make
+# assumptions about the test directory layout.
+set full_filelink [standard_output_file $filelink]
+set lastdir [file tail [file dirname $full_filelink]]
 
 if { [build_executable ${testfile}.exp ${testfile} ${srcfile}] == -1 } {
     return -1
 }
 
+# Remove any existing link.
+cleanup "$filelink" "$dirlink"
+
+# Test with symlink to files.
 set test "kept file symbolic link name"
-set filelink "${testfile}-filelink"
 
-remote_file host delete [standard_output_file $filelink]
-set status [remote_exec host "ln -sf ${testfile} [standard_output_file $filelink]"]
-if {[lindex $status 0] != 0} {
+if { ![create_link "${testfile}" "[standard_output_file $filelink]"] } {
     unsupported "$test (host does not support symbolic links)"
+    cleanup "$filelink" "$dirlink"
     return 0
 }
 
 clean_restart "$filelink"
 
-if ![runto_main] {
+if { ![runto_main] } {
     untested "could not run to main"
+    cleanup "$filelink" "$dirlink"
     return -1
 }
 
 gdb_test_no_output "set print repeats 10000"
 gdb_test_no_output "set print elements 10000"
 
-if { $has_argv0 } {
-    gdb_test {print argv[0]} "/$filelink\"" $test
-} else {
-    unsupported $test
-}
-
-# For a link named /PATH/TO/DIR/LINK, we want to check the output
-# against "/DIR/LINK", but computed in a way that doesn't make
-# assumptions about the test directory layout.
-set full_filelink [standard_output_file $filelink]
-set lastdir [file tail [file dirname $full_filelink]]
+gdb_test {print argv[0]} "/$filelink\"" $test
 
 gdb_test "info inferiors" "/$lastdir/$filelink *" "$test for info inferiors"
 
-
+# Test with symlink to dir.
 set test "kept directory symbolic link name"
-set dirlink "${testfile}-dirlink"
 
-# 'ln -sf' does not overwrite symbol link to a directory.
-# 'remote_file host delete' uses stat (not lstat), therefore it refuses to
-# delete a directory.
-remote_exec host "rm -f [standard_output_file $dirlink]"
-set status [remote_exec host "ln -sf . [standard_output_file $dirlink]"]
-if {[lindex $status 0] != 0} {
+if { ![create_link "." "[standard_output_file $dirlink]"] } {
     unsupported "$test (host does not support symbolic links)"
+    cleanup "$filelink" "$dirlink"
     return 0
 }
 
 clean_restart "$dirlink/$filelink"
 
-if ![runto_main] {
+if { ![runto_main] } {
     untested "could not run to main"
+    cleanup "$filelink" "$dirlink"
     return -1
 }
 
 gdb_test_no_output "set print repeats 10000"
 gdb_test_no_output "set print elements 10000"
 
-if { $has_argv0 } {
-    # gdbserver does not have this issue.
-    if ![is_remote target] {
-	setup_kfail "*-*-*" gdb/15934
-    }
-    gdb_test {print argv[0]} "/$dirlink/$filelink\"" $test
-} else {
-    unsupported $test
+# gdbserver does not have this issue.
+if { ![is_remote target] } {
+    setup_kfail "*-*-*" gdb/15934
 }
+gdb_test {print argv[0]} "/$dirlink/$filelink\"" $test
 
 gdb_test "info inferiors" "/$lastdir/$filelink *" "$test for info inferiors"
+
+cleanup "$filelink" "$dirlink"
-- 
2.1.4


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