1# Copyright (c) 2003, 2012, 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 4262583 4418997 4795136 25# @summary Check support for jar file members with sizes > 2GB 26# @author Martin Buchholz 27# 28# @build FileBuilder 29# @run shell 3GBZipFiles.sh 9986 30# @ignore runs for hours and eats up 7 Gigabytes of disk space 31# @run shell/timeout=604800 3GBZipFiles.sh 3141592653 32# @key randomness 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 47die () { echo "$1" >&2; exit 1; } 48 49sys () { "$@" || die "Command $@ failed: rc=$?"; } 50 51set -u 52 53myName=`printf %s "$0" | sed 's:.*[/\\]::'`; 54 55if test -z "${TESTJAVA-}"; then 56 test "$#" -eq 2 || die "Usage: $myName /path/to/jdk filesize" 57 TESTJAVA="$1"; shift 58 TESTCLASSES="`pwd`" 59fi 60 61hugeSize="$1"; shift 62tinySize=42 63 64JAVA="$TESTJAVA/bin/java" 65JAR="$TESTJAVA/bin/jar" 66 67currentDir="`pwd`" 68tmpDir="$myName.tmp" 69 70cleanup () { cd "$currentDir" && rm -rf "$tmpDir"; } 71 72trap cleanup 0 1 2 15 73 74sys rm -rf "$tmpDir" 75sys mkdir "$tmpDir" 76cd "$tmpDir" 77 78buildFile () 79{ 80 filetype_="$1" 81 filename_="$2" 82 case "$filename_" in 83 huge-*) filesize_="$hugeSize" ;; 84 tiny-*) filesize_="$tinySize" ;; 85 esac 86 sys "$JAVA" ${TESTVMOPTS} "-cp" "$TESTCLASSES" "FileBuilder" \ 87 "$filetype_" "$filename_" "$filesize_" 88} 89 90testJarFile () 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 132testJarFile "MostlyEmpty" "DEFLATED" "tiny-1 huge-1 tiny-2 huge-2 tiny-3" 133testJarFile "MostlyEmpty" "STORED" "tiny-1 huge-1 tiny-2" 134testJarFile "SlightlyCompressible" "DEFLATED" "tiny-1 huge-1 tiny-2" 135 136cleanup 137 138exit 0 139