jdk/test/tools/pack200/Pack200Simple.sh
author duke
Wed, 05 Jul 2017 17:10:17 +0200
changeset 5271 e6f21008e6f7
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Added tag jdk7-b90 for changeset 1d1927f9ec09
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
# Copyright 2003-2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
# This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
# under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
# published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
# This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
# version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
# accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
# You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
# 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
# CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
# have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
#
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
# @test Pack200Simple.sh
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
# @bug  6521334
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
# @build Pack200Test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
# @run shell/timeout=1200 Pack200Simple.sh
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
# @summary An ad hoc test to verify class-file format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
# @author Kumar Srinivasan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
# The goal of this test is to assist javac or other developers 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
# who modify class file formats, to quickly test those modifications
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
# without having to build the install workspace. However it must
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
# be noted that building the install workspace is the only know
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
# way to prevent build breakages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
# Pack200 developers could use this  as a basic smoke-test, however 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
# please note, there are other more elaborate and  thorough tests for 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
# this very purpose. 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
# We try a potpouri of things ie. we have pack.conf to setup some 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
# options as well as a couple of command line options. We also test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
# the packing and unpacking mechanism using the Java APIs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
# print error and exit with a message 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
errorOut() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
  if [ "x$1" = "x" ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    printf "Error: Unknown error\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    printf "Error: %s\n" "$1"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
  exit 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
# Verify directory context variables are set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
if [ "${TESTJAVA}" = "" ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
  errorOut "TESTJAVA not set.  Test cannot execute.  Failed."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
if [ "${TESTSRC}" = "" ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
  errorOut "TESTSRC not set.  Test cannot execute.  Failed."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
if [ "${TESTCLASSES}" = "" ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
  errorOut "TESTCLASSES not set.  Test cannot execute.  Failed."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
# The common java utils we need
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
PACK200=${TESTJAVA}/bin/pack200
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
UNPACK200=${TESTJAVA}/bin/unpack200
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
JAR=${TESTJAVA}/bin/jar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
# For Windows and Linux needs the heap to be set, for others ergonomics
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
# will do the rest. It is important to use ea, which can expose class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
# format errors much earlier than later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
OS=`uname -s`
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
case "$OS" in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
  Windows*|CYGWIN* )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    PackOptions="-J-Xmx512m -J-ea"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    break
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    ;;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
  Linux )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    PackOptions="-J-Xmx512m -J-ea"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    break
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    ;;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
  * )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    PackOptions="-J-ea"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    ;;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
esac
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
# Creates a packfile of choice expects 1 argument the filename
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
createConfigFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 # optimize for speed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 printf "pack.effort=1\n" > $1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 # we DO want to know about new attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 printf "pack.unknown.attribute=error\n" >> $1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 # optimize for speed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 printf "pack.deflate.hint=false\n" >> $1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 # keep the ordering for easy compare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 printf "pack.keep.class.order=true\n" >> $1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
# Tests a given jar, expects 1 argument the fully qualified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
# name to a test jar, it writes all output to the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
# directory which is a scratch  area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
testAJar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
  PackConf="pack.conf"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
  createConfigFile $PackConf
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
  # Try some command line options
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
  CLIPackOptions="$PackOptions -v --no-gzip --segment-limit=10000 --config-file=$PackConf"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
  jfName=`basename $1`
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
  ${PACK200}   $CLIPackOptions  ${jfName}.pack $1 > ${jfName}.pack.log 2>&1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
  if [ $? != 0 ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    errorOut "$jfName packing failed"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
  fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  # We want to test unpack200, therefore we dont use -r with pack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  ${UNPACK200} -v ${jfName}.pack $jfName > ${jfName}.unpack.log 2>&1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
  if [ $? != 0 ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    errorOut "$jfName unpacking failed"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
  fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
  # A quick crc compare test to ensure a well formed zip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
  # archive, this is a critical unpack200 behaviour.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
  unzip -t $jfName > ${jfName}.unzip.log 2>&1 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
  if [ $? != 0 ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    errorOut "$jfName unzip -t test failed"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
  fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
  # The PACK200 signature should be at the top of the log
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
  # this tag is critical for deployment related tools.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
  head -5 ${jfName}.unzip.log | grep PACK200 > /dev/null 2>&1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
  if [ $? != 0 ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    errorOut "$jfName PACK200 signature missing"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
  fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
  # we know  the size fields don't match, strip 'em out, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
  # extremely important to ensure that the date stamps match up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
  # Don't EVER sort the output we are checking for correct ordering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
  ${JAR} -tvf $1 | sed -e 's/^ *[0-9]* //g'> ${jfName}.ref.txt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
  ${JAR} -tvf $jfName | sed -e 's/^ *[0-9]* //g'> ${jfName}.cmp.txt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
  diff ${jfName}.ref.txt ${jfName}.cmp.txt > ${jfName}.diff.log 2>&1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
  if [ $? != 0 ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    errorOut "$jfName files missing"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
  fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
# These JARs are the largest and also the most likely specimens to 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
# expose class format issues and stress the packer as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
JLIST="${TESTJAVA}/lib/tools.jar ${TESTJAVA}/jre/lib/rt.jar"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
# Test the Command Line Interfaces (CLI).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
mkdir cliTestDir 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
_pwd=`pwd`
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
cd cliTestDir
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
for jarfile in $JLIST ; do 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
  if [ -f $jarfile ]; then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    testAJar $jarfile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    errorOut "Error: '$jarFile' does not exist\nTest requires a j2sdk-image\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
  fi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
cd $_pwd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
# Test the Java APIs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
mkdir apiTestDir 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
_pwd=`pwd`
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
cd  apiTestDir
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
# Strip out the -J prefixes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
JavaPackOptions=`printf %s "$PackOptions" | sed -e 's/-J//g'`
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
# Test the Java APIs now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
$TESTJAVA/bin/java $JavaPackOptions -cp $TESTCLASSES Pack200Test $JLIST || exit 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
cd $_pwd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
exit 0