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 
  33 # Command-line usage:
  34 # javac FileBuilder.java && sh 3GBZipFiles.sh /path/to/jdk filesize
  35 
  36 # -------------------------------------------------------------------
  37 # Testing strategy: We want to test for size limits on the Jar file
  38 # itself, as well as on the compressed and uncompressed sizes of the
  39 # files stored therein.  All of these limits should be 4GB and should
  40 # be tested in the 2GB-4GB range.  We also want to check that it is
  41 # possible to store more than 6GB of actual data in a zip file, if we
  42 # have two files of size 3GB which compress nicely.  We also want to
  43 # test both the "STORED" and "DEFLATED" compression methods.
  44 # -------------------------------------------------------------------
  45 
  46 die () { echo "$1" >&2; exit 1; }
  47 
  48 sys () { "$@" || die "Command $@ failed: rc=$?"; }
  49 
  50 set -u
  51 
  52 myName=`printf %s "$0" | sed 's:.*[/\\]::'`;
  53 
  54 if test -z "${TESTJAVA-}"; then
  55   test "$#" -eq 2 || die "Usage: $myName /path/to/jdk filesize"
  56   TESTJAVA="$1"; shift
  57   TESTCLASSES="`pwd`"
  58 fi
  59 
  60 hugeSize="$1"; shift
  61 tinySize=42
  62 
  63 JAVA="$TESTJAVA/bin/java"
  64 JAR="$TESTJAVA/bin/jar"
  65 
  66 currentDir="`pwd`"
  67 tmpDir="$myName.tmp"
  68 
  69 cleanup () { cd "$currentDir" && rm -rf "$tmpDir"; }
  70 
  71 trap cleanup 0 1 2 15
  72 
  73 sys rm -rf "$tmpDir"
  74 sys mkdir "$tmpDir"
  75 cd "$tmpDir"
  76 
  77 buildFile ()
  78 {
  79   filetype_="$1"
  80   filename_="$2"
  81   case "$filename_" in
  82     huge-*) filesize_="$hugeSize" ;;
  83     tiny-*) filesize_="$tinySize" ;;
  84   esac
  85   sys "$JAVA" ${TESTVMOPTS} "-cp" "$TESTCLASSES" "FileBuilder" \
  86    "$filetype_" "$filename_" "$filesize_"
  87 }
  88 
  89 testJarFile ()
  90 {
  91   echo "-------------------------------------------------------"
  92   echo "Testing $1 $2"
  93   echo "-------------------------------------------------------"
  94 
  95   filetype="$1"
  96   if test "$2" = "STORED"; then jarOpt="0"; else jarOpt=""; fi
  97   filelist="$3"
  98   jarFile="$myName.jar"
  99 
 100   for file in $filelist; do
 101     buildFile "$filetype" "$file"
 102   done
 103 
 104   sys "$JAR" cvM${jarOpt}f "$jarFile" $filelist
 105   sys ls -l "$jarFile"
 106   sys "$JAR" tvf "$jarFile"
 107 
 108   for file in $filelist; do
 109     case "$file" in
 110       huge-*) size="$hugeSize" ;;
 111       tiny-*) size="$tinySize" ;;
 112     esac
 113     case "`$JAR tvf $jarFile $file`" in
 114       *"$size"*"$file"*) : ;;
 115       *) die "Output of \"jar tvf\" is incorrect." ;;
 116     esac
 117     # Try to minimize disk space used while verifying the jar file.
 118     sum1="`sum $file`"
 119     sys rm "$file"
 120     sys "$JAR" xvf "$jarFile" "$file"
 121     sum2="`sum $file`"
 122     test "$sum1" = "$sum2" || die "Jar File is corrupted."
 123     sys rm "$file"
 124     # unzip $jarFile $file
 125     # sys rm "$file"
 126   done
 127 
 128   sys rm "$jarFile"
 129 }
 130 
 131 testJarFile "MostlyEmpty" "DEFLATED" "tiny-1 huge-1 tiny-2 huge-2 tiny-3"
 132 testJarFile "MostlyEmpty" "STORED" "tiny-1 huge-1 tiny-2"
 133 testJarFile "SlightlyCompressible" "DEFLATED" "tiny-1 huge-1 tiny-2"
 134 
 135 cleanup
 136 
 137 exit 0