[2/2] Try both make_relative_prefix{,ignore_links} for relocatability

Message ID 001a113803b2aff208051d215382@google.com
State New, archived
Headers

Commit Message

Doug Evans Aug. 12, 2015, 6:24 p.m. UTC
  Hi.

This patch is the testcase.
It's pretty simple, but it does do things a little differently.

Adding bindir to the output of "show config" is reasonable regardless:
We tell the user that certain dirs are relocatable, but we don't
provide the necessary information to answer the question
"Relocatable relative to what?".

2015-08-12  Doug Evans  <dje@google.com>

	* top.c (print_gdb_configuration): Print BINDIR.

	testsuite/
	* gdb.base/relocatable.exp: New file.

+
+	start_and_check_data_dir ${install_bindir}/gdb \
+	    "${install_dir}${datadir}"
+    }
+}
  

Comments

Pedro Alves Sept. 29, 2015, 11:01 a.m. UTC | #1
Hi Doug,

FWIW, I see no issue with installed testing.

On 08/12/2015 07:24 PM, Doug Evans wrote:

> +# Test gdb's handling of relocatability.
> +# This only works if gdb was configured to be relocatable.
> +# We can't rebuild gdb just for this test, but we can check whether
> +# the built gdb is relocatable and if so then run the tests.
> +
> +# It's not clear what systems this test will work on.
> +# For now pick the ones we know will work.
> +if {![istarget *-*-linux*]
> +    || [is_remote host]} {
> +    return 0
> +}

IIUC, this is a host property, not target property, so sounds
like that should be ishost.  IOW, depends on where gdb runs, not
what target it was configured to debug.

But, how about dropping the Linux filter altogether for now?
I think not exposing the test to other hosts/targets is a recipe for never
relaxing the check in the future either, because nobody will be looking
for tests to enable on other hosts.  I favor instead letting new tests
run on all systems, and then selectively skip on those which we then
find it can't work (and then with a comment on why it can't work).

> +    set test "make install"
> +    if { $result != 0 } {
> +	fail $test
> +    } else {
> +	pass $test
> +    }

Note you can use gdb_assert instead of this if/else/fail/pass
sequence.

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/top.c b/gdb/top.c
index 061b52f..247650d 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1285,6 +1285,9 @@  This GDB was configured as follows:\n\
     configure --host=%s --target=%s\n\
  "), host_name, target_name);
    fprintf_filtered (stream, _("\
+             --bindir=%s\n\
+"), BINDIR);
+  fprintf_filtered (stream, _("\
               --with-auto-load-dir=%s\n\
               --with-auto-load-safe-path=%s\n\
  "), AUTO_LOAD_DIR, AUTO_LOAD_SAFE_PATH);
