[testsuite][RFC] clean up use of GCC_EXEC_PREFIX in testsuite

Janis Johnson janis187@us.ibm.com
Fri Jan 30 05:06:00 GMT 2009


The compiler testsuite sets GCC_EXEC_PREFIX to a variable from site.exp,
which the Makefile sets to "$(libdir)/gcc/".  This lets the compiler
under test use start files that were installed in the GCC install tree
by an earlier library build with the same install location.  The -B
option, which overrides GCC_EXEC_PREFIX, is used within the testsuite to
get GCC files from within the build directory instead of using files
from the install tree that might be left over from an older build.

This patch attempts to clean things up a bit by setting and restoring
GCC_EXEC_PREFIX within existing procedures that set and restore
LD_LIBRARY_PATH and related variables.  Those procs are now used to
switch the environments before and after uses of $HOSTCC.

GCC_EXEC_PREFIX should probably also be used for the library tests by
having their Makefiles add the appropriate variable to their site.exp
files.

I would greatly appreciate it if people who rely on using non-GCC files
in the install tree could test this patch, as well as people who have
had problems with the various patches that have modified the use of
GCC_EXEC_PREFIX in the testsuite.

Tested with all languages but Ada on powerpc64-linux, without an
existing install tree.  Also tested by running a few tests when
a leftover install tree of the same name containing broken cc1,
float.h, and libgcc.a, using tests that would have failed if any
of those files had been used instead of the ones in the build.

2009-01-29  Janis Johnson  <janis187@us.ibm.com>

gcc/
	PR testsuite/36443
	* Makefile.in (site.exp): Rename TEST_GCC_EXEC_PREFIX and comment
	its use.
	(check-%): Don't set GCC_EXEC_PREFIX when invoking runtest.
	(check-parallel-%): Ditto.
	(check-consistency): Ditto.

testsuite/
	PR testsuite/36443
	* lib/target-libpath.exp (set_ld_library_path_env_vars): Save
	existing GCC_EXEC_PREFIX, set to TEST_GCC_EXEC_PREFIX if that
	is defined.
	(restore_ld_library_path_env_vars): Restore GCC_EXEC_PREFIX to
	its original value, or unset if it was not defined.
	* gcc.dg/compat/struct-layout-1.exp: Use set/restore library
	path procs around use of HOSTCC.
	* g++.dg/compat/struct-layout-1.exp: Ditto.
	* objc.dg/gnu-encoding/gnu-encoding.exp: Ditto.

Index: gcc/Makefile.in
===================================================================
--- gcc/Makefile.in	(revision 143743)
+++ gcc/Makefile.in	(working copy)
@@ -4434,9 +4434,13 @@
 	@echo "set CXXFLAGS \"\"" >> ./tmp0
 	@echo "set HOSTCC \"$(CC)\"" >> ./tmp0
 	@echo "set HOSTCFLAGS \"$(CFLAGS)\"" >> ./tmp0
+# When running the tests we set GCC_EXEC_PREFIX to the install tree so that
+# files that have already been installed there will be found.  The -B option
+# overrides it, so use of GCC_EXEC_PREFIX will not result in using GCC files
+# from the install tree.
+	@echo "set TEST_GCC_EXEC_PREFIX \"$(libdir)/gcc/\"" >> ./tmp0
 	@echo "set TESTING_IN_BUILD_TREE 1" >> ./tmp0
 	@echo "set HAVE_LIBSTDCXX_V3 1" >> ./tmp0
-	@echo "set GCC_EXEC_PREFIX \"$(libdir)/gcc/\"" >> ./tmp0
 # If newlib has been configured, we need to pass -B to gcc so it can find
 # newlib's crt0.o if it exists.  This will cause a "path prefix not used"
 # message if it doesn't, but the testsuite is supposed to ignore the message -
@@ -4521,7 +4525,6 @@
 	if [ -f $${rootme}/../expect/expect ] ; then  \
 	   TCL_LIBRARY=`cd .. ; cd $${srcdir}/../tcl/library ; ${PWD_COMMAND}` ; \
 	    export TCL_LIBRARY ; fi ; \
-	GCC_EXEC_PREFIX="$(libdir)/gcc/" ; export GCC_EXEC_PREFIX ; \
 	$(RUNTEST) --tool $* $(RUNTESTFLAGS))
 
 $(patsubst %,%-subtargets,$(filter-out $(lang_checks_parallelized),$(lang_checks))): check-%-subtargets:
@@ -4609,7 +4612,6 @@
 	if [ -f $${rootme}/../expect/expect ] ; then  \
 	   TCL_LIBRARY=`cd .. ; cd $${srcdir}/../tcl/library ; ${PWD_COMMAND}` ; \
 	    export TCL_LIBRARY ; fi ; \
