J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | # |
| 2 | # Copyright 2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | # CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | # have any questions. |
| 22 | # |
| 23 | |
| 24 | # @test |
| 25 | # @bug 4262583 4418997 4795136 |
| 26 | # @summary Check support for jar file members with sizes > 2GB |
| 27 | # @author Martin Buchholz |
| 28 | # |
| 29 | # @build FileBuilder |
| 30 | # @run shell 3GBZipFiles.sh 9986 |
| 31 | # @ignore runs for hours and eats up 7 Gigabytes of disk space |
| 32 | # @run shell/timeout=604800 3GBZipFiles.sh 3141592653 |
| 33 | |
| 34 | # Command-line usage: |
| 35 | # javac FileBuilder.java && sh 3GBZipFiles.sh /path/to/jdk filesize |
| 36 | |
| 37 | # ------------------------------------------------------------------- |
| 38 | # Testing strategy: We want to test for size limits on the Jar file |
| 39 | # itself, as well as on the compressed and uncompressed sizes of the |
| 40 | # files stored therein. All of these limits should be 4GB and should |
| 41 | # be tested in the 2GB-4GB range. We also want to check that it is |
| 42 | # possible to store more than 6GB of actual data in a zip file, if we |
| 43 | # have two files of size 3GB which compress nicely. We also want to |
| 44 | # test both the "STORED" and "DEFLATED" compression methods. |
| 45 | # ------------------------------------------------------------------- |
| 46 | |
| 47 | die () { echo "$1" >&2; exit 1; } |
| 48 | |
| 49 | sys () { "$@" || die "Command $@ failed: rc=$?"; } |
| 50 | |
| 51 | set -u |
| 52 | |
| 53 | myName=`printf %s "$0" | sed 's:.*[/\\]::'`; |
| 54 | |
| 55 | if test -z "${TESTJAVA-}"; then |
| 56 | test "$#" -eq 2 || die "Usage: $myName /path/to/jdk filesize" |
| 57 | TESTJAVA="$1"; shift |
| 58 | TESTCLASSES="`pwd`" |
| 59 | fi |
| 60 | |
| 61 | hugeSize="$1"; shift |
| 62 | tinySize=42 |
| 63 | |
| 64 | JAVA="$TESTJAVA/bin/java" |
| 65 | JAR="$TESTJAVA/bin/jar" |
| 66 | |
| 67 | currentDir="`pwd`" |
| 68 | tmpDir="$myName.tmp" |
| 69 | |
| 70 | cleanup () { cd "$currentDir" && rm -rf "$tmpDir"; } |
| 71 | |
| 72 | trap cleanup 0 1 2 15 |
| 73 | |
| 74 | sys rm -rf "$tmpDir" |
| 75 | sys mkdir "$tmpDir" |
| 76 | cd "$tmpDir" |
| 77 | |
| 78 | buildFile () |
| 79 | { |
| 80 | filetype_="$1" |
| 81 | filename_="$2" |
| 82 | case "$filename_" in |
| 83 | huge-*) filesize_="$hugeSize" ;; |
| 84 | tiny-*) filesize_="$tinySize" ;; |
| 85 | esac |
| 86 | sys "$JAVA" "-cp" "$TESTCLASSES" "FileBuilder" \ |
| 87 | "$filetype_" "$filename_" "$filesize_" |
| 88 | } |
| 89 | |
| 90 | testJarFile () |
| 91 | { |
| 92 | echo "-------------------------------------------------------" |
| 93 | echo "Testing $1 $2" |
| 94 | echo "-------------------------------------------------------" |
| 95 | |
| 96 | filetype="$1" |
| 97 | if test "$2" = "STORED"; then jarOpt="0"; else jarOpt=""; fi |
| 98 | filelist="$3" |
| 99 | jarFile="$myName.jar" |
| 100 | |
| 101 | for file in $filelist; do |
| 102 | buildFile "$filetype" "$file" |
| 103 | done |
| 104 | |
| 105 | sys "$JAR" cvM${jarOpt}f "$jarFile" $filelist |
| 106 | sys ls -l "$jarFile" |
| 107 | sys "$JAR" tvf "$jarFile" |
| 108 | |
| 109 | for file in $filelist; do |
| 110 | case "$file" in |
| 111 | huge-*) size="$hugeSize" ;; |
| 112 | tiny-*) size="$tinySize" ;; |
| 113 | esac |
| 114 | case "`$JAR tvf $jarFile $file`" in |
| 115 | *"$size"*"$file"*) : ;; |
| 116 | *) die "Output of \"jar tvf\" is incorrect." ;; |
| 117 | esac |
| 118 | # Try to minimize disk space used while verifying the jar file. |
| 119 | sum1="`sum $file`" |
| 120 | sys rm "$file" |
| 121 | sys "$JAR" xvf "$jarFile" "$file" |
| 122 | sum2="`sum $file`" |
| 123 | test "$sum1" = "$sum2" || die "Jar File is corrupted." |
| 124 | sys rm "$file" |
| 125 | # unzip $jarFile $file |
| 126 | # sys rm "$file" |
| 127 | done |
| 128 | |
| 129 | sys rm "$jarFile" |
| 130 | } |
| 131 | |
| 132 | testJarFile "MostlyEmpty" "DEFLATED" "tiny-1 huge-1 tiny-2 huge-2 tiny-3" |
| 133 | testJarFile "MostlyEmpty" "STORED" "tiny-1 huge-1 tiny-2" |
| 134 | testJarFile "SlightlyCompressible" "DEFLATED" "tiny-1 huge-1 tiny-2" |
| 135 | |
| 136 | cleanup |
| 137 | |
| 138 | exit 0 |