diff --git a/gdb/testsuite/gdb.base/relocatable.exp  
b/gdb/testsuite/gdb.base/relocatable.exp
new file mode 100644
index 0000000..ea35f29
--- /dev/null
+++ b/gdb/testsuite/gdb.base/relocatable.exp
@@ -0,0 +1,161 @@ 
+# Copyright 2015 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+# Test gdb's handling of relocatability.
+# This only works if gdb was configured to be relocatable.
+# We can't rebuild gdb just for this test, but we can check whether
+# the built gdb is relocatable and if so then run the tests.
+
+# It's not clear what systems this test will work on.
+# For now pick the ones we know will work.
+if {![istarget *-*-linux*]
+    || [is_remote host]} {
+    return 0
+}
+
+gdb_exit
+gdb_start
+set config [capture_command_output "show config" ""]
+
+regsub "^.*(--bindir=\[\^\r\n\]+).*$" $config "\\1" bindir_text
+regsub "^.*(--with-gdb-datadir=\[\^\r\n\]+).*$" $config "\\1" datadir_text
+
+verbose -log "bindir_text: $bindir_text"
+verbose -log "datadir_text: $datadir_text"
+
+if { [string first " (relocatable)" $datadir_text] < 0 } {
+    unsupported "gdb not relocatable"
+    return 0
+}
+
+regsub "^--bindir=" $bindir_text "" bindir
+regsub "^--with-gdb-datadir=" $datadir_text "" datadir
+regsub " \\(relocatable\\)" $datadir "" datadir
+
+verbose -log "bindir: $bindir"
+verbose -log "datadir: $datadir"
+
+set env_program "env" ;# TODO: gdb_find_env
+set make_program "make" ;# TODO: gdb_find_make
+
+# Run "make install" to install gdb in INSTALL_DIR.
+# The result is zero for success, non-zero for failure.
+
+proc make_install { install_dir } {
+    global env_program
+    global make_program
+
+    file delete -force -- $install_dir
+
+    # If invoked from make check-parallel, several env vars are set up  
which
+    # will confuse this make, so unset them.
+    set env_options "-u MAKELEVEL -u MAKEFLAGS -u MFLAGS -u MAKEOVERRIDES"
+
+    # We don't need to install the docs or gdbserver, just gdb.
+    # And we don't want to cause a rebuild of gdb, so use install-only.
+    set make_options "-C .. install-only SUBDIRS=data-directory  
DESTDIR=$install_dir"
+
+    set cmd "$env_program $env_options $make_program $make_options"
+    verbose -log "Executing: $cmd"
+    set result [catch "exec $cmd" output]
+
+    verbose -log "result is $result"
+    verbose -log "output is $output"
+
+    set test "make install"
+    if { $result != 0 } {
+	fail $test
+    } else {
+	pass $test
+    }
+    return $result
+}
+
+proc start_and_check_data_dir { gdb_path expected_data_dir } {
+    global GDB INTERNAL_GDBFLAGS
+    save_vars { GDB INTERNAL_GDBFLAGS } {
+	set GDB $gdb_path
+	# We want this gdb to find its installed data-directory, so don't
+	# pass it one.
+	regsub -- "-data-directory \[^ \]+" $INTERNAL_GDBFLAGS ""  
INTERNAL_GDBFLAGS
+	gdb_exit
+	gdb_start
+	set datadir_in_gdb [capture_command_output "show data-dir" ""]
+	regsub "^GDB's data directory is \"" $datadir_in_gdb "" datadir_in_gdb
+	regsub "\".\[\r\n\]+$" $datadir_in_gdb "" datadir_in_gdb
+	set test "data-dir updated correctly"
+	if { $datadir_in_gdb == $expected_data_dir } {
+	    pass $test
+	} else {
+	    fail $test
+	}
+    }
+}
+
+# Move all files (and directories) from from_dir to to_dir and leave behind
+# symlinks pointing to the new location.
+
+proc move_and_leave_symlinks { from_dir to_dir } {
+    file delete -force -- $to_dir
+    file mkdir $to_dir
+    set files [glob -tails -directory $from_dir *]
+    foreach f $files {
+	file copy -- "${from_dir}/$f" "${to_dir}"
+	file delete -force -- "${from_dir}/$f"
+	file link -symbolic "${from_dir}/$f" "${to_dir}/$f"
+    }
+}
+
+# First test the case where gdb is a symlink to its installed copy.
+# This exercises make_relative_prefix (where we need to call lrealname
+# on gdb's argv[0] in order to establish our location).
+
+with_test_prefix "realpath_symlinks" {
+    set install_dir [standard_output_file make_relative_prefix]
+
+    if { [make_install $install_dir] == 0 } {
+	set linked_gdb [standard_output_file ${install_dir}/gdb]
+	file delete -force -- "${linked_gdb}"
+	file link -symbolic "${linked_gdb}" ".${bindir}/gdb"
+
+	start_and_check_data_dir $linked_gdb "${install_dir}${datadir}"
+    }
+}
+
+# Second test is having the install tree being a set of symlinks pointing
+# to (essentially) random places
+# This exercises make_relative_prefix_ignore_links (where calling  
lrealname on
+# gdb's argv[0] is the wrong thing to do).
+
+with_test_prefix "ignore_symlinks" {
+    set install_dir [standard_output_file  
make_relative_prefix_ignore_links]
+
+    if { [make_install $install_dir] == 0 } {
+	# Now that we've created an install tree, move bindir and datadir to
+	# "random" places and create symlinks in their place.
+
+	set install_bindir "${install_dir}${bindir}"
+	set install_datadir "${install_dir}${datadir}"
+
+	set random_bindir "${install_dir}/random1/bindir"
+	set random_datadir "${install_dir}/random2/datadir"
+
+	move_and_leave_symlinks $install_bindir $random_bindir
+	move_and_leave_symlinks $install_datadir $random_datadir