-	GCC_EXEC_PREFIX="$(libdir)/gcc/" ; export GCC_EXEC_PREFIX ; \
 	runtestflags= ; \
 	if [ -n "$(check_p_subno)" ] ; then \
 	  runtestflags="$(check_p_subwork)"; \
@@ -4634,7 +4636,6 @@
 	if [ -f $${rootme}/../expect/expect ] ; then  \
 	   TCL_LIBRARY=`cd .. ; cd $${srcdir}/../tcl/library ; ${PWD_COMMAND}` ; \
 	   export TCL_LIBRARY ; fi ; \
-	GCC_EXEC_PREFIX="$(libdir)/gcc/" ; export GCC_EXEC_PREFIX ; \
 	$(RUNTEST) --tool consistency $(RUNTESTFLAGS)
 
 # QMTest targets
Index: gcc/testsuite/lib/target-libpath.exp
===================================================================
--- gcc/testsuite/lib/target-libpath.exp	(revision 143743)
+++ gcc/testsuite/lib/target-libpath.exp	(working copy)
@@ -25,6 +25,8 @@
 set orig_ld_library_path_32_saved 0
 set orig_ld_library_path_64_saved 0
 set orig_dyld_library_path_saved 0
+set orig_gcc_exec_prefix_saved 0
+set orig_gcc_exec_prefix_checked 0
 
 
 #######################################
@@ -42,6 +44,8 @@
   global orig_ld_library_path_32_saved
   global orig_ld_library_path_64_saved
   global orig_dyld_library_path_saved
+  global orig_gcc_exec_prefix_saved
+  global orig_gcc_exec_prefix_checked
   global orig_ld_library_path
   global orig_ld_run_path
   global orig_shlib_path
@@ -50,21 +54,31 @@
   global orig_ld_library_path_32
   global orig_ld_library_path_64
   global orig_dyld_library_path
-  global GCC_EXEC_PREFIX
+  global orig_gcc_exec_prefix
+  global TEST_GCC_EXEC_PREFIX
+  global env
 
