OSDN Git Service

PR other/12009
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / compat / compat.exp
1 # Copyright (C) 2002 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 #
17 # This file was written by Janis Johnson, <janis187@us.ibm.com>
18
19
20 # Test interoperability of two compilers that follow the same ABI.
21 #
22 # Break simple tests into two pieces and see that they work when linked
23 # together.  If an alternate compiler is specified then the two main
24 # pieces of each test are compiled with different compilers.  The
25 # alternate compiler must be installed, and is specified by defining
26 # ALT_CXX_UNDER_TEST in the environment.
27
28 if $tracelevel then {
29     strace $tracelevel
30 }
31
32 global GXX_UNDER_TEST
33 global ld_library_path
34
35 # Load procedures from common libraries. 
36 load_lib standard.exp
37 load_lib g++.exp
38
39 #
40 # compat-fix-library-path -- switch LD_LIBRARY_PATH
41 #
42 proc compat-fix-library-path { } {
43     global ld_library_path
44
45     # See comments in lib/g++.exp for why this is needed.
46     if {![is_remote target]} {
47         # See comments in lib/g++.exp for why this is needed.
48         setenv  LD_LIBRARY_PATH     $ld_library_path
49         setenv  SHLIB_PATH          $ld_library_path
50         setenv  LD_LIBRARYN32_PATH  $ld_library_path
51         setenv  LD_LIBRARY64_PATH   $ld_library_path
52     }
53 }
54
55 #
56 # compat-use-alt-compiler -- make the alternate compiler the default
57
58 proc compat-use-alt-compiler { } {
59     global GXX_UNDER_TEST ALT_CXX_UNDER_TEST
60     global CXXFLAGS
61     global ALWAYS_CXXFLAGS
62     global ld_library_path alt_ld_library_path
63     global same_alt
64
65     # We don't need to do this if the alternate compiler is actually
66     # the same as the compiler under test.
67     if { $same_alt == 0 } then {
68         set GXX_UNDER_TEST $ALT_CXX_UNDER_TEST
69         set CXXFLAGS ""
70         set ALWAYS_CXXFLAGS ""
71         set ld_library_path $alt_ld_library_path
72         compat-fix-library-path
73     }
74 }
75
76 #
77 # compat-use-tst-compiler -- make compiler under test the default
78 #
79 proc compat-use-tst-compiler { } {
80     global GXX_UNDER_TEST save_gxx_under_test
81     global CXXFLAGS save_cxxflags
82     global ALWAYS_CXXFLAGS save_always_cxxflags
83     global ld_library_path save_ld_library_path
84     global same_alt
85
86     # We don't need to do this if the alternate compiler is actually
87     # the same as the compiler under test.
88
89     if { $same_alt == 0 } then {
90         set GXX_UNDER_TEST $save_gxx_under_test
91         set CXXFLAGS $save_cxxflags
92         set ALWAYS_CXXFLAGS $save_always_cxxflags
93         set ld_library_path $save_ld_library_path
94         compat-fix-library-path
95     }
96 }
97
98 # Load the language-independent compabibility support procedures.
99 # This must be done after the compat-use-*-compiler definitions.
100 load_lib compat.exp
101
102 g++_init
103
104 # Save variables for the C++ compiler under test, which each test will
105 # change a couple of times.  This must be done after calling g++-init.
106 set save_gxx_under_test $GXX_UNDER_TEST
107 set save_cxxflags $CXXFLAGS
108 set save_always_cxxflags $ALWAYS_CXXFLAGS
109 set save_ld_library_path $ld_library_path
110
111 # Define an identifier for use with this suite to avoid name conflicts
112 # with other compat tests running at the same time.
113 set sid "cp_compat"
114
115 # Find out whether there is an alternate compiler to test.  If the
116 # variable is defined but is set to "same", that means we use the same
117 # compiler twice, which is meaningful if the two parts of COMPAT_OPTIONS
118 # are different.
119 set use_alt 0
120 set same_alt 0
121 set alt_ld_library_path "."
122 if [info exists ALT_CXX_UNDER_TEST] then {
123     set use_alt 1
124     if [string match "same" $ALT_CXX_UNDER_TEST] then {
125         set same_alt 1
126     } else {
127         if [info exists ALT_LD_LIBRARY_PATH] then {
128             append alt_ld_library_path ":${ALT_LD_LIBRARY_PATH}"
129         }
130     }
131 }
132
133 # Main loop.
134 foreach src [lsort [find $srcdir/$subdir *_main.C]] {
135     # If we're only testing specific files and this isn't one of them, skip it.
136     if ![runtest_file_p $runtests $src] then {
137         continue
138     }
139
140     compat-execute $src $sid $use_alt
141 }
142
143 # Restore the original compiler under test.
144 compat-use-tst-compiler