Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/tools/pack200/Pack200Props.java
38833 views
/*1* Copyright (c) 2010, 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* @test25* @bug 6575373 696906326* @summary verify default properties of the packer/unpacker and segment limit27* @compile -XDignore.symbol.file Utils.java Pack200Props.java28* @run main Pack200Props29* @author ksrini30*/3132import java.io.File;33import java.io.IOException;34import java.util.ArrayList;35import java.util.HashMap;36import java.util.List;37import java.util.Map;38import java.util.jar.Pack200;39import java.util.jar.Pack200.Packer;4041/*42* Run this against a large jar file, by default the packer should generate only43* one segment, parse the output of the packer to verify if this is indeed true.44*/4546public class Pack200Props {4748public static void main(String... args) throws IOException {49verifyDefaults();50File out = new File("test" + Utils.PACK_FILE_EXT);51out.delete();52verifySegmentLimit(out);53Utils.cleanup();54}5556static void verifySegmentLimit(File outFile) {57File sdkHome = Utils.JavaSDK;58File testJar = new File(new File(sdkHome, "lib"), "tools.jar");5960System.out.println("using pack200: " + Utils.getPack200Cmd());6162List<String> cmdsList = new ArrayList<>();63cmdsList.add(Utils.getPack200Cmd());64cmdsList.add("--effort=1");65cmdsList.add("--verbose");66cmdsList.add("--no-gzip");67cmdsList.add(outFile.getName());68cmdsList.add(testJar.getAbsolutePath());69List<String> outList = Utils.runExec(cmdsList);7071int count = 0;72for (String line : outList) {73System.out.println(line);74if (line.matches(".*Transmitted.*files of.*input bytes in a segment of.*bytes")) {75count++;76}77}78if (count == 0) {79throw new RuntimeException("no segments or no output ????");80} else if (count > 1) {81throw new RuntimeException("multiple segments detected, expected 1");82}83}8485private static void verifyDefaults() {86Map<String, String> expectedDefaults = new HashMap<>();87Packer p = Pack200.newPacker();88expectedDefaults.put("com.sun.java.util.jar.pack.default.timezone",89p.FALSE);90expectedDefaults.put("com.sun.java.util.jar.pack.disable.native",91p.FALSE);92expectedDefaults.put("com.sun.java.util.jar.pack.verbose", "0");93expectedDefaults.put(p.CLASS_ATTRIBUTE_PFX + "CompilationID", "RUH");94expectedDefaults.put(p.CLASS_ATTRIBUTE_PFX + "SourceID", "RUH");95expectedDefaults.put(p.CODE_ATTRIBUTE_PFX + "CharacterRangeTable",96"NH[PHPOHIIH]");97expectedDefaults.put(p.CODE_ATTRIBUTE_PFX + "CoverageTable",98"NH[PHHII]");99expectedDefaults.put(p.DEFLATE_HINT, p.KEEP);100expectedDefaults.put(p.EFFORT, "5");101expectedDefaults.put(p.KEEP_FILE_ORDER, p.TRUE);102expectedDefaults.put(p.MODIFICATION_TIME, p.KEEP);103expectedDefaults.put(p.SEGMENT_LIMIT, "-1");104expectedDefaults.put(p.UNKNOWN_ATTRIBUTE, p.PASS);105106Map<String, String> props = p.properties();107int errors = 0;108for (String key : expectedDefaults.keySet()) {109String def = expectedDefaults.get(key);110String x = props.get(key);111if (x == null) {112System.out.println("Error: key not found:" + key);113errors++;114} else {115if (!def.equals(x)) {116System.out.println("Error: key " + key117+ "\n value expected: " + def118+ "\n value obtained: " + x);119errors++;120}121}122}123if (errors > 0) {124throw new RuntimeException(errors +125" error(s) encountered in default properties verification");126}127}128}129130131132