-  # Set the relocated compiler prefix, but only if the user hasn't specified one.
-  if { [info exists GCC_EXEC_PREFIX] && ![info exists env(GCC_EXEC_PREFIX)] } {
-    setenv GCC_EXEC_PREFIX "$GCC_EXEC_PREFIX"
+  # Save the original GCC_EXEC_PREFIX.
+  if { $orig_gcc_exec_prefix_checked == 0 } {
+    if [info exists env(GCC_EXEC_PREFIX)] {
+      set orig_gcc_exec_prefix "$env(GCC_EXEC_PREFIX)"
+      set orig_gcc_exec_prefix_saved 1
+    }
+    set orig_gcc_exec_prefix_checked 1
   }
 
+  # Set GCC_EXEC_PREFIX for the compiler under test to pick up files not in
+  # the build tree from a specified location (normally the install tree).
+  if [info exists env(TEST_GCC_EXEC_PREFIX)] {
+    setenv GCC_EXEC_PREFIX "$TEST_GCC_EXEC_PREFIX"
+  }
+
   # Setting the ld library path causes trouble when testing cross-compilers.
   if { [is_remote target] } {
     return
   }
 
   if { $orig_environment_saved == 0 } {
-    global env
-
     set orig_environment_saved 1
 
     # Save the original environment.
@@ -187,6 +201,7 @@
   global orig_ld_library_path_32_saved
   global orig_ld_library_path_64_saved
   global orig_dyld_library_path_saved
+  global orig_gcc_exec_prefix_saved
   global orig_ld_library_path
   global orig_ld_run_path
   global orig_shlib_path
@@ -195,11 +210,19 @@
   global orig_ld_library_path_32
   global orig_ld_library_path_64
   global orig_dyld_library_path
+  global orig_gcc_exec_prefix
+  global env
 
   if { $orig_environment_saved == 0 } {
     return
   }
 
+  if { $orig_gcc_exec_prefix_saved } {
+    setenv GCC_EXEC_PREFIX "$orig_gcc_exec_prefix"
+  } elseif [info exists env(GCC_EXEC_PREFIX)] {
+    unsetenv GCC_EXEC_PREFIX
+  }
+
   if { $orig_ld_library_path_saved } {
     setenv LD_LIBRARY_PATH "$orig_ld_library_path"
   } elseif [info exists env(LD_LIBRARY_PATH)] {
Index: gcc/testsuite/gcc.dg/compat/struct-layout-1.exp
===================================================================
--- gcc/testsuite/gcc.dg/compat/struct-layout-1.exp	(revision 143743)
+++ gcc/testsuite/gcc.dg/compat/struct-layout-1.exp	(working copy)
@@ -43,6 +43,7 @@
 # Load procedures from common libraries. 
 load_lib standard.exp
 load_lib gcc.exp
+load_lib target-libpath.exp
 
 # Load the language-dependent compabibility support procedures.
 load_lib c-compat.exp
@@ -90,20 +91,12 @@
 set generator_src "$generator_src $srcdir/$subdir/generate-random_r.c"
 set generator_cmd "-o $generator $skip_dfp $generator_src"
 
-# Temporarily unset GCC_EXEC_PREFIX from environment, as that might
-# confuse the $HOSTCC.
-set orig_gcc_exec_prefix_saved 0
-if [info exists env(GCC_EXEC_PREFIX)] {
-     set orig_gcc_exec_prefix "$env(GCC_EXEC_PREFIX)"
-     set orig_gcc_exec_prefix_saved 1
-     unsetenv GCC_EXEC_PREFIX
-}
+# Temporarily switch to the environment for the host compiler.
+restore_ld_library_path_env_vars
 set status [remote_exec build "$HOSTCC $HOSTCFLAGS $generator_cmd"]
 set status [lindex $status 0]
-if { $orig_gcc_exec_prefix_saved } {
-     set orig_gcc_exec_prefix_saved 0
-     setenv GCC_EXEC_PREFIX "$orig_gcc_exec_prefix"
-}
+set_ld_library_path_env_vars
+
 if { $status == 0 } then {
     file delete -force $tstobjdir
     file mkdir $tstobjdir
Index: gcc/testsuite/g++.dg/compat/struct-layout-1.exp
===================================================================
--- gcc/testsuite/g++.dg/compat/struct-layout-1.exp	(revision 143743)
+++ gcc/testsuite/g++.dg/compat/struct-layout-1.exp	(working copy)
@@ -128,20 +128,11 @@
 set generator_src "$generator_src $srcdir/$subdir/../../gcc.dg/compat/generate-random_r.c"
 set generator_cmd "-o $generator $generator_src"
 
-# Temporarily unset GCC_EXEC_PREFIX from environment, as that might
-# confuse the $HOSTCC.
-set orig_gcc_exec_prefix_saved 0
-if [info exists env(GCC_EXEC_PREFIX)] {
-     set orig_gcc_exec_prefix "$env(GCC_EXEC_PREFIX)"
-     set orig_gcc_exec_prefix_saved 1
-     unsetenv GCC_EXEC_PREFIX
-}
+# Temporarily switch to the environment of the host compiler.
+restore_ld_library_path_env_vars
 set status [remote_exec build "$HOSTCC $HOSTCFLAGS $generator_cmd"]
 set status [lindex $status 0]
-if { $orig_gcc_exec_prefix_saved } {
-     set orig_gcc_exec_prefix_saved 0
-     setenv GCC_EXEC_PREFIX "$orig_gcc_exec_prefix"
-}
+set_ld_library_path_env_vars
 if { $status == 0 } then {
     file delete -force $tstobjdir
     file mkdir $tstobjdir
Index: gcc/testsuite/objc.dg/gnu-encoding/gnu-encoding.exp
===================================================================
--- gcc/testsuite/objc.dg/gnu-encoding/gnu-encoding.exp	(revision 143743)
+++ gcc/testsuite/objc.dg/gnu-encoding/gnu-encoding.exp	(working copy)
@@ -17,6 +17,7 @@
 
 # Load support procs.
 load_lib objc-dg.exp
+load_lib target-libpath.exp
 
 # If a testcase doesn't have special options, use these.
 global DEFAULT_CFLAGS
@@ -37,20 +38,11 @@
 set generator_src "$generator_src $srcdir/$subdir/generate-random.c"
 set generator_src "$generator_src $srcdir/$subdir/generate-random_r.c"
 set generator_cmd "-o $generator $generator_src"
-# Temporarily unset GCC_EXEC_PREFIX from environment, as that might
-# confuse the $HOSTCC.
-set orig_gcc_exec_prefix_saved 0
-if [info exists env(GCC_EXEC_PREFIX)] {
-     set orig_gcc_exec_prefix "$env(GCC_EXEC_PREFIX)"
-     set orig_gcc_exec_prefix_saved 1
-     unsetenv GCC_EXEC_PREFIX
-}
+# Temporarily switch to the environment of the host compiler.
+restore_ld_library_path_env_vars
 set status [remote_exec build "$HOSTCC $HOSTCFLAGS $generator_cmd"]
 set status [lindex $status 0]
-if { $orig_gcc_exec_prefix_saved } {
-     set orig_gcc_exec_prefix_saved 0
-     setenv GCC_EXEC_PREFIX "$orig_gcc_exec_prefix"
-}
+set_ld_library_path_env_vars
 if { $status == 0 } then {
     file delete -force $tstobjdir
     file mkdir $tstobjdir





More information about the Gcc-patches mailing list