ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 1 | /* |
ksrini | ac5e02f | 2012-01-11 08:14:47 -0800 | [diff] [blame] | 2 | * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 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 | * |
ohair | 2283b9d | 2010-05-25 15:58:33 -0700 | [diff] [blame] | 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. |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 22 | */ |
| 23 | |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 24 | import java.io.BufferedReader; |
| 25 | import java.io.File; |
ksrini | ac5e02f | 2012-01-11 08:14:47 -0800 | [diff] [blame] | 26 | import java.io.FileFilter; |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 27 | import java.io.FileNotFoundException; |
| 28 | import java.io.FileOutputStream; |
ksrini | f8cc597 | 2011-04-07 12:06:32 -0700 | [diff] [blame] | 29 | import java.io.IOException; |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 30 | import java.io.InputStreamReader; |
| 31 | import java.io.PrintStream; |
ksrini | ac5e02f | 2012-01-11 08:14:47 -0800 | [diff] [blame] | 32 | import java.nio.file.attribute.BasicFileAttributes; |
ksrini | f8cc597 | 2011-04-07 12:06:32 -0700 | [diff] [blame] | 33 | import java.nio.file.Files; |
ksrini | ac5e02f | 2012-01-11 08:14:47 -0800 | [diff] [blame] | 34 | import java.nio.file.FileVisitResult; |
| 35 | import java.nio.file.SimpleFileVisitor; |
ksrini | f8cc597 | 2011-04-07 12:06:32 -0700 | [diff] [blame] | 36 | import java.nio.file.Path; |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 37 | import java.util.ArrayList; |
| 38 | import java.util.List; |
| 39 | import java.util.Map; |
| 40 | import javax.tools.JavaCompiler; |
ksrini | ac5e02f | 2012-01-11 08:14:47 -0800 | [diff] [blame] | 41 | import javax.tools.ToolProvider; |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 42 | |
ksrini | f8cc597 | 2011-04-07 12:06:32 -0700 | [diff] [blame] | 43 | import static java.nio.file.StandardCopyOption.*; |
| 44 | |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 45 | /** |
ksrini | f8cc597 | 2011-04-07 12:06:32 -0700 | [diff] [blame] | 46 | * This class provides some common utilities for the launcher tests. |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 47 | */ |
| 48 | public enum TestHelper { |
| 49 | INSTANCE; |
ksrini | 11e7f1b | 2009-11-20 11:01:32 -0800 | [diff] [blame] | 50 | static final String JAVAHOME = System.getProperty("java.home"); |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 51 | static final boolean isSDK = JAVAHOME.endsWith("jre"); |
| 52 | static final String javaCmd; |
ksrini | dd19404 | 2012-01-03 08:33:30 -0800 | [diff] [blame] | 53 | static final String javawCmd; |
ksrini | 11e7f1b | 2009-11-20 11:01:32 -0800 | [diff] [blame] | 54 | static final String java64Cmd; |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 55 | static final String javacCmd; |
| 56 | static final JavaCompiler compiler; |
| 57 | |
ksrini | 11e7f1b | 2009-11-20 11:01:32 -0800 | [diff] [blame] | 58 | static final boolean debug = Boolean.getBoolean("TestHelper.Debug"); |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 59 | static final boolean isWindows = |
| 60 | System.getProperty("os.name", "unknown").startsWith("Windows"); |
ksrini | 11e7f1b | 2009-11-20 11:01:32 -0800 | [diff] [blame] | 61 | static final boolean is64Bit = |
| 62 | System.getProperty("sun.arch.data.model").equals("64"); |
| 63 | static final boolean is32Bit = |
| 64 | System.getProperty("sun.arch.data.model").equals("32"); |
| 65 | static final boolean isSolaris = |
| 66 | System.getProperty("os.name", "unknown").startsWith("SunOS"); |
| 67 | static final boolean isLinux = |
| 68 | System.getProperty("os.name", "unknown").startsWith("Linux"); |
| 69 | static final boolean isDualMode = isSolaris; |
| 70 | static final boolean isSparc = System.getProperty("os.arch").startsWith("sparc"); |
| 71 | |
ksrini | ac5e02f | 2012-01-11 08:14:47 -0800 | [diff] [blame] | 72 | static final String JAVA_FILE_EXT = ".java"; |
| 73 | static final String CLASS_FILE_EXT = ".class"; |
| 74 | static final String JAR_FILE_EXT = ".jar"; |
| 75 | |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 76 | static int testExitValue = 0; |
| 77 | |
| 78 | static { |
ksrini | 11e7f1b | 2009-11-20 11:01:32 -0800 | [diff] [blame] | 79 | if (is64Bit && is32Bit) { |
| 80 | throw new RuntimeException("arch model cannot be both 32 and 64 bit"); |
| 81 | } |
| 82 | if (!is64Bit && !is32Bit) { |
| 83 | throw new RuntimeException("arch model is not 32 or 64 bit ?"); |
| 84 | } |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 85 | compiler = ToolProvider.getSystemJavaCompiler(); |
| 86 | File binDir = (isSDK) ? new File((new File(JAVAHOME)).getParentFile(), "bin") |
| 87 | : new File(JAVAHOME, "bin"); |
| 88 | File javaCmdFile = (isWindows) |
| 89 | ? new File(binDir, "java.exe") |
| 90 | : new File(binDir, "java"); |
| 91 | javaCmd = javaCmdFile.getAbsolutePath(); |
| 92 | if (!javaCmdFile.canExecute()) { |
ksrini | dd19404 | 2012-01-03 08:33:30 -0800 | [diff] [blame] | 93 | throw new RuntimeException("java <" + TestHelper.javaCmd + |
| 94 | "> must exist and should be executable"); |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | File javacCmdFile = (isWindows) |
| 98 | ? new File(binDir, "javac.exe") |
| 99 | : new File(binDir, "javac"); |
| 100 | javacCmd = javacCmdFile.getAbsolutePath(); |
ksrini | dd19404 | 2012-01-03 08:33:30 -0800 | [diff] [blame] | 101 | |
| 102 | if (isWindows) { |
| 103 | File javawCmdFile = new File(binDir, "javaw.exe"); |
| 104 | javawCmd = javawCmdFile.getAbsolutePath(); |
| 105 | if (!javawCmdFile.canExecute()) { |
| 106 | throw new RuntimeException("java <" + javawCmd + |
| 107 | "> must exist and should be executable"); |
| 108 | } |
| 109 | } else { |
| 110 | javawCmd = null; |
| 111 | } |
| 112 | |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 113 | if (!javacCmdFile.canExecute()) { |
ksrini | dd19404 | 2012-01-03 08:33:30 -0800 | [diff] [blame] | 114 | throw new RuntimeException("java <" + javacCmd + |
| 115 | "> must exist and should be executable"); |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 116 | } |
ksrini | 11e7f1b | 2009-11-20 11:01:32 -0800 | [diff] [blame] | 117 | if (isSolaris) { |
| 118 | File sparc64BinDir = new File(binDir,isSparc ? "sparcv9" : "amd64"); |
| 119 | File java64CmdFile= new File(sparc64BinDir, "java"); |
| 120 | if (java64CmdFile.exists() && java64CmdFile.canExecute()) { |
| 121 | java64Cmd = java64CmdFile.getAbsolutePath(); |
| 122 | } else { |
| 123 | java64Cmd = null; |
| 124 | } |
| 125 | } else { |
| 126 | java64Cmd = null; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | /* |
ksrini | f8cc597 | 2011-04-07 12:06:32 -0700 | [diff] [blame] | 131 | * is a dual mode available in the test jdk |
| 132 | */ |
| 133 | static boolean dualModePresent() { |
| 134 | return isDualMode && java64Cmd != null; |
| 135 | } |
| 136 | |
| 137 | /* |
ksrini | 11e7f1b | 2009-11-20 11:01:32 -0800 | [diff] [blame] | 138 | * usually the jre/lib/arch-name is the same as os.arch, except for x86. |
| 139 | */ |
| 140 | static String getJreArch() { |
| 141 | String arch = System.getProperty("os.arch"); |
| 142 | return arch.equals("x86") ? "i386" : arch; |
| 143 | } |
| 144 | |
| 145 | /* |
ksrini | f8cc597 | 2011-04-07 12:06:32 -0700 | [diff] [blame] | 146 | * get the complementary jre arch ie. if sparc then return sparcv9 and |
| 147 | * vice-versa. |
| 148 | */ |
| 149 | static String getComplementaryJreArch() { |
| 150 | String arch = System.getProperty("os.arch"); |
| 151 | if (arch != null) { |
| 152 | switch (arch) { |
| 153 | case "sparc": |
| 154 | return "sparcv9"; |
| 155 | case "sparcv9": |
| 156 | return "sparc"; |
| 157 | case "x86": |
| 158 | return "amd64"; |
| 159 | case "amd64": |
| 160 | return "i386"; |
| 161 | } |
| 162 | } |
| 163 | return null; |
| 164 | } |
| 165 | |
| 166 | /* |
ksrini | 11e7f1b | 2009-11-20 11:01:32 -0800 | [diff] [blame] | 167 | * A convenience method to create a jar with jar file name and defs |
| 168 | */ |
| 169 | static void createJar(File jarName, String... mainDefs) |
| 170 | throws FileNotFoundException{ |
| 171 | createJar(null, jarName, new File("Foo"), mainDefs); |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /* |
ksrini | cafaf7c | 2008-10-01 09:04:42 -0700 | [diff] [blame] | 175 | * A convenience method to create a java file, compile and jar it up, using |
| 176 | * the sole class file name in the jar, as the Main-Class attribute value. |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 177 | */ |
| 178 | static void createJar(File jarName, File mainClass, String... mainDefs) |
| 179 | throws FileNotFoundException { |
| 180 | createJar(null, jarName, mainClass, mainDefs); |
| 181 | } |
| 182 | |
| 183 | /* |
ksrini | cafaf7c | 2008-10-01 09:04:42 -0700 | [diff] [blame] | 184 | * A generic jar file creator to create a java file, compile it |
| 185 | * and jar it up, a specific Main-Class entry name in the |
| 186 | * manifest can be specified or a null to use the sole class file name |
| 187 | * as the Main-Class attribute value. |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 188 | */ |
ksrini | cafaf7c | 2008-10-01 09:04:42 -0700 | [diff] [blame] | 189 | static void createJar(String mEntry, File jarName, File mainClass, |
| 190 | String... mainDefs) throws FileNotFoundException { |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 191 | if (jarName.exists()) { |
| 192 | jarName.delete(); |
| 193 | } |
ksrini | 37e8b50 | 2011-07-19 10:58:50 -0700 | [diff] [blame] | 194 | try (PrintStream ps = new PrintStream(new FileOutputStream(mainClass + ".java"))) { |
| 195 | ps.println("public class Foo {"); |
| 196 | if (mainDefs != null) { |
| 197 | for (String x : mainDefs) { |
| 198 | ps.println(x); |
| 199 | } |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 200 | } |
ksrini | 37e8b50 | 2011-07-19 10:58:50 -0700 | [diff] [blame] | 201 | ps.println("}"); |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 202 | } |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 203 | |
| 204 | String compileArgs[] = { |
| 205 | mainClass + ".java" |
| 206 | }; |
| 207 | if (compiler.run(null, null, null, compileArgs) != 0) { |
| 208 | throw new RuntimeException("compilation failed " + mainClass + ".java"); |
| 209 | } |
ksrini | cafaf7c | 2008-10-01 09:04:42 -0700 | [diff] [blame] | 210 | if (mEntry == null) { |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 211 | mEntry = mainClass.getName(); |
| 212 | } |
| 213 | String jarArgs[] = { |
| 214 | (debug) ? "cvfe" : "cfe", |
| 215 | jarName.getAbsolutePath(), |
| 216 | mEntry, |
| 217 | mainClass.getName() + ".class" |
| 218 | }; |
ksrini | 37e8b50 | 2011-07-19 10:58:50 -0700 | [diff] [blame] | 219 | createJar(jarArgs); |
| 220 | } |
| 221 | |
| 222 | static void createJar(String... args) { |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 223 | sun.tools.jar.Main jarTool = |
| 224 | new sun.tools.jar.Main(System.out, System.err, "JarCreator"); |
ksrini | 37e8b50 | 2011-07-19 10:58:50 -0700 | [diff] [blame] | 225 | if (!jarTool.run(args)) { |
| 226 | String message = "jar creation failed with command:"; |
| 227 | for (String x : args) { |
| 228 | message = message.concat(" " + x); |
| 229 | } |
| 230 | throw new RuntimeException(message); |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 231 | } |
ksrini | 37e8b50 | 2011-07-19 10:58:50 -0700 | [diff] [blame] | 232 | } |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 233 | |
ksrini | f8cc597 | 2011-04-07 12:06:32 -0700 | [diff] [blame] | 234 | static void copyFile(File src, File dst) throws IOException { |
| 235 | Path parent = dst.toPath().getParent(); |
| 236 | if (parent != null) { |
| 237 | Files.createDirectories(parent); |
| 238 | } |
| 239 | Files.copy(src.toPath(), dst.toPath(), COPY_ATTRIBUTES, REPLACE_EXISTING); |
| 240 | } |
| 241 | |
| 242 | static void recursiveDelete(File target) throws IOException { |
| 243 | if (!target.exists()) { |
| 244 | return; |
| 245 | } |
| 246 | Files.walkFileTree(target.toPath(), new SimpleFileVisitor<Path>() { |
| 247 | @Override |
| 248 | public FileVisitResult postVisitDirectory(Path dir, IOException exc) { |
| 249 | try { |
| 250 | Files.deleteIfExists(dir); |
| 251 | } catch (IOException ex) { |
| 252 | System.out.println("Error: could not delete: " + dir.toString()); |
| 253 | System.out.println(ex.getMessage()); |
| 254 | return FileVisitResult.TERMINATE; |
| 255 | } |
| 256 | return FileVisitResult.CONTINUE; |
| 257 | } |
| 258 | @Override |
| 259 | public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { |
| 260 | try { |
| 261 | Files.deleteIfExists(file); |
| 262 | } catch (IOException ex) { |
| 263 | System.out.println("Error: could not delete: " + file.toString()); |
| 264 | System.out.println(ex.getMessage()); |
| 265 | return FileVisitResult.TERMINATE; |
| 266 | } |
| 267 | return FileVisitResult.CONTINUE; |
| 268 | } |
| 269 | }); |
| 270 | } |
| 271 | |
ksrini | 11e7f1b | 2009-11-20 11:01:32 -0800 | [diff] [blame] | 272 | static TestResult doExec(String...cmds) { |
| 273 | return doExec(null, cmds); |
| 274 | } |
| 275 | |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 276 | /* |
ksrini | cafaf7c | 2008-10-01 09:04:42 -0700 | [diff] [blame] | 277 | * A method which executes a java cmd and returns the results in a container |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 278 | */ |
ksrini | 11e7f1b | 2009-11-20 11:01:32 -0800 | [diff] [blame] | 279 | static TestResult doExec(Map<String, String> envToSet, String...cmds) { |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 280 | String cmdStr = ""; |
| 281 | for (String x : cmds) { |
| 282 | cmdStr = cmdStr.concat(x + " "); |
| 283 | } |
| 284 | ProcessBuilder pb = new ProcessBuilder(cmds); |
| 285 | Map<String, String> env = pb.environment(); |
ksrini | 11e7f1b | 2009-11-20 11:01:32 -0800 | [diff] [blame] | 286 | if (envToSet != null) { |
| 287 | env.putAll(envToSet); |
| 288 | } |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 289 | BufferedReader rdr = null; |
| 290 | try { |
ksrini | f8cc597 | 2011-04-07 12:06:32 -0700 | [diff] [blame] | 291 | List<String> outputList = new ArrayList<>(); |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 292 | pb.redirectErrorStream(true); |
| 293 | Process p = pb.start(); |
| 294 | rdr = new BufferedReader(new InputStreamReader(p.getInputStream())); |
| 295 | String in = rdr.readLine(); |
| 296 | while (in != null) { |
| 297 | outputList.add(in); |
| 298 | in = rdr.readLine(); |
| 299 | } |
| 300 | p.waitFor(); |
| 301 | p.destroy(); |
ksrini | f8cc597 | 2011-04-07 12:06:32 -0700 | [diff] [blame] | 302 | |
| 303 | return new TestHelper.TestResult(cmdStr, p.exitValue(), outputList, |
| 304 | env, new Throwable("current stack of the test")); |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 305 | } catch (Exception ex) { |
| 306 | ex.printStackTrace(); |
| 307 | throw new RuntimeException(ex.getMessage()); |
| 308 | } |
| 309 | } |
| 310 | |
ksrini | ac5e02f | 2012-01-11 08:14:47 -0800 | [diff] [blame] | 311 | static FileFilter createFilter(final String extension) { |
| 312 | return new FileFilter() { |
| 313 | @Override |
| 314 | public boolean accept(File pathname) { |
| 315 | String name = pathname.getName(); |
| 316 | if (name.endsWith(extension)) { |
| 317 | return true; |
| 318 | } |
| 319 | return false; |
| 320 | } |
| 321 | }; |
| 322 | } |
| 323 | |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 324 | /* |
| 325 | * A class to encapsulate the test results and stuff, with some ease |
| 326 | * of use methods to check the test results. |
| 327 | */ |
| 328 | static class TestResult { |
| 329 | StringBuilder status; |
| 330 | int exitValue; |
| 331 | List<String> testOutput; |
ksrini | f8cc597 | 2011-04-07 12:06:32 -0700 | [diff] [blame] | 332 | Map<String, String> env; |
| 333 | Throwable t; |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 334 | |
ksrini | f8cc597 | 2011-04-07 12:06:32 -0700 | [diff] [blame] | 335 | public TestResult(String str, int rv, List<String> oList, |
| 336 | Map<String, String> env, Throwable t) { |
ksrini | 11e7f1b | 2009-11-20 11:01:32 -0800 | [diff] [blame] | 337 | status = new StringBuilder("Executed command: " + str + "\n"); |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 338 | exitValue = rv; |
| 339 | testOutput = oList; |
ksrini | f8cc597 | 2011-04-07 12:06:32 -0700 | [diff] [blame] | 340 | this.env = env; |
| 341 | this.t = t; |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 342 | } |
| 343 | |
ksrini | 11e7f1b | 2009-11-20 11:01:32 -0800 | [diff] [blame] | 344 | void appendStatus(String x) { |
| 345 | status = status.append(" " + x + "\n"); |
| 346 | } |
| 347 | |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 348 | void checkNegative() { |
| 349 | if (exitValue == 0) { |
ksrini | 11e7f1b | 2009-11-20 11:01:32 -0800 | [diff] [blame] | 350 | appendStatus("Error: test must not return 0 exit value"); |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 351 | testExitValue++; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | void checkPositive() { |
| 356 | if (exitValue != 0) { |
ksrini | 11e7f1b | 2009-11-20 11:01:32 -0800 | [diff] [blame] | 357 | appendStatus("Error: test did not return 0 exit value"); |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 358 | testExitValue++; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | boolean isOK() { |
| 363 | return exitValue == 0; |
| 364 | } |
| 365 | |
| 366 | boolean isZeroOutput() { |
| 367 | if (!testOutput.isEmpty()) { |
ksrini | 11e7f1b | 2009-11-20 11:01:32 -0800 | [diff] [blame] | 368 | appendStatus("Error: No message from cmd please"); |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 369 | testExitValue++; |
| 370 | return false; |
| 371 | } |
| 372 | return true; |
| 373 | } |
| 374 | |
| 375 | boolean isNotZeroOutput() { |
| 376 | if (testOutput.isEmpty()) { |
ksrini | 11e7f1b | 2009-11-20 11:01:32 -0800 | [diff] [blame] | 377 | appendStatus("Error: Missing message"); |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 378 | testExitValue++; |
| 379 | return false; |
| 380 | } |
| 381 | return true; |
| 382 | } |
| 383 | |
ksrini | 11e7f1b | 2009-11-20 11:01:32 -0800 | [diff] [blame] | 384 | @Override |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 385 | public String toString() { |
ksrini | f8cc597 | 2011-04-07 12:06:32 -0700 | [diff] [blame] | 386 | status.append("++++Begin Test Info++++\n"); |
| 387 | status.append("++++Test Environment++++\n"); |
| 388 | for (String x : env.keySet()) { |
| 389 | status.append(x).append("=").append(env.get(x)).append("\n"); |
| 390 | } |
| 391 | status.append("++++Test Output++++\n"); |
ksrini | 11e7f1b | 2009-11-20 11:01:32 -0800 | [diff] [blame] | 392 | for (String x : testOutput) { |
| 393 | appendStatus(x); |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 394 | } |
ksrini | f8cc597 | 2011-04-07 12:06:32 -0700 | [diff] [blame] | 395 | status.append("++++Test Stack Trace++++\n"); |
| 396 | status.append(t.toString()); |
| 397 | for (StackTraceElement e : t.getStackTrace()) { |
| 398 | status.append(e.toString()); |
| 399 | } |
| 400 | status.append("++++End of Test Info++++\n"); |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 401 | return status.toString(); |
| 402 | } |
| 403 | |
| 404 | boolean contains(String str) { |
| 405 | for (String x : testOutput) { |
| 406 | if (x.contains(str)) { |
| 407 | return true; |
| 408 | } |
| 409 | } |
ksrini | 11e7f1b | 2009-11-20 11:01:32 -0800 | [diff] [blame] | 410 | appendStatus("Error: string <" + str + "> not found"); |
| 411 | testExitValue++; |
| 412 | return false; |
| 413 | } |
| 414 | |
| 415 | boolean matches(String stringToMatch) { |
| 416 | for (String x : testOutput) { |
| 417 | if (x.matches(stringToMatch)) { |
| 418 | return true; |
| 419 | } |
| 420 | } |
| 421 | appendStatus("Error: string <" + stringToMatch + "> not found"); |
ksrini | 20a64b2 | 2008-09-24 15:07:41 -0700 | [diff] [blame] | 422 | testExitValue++; |
| 423 | return false; |
| 424 | } |
| 425 | } |
| 426 | } |