annotate test/tools/javac/Paths/MineField.sh @ 3721:f8d19ddddc79

8168343: 3 javac tests fail when run on an exploded image Reviewed-by: darcy
author jjg
date Thu, 20 Oct 2016 16:31:42 -0700
parents cf467a017641
children
rev   line source
duke@0 1 #!/bin/sh
duke@0 2
duke@0 3 #
jjg@3407 4 # Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
duke@0 5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 6 #
duke@0 7 # This code is free software; you can redistribute it and/or modify it
duke@0 8 # under the terms of the GNU General Public License version 2 only, as
duke@0 9 # published by the Free Software Foundation.
duke@0 10 #
duke@0 11 # This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 14 # version 2 for more details (a copy is included in the LICENSE file that
duke@0 15 # accompanied this code).
duke@0 16 #
duke@0 17 # You should have received a copy of the GNU General Public License version
duke@0 18 # 2 along with this work; if not, write to the Free Software Foundation,
duke@0 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 20 #
ohair@553 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@553 22 # or visit www.oracle.com if you need additional information or have any
ohair@553 23 # questions.
duke@0 24 #
duke@0 25
duke@0 26 #
duke@0 27 # @test
jjg@3407 28 # @bug 4758537 4809833 8149599
duke@0 29 # @summary Test that javac and java find files in similar ways
duke@0 30 # @author Martin Buchholz
duke@0 31 #
duke@0 32 # @run shell/timeout=600 MineField.sh
duke@0 33
duke@0 34 # To run this test manually, simply do ./MineField.sh
duke@0 35
duke@0 36 #----------------------------------------------------------------
duke@0 37 # The search order for classes used by both java and javac is:
duke@0 38 #
duke@0 39 # -Xbootclasspath/p:<path>
duke@0 40 # -endorseddirs <dirs> or -Djava.endorsed.dirs=<dirs> (search for jar/zip only)
duke@0 41 # -bootclasspath <path> or -Xbootclasspath:<path>
duke@0 42 # -Xbootclasspath/a:<path>
duke@0 43 # -extdirs <dirs> or -Djava.ext.dirs=<dirs> (search for jar/zip only)
duke@0 44 # -classpath <path>, -cp <path>, env CLASSPATH=<path>
duke@0 45 #
duke@0 46 # Peculiarities of the class file search:
duke@0 47 # - Empty elements of the (user) classpath default to ".",
duke@0 48 # while empty elements of other paths are ignored.
duke@0 49 # - Only for the user classpath is an empty string value equivalent to "."
duke@0 50 # - Specifying a bootclasspath on the command line obliterates any
duke@0 51 # previous -Xbootclasspath/p: or -Xbootclasspath/a: command line flags.
jjg@3407 52 #
jjg@3407 53 # JDK 9 update:
jjg@3407 54 # java: The java launcher does not support any of the following:
jjg@3407 55 # * -Xbootclasspath/p: -Xbootclasspath:
jjg@3407 56 # * -endorseddirs -Djava.endorsed.dirs
jjg@3407 57 # * -extdirs -Djava.ext.dirs
jjg@3407 58 # All test cases exercising these features have been removed.
jjg@3407 59 # javac: The following features are only supported when compiling
jjg@3407 60 # for older releases:
jjg@3407 61 # * -Xbootclasspath/p: -Xbootclasspath: -bootclasspath -Xbootclasspath/a:
jjg@3407 62 # * -endorseddirs -Djava.endorsed.dirs
jjg@3407 63 # * -extdirs -Djava.ext.dirs
jjg@3407 64 # All test cases exercising these features have been modified to
jjg@3407 65 # use -source 8 -target 8. In addition, javac test cases involving
jjg@3407 66 # use of the runtime properties java.endorsed.dirs and java.extdirs
jjg@3407 67 # (by means of -J-Dname=value) have been removed.
jjg@3407 68 # Although the primary purpose of the test cases in this file is to
jjg@3407 69 # compare javac and java behavior, some tests remain for javac for
jjg@3407 70 # which there is no java equivalent. However, the cases remain as useful
jjg@3407 71 # test cases for javac handling of the paths involved.
jjg@3407 72
duke@0 73 #----------------------------------------------------------------
duke@0 74
duke@0 75 . ${TESTSRC-.}/Util.sh
duke@0 76
duke@0 77 set -u
duke@0 78
duke@0 79 #----------------------------------------------------------------
duke@0 80 # Prepare the "Minefield"
duke@0 81 #----------------------------------------------------------------
duke@0 82 Cleanup() {
duke@0 83 Sys rm -rf GooSrc GooJar GooZip GooClass
duke@0 84 Sys rm -rf BadSrc BadJar BadZip BadClass
duke@0 85 Sys rm -rf OneDir *.class Main.java MANIFEST.MF
jjg@3407 86 Sys rm -f java-lang.jar
duke@0 87 }
duke@0 88
duke@0 89 Cleanup
duke@0 90 Sys mkdir GooSrc GooJar GooZip GooClass
duke@0 91 Sys mkdir BadSrc BadJar BadZip BadClass
duke@0 92
duke@0 93 echo 'public class Lib {public static void f(){}}' > Lib.java
duke@0 94 Sys "$javac" ${TESTTOOLVMOPTS} Lib.java
duke@0 95 Sys "$jar" cf GooJar/Lib.jar Lib.class
duke@0 96 Sys "$jar" cf GooZip/Lib.zip Lib.class
duke@0 97 Sys mv Lib.class GooClass/.
duke@0 98 Sys mv Lib.java GooSrc/.
duke@0 99 CheckFiles GooZip/Lib.zip GooJar/Lib.jar GooSrc/Lib.java
duke@0 100
duke@0 101 echo 'public class Lib {/* Bad */}' > Lib.java
duke@0 102 Sys "$javac" ${TESTTOOLVMOPTS} Lib.java
duke@0 103 Sys "$jar" cf BadJar/Lib.jar Lib.class
duke@0 104 Sys "$jar" cf BadZip/Lib.zip Lib.class
duke@0 105 Sys mv Lib.class BadClass/.
duke@0 106 Sys mv Lib.java BadSrc/.
duke@0 107 CheckFiles BadZip/Lib.zip BadJar/Lib.jar BadSrc/Lib.java
duke@0 108
duke@0 109 echo 'public class Main {public static void main(String[] a) {Lib.f();}}' > Main.java
duke@0 110
jjg@3407 111 # Create a jar file that is good enough to put on the javac boot class path (i.e. contains java.lang.**)
jjg@3721 112 if [ -r ${TESTJAVA}/lib/modules ]; then
jjg@3721 113 Sys "$jimage" extract --dir modules ${TESTJAVA}/lib/modules
jjg@3721 114 Sys "$jar" cf java-lang.jar -C modules/java.base java/lang
jjg@3721 115 Sys rm -rf modules
jjg@3721 116 elif [ -d ${TESTJAVA}/modules ]; then
jjg@3721 117 Sys "$jar" cf java-lang.jar -C ${TESTJAVA}/modules/java.base java/lang
jjg@3721 118 else
jjg@3721 119 echo 'cannot create java-lang.jar' ; exit 1
jjg@3721 120 fi
jjg@3407 121
duke@0 122 #----------------------------------------------------------------
duke@0 123 # Verify that javac class search order is the same as java's
duke@0 124 #----------------------------------------------------------------
jjg@3407 125 Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
jjg@3407 126 -Xbootclasspath/p:"GooClass" \
jjg@3407 127 -bootclasspath "java-lang.jar${PS}BadZip/Lib.zip" \
jjg@3407 128 Main.java
jjg@3407 129 Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
jjg@3407 130 -Xbootclasspath/p:"BadClass${PS}GooClass" \
jjg@3407 131 -bootclasspath "java-lang.jar${PS}GooZip/Lib.zip${PS}BadClass" \
jjg@3407 132 Main.java
jjg@3407 133 Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
jjg@3407 134 -Xbootclasspath/p:"BadJar/Lib.jar" \
jjg@3407 135 -Xbootclasspath:"java-lang.jar${PS}GooClass" \
jjg@3407 136 Main.java
duke@0 137
duke@0 138 #----------------------------------------------------------------
jjg@3407 139 Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
jjg@3407 140 -bootclasspath "java-lang.jar${PS}GooZip/Lib.zip" \
jjg@3407 141 -Xbootclasspath/p:"BadClass" \
jjg@3407 142 Main.java
jjg@3407 143 Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
jjg@3407 144 -bootclasspath "java-lang.jar${PS}BadZip/Lib.zip" \
jjg@3407 145 -Xbootclasspath/p:"GooClass${PS}BadJar/Lib.jar" \
jjg@3407 146 Main.java
duke@0 147
duke@0 148 #----------------------------------------------------------------
jjg@3407 149 Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
duke@0 150 -Xbootclasspath/p:"BadClass" \
duke@0 151 -Xbootclasspath/a:"GooClass" \
duke@0 152 Main.java
jjg@3407 153 Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
duke@0 154 -Xbootclasspath/p:"GooClass${PS}BadClass" \
duke@0 155 -Xbootclasspath/a:"BadClass" \
duke@0 156 Main.java
jjg@3407 157 Success "$java" ${TESTVMOPTS} \
duke@0 158 -Xbootclasspath/a:"GooClass" \
duke@0 159 Main
duke@0 160
duke@0 161 #----------------------------------------------------------------
jjg@3407 162 Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
jjg@3407 163 -Xbootclasspath/p:"GooClass" \
jjg@3407 164 -Xbootclasspath:"BadClass${PS}java-lang.jar" \
jjg@3407 165 -Xbootclasspath/a:"GooClass" \
jjg@3407 166 Main.java
jjg@3407 167 Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
jjg@3407 168 -Xbootclasspath/p:"BadClass" \
jjg@3407 169 -Xbootclasspath:"GooClass${PS}BadClass${PS}java-lang.jar" \
jjg@3407 170 -Xbootclasspath/a:"BadClass" \
jjg@3407 171 Main.java
duke@0 172
duke@0 173 #----------------------------------------------------------------
jjg@3407 174 Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
jjg@3407 175 -endorseddirs "BadClass${PS}GooZip${PS}BadJar" \
jjg@3407 176 -Xbootclasspath:"BadClass${PS}java-lang.jar" \
jjg@3407 177 Main.java
jjg@3407 178 Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
jjg@3407 179 -Djava.endorsed.dirs="BadClass${PS}GooZip${PS}BadJar" \
jjg@3407 180 -Xbootclasspath:"BadClass${PS}java-lang.jar" \
jjg@3407 181 Main.java
duke@0 182
duke@0 183 #----------------------------------------------------------------
jjg@3407 184 Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
duke@0 185 -Xbootclasspath/a:"BadClass" \
duke@0 186 -extdirs "GooZip" \
duke@0 187 Main.java
jjg@3407 188 Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
duke@0 189 -Xbootclasspath/a:"GooClass${PS}BadClass" \
duke@0 190 -extdirs "BadZip" \
duke@0 191 Main.java
duke@0 192
duke@0 193 #----------------------------------------------------------------
jjg@3407 194 Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
duke@0 195 -extdirs "GooClass${PS}BadZip" \
duke@0 196 -cp "GooZip/Lib.zip" \
duke@0 197 Main.java
jjg@3407 198 Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
duke@0 199 -extdirs "BadClass${PS}GooZip${PS}BadJar" \
duke@0 200 -cp "BadZip/Lib.zip" \
duke@0 201 Main.java
jjg@3407 202 Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} \
duke@0 203 -Djava.ext.dirs="GooZip${PS}BadJar" \
duke@0 204 -classpath "BadZip/Lib.zip" \
duke@0 205 Main.java
duke@0 206
duke@0 207 #----------------------------------------------------------------
duke@0 208 Failure "$javac" ${TESTTOOLVMOPTS} -classpath "BadClass${PS}GooClass" Main.java
duke@0 209 Success "$javac" ${TESTTOOLVMOPTS} -classpath "GooClass${PS}BadClass" Main.java
duke@0 210 Failure "$java" ${TESTVMOPTS} -classpath "BadClass${PS}GooClass${PS}." Main
duke@0 211 Success "$java" ${TESTVMOPTS} -classpath "GooClass${PS}BadClass${PS}." Main
duke@0 212
duke@0 213 Failure "$javac" ${TESTTOOLVMOPTS} -cp "BadJar/Lib.jar${PS}GooZip/Lib.zip" Main.java
duke@0 214 Success "$javac" ${TESTTOOLVMOPTS} -cp "GooJar/Lib.jar${PS}BadZip/Lib.zip" Main.java
duke@0 215 Failure "$java" ${TESTVMOPTS} -cp "BadJar/Lib.jar${PS}${PS}GooZip/Lib.zip" Main
duke@0 216 Success "$java" ${TESTVMOPTS} -cp "GooJar/Lib.jar${PS}${PS}BadZip/Lib.zip" Main
duke@0 217
duke@0 218 Failure env CLASSPATH="BadZip/Lib.zip${PS}GooJar/Lib.jar" "$javac" ${TESTTOOLVMOPTS} Main.java
duke@0 219 Success env CLASSPATH="GooZip/Lib.zip${PS}BadJar/Lib.jar" "$javac" ${TESTTOOLVMOPTS} Main.java
duke@0 220 Failure env CLASSPATH="${PS}BadZip/Lib.zip${PS}GooJar/Lib.jar" "$java" ${TESTVMOPTS} Main
duke@0 221 Success env CLASSPATH="${PS}GooZip/Lib.zip${PS}BadJar/Lib.jar" "$java" ${TESTVMOPTS} Main
duke@0 222
duke@0 223 #----------------------------------------------------------------
duke@0 224 # Check behavior of empty paths and empty path elements
duke@0 225 #----------------------------------------------------------------
duke@0 226 In() { cd "$1"; shift; "$@"; cd ..; }
duke@0 227
duke@0 228 In GooClass Failure "$javac" ${TESTTOOLVMOPTS} -cp ".." ../Main.java
duke@0 229 In GooClass Failure "$java" ${TESTVMOPTS} -cp ".." Main
duke@0 230
duke@0 231 # Unspecified classpath defaults to "."
jjg@2902 232 Sys mkdir OneDir; Sys cp Main.java GooClass/Lib.class OneDir/.
duke@0 233 In OneDir Success "$javac" ${TESTTOOLVMOPTS} Main.java
duke@0 234 In OneDir Success "$java" ${TESTVMOPTS} Main
duke@0 235
duke@0 236 # Empty classpath elements mean "."
duke@0 237 In GooClass Success "$javac" ${TESTTOOLVMOPTS} -cp "${PS}.." ../Main.java
duke@0 238 In GooClass Success "$java" ${TESTVMOPTS} -cp "${PS}.." Main
duke@0 239
duke@0 240 In GooClass Success "$javac" ${TESTTOOLVMOPTS} -cp "..${PS}" ../Main.java
duke@0 241 In GooClass Success "$java" ${TESTVMOPTS} -cp "..${PS}" Main
duke@0 242
duke@0 243 In GooClass Success "$javac" ${TESTTOOLVMOPTS} -cp "..${PS}${PS}/xyzzy" ../Main.java
duke@0 244 In GooClass Success "$java" ${TESTVMOPTS} -cp "..${PS}${PS}/xyzzy" Main
duke@0 245
duke@0 246 # All other empty path elements are ignored.
jjg@3407 247 In GooJar Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -extdirs "" -cp ".." ../Main.java
duke@0 248
jjg@3407 249 In GooJar Failure "$javac" -source 8 -targt 8 ${TESTTOOLVMOPTS} -extdirs "${PS}" -cp ".." ../Main.java
jjg@3407 250 In GooJar Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -Djava.ext.dirs="${PS}" -cp ".." ../Main.java
duke@0 251
jjg@3407 252 In GooJar Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -extdirs "." -cp ".." ../Main.java
jjg@3407 253 In GooJar Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -Djava.ext.dirs="." -cp ".." ../Main.java
duke@0 254
jjg@3407 255 In GooJar Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -Djava.endorsed.dirs="" -cp ".." ../Main.java
duke@0 256
jjg@3407 257 In GooJar Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -endorseddirs "${PS}" -cp ".." ../Main.java
duke@0 258
jjg@3407 259 In GooJar Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -Djava.endorsed.dirs="." -cp ".." ../Main.java
duke@0 260
jjg@3407 261 In GooClass Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -Xbootclasspath/p: -cp ".." ../Main.java
duke@0 262
jjg@3407 263 In GooClass Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -Xbootclasspath/p:. -cp ".." ../Main.java
duke@0 264
jjg@3407 265 In GooClass Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -Xbootclasspath:"../java-lang.jar" -cp ".." ../Main.java
duke@0 266
jjg@3407 267 In GooClass Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -Xbootclasspath:"../java-lang.jar${PS}." -cp ".." ../Main.java
duke@0 268
jjg@3407 269 In GooClass Failure "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -Xbootclasspath/a: -cp ".." ../Main.java
duke@0 270 In GooClass Failure "$java" ${TESTVMOPTS} -Xbootclasspath/a: -cp ".." Main
duke@0 271
jjg@3407 272 In GooClass Success "$javac" -source 8 -target 8 ${TESTTOOLVMOPTS} -Xbootclasspath/a:. -cp ".." ../Main.java
duke@0 273 In GooClass Success "$java" ${TESTVMOPTS} -Xbootclasspath/a:. -cp ".." Main
duke@0 274
duke@0 275 Cleanup
duke@0 276
duke@0 277 Bottom Line