source: trunk/openjdk/jdk/test/tools/pack200/Pack200Simple.sh

Last change on this file was 278, checked in by dmik, 14 years ago

trunk: Merged in openjdk6 b22 from branches/vendor/oracle.

File size: 5.6 KB
Line 
1#
2# Copyright (c) 2003, 2007, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20# or visit www.oracle.com if you need additional information or have any
21# questions.
22#
23
24# @test Pack200Simple.sh
25# @bug 6521334
26# @build Pack200Test
27# @run shell/timeout=1200 Pack200Simple.sh
28# @summary An ad hoc test to verify class-file format.
29# @author Kumar Srinivasan
30
31# The goal of this test is to assist javac or other developers
32# who modify class file formats, to quickly test those modifications
33# without having to build the install workspace. However it must
34# be noted that building the install workspace is the only know
35# way to prevent build breakages.
36
37# Pack200 developers could use this as a basic smoke-test, however
38# please note, there are other more elaborate and thorough tests for
39# this very purpose.
40
41# We try a potpouri of things ie. we have pack.conf to setup some
42# options as well as a couple of command line options. We also test
43# the packing and unpacking mechanism using the Java APIs.
44
45# print error and exit with a message
46errorOut() {
47 if [ "x$1" = "x" ]; then
48 printf "Error: Unknown error\n"
49 else
50 printf "Error: %s\n" "$1"
51 fi
52
53 exit 1
54}
55
56# Verify directory context variables are set
57if [ "${TESTJAVA}" = "" ]; then
58 errorOut "TESTJAVA not set. Test cannot execute. Failed."
59fi
60
61if [ "${TESTSRC}" = "" ]; then
62 errorOut "TESTSRC not set. Test cannot execute. Failed."
63fi
64
65
66if [ "${TESTCLASSES}" = "" ]; then
67 errorOut "TESTCLASSES not set. Test cannot execute. Failed."
68fi
69
70# The common java utils we need
71PACK200=${TESTJAVA}/bin/pack200
72UNPACK200=${TESTJAVA}/bin/unpack200
73JAR=${TESTJAVA}/bin/jar
74
75# For Windows and Linux needs the heap to be set, for others ergonomics
76# will do the rest. It is important to use ea, which can expose class
77# format errors much earlier than later.
78
79OS=`uname -s`
80
81
82case "$OS" in
83 Windows*|CYGWIN* )
84 PackOptions="-J-Xmx512m -J-ea"
85 break
86 ;;
87
88 Linux )
89 PackOptions="-J-Xmx512m -J-ea"
90 break
91 ;;
92
93 * )
94 PackOptions="-J-ea"
95 ;;
96esac
97
98# Creates a packfile of choice expects 1 argument the filename
99createConfigFile() {
100 # optimize for speed
101 printf "pack.effort=1\n" > $1
102 # we DO want to know about new attributes
103 printf "pack.unknown.attribute=error\n" >> $1
104 # optimize for speed
105 printf "pack.deflate.hint=false\n" >> $1
106 # keep the ordering for easy compare
107 printf "pack.keep.class.order=true\n" >> $1
108}
109
110
111# Tests a given jar, expects 1 argument the fully qualified
112# name to a test jar, it writes all output to the current
113# directory which is a scratch area.
114testAJar() {
115 PackConf="pack.conf"
116 createConfigFile $PackConf
117
118 # Try some command line options
119 CLIPackOptions="$PackOptions -v --no-gzip --segment-limit=10000 --config-file=$PackConf"
120
121 jfName=`basename $1`
122
123 ${PACK200} $CLIPackOptions ${jfName}.pack $1 > ${jfName}.pack.log 2>&1
124 if [ $? != 0 ]; then
125 errorOut "$jfName packing failed"
126 fi
127
128 # We want to test unpack200, therefore we dont use -r with pack
129 ${UNPACK200} -v ${jfName}.pack $jfName > ${jfName}.unpack.log 2>&1
130 if [ $? != 0 ]; then
131 errorOut "$jfName unpacking failed"
132 fi
133
134 # A quick crc compare test to ensure a well formed zip
135 # archive, this is a critical unpack200 behaviour.
136
137 unzip -t $jfName > ${jfName}.unzip.log 2>&1
138 if [ $? != 0 ]; then
139 errorOut "$jfName unzip -t test failed"
140 fi
141
142 # The PACK200 signature should be at the top of the log
143 # this tag is critical for deployment related tools.
144
145 head -5 ${jfName}.unzip.log | grep PACK200 > /dev/null 2>&1
146 if [ $? != 0 ]; then
147 errorOut "$jfName PACK200 signature missing"
148 fi
149
150
151 # we know the size fields don't match, strip 'em out, its
152 # extremely important to ensure that the date stamps match up.
153 # Don't EVER sort the output we are checking for correct ordering.
154
155 ${JAR} -tvf $1 | sed -e 's/^ *[0-9]* //g'> ${jfName}.ref.txt
156 ${JAR} -tvf $jfName | sed -e 's/^ *[0-9]* //g'> ${jfName}.cmp.txt
157
158 diff ${jfName}.ref.txt ${jfName}.cmp.txt > ${jfName}.diff.log 2>&1
159 if [ $? != 0 ]; then
160 errorOut "$jfName files missing"
161 fi
162}
163
164# These JARs are the largest and also the most likely specimens to
165# expose class format issues and stress the packer as well.
166
167JLIST="${TESTJAVA}/lib/tools.jar ${TESTJAVA}/jre/lib/rt.jar"
168
169
170# Test the Command Line Interfaces (CLI).
171mkdir cliTestDir
172_pwd=`pwd`
173cd cliTestDir
174
175for jarfile in $JLIST ; do
176 if [ -f $jarfile ]; then
177 testAJar $jarfile
178 else
179 errorOut "Error: '$jarFile' does not exist\nTest requires a j2sdk-image\n"
180 fi
181done
182cd $_pwd
183
184# Test the Java APIs.
185mkdir apiTestDir
186_pwd=`pwd`
187cd apiTestDir
188
189# Strip out the -J prefixes.
190JavaPackOptions=`printf %s "$PackOptions" | sed -e 's/-J//g'`
191
192# Test the Java APIs now.
193$TESTJAVA/bin/java $JavaPackOptions -cp $TESTCLASSES Pack200Test $JLIST || exit 1
194
195cd $_pwd
196
197exit 0
Note: See TracBrowser for help on using the repository browser.