1 # |
|
2 # Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. |
|
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 # |
|
5 # This code is free software; you can redistribute it and/or modify it |
|
6 # under the terms of the GNU General Public License version 2 only, as |
|
7 # published by the Free Software Foundation. |
|
8 # |
|
9 # This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 # version 2 for more details (a copy is included in the LICENSE file that |
|
13 # accompanied this code). |
|
14 # |
|
15 # You should have received a copy of the GNU General Public License version |
|
16 # 2 along with this work; if not, write to the Free Software Foundation, |
|
17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 # |
|
19 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 # or visit www.oracle.com if you need additional information or have any |
|
21 # questions. |
|
22 # |
|
23 |
|
24 # @test |
|
25 # @bug 4894330 4810347 6277269 |
|
26 # @run shell ChangeDataModel.sh |
|
27 # @summary Verify -d32 and -d64 options are accepted(rejected) on all platforms |
|
28 # @author Joseph D. Darcy |
|
29 |
|
30 OS=`uname -s`; |
|
31 |
|
32 # To remove CR from output, needed for java apps in CYGWIN, harmless otherwise |
|
33 SED_CR="sed -e s@\\r@@g" |
|
34 |
|
35 case "$OS" in |
|
36 Windows* | CYGWIN* ) |
|
37 PATHSEP=";" |
|
38 ;; |
|
39 |
|
40 * ) |
|
41 PATHSEP=":" |
|
42 ;; |
|
43 esac |
|
44 |
|
45 # Verify directory context variables are set |
|
46 if [ "${TESTJAVA}" = "" ] |
|
47 then |
|
48 echo "TESTJAVA not set. Test cannot execute. Failed." |
|
49 exit 1 |
|
50 fi |
|
51 |
|
52 if [ "${TESTSRC}" = "" ] |
|
53 then |
|
54 echo "TESTSRC not set. Test cannot execute. Failed." |
|
55 exit 1 |
|
56 fi |
|
57 |
|
58 if [ "${TESTCLASSES}" = "" ] |
|
59 then |
|
60 echo "TESTCLASSES not set. Test cannot execute. Failed." |
|
61 exit 1 |
|
62 fi |
|
63 |
|
64 # Construct paths to default Java executables |
|
65 JAVA="$TESTJAVA/bin/java -classpath $TESTCLASSES${PATHSEP}." |
|
66 JAVAC="$TESTJAVA/bin/javac" |
|
67 |
|
68 |
|
69 # Create our little Java test on the fly |
|
70 ( printf "public class GetDataModel {" |
|
71 printf " public static void main(String argv[]) {" |
|
72 printf " System.out.println(System.getProperty(\"sun.arch.data.model\", \"none\"));" |
|
73 printf " }" |
|
74 printf "}" |
|
75 ) > GetDataModel.java |
|
76 |
|
77 $JAVAC GetDataModel.java |
|
78 |
|
79 |
|
80 # All preconditions are met; run the tests. |
|
81 |
|
82 |
|
83 # Verify data model flag for default data model is accepted |
|
84 |
|
85 DM=`$JAVA GetDataModel | ${SED_CR}` |
|
86 case "$DM" in |
|
87 32 ) |
|
88 DM2=`${JAVA} -d32 GetDataModel | ${SED_CR}` |
|
89 if [ "${DM2}" != "32" ] |
|
90 then |
|
91 echo "Data model flag -d32 not accepted or had improper effect." |
|
92 exit 1 |
|
93 fi |
|
94 ;; |
|
95 |
|
96 64 ) |
|
97 DM2=`${JAVA} -d64 GetDataModel | ${SED_CR}` |
|
98 if [ "${DM2}" != "64" ] |
|
99 then |
|
100 echo "Data model flag -d64 not accepted or had improper effect." |
|
101 exit 1 |
|
102 fi |
|
103 ;; |
|
104 |
|
105 * ) |
|
106 echo "Unrecognized data model: $DM" |
|
107 exit 1 |
|
108 ;; |
|
109 esac |
|
110 |
|
111 # Determine if platform might be dual-mode capable. |
|
112 |
|
113 case "$OS" in |
|
114 SunOS ) |
|
115 # ARCH should be sparc or i386 |
|
116 ARCH=`uname -p` |
|
117 case "${ARCH}" in |
|
118 sparc ) |
|
119 DUALMODE=true |
|
120 PATH64=sparcv9 |
|
121 ;; |
|
122 |
|
123 i386 ) |
|
124 DUALMODE=true |
|
125 PATH64=amd64 |
|
126 ;; |
|
127 |
|
128 * ) |
|
129 DUALMODE=false |
|
130 ;; |
|
131 esac |
|
132 ;; |
|
133 |
|
134 |
|
135 Linux ) |
|
136 # ARCH should be ia64, x86_64, or i*86 |
|
137 ARCH=`uname -m` |
|
138 case "${ARCH}" in |
|
139 ia64 ) |
|
140 DUALMODE=false |
|
141 ;; |
|
142 |
|
143 x86_64 ) |
|
144 DUALMODE=true |
|
145 PATH64=amd64 |
|
146 ;; |
|
147 |
|
148 * ) |
|
149 DUALMODE=false; |
|
150 ;; |
|
151 esac |
|
152 ;; |
|
153 |
|
154 Windows* | CYGWIN* ) |
|
155 ARCH=`uname -m` |
|
156 case "${ARCH}" in |
|
157 * ) |
|
158 DUALMODE=false; |
|
159 ;; |
|
160 esac |
|
161 ;; |
|
162 |
|
163 * ) |
|
164 echo "Warning: unknown environment." |
|
165 DUALMODE=false |
|
166 ;; |
|
167 esac |
|
168 |
|
169 if [ "${DUALMODE}" = "true" ] |
|
170 then |
|
171 # Construct path to 64-bit Java executable, might not exist |
|
172 JAVA64FILE="${TESTJAVA}/bin/${PATH64}/java" |
|
173 JAVA64="${JAVA64FILE} -classpath ${TESTCLASSES}${PATHSEP}." |
|
174 |
|
175 if [ -f ${JAVA64FILE} ]; then |
|
176 # Verify that, at least on Solaris, only one exec is |
|
177 # used to change data models |
|
178 if [ "${OS}" = "SunOS" ] |
|
179 then |
|
180 rm -f truss.out |
|
181 truss -texec ${JAVA} -d64 GetDataModel > /dev/null 2> truss.out |
|
182 execCount=`grep -c execve truss.out` |
|
183 if [ "${execCount}" -gt 2 ] |
|
184 then |
|
185 echo "Maximum exec count of 2 exceeded: got $execCount." |
|
186 exit 1 |
|
187 fi |
|
188 |
|
189 rm -f truss.out |
|
190 truss -texec ${JAVA64} -d32 GetDataModel > /dev/null 2> truss.out |
|
191 execCount=`grep -c execve truss.out` |
|
192 if [ "${execCount}" -gt 2 ] |
|
193 then |
|
194 echo "Maximum exec count of 2 exceeded: got $execCount." |
|
195 exit 1 |
|
196 fi |
|
197 fi |
|
198 |
|
199 DM2=`${JAVA} -d64 GetDataModel` |
|
200 if [ "${DM2}" != "64" ] |
|
201 then |
|
202 echo "Data model flag -d64 not accepted or had improper effect." |
|
203 exit 1 |
|
204 fi |
|
205 |
|
206 DM2=`${JAVA64} GetDataModel` |
|
207 if [ "${DM2}" != "64" ] |
|
208 then |
|
209 echo "Improper data model returned." |
|
210 exit 1 |
|
211 fi |
|
212 |
|
213 DM2=`${JAVA64} -d64 GetDataModel` |
|
214 if [ "${DM2}" != "64" ] |
|
215 then |
|
216 echo "Data model flag -d64 not accepted or had improper effect." |
|
217 exit 1 |
|
218 fi |
|
219 |
|
220 DM2=`${JAVA64} -d32 GetDataModel` |
|
221 if [ "${DM2}" != "32" ] |
|
222 then |
|
223 echo "Data model flag -d32 not accepted or had improper effect." |
|
224 exit 1 |
|
225 fi |
|
226 |
|
227 else |
|
228 echo "Warning: no 64-bit components found; only one data model tested." |
|
229 fi |
|
230 else |
|
231 # Negative tests for non-dual mode platforms to ensure the other data model is |
|
232 # rejected |
|
233 DM=`$JAVA GetDataModel | ${SED_CR}` |
|
234 case "$DM" in |
|
235 32 ) |
|
236 DM2=`${JAVA} -d64 GetDataModel | ${SED_CR}` |
|
237 if [ "x${DM2}" != "x" ] |
|
238 then |
|
239 echo "Data model flag -d64 was accepted." |
|
240 exit 1 |
|
241 fi |
|
242 ;; |
|
243 |
|
244 64 ) |
|
245 DM2=`${JAVA} -d32 GetDataModel | ${SED_CR}` |
|
246 if [ "x${DM2}" != "x" ] |
|
247 then |
|
248 echo "Data model flag -d32 was accepted." |
|
249 exit 1 |
|
250 fi |
|
251 ;; |
|
252 |
|
253 * ) |
|
254 echo "Unrecognized data model: $DM" |
|
255 exit 1 |
|
256 ;; |
|
257 esac |
|
258 fi |
|
259 |
|
260 exit 0; |
|