78 // most other artifacts created in jtreg testing. 79 // Therefore it is a good idea to clean the old archives when they are not needed. 80 // In most cases the deletion attempt will succeed; on rare occasion the 81 // delete operation will fail since the system or VM process still holds a handle 82 // to the file; in such cases the File.delete() operation will silently fail, w/o 83 // throwing an exception, thus allowing testing to continue. 84 public static void deletePriorArchives() { 85 File dir = new File(System.getProperty("user.dir")); 86 String files[] = dir.list(); 87 for (String name : files) { 88 if (name.startsWith("appcds-") && name.endsWith(".jsa")) { 89 if (!(new File(dir, name)).delete()) 90 System.out.println("deletePriorArchives(): delete failed for file " + name); 91 } 92 } 93 } 94 95 96 // Create AppCDS archive using most common args - convenience method 97 // Legacy name preserved for compatibility 98 public static OutputAnalyzer dump(String appJar, String appClasses[], 99 String... suffix) throws Exception { 100 return createArchive(appJar, appClasses, suffix); 101 } 102 103 104 // Create AppCDS archive using most common args - convenience method 105 public static OutputAnalyzer createArchive(String appJar, String appClasses[], 106 String... suffix) throws Exception { 107 AppCDSOptions opts = (new AppCDSOptions()).setAppJar(appJar) 108 .setAppClasses(appClasses); 109 opts.addSuffix(suffix); 110 return createArchive(opts); 111 } 112 113 // Create AppCDS archive using appcds options 114 public static OutputAnalyzer createArchive(AppCDSOptions opts) 115 throws Exception { 116 117 ArrayList<String> cmd = new ArrayList<String>(); 118 File classList = makeClassList(opts.appClasses); 119 startNewArchiveName(); 120 121 for (String p : opts.prefix) cmd.add(p); 122 123 if (opts.appJar != null) { 124 cmd.add("-cp"); 125 cmd.add(opts.appJar); 126 } else { 127 cmd.add("-cp"); 128 cmd.add("\"\""); 129 } 130 131 cmd.add("-Xshare:dump"); 132 cmd.add("-XX:ExtraSharedClassListFile=" + classList.getPath()); 133 134 if (opts.archiveName == null) 135 opts.archiveName = getCurrentArchiveName(); 136 137 cmd.add("-XX:SharedArchiveFile=" + opts.archiveName); 138 139 for (String s : opts.suffix) cmd.add(s); 140 141 String[] cmdLine = cmd.toArray(new String[cmd.size()]); 142 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine); 143 return executeAndLog(pb, "dump"); 144 } 145 146 147 // Execute JVM using AppCDS archive with specified AppCDSOptions 148 public static OutputAnalyzer runWithArchive(AppCDSOptions opts) 149 throws Exception { 150 151 ArrayList<String> cmd = new ArrayList<String>(); 152 153 for (String p : opts.prefix) cmd.add(p); 154 155 cmd.add("-Xshare:" + opts.xShareMode); 156 cmd.add("-showversion"); 157 cmd.add("-XX:SharedArchiveFile=" + getCurrentArchiveName()); 158 cmd.add("-Dtest.timeout.factor=" + timeoutFactor); 218 if (upgrademodulepath == null) { 219 opts.addSuffix("-p", modulepath, "-m", mid); 220 } else { 221 opts.addSuffix("--upgrade-module-path", upgrademodulepath, 222 "-p", modulepath, "-m", mid); 223 } 224 opts.addSuffix(testClassArgs); 225 return opts; 226 } 227 228 public static OutputAnalyzer execModule(String prefix[], String upgrademodulepath, String modulepath, 229 String mid, String... testClassArgs) 230 throws Exception { 231 AppCDSOptions opts = makeModuleOptions(prefix, upgrademodulepath, modulepath, 232 mid, testClassArgs); 233 return runWithArchive(opts); 234 } 235 236 237 // A common operation: dump, then check results 238 public static OutputAnalyzer testDump(String appJar, String appClasses[], 239 String... suffix) throws Exception { 240 OutputAnalyzer output = dump(appJar, appClasses, suffix); 241 output.shouldContain("Loading classes to share"); 242 output.shouldHaveExitValue(0); 243 return output; 244 } 245 246 247 /** 248 * Simple test -- dump and execute appJar with the given appClasses in classlist. 249 */ 250 public static OutputAnalyzer test(String appJar, String appClasses[], String... args) 251 throws Exception { 252 testDump(appJar, appClasses); 253 254 OutputAnalyzer output = exec(appJar, args); 255 return checkExec(output); 256 } 257 258 259 public static OutputAnalyzer checkExecReturn(OutputAnalyzer output, int ret, 260 boolean checkContain, String... matches) throws Exception { 261 try { 262 for (String s : matches) { 263 if (checkContain) { 264 output.shouldContain(s); 265 } else { 266 output.shouldNotContain(s); 267 } 268 } 269 output.shouldHaveExitValue(ret); 270 } catch (Exception e) { 271 checkCommonExecExceptions(output, e); 272 } | 78 // most other artifacts created in jtreg testing. 79 // Therefore it is a good idea to clean the old archives when they are not needed. 80 // In most cases the deletion attempt will succeed; on rare occasion the 81 // delete operation will fail since the system or VM process still holds a handle 82 // to the file; in such cases the File.delete() operation will silently fail, w/o 83 // throwing an exception, thus allowing testing to continue. 84 public static void deletePriorArchives() { 85 File dir = new File(System.getProperty("user.dir")); 86 String files[] = dir.list(); 87 for (String name : files) { 88 if (name.startsWith("appcds-") && name.endsWith(".jsa")) { 89 if (!(new File(dir, name)).delete()) 90 System.out.println("deletePriorArchives(): delete failed for file " + name); 91 } 92 } 93 } 94 95 96 // Create AppCDS archive using most common args - convenience method 97 // Legacy name preserved for compatibility 98 public static OutputAnalyzer dump(String appJar, String classList[], 99 String... suffix) throws Exception { 100 return createArchive(appJar, classList, suffix); 101 } 102 103 104 // Create AppCDS archive using most common args - convenience method 105 public static OutputAnalyzer createArchive(String appJar, String classList[], 106 String... suffix) throws Exception { 107 AppCDSOptions opts = (new AppCDSOptions()).setAppJar(appJar); 108 opts.setClassList(classList); 109 opts.addSuffix(suffix); 110 return createArchive(opts); 111 } 112 113 // Create AppCDS archive using appcds options 114 public static OutputAnalyzer createArchive(AppCDSOptions opts) 115 throws Exception { 116 117 ArrayList<String> cmd = new ArrayList<String>(); 118 startNewArchiveName(); 119 120 for (String p : opts.prefix) cmd.add(p); 121 122 if (opts.appJar != null) { 123 cmd.add("-cp"); 124 cmd.add(opts.appJar); 125 } else { 126 cmd.add("-cp"); 127 cmd.add("\"\""); 128 } 129 130 cmd.add("-Xshare:dump"); 131 132 if (opts.archiveName == null) 133 opts.archiveName = getCurrentArchiveName(); 134 135 cmd.add("-XX:SharedArchiveFile=" + opts.archiveName); 136 137 if (opts.classList != null) { 138 File classListFile = makeClassList(opts.classList); 139 cmd.add("-XX:ExtraSharedClassListFile=" + classListFile.getPath()); 140 } 141 142 for (String s : opts.suffix) cmd.add(s); 143 144 String[] cmdLine = cmd.toArray(new String[cmd.size()]); 145 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine); 146 return executeAndLog(pb, "dump"); 147 } 148 149 150 // Execute JVM using AppCDS archive with specified AppCDSOptions 151 public static OutputAnalyzer runWithArchive(AppCDSOptions opts) 152 throws Exception { 153 154 ArrayList<String> cmd = new ArrayList<String>(); 155 156 for (String p : opts.prefix) cmd.add(p); 157 158 cmd.add("-Xshare:" + opts.xShareMode); 159 cmd.add("-showversion"); 160 cmd.add("-XX:SharedArchiveFile=" + getCurrentArchiveName()); 161 cmd.add("-Dtest.timeout.factor=" + timeoutFactor); 221 if (upgrademodulepath == null) { 222 opts.addSuffix("-p", modulepath, "-m", mid); 223 } else { 224 opts.addSuffix("--upgrade-module-path", upgrademodulepath, 225 "-p", modulepath, "-m", mid); 226 } 227 opts.addSuffix(testClassArgs); 228 return opts; 229 } 230 231 public static OutputAnalyzer execModule(String prefix[], String upgrademodulepath, String modulepath, 232 String mid, String... testClassArgs) 233 throws Exception { 234 AppCDSOptions opts = makeModuleOptions(prefix, upgrademodulepath, modulepath, 235 mid, testClassArgs); 236 return runWithArchive(opts); 237 } 238 239 240 // A common operation: dump, then check results 241 public static OutputAnalyzer testDump(String appJar, String classList[], 242 String... suffix) throws Exception { 243 OutputAnalyzer output = dump(appJar, classList, suffix); 244 output.shouldContain("Loading classes to share"); 245 output.shouldHaveExitValue(0); 246 return output; 247 } 248 249 250 /** 251 * Simple test -- dump and execute appJar with the given classList in classlist. 252 */ 253 public static OutputAnalyzer test(String appJar, String classList[], String... args) 254 throws Exception { 255 testDump(appJar, classList); 256 257 OutputAnalyzer output = exec(appJar, args); 258 return checkExec(output); 259 } 260 261 262 public static OutputAnalyzer checkExecReturn(OutputAnalyzer output, int ret, 263 boolean checkContain, String... matches) throws Exception { 264 try { 265 for (String s : matches) { 266 if (checkContain) { 267 output.shouldContain(s); 268 } else { 269 output.shouldNotContain(s); 270 } 271 } 272 output.shouldHaveExitValue(ret); 273 } catch (Exception e) { 274 checkCommonExecExceptions(output, e); 275 } |