2668N/A/*
4248N/A * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
2668N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2668N/A *
2668N/A * This code is free software; you can redistribute it and/or modify it
2668N/A * under the terms of the GNU General Public License version 2 only, as
2668N/A * published by the Free Software Foundation.
2668N/A *
2668N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2668N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2668N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2668N/A * version 2 for more details (a copy is included in the LICENSE file that
2668N/A * accompanied this code).
2668N/A *
2668N/A * You should have received a copy of the GNU General Public License version
2668N/A * 2 along with this work; if not, write to the Free Software Foundation,
2668N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2668N/A *
2668N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2668N/A * or visit www.oracle.com if you need additional information or have any
2668N/A * questions.
2668N/A */
2668N/A
2668N/A/*
2668N/A * @test CommandLineTests.sh
2668N/A * @bug 6521334 6965836 6965836
2668N/A * @compile -XDignore.symbol.file CommandLineTests.java Pack200Test.java
2668N/A * @run main/timeout=1200 CommandLineTests
2668N/A * @summary An ad hoc test to verify the behavior of pack200/unpack200 CLIs,
2668N/A * and a simulation of pack/unpacking in the install repo.
2668N/A * @author ksrini
2668N/A */
2668N/A
2668N/Aimport java.io.File;
2668N/Aimport java.io.FileOutputStream;
2668N/Aimport java.io.IOException;
2668N/Aimport java.io.PrintStream;
2668N/Aimport java.util.ArrayList;
2668N/Aimport java.util.List;
2668N/A/*
2668N/A * We try a potpouri of things ie. we have pack.conf to setup some
2668N/A * options as well as a couple of command line options. We also test
2668N/A * the packing and unpacking mechanism using the Java APIs. This also
2668N/A * simulates pack200 the install workspace, noting that this is a simulation
2668N/A * and can only test jars that are guaranteed to be available, also the
2668N/A * configuration may not be in sync with the installer workspace.
2668N/A */
2668N/A
2668N/Apublic class CommandLineTests {
2668N/A private static final File CWD = new File(".");
2668N/A private static final File EXP_SDK = new File(CWD, "exp-sdk-image");
2668N/A private static final File EXP_SDK_LIB_DIR = new File(EXP_SDK, "lib");
2668N/A private static final File EXP_SDK_BIN_DIR = new File(EXP_SDK, "bin");
2668N/A private static final File EXP_JRE_DIR = new File(EXP_SDK, "jre");
2668N/A private static final File EXP_JRE_LIB_DIR = new File(EXP_JRE_DIR, "lib");
2668N/A private static final File RtJar = new File(EXP_JRE_LIB_DIR, "rt.jar");
2668N/A private static final File CharsetsJar = new File(EXP_JRE_LIB_DIR, "charsets.jar");
2668N/A private static final File JsseJar = new File(EXP_JRE_LIB_DIR, "jsse.jar");
2668N/A private static final File ToolsJar = new File(EXP_SDK_LIB_DIR, "tools.jar");
2668N/A private static final File javaCmd;
2668N/A private static final File javacCmd;
2668N/A private static final File ConfigFile = new File("pack.conf");
2668N/A private static final List<File> jarList;
2668N/A
2668N/A static {
2668N/A javaCmd = Utils.IsWindows
2668N/A ? new File(EXP_SDK_BIN_DIR, "java.exe")
2668N/A : new File(EXP_SDK_BIN_DIR, "java");
2668N/A
2668N/A javacCmd = Utils.IsWindows
2668N/A ? new File(EXP_SDK_BIN_DIR, "javac.exe")
2668N/A : new File(EXP_SDK_BIN_DIR, "javac");
2668N/A
2668N/A jarList = new ArrayList<File>();
2668N/A jarList.add(RtJar);
2668N/A jarList.add(CharsetsJar);
2668N/A jarList.add(JsseJar);
2668N/A jarList.add(ToolsJar);
2668N/A }
2668N/A
2668N/A // init test area with a copy of the sdk
2668N/A static void init() throws IOException {
2668N/A Utils.recursiveCopy(Utils.JavaSDK, EXP_SDK);
2668N/A creatConfigFile();
2668N/A }
2668N/A
2668N/A // Hopefully, this should be kept in sync with what the installer does.
2668N/A static void creatConfigFile() throws IOException {
2668N/A FileOutputStream fos = null;
2668N/A PrintStream ps = null;
2668N/A try {
2668N/A fos = new FileOutputStream(ConfigFile);
2668N/A ps = new PrintStream(fos);
2668N/A ps.println("com.sun.java.util.jar.pack.debug.verbose=0");
2668N/A ps.println("pack.modification.time=keep");
2668N/A ps.println("pack.keep.class.order=true");
2668N/A ps.println("pack.deflate.hint=false");
2668N/A // Fail the build, if new or unknown attributes are introduced.
2668N/A ps.println("pack.unknown.attribute=error");
2668N/A ps.println("pack.segment.limit=-1");
2668N/A // BugId: 6328502, These files will be passed-through as-is.
2668N/A ps.println("pack.pass.file.0=java/lang/Error.class");
2668N/A ps.println("pack.pass.file.1=java/lang/LinkageError.class");
2668N/A ps.println("pack.pass.file.2=java/lang/Object.class");
2668N/A ps.println("pack.pass.file.3=java/lang/Throwable.class");
2668N/A ps.println("pack.pass.file.4=java/lang/VerifyError.class");
2668N/A ps.println("pack.pass.file.5=com/sun/demo/jvmti/hprof/Tracker.class");
2668N/A } finally {
2668N/A Utils.close(ps);
2668N/A Utils.close(fos);
2668N/A }
2668N/A }
2668N/A
2668N/A static void runPack200(boolean jre) throws IOException {
2668N/A List<String> cmdsList = new ArrayList<String>();
2668N/A for (File f : jarList) {
2668N/A if (jre && f.getName().equals("tools.jar")) {
2668N/A continue; // need not worry about tools.jar for JRE
2668N/A }
2668N/A // make a backup copy for re-use
2668N/A File bakFile = new File(f.getName() + ".bak");
2668N/A if (!bakFile.exists()) { // backup
3883N/A Utils.copyFile(f, bakFile);
2668N/A } else { // restore
3883N/A Utils.copyFile(bakFile, f);
2668N/A }
2668N/A cmdsList.clear();
2668N/A cmdsList.add(Utils.getPack200Cmd());
2668N/A cmdsList.add("-J-esa");
2668N/A cmdsList.add("-J-ea");
2668N/A cmdsList.add(Utils.Is64Bit ? "-J-Xmx1g" : "-J-Xmx512m");
2668N/A cmdsList.add("--repack");
2668N/A cmdsList.add("--config-file=" + ConfigFile.getAbsolutePath());
2668N/A if (jre) {
2668N/A cmdsList.add("--strip-debug");
2668N/A }
2668N/A // NOTE: commented until 6965836 is fixed
2668N/A // cmdsList.add("--code-attribute=StackMapTable=strip");
2668N/A cmdsList.add(f.getAbsolutePath());
2668N/A Utils.runExec(cmdsList);
2668N/A }
2668N/A }
2668N/A
2668N/A static void testJRE() throws IOException {
2668N/A runPack200(true);
2668N/A // the speciment JRE
2668N/A List<String> cmdsList = new ArrayList<String>();
2668N/A cmdsList.add(javaCmd.getAbsolutePath());
2668N/A cmdsList.add("-verify");
2668N/A cmdsList.add("-version");
2668N/A Utils.runExec(cmdsList);
2668N/A }
2668N/A
2668N/A static void testJDK() throws IOException {
2668N/A runPack200(false);
2668N/A // test the specimen JDK
2668N/A List<String> cmdsList = new ArrayList<String>();
2668N/A cmdsList.add(javaCmd.getAbsolutePath());
2668N/A cmdsList.add("-verify");
2668N/A cmdsList.add("-version");
2668N/A Utils.runExec(cmdsList);
2668N/A
2668N/A // invoke javac to test the tools.jar
2668N/A cmdsList.clear();
2668N/A cmdsList.add(javacCmd.getAbsolutePath());
2668N/A cmdsList.add("-J-verify");
2668N/A cmdsList.add("-help");
2668N/A Utils.runExec(cmdsList);
2668N/A }
2668N/A public static void main(String... args) {
2668N/A try {
2668N/A init();
2668N/A testJRE();
2668N/A testJDK();
2668N/A } catch (IOException ioe) {
2668N/A throw new RuntimeException(ioe);
2668N/A }
2668N/A }
2668N/A}