001: /*
002:
003: Derby - Class org.apache.derbyTesting.functionTests.harness.RunSuite
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derbyTesting.functionTests.harness;
023:
024: import org.apache.derby.tools.sysinfo;
025: import java.io.File;
026: import java.io.InputStream;
027: import java.io.InputStreamReader;
028: import java.io.BufferedReader;
029: import java.io.FileReader;
030: import java.io.FileInputStream;
031: import java.io.FileOutputStream;
032: import java.io.BufferedOutputStream;
033: import java.io.BufferedWriter;
034: import java.io.FileWriter;
035: import java.io.PrintWriter;
036: import java.io.IOException;
037: import java.io.FileNotFoundException;
038: import java.lang.ClassNotFoundException;
039: import java.sql.Timestamp;
040: import java.util.Enumeration;
041: import java.util.Properties;
042: import java.util.Vector;
043: import java.util.StringTokenizer;
044:
045: public class RunSuite {
046:
047: static final boolean verbose = true;
048:
049: static String suites; // list of subsuites in this suite
050: static Vector suitesToRun; // Vector of suites to run
051:
052: // Properties which may be specified
053: static String jvmName = "";
054: static String javaCmd = "java";
055: static String jvmflags = ""; // jvm flags as one string
056: static String javaVersion;
057: static String classpath;
058: static String classpathServer;
059: static String testJavaFlags = ""; // formerly systest_javaflags
060: static String testSpecialProps = "";
061: static String userdir;
062: static String framework;
063: static String runwithibmjvm;
064: static String excludeJCC;
065: static boolean useprocess = true;
066: static boolean skipsed = false;
067: static String systemdiff = "false";
068: static String topSuiteName = "";
069: static String outputdir; // location of output (default is userdir)
070: static String outcopy = "false"; // true if support files should go to outDir
071: static String canondir; // location of master dir (default is master)
072: static String bootcp; // path for j9 bootclasspath setting
073: static String serverJvm; // path for j9 bootclasspath setting
074: static String hostName; // needs to be settable for IPV6 testing; localhost otherwise.
075: static String testEncoding; // setting the encoding.
076: static String ijdefaultResourcePackage; // for ij tests only
077: static String debug; // for setting verbose mode to pass down to RunTest
078: static String timeout; // to allow killing a hanging test
079: static String shutdownurl; //used mainly by useprocess=false tests
080: static String reportstderr; // can set to disable (to turn off JIT errors, etc.)
081: static Properties suiteProperties;
082: static Properties specialProperties;
083:
084: // Output variables
085: static PrintWriter pwOut = null; // for writing suite output
086: static File outDir; // test out dir
087: static File runDir; // where the suite/tests are run
088: static File outFile; // suite output file
089:
090: public static void main(String[] args) throws Exception {
091: if ((System.getProperty("java.vm.name") != null)
092: && System.getProperty("java.vm.name").equals("J9")) {
093: javaCmd = "j9";
094: String javaHome = System.getProperty("java.home");
095: }
096: String j9config = System
097: .getProperty("com.ibm.oti.configuration");
098: if (j9config != null)
099: if (j9config.equals("foun10"))
100: jvmName = "j9_foundation";
101: else if (j9config.equals("max"))
102: jvmName = "j9_13";
103:
104: String suiteName = args[0];
105: if (suiteName == null) {
106: System.out.println("No suite name argument.");
107: System.exit(1);
108: }
109: topSuiteName = suiteName;
110: System.out.println("Top suite: " + suiteName);
111:
112: // suiteName may be one suite or a list of suites
113: suitesToRun = new Vector();
114:
115: // Get properties set in the suite's properties file
116: suiteProperties = getSuiteProperties(suiteName, true);
117:
118: // There may be system properties which will override
119: // the suiteProperties. This will make it easier when you
120: // do not want to edit the suite props for a special case
121: getSystemProperties();
122:
123: // Get any special properties that are not the usual
124: // expected properties (we separate these from suiteProperties
125: // to avoid conflicts)
126: specialProperties = SpecialFlags
127: .getSpecialProperties(suiteProperties);
128:
129: // Setup the initial output
130: setOutput(suiteName);
131:
132: // Get the current time to write a timestamp
133: String startTime = CurrentTime.getTime();
134:
135: pwOut.println("******* Start Suite: " + suiteName + " "
136: + startTime + " *******");
137:
138: // Write sysinfo to the output file
139: if (useprocess) // doesn't work on Mac
140: {
141: SysInfoLog sysLog = new SysInfoLog();
142: sysLog.exec(jvmName, javaCmd, classpath, framework, pwOut,
143: useprocess);
144: }
145:
146: getSuitesList(suiteName, true);
147:
148: // Get the current time to write a timestamp
149: String endTime = CurrentTime.getTime();
150: pwOut.println("******* End Suite: " + suiteName + " " + endTime
151: + " *******");
152: pwOut.close();
153:
154: String genrep = System.getProperty("genrep");
155: boolean isGenrep = true;
156: if (genrep != null)
157: isGenrep = "true".equalsIgnoreCase(genrep);
158: if (isGenrep) {
159: String[] genargs = new String[6];
160: genargs[0] = args[0];
161: genargs[1] = jvmName;
162: genargs[2] = javaCmd;
163: genargs[3] = classpath;
164: genargs[4] = framework;
165: if (useprocess)
166: genargs[5] = "true";
167: else
168: genargs[5] = "false";
169: GenerateReport.main(genargs);
170: }
171: }
172:
173: static void getSuitesList(String topparent, boolean isTop)
174: throws Exception, ClassNotFoundException, IOException {
175: // Get the suite properties if it exists
176: Properties p;
177: if ((suites == null) || (suites.length() == 0)) {
178: // There is a single suite, not a list, just add it
179: if (verbose)
180: System.out.println("Suite to run: " + topparent + ":"
181: + topparent);
182: suitesToRun.addElement(topparent + ":" + topparent);
183: // Use RunList class to issue the RunTest commands
184: if (verbose)
185: System.out.println("Now do RunList");
186: //System.out.println("skipsed: " + skipsed);
187: RunList rl = new RunList(suitesToRun, runDir, outDir,
188: pwOut, suiteProperties, specialProperties,
189: topparent);
190: suitesToRun.removeAllElements();
191: } else {
192: isTop = false;
193: // Build the Vector from suites string
194: StringTokenizer st = new StringTokenizer(suites);
195: String subparent = "";
196: while (st.hasMoreTokens()) {
197: subparent = st.nextToken();
198: p = getSuiteProperties(subparent, isTop);
199: if ((p.getProperty("suites") == null)
200: || (subparent.equals(topparent))) {
201: suitesToRun.addElement(topparent + ":" + subparent);
202: //System.out.println("Add to suitesToRun: " + topparent+":"+subparent);
203: // Use RunList class to issue the RunTest commands
204: if (verbose)
205: System.out.println("Now do RunList");
206: //System.out.println("skipsed: " + skipsed);
207: RunList rl = new RunList(suitesToRun, runDir,
208: outDir, pwOut, suiteProperties,
209: specialProperties, topparent);
210: suitesToRun.removeAllElements();
211: } else // This suite also has nested suites
212: {
213: String sublist = p.getProperty("suites");
214: //System.out.println("list for this SubSuite= " + sublist);
215: BuildSuitesVector(subparent, sublist);
216: // Use RunList class to issue the RunTest commands
217: if (verbose)
218: System.out.println("Now do RunList");
219: //System.out.println("skipsed: " + skipsed);
220: RunList rl = new RunList(suitesToRun, runDir,
221: outDir, pwOut, suiteProperties,
222: specialProperties, subparent);
223: suitesToRun.removeAllElements();
224: }
225: }
226: }
227: }
228:
229: static void BuildSuitesVector(String parent, String subsuites)
230: throws ClassNotFoundException, IOException {
231: Properties p;
232: StringTokenizer st = new StringTokenizer(subsuites);
233: String child = "";
234: while (st.hasMoreTokens()) {
235: child = st.nextToken();
236: if (child.equals(parent)) {
237: suitesToRun.addElement(parent + ":" + child);
238: //System.out.println("Add this: " + parent+":"+child);
239: } else {
240: p = getSuiteProperties(child, false);
241: if (p.getProperty("suites") == null) {
242: suitesToRun.addElement(parent + ":" + child);
243: //System.out.println("Add this: " + parent+":"+child);
244: } else {
245: String moresuites = p.getProperty("suites");
246: BuildSuitesVector(child, moresuites);
247: }
248: }
249: }
250: }
251:
252: static Properties getSuiteProperties(String suiteName, boolean isTop)
253: throws ClassNotFoundException, IOException {
254: // Locate the suite's config file and get the properties
255: // The file should be in the harness dir or user.dir
256: String suiteProps = "suites" + '/' + suiteName + ".properties";
257: userdir = System.getProperty("user.dir");
258:
259: InputStream is = RunTest.loadTestResource(suiteProps);
260: if (is == null) {
261: // Look in userdir
262: suiteProps = userdir + '/' + suiteName + ".properties";
263: is = RunTest.loadTestResource(suiteProps);
264: }
265: Properties p = new Properties();
266: if (is == null)
267: return p;
268:
269: p.load(is);
270: // The top level suite may have special properties
271: // which get propagated to any subsuites
272: if (isTop == true) {
273: String tmpjvmName = jvmName;
274: jvmName = p.getProperty("jvm");
275: if ((jvmName == null) || (jvmName.length() == 0)) {
276: javaVersion = System.getProperty("java.version");
277: } else
278: javaVersion = jvmName;
279:
280: // for j9, we cannot just use java.version.
281: String javavmVersion;
282: if (System.getProperty("java.vm.name").equals("J9"))
283: javavmVersion = (System.getProperty("java.vm.version"));
284: else
285: javavmVersion = javaVersion;
286:
287: JavaVersionHolder jvh = new JavaVersionHolder(javavmVersion);
288: String majorVersion = jvh.getMajorVersion();
289: String minorVersion = jvh.getMinorVersion();
290: int iminor = jvh.getMinorNumber();
291: int imajor = jvh.getMajorNumber();
292:
293: if ((iminor < 2) && (imajor < 2))
294: jvmName = "currentjvm";
295: else
296: jvmName = "jdk" + majorVersion + minorVersion;
297: if (tmpjvmName != null)
298: jvmName = tmpjvmName;
299: javaCmd = p.getProperty("javaCmd");
300: jvmflags = p.getProperty("jvmflags");
301: testJavaFlags = p.getProperty("testJavaFlags");
302: testSpecialProps = p.getProperty("testSpecialProps");
303: classpath = p.getProperty("classpath");
304: classpathServer = p.getProperty("classpathServer");
305: framework = p.getProperty("framework");
306: String usepr = p.getProperty("useprocess");
307: if (usepr != null) {
308: usepr = usepr.toLowerCase();
309: if (usepr.equals("false"))
310: useprocess = false;
311: else
312: useprocess = true;
313: } else
314: useprocess = true;
315:
316: String nosed = p.getProperty("skipsed");
317: if (nosed != null) {
318: nosed = nosed.toLowerCase();
319: if (nosed.equals("true"))
320: skipsed = true;
321: else
322: skipsed = false;
323: } else
324: skipsed = false;
325:
326: outputdir = p.getProperty("outputdir");
327: canondir = p.getProperty("canondir");
328: bootcp = p.getProperty("bootcp");
329: hostName = p.getProperty("hostName");
330: serverJvm = p.getProperty("serverJvm");
331: systemdiff = p.getProperty("systemdiff");
332: ijdefaultResourcePackage = p
333: .getProperty("ij.defaultResourcePackage");
334: outcopy = p.getProperty("outcopy");
335: debug = p.getProperty("verbose");
336: reportstderr = p.getProperty("reportstderr");
337: timeout = p.getProperty("timeout");
338: shutdownurl = p.getProperty("shutdownurl");
339: testEncoding = p.getProperty("derbyTesting.encoding");
340: }
341: suites = p.getProperty("suites");
342: return p;
343: }
344:
345: private static void getSystemProperties() {
346: // Get any properties specified on the command line
347: // which may not have been specified in the suite prop file
348: Properties sp = System.getProperties();
349: String searchCP = sp.getProperty("ij.searchClassPath");
350: if (searchCP != null)
351: suiteProperties.put("ij.searchClassPath", searchCP);
352: String frm = sp.getProperty("framework");
353: if ((frm != null) && (!frm.equals("embedded"))) {
354: framework = frm;
355: suiteProperties.put("framework", framework);
356: }
357: String j = sp.getProperty("jvm");
358: if (j != null)
359: suiteProperties.put("jversion", j);
360:
361: String jcmd = sp.getProperty("javaCmd");
362: if ((System.getProperty("java.vm.name") != null)
363: && System.getProperty("java.vm.name").equals("J9"))
364: jcmd = "j9";
365: if (jcmd != null) {
366: javaCmd = jcmd;
367: suiteProperties.put("javaCmd", javaCmd);
368: }
369: // get System properties for jvmflags, and put them to the end, thus
370: // when the time comes to have this converted into actual jvm flags
371: // the ones given at the command line will overwrite whatever's in the suite
372: String jflags = sp.getProperty("jvmflags");
373: if (jvmflags != null) {
374: if (jflags != null)
375: suiteProperties.put("jvmflags",
376: (jvmflags + "^" + jflags));
377: else
378: suiteProperties.put("jvmflags", jvmflags);
379: } else {
380: if (jflags != null)
381: suiteProperties.put("jvmflags", jflags);
382: }
383: String testflags = sp.getProperty("testJavaFlags");
384: if (testflags != null) {
385: if (testJavaFlags == null)
386: testJavaFlags = testflags;
387: else
388: // add to testJavaFlags
389: testJavaFlags = testJavaFlags + "^" + testflags;
390: suiteProperties.put("testJavaFlags", testJavaFlags);
391: }
392: String testprops = sp.getProperty("testSpecialProps");
393: if (testprops != null) {
394: if (testSpecialProps == null)
395: testSpecialProps = testprops;
396: else
397: // add to testSpecialProps
398: testSpecialProps = testSpecialProps + "^" + testprops;
399: suiteProperties.put("testSpecialProps", testSpecialProps);
400: }
401: String clpth = sp.getProperty("classpath");
402: if (clpth != null) {
403: classpath = clpth;
404: suiteProperties.put("classpath", classpath);
405: }
406: String clsrv = sp.getProperty("classpathServer");
407: if ((clsrv != null) && (!clsrv.startsWith("${"))) {
408: classpathServer = clsrv;
409: suiteProperties.put("classpathServer", clsrv);
410: }
411: String usesys = sp.getProperty("usesystem");
412: if (usesys != null)
413: suiteProperties.put("usesystem", usesys);
414: String jarf = sp.getProperty("jarfile");
415: if (jarf != null)
416: suiteProperties.put("jarfile", jarf);
417: String upgtest = sp.getProperty("upgradetest");
418: if (upgtest != null)
419: suiteProperties.put("upgradetest", upgtest);
420: String rep = sp.getProperty("replication");
421: if (rep != null)
422: suiteProperties.put("replication", rep);
423: String encrypt = sp.getProperty("encryption");
424: if (encrypt != null)
425: suiteProperties.put("encryption", encrypt);
426: String encryptAlgorithm = sp
427: .getProperty("testEncryptionAlgorithm");
428: if (encryptAlgorithm != null)
429: suiteProperties.put("testEncryptionAlgorithm",
430: encryptAlgorithm);
431: String jdk12test = sp.getProperty("jdk12test");
432: if (jdk12test != null)
433: suiteProperties.put("jdk12test", jdk12test);
434: String jdk12ex = sp.getProperty("jdk12exttest");
435: if (jdk12ex != null)
436: suiteProperties.put("jdk12exttest", jdk12ex);
437: String runwithibmjvm = sp.getProperty("runwithibmjvm");
438: if (runwithibmjvm != null)
439: suiteProperties.put("runwithibmjvm", runwithibmjvm);
440: String excludeJCC = sp.getProperty("excludeJCC");
441: if (excludeJCC != null)
442: suiteProperties.put("excludeJCC", excludeJCC);
443: String keep = sp.getProperty("keepfiles");
444: if (keep != null)
445: suiteProperties.put("keepfiles", keep);
446: String outd = sp.getProperty("outputdir");
447: if (outd != null) {
448: outputdir = outd;
449: suiteProperties.put("outputdir", outputdir);
450: }
451: String canond = sp.getProperty("canondir");
452: if (canond != null) {
453: canondir = canond;
454: suiteProperties.put("canondir", canondir);
455: }
456: String j9bootcp = sp.getProperty("bootcp");
457: if (j9bootcp != null) {
458: bootcp = j9bootcp;
459: suiteProperties.put("bootcp", bootcp);
460: }
461: String hostname = sp.getProperty("hostName");
462: if (hostname != null)
463: suiteProperties.put("hostName", hostname);
464: String serverJvm = sp.getProperty("serverJvm");
465: if (serverJvm != null)
466: suiteProperties.put("serverJvm", serverJvm);
467: String cmlTestEncoding = sp
468: .getProperty("derbyTesting.encoding");
469: if (cmlTestEncoding != null)
470: suiteProperties.put("derbyTesting.encoding",
471: cmlTestEncoding);
472: String upgradejarpath = sp.getProperty("derbyTesting.jar.path");
473: if (upgradejarpath != null)
474: suiteProperties
475: .put("derbyTesting.jar.path", upgradejarpath);
476: String testout = sp.getProperty("testoutname");
477: if (testout != null)
478: suiteProperties.put("testoutname", testout); // toursDemo
479: String mtdir = sp.getProperty("mtestdir"); // used by multi tests
480: if (mtdir != null)
481: suiteProperties.put("mtestdir", mtdir);
482: String usepr = sp.getProperty("useprocess");
483: if (usepr != null) {
484: // Some platforms cannot handle process exec
485: usepr = usepr.toLowerCase();
486: if (usepr.equals("false")) {
487: useprocess = false;
488: suiteProperties.put("useprocess", usepr);
489: }
490: }
491:
492: String nosed = sp.getProperty("skipsed");
493: if (nosed != null) {
494: // in some cases (like locales, we may want to skip the Sed)
495: nosed = nosed.toLowerCase();
496: if (nosed.equals("true")) {
497: skipsed = true;
498: suiteProperties.put("skipsed", nosed);
499: }
500: }
501:
502: String sysdiff = sp.getProperty("systemdiff");
503: if (sysdiff != null) {
504: // Use system diff if set to true
505: sysdiff = sysdiff.toLowerCase();
506: if (sysdiff.equals("true"))
507: suiteProperties.put("systemdiff", "true");
508: }
509: String defrespckg = sp.getProperty("ij.defaultResourcePackage");
510: if (defrespckg != null)
511: suiteProperties
512: .put("ij.defaultResourcePackage", defrespckg);
513: String outcpy = sp.getProperty("outcopy");
514: if (outcpy != null)
515: suiteProperties.put("outcopy", outcpy);
516: String topsuite = sp.getProperty("suitename");
517: if (topsuite != null)
518: suiteProperties.put("suitename", topsuite);
519: else
520: suiteProperties.put("suitename", topSuiteName);
521: String dbug = sp.getProperty("verbose");
522: if (dbug != null)
523: suiteProperties.put("verbose", dbug);
524: String reporterr = sp.getProperty("reportstderr");
525: if (reporterr != null)
526: suiteProperties.put("reportstderr", reporterr);
527: String tout = sp.getProperty("timeout");
528: if (tout != null)
529: suiteProperties.put("timeout", tout);
530: }
531:
532: private static void setOutput(String suiteName)
533: throws ClassNotFoundException, FileNotFoundException,
534: IOException {
535: boolean status = false;
536: // Use the defined output directory or user.dir by default
537: File tmpoutDir;
538: if ((outputdir == null) || (outputdir.length() == 0)) {
539: tmpoutDir = new File((new File(userdir)).getCanonicalPath());
540: } else {
541: tmpoutDir = new File((new File(outputdir))
542: .getCanonicalPath());
543: }
544: outDir = tmpoutDir;
545: outDir.mkdir();
546:
547: // runDir is where the suites/tests are run and where
548: // any support files or scripts will be expected to live
549: runDir = new File((new File(userdir)).getCanonicalPath());
550:
551: // Set the suite property outputdir
552: suiteProperties.put("outputdir", outDir.getCanonicalPath());
553:
554: // Define the final suite summary file file
555: outFile = new File(outDir, suiteName + ".sum");
556: if (outFile.exists())
557: status = outFile.delete();
558:
559: // Define the suite.pass file
560: File passFile = new File(outDir, suiteName + ".pass");
561: if (passFile.exists())
562: status = passFile.delete();
563:
564: // Define the suite.fail file
565: File failFile = new File(outDir, suiteName + ".fail");
566: if (failFile.exists())
567: status = failFile.delete();
568:
569: // Create a PrintWriter for writing env and test info to the diff file
570: pwOut = new PrintWriter(new BufferedWriter(new FileWriter(
571: outFile.getPath()), 4096), true);
572: }
573: }
|