1 | # Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
---|
2 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
---|
3 | #
|
---|
4 | # This code is free software; you can redistribute it and/or modify it
|
---|
5 | # under the terms of the GNU General Public License version 2 only, as
|
---|
6 | # published by the Free Software Foundation.
|
---|
7 | #
|
---|
8 | # This code is distributed in the hope that it will be useful, but WITHOUT
|
---|
9 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
---|
10 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
---|
11 | # version 2 for more details (a copy is included in the LICENSE file that
|
---|
12 | # accompanied this code).
|
---|
13 | #
|
---|
14 | # You should have received a copy of the GNU General Public License version
|
---|
15 | # 2 along with this work; if not, write to the Free Software Foundation,
|
---|
16 | # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
---|
17 | #
|
---|
18 | # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
---|
19 | # or visit www.oracle.com if you need additional information or have any
|
---|
20 | # questions.
|
---|
21 |
|
---|
22 |
|
---|
23 | # @test
|
---|
24 | # @bug 4731671
|
---|
25 | # @build libraryCaller
|
---|
26 | # @run shell SolarisRunpath.sh
|
---|
27 | # @summary Verify that Solaris LD_LIBRARY_PATH rules are followed
|
---|
28 | # @author Joseph D. Darcy
|
---|
29 |
|
---|
30 | # The launcher has been updated to properly take account of Solaris
|
---|
31 | # LD_LIBRARY_PATH rules when constructing the runpath for the Java
|
---|
32 | # executable. That is, data model dependent LD_LIBRARY_PATH variables
|
---|
33 | # are tested for and override LD_LIBRARY_PATH if present. The current
|
---|
34 | # launcher design relies on LD_LIBRARY_PATH settings to ensure the
|
---|
35 | # proper jre/jdk libraries are opening during program execution. In
|
---|
36 | # the future, this dependence might be removed by having the vm
|
---|
37 | # explicitly dlopen the needed files. If that change occurs, this
|
---|
38 | # test will be harmless but no long relevant.
|
---|
39 |
|
---|
40 | # A more robust test for Solaris SPARC would set the different
|
---|
41 | # LD_LIBRARY_PATH variables while also varying the -d[32|64] options
|
---|
42 | # to make sure the LD_LIBRARY_PATH of the *target* data model were
|
---|
43 | # being respected. That is "java -d64" should use the 64-bit
|
---|
44 | # LD_LIBRARY_PATH while "java -d32" should use the 32-bit
|
---|
45 | # LD_LIBRARY_PATH regardless of the data model of the "java" binary.
|
---|
46 | # However, by default builds do not contain both 32 and 64 bit
|
---|
47 | # components so such a test would often not be applicable.
|
---|
48 |
|
---|
49 |
|
---|
50 | # If the test is not being run on a Solaris box, SPARC or x86, the
|
---|
51 | # test succeeds immediately.
|
---|
52 |
|
---|
53 | OS=`uname -s`;
|
---|
54 |
|
---|
55 | case "$OS" in
|
---|
56 | SunOS )
|
---|
57 | PATHSEP=":"
|
---|
58 | ;;
|
---|
59 |
|
---|
60 | * )
|
---|
61 | echo "Not a Solaris environment; test vacuously succeeds."
|
---|
62 | exit 0;
|
---|
63 | ;;
|
---|
64 | esac
|
---|
65 |
|
---|
66 | # Verify directory context variables are set
|
---|
67 | if [ "${TESTJAVA}" = "" ]
|
---|
68 | then
|
---|
69 | echo "TESTJAVA not set. Test cannot execute. Failed."
|
---|
70 | exit 1
|
---|
71 | fi
|
---|
72 |
|
---|
73 | if [ "${TESTSRC}" = "" ]
|
---|
74 | then
|
---|
75 | echo "TESTSRC not set. Test cannot execute. Failed."
|
---|
76 | exit 1
|
---|
77 | fi
|
---|
78 |
|
---|
79 |
|
---|
80 | if [ "${TESTCLASSES}" = "" ]
|
---|
81 | then
|
---|
82 | echo "TESTCLASSES not set. Test cannot execute. Failed."
|
---|
83 | exit 1
|
---|
84 | fi
|
---|
85 |
|
---|
86 | # Construct paths to default Java executables
|
---|
87 | JAVAC="$TESTJAVA/bin/javac"
|
---|
88 |
|
---|
89 |
|
---|
90 | # Create our little Java test on the fly
|
---|
91 | ( printf "public class GetDataModel {"
|
---|
92 | printf " public static void main(String argv[]) {"
|
---|
93 | printf " System.out.println(System.getProperty(\"sun.arch.data.model\", \"none\"));"
|
---|
94 | printf " }"
|
---|
95 | printf "}"
|
---|
96 | ) > GetDataModel.java
|
---|
97 |
|
---|
98 | $JAVAC GetDataModel.java
|
---|
99 |
|
---|
100 |
|
---|
101 | # ARCH should be sparc or i386
|
---|
102 | ARCH=`uname -p`
|
---|
103 | case "$ARCH" in
|
---|
104 | sparc | i386 )
|
---|
105 | ;;
|
---|
106 |
|
---|
107 | * )
|
---|
108 | echo "Unrecognized architecture; test fails."
|
---|
109 | exit 1
|
---|
110 | esac
|
---|
111 |
|
---|
112 | # The following construction may not work as desired in a
|
---|
113 | # 64-bit build.
|
---|
114 | JAVA="$TESTJAVA/bin/java -classpath $TESTCLASSES${PATHSEP}."
|
---|
115 |
|
---|
116 | # Determine data model
|
---|
117 | DM=`$JAVA GetDataModel`
|
---|
118 |
|
---|
119 | # verify DM is 32 or 64
|
---|
120 | case "$DM" in
|
---|
121 | 32 )
|
---|
122 | ODM=64;
|
---|
123 | ;;
|
---|
124 |
|
---|
125 | 64 )
|
---|
126 | ODM=32;
|
---|
127 | ;;
|
---|
128 |
|
---|
129 | * )
|
---|
130 | echo "Unknown data model \"$DM\"; test fails."
|
---|
131 | exit 1
|
---|
132 | esac
|
---|
133 |
|
---|
134 | # -------------------- Test 1 --------------------
|
---|
135 |
|
---|
136 | LD_LIBRARY_PATH=$TESTSRC/lib/$ARCH/lib$DM
|
---|
137 | export LD_LIBRARY_PATH
|
---|
138 | unset LD_LIBRARY_PATH_32
|
---|
139 | unset LD_LIBRARY_PATH_64
|
---|
140 |
|
---|
141 | # With plain LD_LIBRARY_PATH, result should always be 0
|
---|
142 | RESULT=`$JAVA libraryCaller`
|
---|
143 | if [ "${RESULT}" != "0" ];
|
---|
144 | then
|
---|
145 | echo "Not using LD_LIBRARY_PATH; test fails."
|
---|
146 | exit 1
|
---|
147 | fi
|
---|
148 |
|
---|
149 | # The following two tests sets both data model dependent
|
---|
150 | # LD_LIBRARY_PATH variables individually.
|
---|
151 |
|
---|
152 | # -------------------- Test 2 --------------------
|
---|
153 |
|
---|
154 | # Set opposite data model variable; should return same result
|
---|
155 | # as plain LD_LIBRARY_PATH.
|
---|
156 |
|
---|
157 | if [ "${DM}" = "32" ]; then
|
---|
158 | LD_LIBRARY_PATH_64=$TESTSRC/lib/$ARCH/lib$DM/lib$DM
|
---|
159 | export LD_LIBRARY_PATH_64
|
---|
160 | else
|
---|
161 | LD_LIBRARY_PATH_32=$TESTSRC/lib/$ARCH/lib$DM/lib$DM
|
---|
162 | export LD_LIBRARY_PATH_32
|
---|
163 | fi
|
---|
164 |
|
---|
165 | RESULT=`$JAVA libraryCaller`
|
---|
166 | if [ "${RESULT}" != "0" ];
|
---|
167 | then
|
---|
168 | echo "Using LD_LIBRARY_PATH_$ODM for $DM binary;"
|
---|
169 | echo "test fails."
|
---|
170 | exit 1
|
---|
171 | fi
|
---|
172 |
|
---|
173 | unset LD_LIBRARY_PATH_32
|
---|
174 | unset LD_LIBRARY_PATH_64
|
---|
175 |
|
---|
176 | # -------------------- Test 3 --------------------
|
---|
177 |
|
---|
178 | # Set appropriate data model variable; result should match
|
---|
179 | # data model.
|
---|
180 | if [ "${DM}" = "32" ]; then
|
---|
181 | LD_LIBRARY_PATH_32=$TESTSRC/lib/$ARCH/lib$DM/lib$DM
|
---|
182 | export LD_LIBRARY_PATH_32
|
---|
183 | else
|
---|
184 | LD_LIBRARY_PATH_64=$TESTSRC/lib/$ARCH/lib$DM/lib$DM
|
---|
185 | export LD_LIBRARY_PATH_64
|
---|
186 | fi
|
---|
187 |
|
---|
188 | RESULT=`$JAVA libraryCaller`
|
---|
189 | if [ "${RESULT}" != "$DM" ];
|
---|
190 | then
|
---|
191 | echo "Data model dependent LD_LIBRARY_PATH_$DM"
|
---|
192 | echo "not overriding LD_LIBRARY_PATH; test fails."
|
---|
193 | exit 1
|
---|
194 | fi
|
---|
195 |
|
---|
196 | unset LD_LIBRARY_PATH
|
---|
197 | unset LD_LIBRARY_PATH_32
|
---|
198 | unset LD_LIBRARY_PATH_64
|
---|
199 |
|
---|
200 | # -------------------- Test 4 --------------------
|
---|
201 |
|
---|
202 | # Have only data model dependent LD_LIBRARY_PATH set; result
|
---|
203 | # should match data model.
|
---|
204 |
|
---|
205 | if [ "${DM}" = "32" ]; then
|
---|
206 | LD_LIBRARY_PATH_32=$TESTSRC/lib/$ARCH/lib$DM/lib$DM
|
---|
207 | export LD_LIBRARY_PATH_32
|
---|
208 | else
|
---|
209 | LD_LIBRARY_PATH_64=$TESTSRC/lib/$ARCH/lib$DM/lib$DM
|
---|
210 | export LD_LIBRARY_PATH_64
|
---|
211 | fi
|
---|
212 |
|
---|
213 | RESULT=`$JAVA libraryCaller`
|
---|
214 | if [ "${RESULT}" != "$DM" ];
|
---|
215 | then
|
---|
216 | echo "Not using data-model dependent LD_LIBRARY_PATH; test fails."
|
---|
217 | exit 1
|
---|
218 | fi
|
---|
219 |
|
---|
220 | # All tests have passed
|
---|
221 | exit 0
|
---|