test/lib/jdk/test/lib/cds/CDSTestUtils.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File jdk10-hs-dev Sdiff test/lib/jdk/test/lib/cds

test/lib/jdk/test/lib/cds/CDSTestUtils.java

Print this page




   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 package jdk.test.lib.cds;
  24 
  25 import java.io.IOException;
  26 import java.io.File;
  27 import java.io.FileOutputStream;
  28 import java.io.PrintStream;

  29 import java.util.ArrayList;

  30 import jdk.test.lib.Utils;
  31 import jdk.test.lib.process.OutputAnalyzer;
  32 import jdk.test.lib.process.ProcessTools;
  33 
  34 
  35 // This class contains common test utilities for testing CDS
  36 public class CDSTestUtils {
  37     // Specify this property to copy sdandard output of the child test process to
  38     // the parent/main stdout of the test.
  39     // By default such output is logged into a file, and is copied into the main stdout.
  40     public static final boolean CopyChildStdoutToMainStdout =
  41         Boolean.valueOf(System.getProperty("test.cds.copy.child.stdout", "true"));
  42 
  43     // This property is passed to child test processes
  44     public static final String TestTimeoutFactor = System.getProperty("test.timeout.factor", "1.0");
  45 
  46     public static final String UnableToMapMsg =
  47         "Unable to map shared archive: test did not complete; assumed PASS";
  48 
  49     // Create bootstrap CDS archive,
  50     // use extra JVM command line args as a prefix.
  51     // For CDS tests specifying prefix makes more sense than specifying suffix, since
  52     // normally there are no classes or arguments to classes, just "-version"
  53     // To specify suffix explicitly use CDSOptions.addSuffix()
  54     public static OutputAnalyzer createArchive(String... cliPrefix)
  55         throws Exception {
  56         return createArchive((new CDSOptions()).addPrefix(cliPrefix));
  57     }
  58 
  59     // Create bootstrap CDS archive
  60     public static OutputAnalyzer createArchive(CDSOptions opts)
  61         throws Exception {
  62 


  63         ArrayList<String> cmd = new ArrayList<String>();
  64 
  65         for (String p : opts.prefix) cmd.add(p);
  66 
  67         cmd.add("-Xshare:dump");
  68         cmd.add("-Xlog:cds,cds+hashtables");
  69         cmd.add("-XX:+UnlockDiagnosticVMOptions");
  70         if (opts.archiveName == null)
  71             opts.archiveName = getDefaultArchiveName();
  72         cmd.add("-XX:SharedArchiveFile=./" + opts.archiveName);
  73 
  74         for (String s : opts.suffix) cmd.add(s);
  75 
  76         String[] cmdLine = cmd.toArray(new String[cmd.size()]);
  77         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine);
  78         return executeAndLog(pb, "dump");
  79     }
  80 
  81 
  82     // check result of 'dump-the-archive' operation, that is "-Xshare:dump"


 311         if (classes != null) {
 312             for (String s : classes) {
 313                 ps.println(s);
 314             }
 315         }
 316     }
 317 
 318 
 319     // Optimization for getting a test name.
 320     // Test name does not change during execution of the test,
 321     // but getTestName() uses stack walking hence it is expensive.
 322     // Therefore cache it and reuse it.
 323     private static String testName;
 324     public static String getTestName() {
 325         if (testName == null) {
 326             testName = Utils.getTestName();
 327         }
 328         return testName;
 329     }
 330 










 331 
 332     public static String getDefaultArchiveName() {
 333         return getTestName() + ".jsa";
 334     }
 335 
 336 
 337     // ===================== FILE ACCESS convenience methods
 338     public static File getOutputFile(String name) {
 339         File dir = new File(System.getProperty("test.classes", "."));
 340         return new File(dir, getTestName() + "-" + name);
 341     }
 342 
 343 
 344     public static File getOutputSourceFile(String name) {
 345         File dir = new File(System.getProperty("test.classes", "."));
 346         return new File(dir, name);
 347     }
 348 
 349 
 350     public static File getSourceFile(String name) {
 351         File dir = new File(System.getProperty("test.src", "."));
 352         return new File(dir, name);
 353     }




   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 package jdk.test.lib.cds;
  24 
  25 import java.io.IOException;
  26 import java.io.File;
  27 import java.io.FileOutputStream;
  28 import java.io.PrintStream;
  29 import java.text.SimpleDateFormat;
  30 import java.util.ArrayList;
  31 import java.util.Date;
  32 import jdk.test.lib.Utils;
  33 import jdk.test.lib.process.OutputAnalyzer;
  34 import jdk.test.lib.process.ProcessTools;
  35 
  36 
  37 // This class contains common test utilities for testing CDS
  38 public class CDSTestUtils {
  39     // Specify this property to copy sdandard output of the child test process to
  40     // the parent/main stdout of the test.
  41     // By default such output is logged into a file, and is copied into the main stdout.
  42     public static final boolean CopyChildStdoutToMainStdout =
  43         Boolean.valueOf(System.getProperty("test.cds.copy.child.stdout", "true"));
  44 
  45     // This property is passed to child test processes
  46     public static final String TestTimeoutFactor = System.getProperty("test.timeout.factor", "1.0");
  47 
  48     public static final String UnableToMapMsg =
  49         "Unable to map shared archive: test did not complete; assumed PASS";
  50 
  51     // Create bootstrap CDS archive,
  52     // use extra JVM command line args as a prefix.
  53     // For CDS tests specifying prefix makes more sense than specifying suffix, since
  54     // normally there are no classes or arguments to classes, just "-version"
  55     // To specify suffix explicitly use CDSOptions.addSuffix()
  56     public static OutputAnalyzer createArchive(String... cliPrefix)
  57         throws Exception {
  58         return createArchive((new CDSOptions()).addPrefix(cliPrefix));
  59     }
  60 
  61     // Create bootstrap CDS archive
  62     public static OutputAnalyzer createArchive(CDSOptions opts)
  63         throws Exception {
  64 
  65         startNewArchiveName();
  66 
  67         ArrayList<String> cmd = new ArrayList<String>();
  68 
  69         for (String p : opts.prefix) cmd.add(p);
  70 
  71         cmd.add("-Xshare:dump");
  72         cmd.add("-Xlog:cds,cds+hashtables");
  73         cmd.add("-XX:+UnlockDiagnosticVMOptions");
  74         if (opts.archiveName == null)
  75             opts.archiveName = getDefaultArchiveName();
  76         cmd.add("-XX:SharedArchiveFile=./" + opts.archiveName);
  77 
  78         for (String s : opts.suffix) cmd.add(s);
  79 
  80         String[] cmdLine = cmd.toArray(new String[cmd.size()]);
  81         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine);
  82         return executeAndLog(pb, "dump");
  83     }
  84 
  85 
  86     // check result of 'dump-the-archive' operation, that is "-Xshare:dump"


 315         if (classes != null) {
 316             for (String s : classes) {
 317                 ps.println(s);
 318             }
 319         }
 320     }
 321 
 322 
 323     // Optimization for getting a test name.
 324     // Test name does not change during execution of the test,
 325     // but getTestName() uses stack walking hence it is expensive.
 326     // Therefore cache it and reuse it.
 327     private static String testName;
 328     public static String getTestName() {
 329         if (testName == null) {
 330             testName = Utils.getTestName();
 331         }
 332         return testName;
 333     }
 334 
 335     private static final SimpleDateFormat timeStampFormat =
 336         new SimpleDateFormat("HH'h'mm'm'ss's'SSS");
 337 
 338     private static String defaultArchiveName;
 339 
 340     // Call this method to start new archive with new unique name
 341     public static void startNewArchiveName() {
 342         defaultArchiveName = getTestName() +
 343             timeStampFormat.format(new Date()) + ".jsa";
 344     }
 345 
 346     public static String getDefaultArchiveName() {
 347         return defaultArchiveName;
 348     }
 349 
 350 
 351     // ===================== FILE ACCESS convenience methods
 352     public static File getOutputFile(String name) {
 353         File dir = new File(System.getProperty("test.classes", "."));
 354         return new File(dir, getTestName() + "-" + name);
 355     }
 356 
 357 
 358     public static File getOutputSourceFile(String name) {
 359         File dir = new File(System.getProperty("test.classes", "."));
 360         return new File(dir, name);
 361     }
 362 
 363 
 364     public static File getSourceFile(String name) {
 365         File dir = new File(System.getProperty("test.src", "."));
 366         return new File(dir, name);
 367     }


test/lib/jdk/test/lib/cds/CDSTestUtils.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File