Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/tools/pack200/CommandLineTests.java
38833 views
/*1* Copyright (c) 2007, 2013, 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 it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 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 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test CommandLineTests.sh25* @bug 6521334 6965836 696583626* @compile -XDignore.symbol.file CommandLineTests.java Pack200Test.java27* @run main/timeout=1200 CommandLineTests28* @summary An ad hoc test to verify the behavior of pack200/unpack200 CLIs,29* and a simulation of pack/unpacking in the install repo.30* @author ksrini31*/3233import java.io.File;34import java.io.FileOutputStream;35import java.io.IOException;36import java.io.PrintStream;37import java.util.ArrayList;38import java.util.List;39/*40* We try a potpouri of things ie. we have pack.conf to setup some41* options as well as a couple of command line options. We also test42* the packing and unpacking mechanism using the Java APIs. This also43* simulates pack200 the install workspace, noting that this is a simulation44* and can only test jars that are guaranteed to be available, also the45* configuration may not be in sync with the installer workspace.46*/4748public class CommandLineTests {49private static final File CWD = new File(".");50private static final File EXP_SDK = new File(CWD, "exp-sdk-image");51private static final File EXP_SDK_LIB_DIR = new File(EXP_SDK, "lib");52private static final File EXP_SDK_BIN_DIR = new File(EXP_SDK, "bin");53private static final File EXP_JRE_DIR = new File(EXP_SDK, "jre");54private static final File EXP_JRE_LIB_DIR = new File(EXP_JRE_DIR, "lib");55private static final File RtJar = new File(EXP_JRE_LIB_DIR, "rt.jar");56private static final File CharsetsJar = new File(EXP_JRE_LIB_DIR, "charsets.jar");57private static final File JsseJar = new File(EXP_JRE_LIB_DIR, "jsse.jar");58private static final File ToolsJar = new File(EXP_SDK_LIB_DIR, "tools.jar");59private static final File javaCmd;60private static final File javacCmd;61private static final File ConfigFile = new File("pack.conf");62private static final List<File> jarList;6364static {65javaCmd = Utils.IsWindows66? new File(EXP_SDK_BIN_DIR, "java.exe")67: new File(EXP_SDK_BIN_DIR, "java");6869javacCmd = Utils.IsWindows70? new File(EXP_SDK_BIN_DIR, "javac.exe")71: new File(EXP_SDK_BIN_DIR, "javac");7273jarList = new ArrayList<File>();74jarList.add(RtJar);75jarList.add(CharsetsJar);76jarList.add(JsseJar);77jarList.add(ToolsJar);78}7980// init test area with a copy of the sdk81static void init() throws IOException {82Utils.recursiveCopy(Utils.JavaSDK, EXP_SDK);83creatConfigFile();84}85// cleanup the test area86static void cleanup() throws IOException {87Utils.recursiveDelete(EXP_SDK);88Utils.cleanup();89}9091// Hopefully, this should be kept in sync with what the installer does.92static void creatConfigFile() throws IOException {93FileOutputStream fos = null;94PrintStream ps = null;95try {96fos = new FileOutputStream(ConfigFile);97ps = new PrintStream(fos);98ps.println("com.sun.java.util.jar.pack.debug.verbose=0");99ps.println("pack.modification.time=keep");100ps.println("pack.keep.class.order=true");101ps.println("pack.deflate.hint=false");102// Fail the build, if new or unknown attributes are introduced.103ps.println("pack.unknown.attribute=error");104ps.println("pack.segment.limit=-1");105// BugId: 6328502, These files will be passed-through as-is.106ps.println("pack.pass.file.0=java/lang/Error.class");107ps.println("pack.pass.file.1=java/lang/LinkageError.class");108ps.println("pack.pass.file.2=java/lang/Object.class");109ps.println("pack.pass.file.3=java/lang/Throwable.class");110ps.println("pack.pass.file.4=java/lang/VerifyError.class");111ps.println("pack.pass.file.5=com/sun/demo/jvmti/hprof/Tracker.class");112} finally {113Utils.close(ps);114Utils.close(fos);115}116}117118static void runPack200(boolean jre) throws IOException {119List<String> cmdsList = new ArrayList<String>();120for (File f : jarList) {121if (jre && f.getName().equals("tools.jar")) {122continue; // need not worry about tools.jar for JRE123}124// make a backup copy for re-use125File bakFile = new File(f.getName() + ".bak");126if (!bakFile.exists()) { // backup127Utils.copyFile(f, bakFile);128} else { // restore129Utils.copyFile(bakFile, f);130}131cmdsList.clear();132cmdsList.add(Utils.getPack200Cmd());133cmdsList.add("-J-esa");134cmdsList.add("-J-ea");135cmdsList.add(Utils.Is64Bit ? "-J-Xmx1g" : "-J-Xmx512m");136cmdsList.add("--repack");137cmdsList.add("--config-file=" + ConfigFile.getAbsolutePath());138if (jre) {139cmdsList.add("--strip-debug");140}141// NOTE: commented until 6965836 is fixed142// cmdsList.add("--code-attribute=StackMapTable=strip");143cmdsList.add(f.getAbsolutePath());144Utils.runExec(cmdsList);145}146}147148static void testJRE() throws IOException {149runPack200(true);150// the speciment JRE151List<String> cmdsList = new ArrayList<String>();152cmdsList.add(javaCmd.getAbsolutePath());153cmdsList.add("-verify");154cmdsList.add("-version");155Utils.runExec(cmdsList);156}157158static void testJDK() throws IOException {159runPack200(false);160// test the specimen JDK161List<String> cmdsList = new ArrayList<String>();162cmdsList.add(javaCmd.getAbsolutePath());163cmdsList.add("-verify");164cmdsList.add("-version");165Utils.runExec(cmdsList);166167// invoke javac to test the tools.jar168cmdsList.clear();169cmdsList.add(javacCmd.getAbsolutePath());170cmdsList.add("-J-verify");171cmdsList.add("-help");172Utils.runExec(cmdsList);173}174public static void main(String... args) {175try {176init();177testJRE();178testJDK();179cleanup(); // cleanup only if we pass successfully180} catch (IOException ioe) {181throw new RuntimeException(ioe);182}183}184}185186187