< prev index next >

test/tools/pack200/Pack200Props.java

Print this page


   1 /*
   2  * Copyright (c) 2010, 2015, 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 /*
  25  * @test
  26  * @bug 6575373 6969063
  27  * @summary verify default properties of the packer/unpacker and segment limit
  28  * @compile -XDignore.symbol.file Utils.java Pack200Props.java
  29  * @run main Pack200Props
  30  * @author ksrini
  31  */
  32 
  33 import java.io.File;
  34 import java.io.IOException;
  35 import java.util.ArrayList;
  36 import java.util.HashMap;
  37 import java.util.List;
  38 import java.util.Map;
  39 import java.util.jar.Pack200;
  40 import java.util.jar.Pack200.Packer;

  41 
  42 /*
  43  * Run this against a large jar file, by default the packer should generate only
  44  * one segment, parse the output of the packer to verify if this is indeed true.
  45  */
  46 
  47 public class Pack200Props {
  48 
  49     public static void main(String... args) throws IOException {


  50         verifyDefaults();
  51         File out = new File("test" + Utils.PACK_FILE_EXT);
  52         out.delete();
  53         verifySegmentLimit(out);

  54         Utils.cleanup();
  55     }
  56 
  57     static void verifySegmentLimit(File outFile) throws IOException {
  58         File sdkHome = Utils.JavaSDK;
  59         File testJar = Utils.createRtJar();
  60 
  61         System.out.println("using pack200: " + Utils.getPack200Cmd());
  62 
  63         List<String> cmdsList = new ArrayList<>();
  64         cmdsList.add(Utils.getPack200Cmd());
  65         cmdsList.add("-J-Xshare:off");
  66         cmdsList.add("-J-Xmx1280m");
  67         cmdsList.add("--effort=1");
  68         cmdsList.add("--verbose");
  69         cmdsList.add("--no-gzip");
  70         cmdsList.add(outFile.getName());
  71         cmdsList.add(testJar.getAbsolutePath());
  72         List<String> outList = Utils.runExec(cmdsList);
  73 

  74         int count = 0;
  75         for (String line : outList) {
  76             System.out.println(line);
  77             if (line.matches(".*Transmitted.*files of.*input bytes in a segment of.*bytes")) {
  78                 count++;
  79             }
  80         }

  81         if (count == 0) {
  82             throw new RuntimeException("no segments or no output ????");
  83         } else if (count > 1) {
  84             throw new RuntimeException("multiple segments detected, expected 1");
  85         }
  86     }
  87 
  88     private static void verifyDefaults() {

  89         Map<String, String> expectedDefaults = new HashMap<>();
  90         Packer p = Pack200.newPacker();
  91         expectedDefaults.put("com.sun.java.util.jar.pack.disable.native",
  92                 p.FALSE);
  93         expectedDefaults.put("com.sun.java.util.jar.pack.verbose", "0");
  94         expectedDefaults.put(p.CLASS_ATTRIBUTE_PFX + "CompilationID", "RUH");
  95         expectedDefaults.put(p.CLASS_ATTRIBUTE_PFX + "SourceID", "RUH");
  96         expectedDefaults.put(p.CODE_ATTRIBUTE_PFX + "CharacterRangeTable",
  97                 "NH[PHPOHIIH]");
  98         expectedDefaults.put(p.CODE_ATTRIBUTE_PFX + "CoverageTable",
  99                 "NH[PHHII]");
 100         expectedDefaults.put(p.DEFLATE_HINT, p.KEEP);
 101         expectedDefaults.put(p.EFFORT, "5");
 102         expectedDefaults.put(p.KEEP_FILE_ORDER, p.TRUE);
 103         expectedDefaults.put(p.MODIFICATION_TIME, p.KEEP);
 104         expectedDefaults.put(p.SEGMENT_LIMIT, "-1");
 105         expectedDefaults.put(p.UNKNOWN_ATTRIBUTE, p.PASS);
 106 
 107         Map<String, String> props = p.properties();
 108         int errors = 0;
 109         for (String key : expectedDefaults.keySet()) {
 110             String def = expectedDefaults.get(key);
 111             String x = props.get(key);
 112             if (x == null) {
 113                 System.out.println("Error: key not found:" + key);
 114                 errors++;
 115             } else {
 116                 if (!def.equals(x)) {
 117                     System.out.println("Error: key " + key
 118                             + "\n  value expected: " + def
 119                             + "\n  value obtained: " + x);
 120                     errors++;
 121                 }
 122             }
 123         }

 124         if (errors > 0) {
 125             throw new RuntimeException(errors +
 126                     " error(s) encountered in default properties verification");
 127         }
 128     }
 129 }
 130 
   1 /*
   2  * Copyright (c) 2010, 2016, 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 /*
  25  * @test
  26  * @bug 6575373 6969063
  27  * @summary verify default properties of the packer/unpacker and segment limit
  28  * @compile -XDignore.symbol.file Utils.java Pack200Props.java
  29  * @run main Pack200Props
  30  * @author ksrini
  31  */
  32 
  33 import java.io.File;
  34 import java.io.IOException;
  35 import java.util.ArrayList;
  36 import java.util.HashMap;
  37 import java.util.List;
  38 import java.util.Map;
  39 import java.util.jar.Pack200;
  40 import java.util.jar.Pack200.Packer;
  41 import java.util.logging.Logger;
  42 
  43 /*
  44  * Run this against a large jar file, by default the packer should generate only
  45  * one segment, parse the output of the packer to verify if this is indeed true.
  46  */
  47 
  48 public class Pack200Props {
  49 
  50     final static Logger log = Logger.getLogger("Pack200Props");
  51 
  52     public static void main(String... args) throws Exception {
  53         verifyDefaults();
  54         File out = new File("test" + Utils.PACK_FILE_EXT);
  55         out.delete();
  56         verifySegmentLimit(out);
  57         log.info("cleanup");
  58         Utils.cleanup();
  59     }
  60 
  61     static void verifySegmentLimit(File outFile) throws Exception {
  62         log.info("creating jar");
  63         File testJar = Utils.createRtJar();
  64 
  65         log.info("using pack200: " + Utils.getPack200Cmd());

  66         List<String> cmdsList = new ArrayList<>();
  67         cmdsList.add(Utils.getPack200Cmd());
  68         cmdsList.add("-J-Xshare:off");
  69         cmdsList.add("-J-Xmx1280m");
  70         cmdsList.add("--effort=1");
  71         cmdsList.add("--verbose");
  72         cmdsList.add("--no-gzip");
  73         cmdsList.add(outFile.getName());
  74         cmdsList.add(testJar.getAbsolutePath());
  75         List<String> outList = Utils.runExec(cmdsList);
  76 
  77         log.info("verifying");
  78         int count = 0;
  79         for (String line : outList) {
  80             System.out.println(line);
  81             if (line.matches(".*Transmitted.*files of.*input bytes in a segment of.*bytes")) {
  82                 count++;
  83             }
  84         }
  85         log.info("fini");
  86         if (count == 0) {
  87             throw new RuntimeException("no segments or no output ????");
  88         } else if (count > 1) {
  89             throw new RuntimeException("multiple segments detected, expected 1");
  90         }
  91     }
  92 
  93     private static void verifyDefaults() {
  94         log.info("start");
  95         Map<String, String> expectedDefaults = new HashMap<>();
  96         Packer p = Pack200.newPacker();
  97         expectedDefaults.put("com.sun.java.util.jar.pack.disable.native",
  98                 p.FALSE);
  99         expectedDefaults.put("com.sun.java.util.jar.pack.verbose", "0");
 100         expectedDefaults.put(p.CLASS_ATTRIBUTE_PFX + "CompilationID", "RUH");
 101         expectedDefaults.put(p.CLASS_ATTRIBUTE_PFX + "SourceID", "RUH");
 102         expectedDefaults.put(p.CODE_ATTRIBUTE_PFX + "CharacterRangeTable",
 103                 "NH[PHPOHIIH]");
 104         expectedDefaults.put(p.CODE_ATTRIBUTE_PFX + "CoverageTable",
 105                 "NH[PHHII]");
 106         expectedDefaults.put(p.DEFLATE_HINT, p.KEEP);
 107         expectedDefaults.put(p.EFFORT, "5");
 108         expectedDefaults.put(p.KEEP_FILE_ORDER, p.TRUE);
 109         expectedDefaults.put(p.MODIFICATION_TIME, p.KEEP);
 110         expectedDefaults.put(p.SEGMENT_LIMIT, "-1");
 111         expectedDefaults.put(p.UNKNOWN_ATTRIBUTE, p.PASS);
 112 
 113         Map<String, String> props = p.properties();
 114         int errors = 0;
 115         for (String key : expectedDefaults.keySet()) {
 116             String def = expectedDefaults.get(key);
 117             String x = props.get(key);
 118             if (x == null) {
 119                 System.out.println("Error: key not found:" + key);
 120                 errors++;
 121             } else {
 122                 if (!def.equals(x)) {
 123                     System.out.println("Error: key " + key
 124                             + "\n  value expected: " + def
 125                             + "\n  value obtained: " + x);
 126                     errors++;
 127                 }
 128             }
 129         }
 130         log.info("fini");
 131         if (errors > 0) {
 132             throw new RuntimeException(errors +
 133                     " error(s) encountered in default properties verification");
 134         }
 135     }
 136 }
 137 
< prev index next >