KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > harness > RunSuite


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.harness.RunSuite
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derbyTesting.functionTests.harness;
23
24 import org.apache.derby.tools.sysinfo;
25 import java.io.File JavaDoc;
26 import java.io.InputStream JavaDoc;
27 import java.io.InputStreamReader JavaDoc;
28 import java.io.BufferedReader JavaDoc;
29 import java.io.FileReader JavaDoc;
30 import java.io.FileInputStream JavaDoc;
31 import java.io.FileOutputStream JavaDoc;
32 import java.io.BufferedOutputStream JavaDoc;
33 import java.io.BufferedWriter JavaDoc;
34 import java.io.FileWriter JavaDoc;
35 import java.io.PrintWriter JavaDoc;
36 import java.io.IOException JavaDoc;
37 import java.io.FileNotFoundException JavaDoc;
38 import java.lang.ClassNotFoundException JavaDoc;
39 import java.sql.Timestamp JavaDoc;
40 import java.util.Enumeration JavaDoc;
41 import java.util.Properties JavaDoc;
42 import java.util.Vector JavaDoc;
43 import java.util.StringTokenizer JavaDoc;
44
45 public class RunSuite
46 {
47
48     static final boolean verbose=true;
49
50     static String JavaDoc suites; // list of subsuites in this suite
51
static Vector JavaDoc suitesToRun; // Vector of suites to run
52

53     // Properties which may be specified
54
static String JavaDoc jvmName = "";
55     static String JavaDoc javaCmd = "java";
56     static String JavaDoc jvmflags = ""; // jvm flags as one string
57
static String JavaDoc javaVersion;
58     static String JavaDoc classpath;
59     static String JavaDoc classpathServer;
60     static String JavaDoc testJavaFlags = ""; // formerly systest_javaflags
61
static String JavaDoc testSpecialProps = "";
62     static String JavaDoc userdir;
63     static String JavaDoc framework;
64     static String JavaDoc runwithibmjvm;
65     static String JavaDoc excludeJCC;
66     static boolean useprocess = true;
67     static boolean skipsed = false;
68     static String JavaDoc systemdiff = "false";
69     static String JavaDoc topSuiteName = "";
70     static String JavaDoc outputdir; // location of output (default is userdir)
71
static String JavaDoc outcopy = "false"; // true if support files should go to outDir
72
static String JavaDoc canondir; // location of master dir (default is master)
73
static String JavaDoc bootcp; // path for j9 bootclasspath setting
74
static String JavaDoc serverJvm; // path for j9 bootclasspath setting
75
static String JavaDoc hostName; // needs to be settable for IPV6 testing; localhost otherwise.
76
static String JavaDoc testEncoding; // setting the encoding.
77
static String JavaDoc ijdefaultResourcePackage; // for ij tests only
78
static String JavaDoc debug; // for setting verbose mode to pass down to RunTest
79
static String JavaDoc timeout; // to allow killing a hanging test
80
static String JavaDoc shutdownurl; //used mainly by useprocess=false tests
81
static String JavaDoc reportstderr; // can set to disable (to turn off JIT errors, etc.)
82
static Properties JavaDoc suiteProperties;
83     static Properties JavaDoc specialProperties;
84
85     // Output variables
86
static PrintWriter JavaDoc pwOut = null; // for writing suite output
87
static File JavaDoc outDir; // test out dir
88
static File JavaDoc runDir; // where the suite/tests are run
89
static File JavaDoc outFile; // suite output file
90

91     public static void main(String JavaDoc[] args) throws Exception JavaDoc
92     {
93         if ((System.getProperty("java.vm.name") != null) && System.getProperty("java.vm.name").equals("J9"))
94         {
95                 javaCmd = "j9";
96                 String JavaDoc javaHome = System.getProperty("java.home");
97         }
98         String JavaDoc j9config = System.getProperty("com.ibm.oti.configuration");
99         if (j9config != null)
100             if (j9config.equals("foun10"))
101                 jvmName="j9_foundation";
102             else if (j9config.equals("max"))
103                 jvmName="j9_13";
104
105         String JavaDoc suiteName = args[0];
106         if ( suiteName == null )
107         {
108             System.out.println("No suite name argument.");
109             System.exit(1);
110         }
111         topSuiteName = suiteName;
112         System.out.println("Top suite: " + suiteName);
113
114         // suiteName may be one suite or a list of suites
115
suitesToRun = new Vector JavaDoc();
116
117         // Get properties set in the suite's properties file
118
suiteProperties = getSuiteProperties(suiteName, true);
119
120         // There may be system properties which will override
121
// the suiteProperties. This will make it easier when you
122
// do not want to edit the suite props for a special case
123
getSystemProperties();
124
125         // Get any special properties that are not the usual
126
// expected properties (we separate these from suiteProperties
127
// to avoid conflicts)
128
specialProperties =
129             SpecialFlags.getSpecialProperties(suiteProperties);
130
131         // Setup the initial output
132
setOutput(suiteName);
133
134         // Get the current time to write a timestamp
135
String JavaDoc startTime = CurrentTime.getTime();
136
137         pwOut.println("******* Start Suite: " + suiteName +
138             " " + startTime + " *******");
139
140         // Write sysinfo to the output file
141
if (useprocess) // doesn't work on Mac
142
{
143             SysInfoLog sysLog= new SysInfoLog();
144             sysLog.exec(jvmName, javaCmd, classpath, framework, pwOut, useprocess);
145         }
146             
147         getSuitesList(suiteName, true);
148         
149         // Get the current time to write a timestamp
150
String JavaDoc endTime = CurrentTime.getTime();
151         pwOut.println("******* End Suite: " + suiteName +
152             " " + endTime + " *******");
153         pwOut.close();
154         
155         String JavaDoc genrep = System.getProperty("genrep");
156         boolean isGenrep = true;
157         if (genrep!=null) isGenrep = "true".equalsIgnoreCase(genrep);
158         if (isGenrep)
159         {
160             String JavaDoc[] genargs = new String JavaDoc[6];
161             genargs[0] = args[0];
162             genargs[1] = jvmName;
163             genargs[2] = javaCmd;
164             genargs[3] = classpath;
165             genargs[4] = framework;
166             if (useprocess)
167                 genargs[5] = "true";
168             else
169                 genargs[5] = "false";
170             GenerateReport.main(genargs);
171         }
172     }
173
174     static void getSuitesList(String JavaDoc topparent, boolean isTop)
175         throws Exception JavaDoc, ClassNotFoundException JavaDoc, IOException JavaDoc
176     {
177         // Get the suite properties if it exists
178
Properties JavaDoc p;
179         if ( (suites == null) || (suites.length()==0) )
180         {
181             // There is a single suite, not a list, just add it
182
if (verbose) System.out.println("Suite to run: " + topparent+":"+topparent);
183             suitesToRun.addElement(topparent+":"+topparent);
184             // Use RunList class to issue the RunTest commands
185
if (verbose) System.out.println("Now do RunList");
186             //System.out.println("skipsed: " + skipsed);
187
RunList rl = new RunList(suitesToRun, runDir, outDir, pwOut,
188                 suiteProperties, specialProperties, topparent);
189             suitesToRun.removeAllElements();
190         }
191         else
192         {
193             isTop = false;
194             // Build the Vector from suites string
195
StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(suites);
196             String JavaDoc subparent = "";
197             while (st.hasMoreTokens())
198             {
199                 subparent = st.nextToken();
200                 p = getSuiteProperties(subparent, isTop);
201                 if ( (p.getProperty("suites") == null) || (subparent.equals(topparent)) )
202                 {
203                     suitesToRun.addElement(topparent+":"+subparent);
204                     //System.out.println("Add to suitesToRun: " + topparent+":"+subparent);
205
// Use RunList class to issue the RunTest commands
206
if (verbose) System.out.println("Now do RunList");
207                     //System.out.println("skipsed: " + skipsed);
208
RunList rl = new RunList(suitesToRun, runDir, outDir, pwOut,
209                         suiteProperties, specialProperties, topparent);
210                     suitesToRun.removeAllElements();
211                 }
212                 else // This suite also has nested suites
213
{
214                     String JavaDoc sublist = p.getProperty("suites");
215                     //System.out.println("list for this SubSuite= " + sublist);
216
BuildSuitesVector(subparent, sublist);
217                     // Use RunList class to issue the RunTest commands
218
if (verbose) System.out.println("Now do RunList");
219                     //System.out.println("skipsed: " + skipsed);
220
RunList rl = new RunList(suitesToRun, runDir, outDir, pwOut,
221                         suiteProperties, specialProperties, subparent);
222                     suitesToRun.removeAllElements();
223                 }
224             }
225         }
226     }
227     
228     static void BuildSuitesVector(String JavaDoc parent, String JavaDoc subsuites)
229         throws ClassNotFoundException JavaDoc, IOException JavaDoc
230     {
231         Properties JavaDoc p;
232         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(subsuites);
233         String JavaDoc child = "";
234         while (st.hasMoreTokens())
235         {
236             child = st.nextToken();
237             if (child.equals(parent))
238             {
239                 suitesToRun.addElement(parent+":"+child);
240                 //System.out.println("Add this: " + parent+":"+child);
241
}
242             else
243             {
244                 p = getSuiteProperties(child, false);
245                 if ( p.getProperty("suites") == null )
246                 {
247                     suitesToRun.addElement(parent+":"+child);
248                     //System.out.println("Add this: " + parent+":"+child);
249
}
250                 else
251                 {
252                     String JavaDoc moresuites = p.getProperty("suites");
253                     BuildSuitesVector(child, moresuites);
254                 }
255             }
256         }
257     }
258             
259     
260     static Properties JavaDoc getSuiteProperties(String JavaDoc suiteName, boolean isTop)
261         throws ClassNotFoundException JavaDoc, IOException JavaDoc
262     {
263         // Locate the suite's config file and get the properties
264
// The file should be in the harness dir or user.dir
265
String JavaDoc suiteProps = "suites" + '/' + suiteName + ".properties";
266         userdir = System.getProperty("user.dir");
267
268         InputStream JavaDoc is = RunTest.loadTestResource(suiteProps);
269         if (is == null)
270         {
271             // Look in userdir
272
suiteProps = userdir + '/' + suiteName + ".properties";
273             is = RunTest.loadTestResource(suiteProps);
274         }
275         Properties JavaDoc p = new Properties JavaDoc();
276         if (is == null)
277             return p;
278
279         p.load(is);
280         // The top level suite may have special properties
281
// which get propagated to any subsuites
282
if (isTop == true)
283         {
284             String JavaDoc tmpjvmName=jvmName;
285             jvmName = p.getProperty("jvm");
286             if ( (jvmName == null) || (jvmName.length()==0) )
287             {
288                 javaVersion = System.getProperty("java.version");
289             }
290             else
291                 javaVersion = jvmName;
292
293             // for j9, we cannot just use java.version.
294
String JavaDoc javavmVersion;
295             if (System.getProperty("java.vm.name").equals("J9"))
296                 javavmVersion = (System.getProperty("java.vm.version"));
297             else
298                 javavmVersion = javaVersion;
299                 
300             JavaVersionHolder jvh = new JavaVersionHolder(javavmVersion);
301             String JavaDoc majorVersion = jvh.getMajorVersion();
302             String JavaDoc minorVersion = jvh.getMinorVersion();
303             int iminor = jvh.getMinorNumber();
304             int imajor = jvh.getMajorNumber();
305             
306             if ( (iminor < 2) && (imajor < 2) )
307                 jvmName = "currentjvm";
308             else
309                 jvmName = "jdk" + majorVersion + minorVersion;
310         if ( tmpjvmName != null)
311             jvmName= tmpjvmName;
312             javaCmd = p.getProperty("javaCmd");
313             jvmflags = p.getProperty("jvmflags");
314             testJavaFlags = p.getProperty("testJavaFlags");
315             testSpecialProps = p.getProperty("testSpecialProps");
316             classpath = p.getProperty("classpath");
317             classpathServer = p.getProperty("classpathServer");
318             framework = p.getProperty("framework");
319             String JavaDoc usepr = p.getProperty("useprocess");
320             if (usepr != null)
321             {
322                 usepr = usepr.toLowerCase();
323                 if (usepr.equals("false"))
324                     useprocess = false;
325                 else
326                     useprocess = true;
327             }
328             else
329                 useprocess = true;
330
331             String JavaDoc nosed = p.getProperty("skipsed");
332             if (nosed != null)
333             {
334                 nosed = nosed.toLowerCase();
335                 if (nosed.equals("true"))
336                     skipsed = true;
337                 else
338                     skipsed = false;
339             }
340             else
341                 skipsed = false;
342                 
343             outputdir = p.getProperty("outputdir");
344             canondir = p.getProperty("canondir");
345             bootcp = p.getProperty("bootcp");
346             hostName = p.getProperty("hostName");
347             serverJvm = p.getProperty("serverJvm");
348             systemdiff = p.getProperty("systemdiff");
349             ijdefaultResourcePackage = p.getProperty("ij.defaultResourcePackage");
350             outcopy = p.getProperty("outcopy");
351             debug = p.getProperty("verbose");
352             reportstderr = p.getProperty("reportstderr");
353             timeout = p.getProperty("timeout");
354             shutdownurl = p.getProperty("shutdownurl");
355             testEncoding = p.getProperty("derbyTesting.encoding");
356         }
357         suites = p.getProperty("suites");
358         return p;
359     }
360
361     private static void getSystemProperties()
362     {
363         // Get any properties specified on the command line
364
// which may not have been specified in the suite prop file
365
Properties JavaDoc sp = System.getProperties();
366         String JavaDoc searchCP = sp.getProperty("ij.searchClassPath");
367         if (searchCP != null)
368             suiteProperties.put("ij.searchClassPath", searchCP);
369         String JavaDoc frm = sp.getProperty("framework");
370         if ( (frm != null) && (!frm.equals("embedded")) )
371         {
372             framework = frm;
373             suiteProperties.put("framework", framework);
374         }
375         String JavaDoc j = sp.getProperty("jvm");
376         if (j != null)
377             suiteProperties.put("jversion", j);
378         
379         String JavaDoc jcmd = sp.getProperty("javaCmd");
380         if ((System.getProperty("java.vm.name") != null) && System.getProperty("java.vm.name").equals("J9"))
381             jcmd = "j9";
382         if (jcmd != null)
383         {
384             javaCmd = jcmd;
385             suiteProperties.put("javaCmd", javaCmd);
386         }
387         // get System properties for jvmflags, and put them to the end, thus
388
// when the time comes to have this converted into actual jvm flags
389
// the ones given at the command line will overwrite whatever's in the suite
390
String JavaDoc jflags = sp.getProperty("jvmflags");
391         if (jvmflags != null)
392         {
393             if (jflags != null)
394                     suiteProperties.put("jvmflags", (jvmflags + "^" + jflags));
395             else
396                     suiteProperties.put("jvmflags", jvmflags);
397         }
398         else
399         {
400             if (jflags != null)
401                     suiteProperties.put("jvmflags", jflags);
402         }
403         String JavaDoc testflags = sp.getProperty("testJavaFlags");
404         if (testflags != null)
405         {
406             if (testJavaFlags == null)
407                 testJavaFlags = testflags;
408             else // add to testJavaFlags
409
testJavaFlags = testJavaFlags + "^" + testflags;
410             suiteProperties.put("testJavaFlags", testJavaFlags);
411         }
412         String JavaDoc testprops = sp.getProperty("testSpecialProps");
413         if (testprops != null)
414         {
415             if (testSpecialProps == null)
416                 testSpecialProps = testprops;
417             else // add to testSpecialProps
418
testSpecialProps = testSpecialProps + "^" + testprops;
419             suiteProperties.put("testSpecialProps", testSpecialProps);
420         }
421         String JavaDoc clpth = sp.getProperty("classpath");
422         if (clpth != null)
423         {
424             classpath = clpth;
425             suiteProperties.put("classpath", classpath);
426         }
427         String JavaDoc clsrv = sp.getProperty("classpathServer");
428         if ( (clsrv != null) && (!clsrv.startsWith("${")) )
429         {
430             classpathServer = clsrv;
431             suiteProperties.put("classpathServer", clsrv);
432         }
433         String JavaDoc usesys = sp.getProperty("usesystem");
434         if (usesys != null)
435             suiteProperties.put("usesystem", usesys);
436         String JavaDoc jarf = sp.getProperty("jarfile");
437         if (jarf != null)
438             suiteProperties.put("jarfile", jarf);
439         String JavaDoc upgtest = sp.getProperty("upgradetest");
440         if (upgtest != null)
441             suiteProperties.put("upgradetest", upgtest);
442         String JavaDoc rep = sp.getProperty("replication");
443         if (rep != null)
444             suiteProperties.put("replication", rep);
445         String JavaDoc encrypt = sp.getProperty("encryption");
446         if (encrypt != null)
447             suiteProperties.put("encryption", encrypt);
448         String JavaDoc encryptAlgorithm = sp.getProperty("testEncryptionAlgorithm");
449         if (encryptAlgorithm != null)
450             suiteProperties.put("testEncryptionAlgorithm", encryptAlgorithm);
451         String JavaDoc jdk12test = sp.getProperty("jdk12test");
452         if (jdk12test != null)
453             suiteProperties.put("jdk12test", jdk12test);
454         String JavaDoc jdk12ex = sp.getProperty("jdk12exttest");
455         if (jdk12ex != null)
456             suiteProperties.put("jdk12exttest", jdk12ex);
457         String JavaDoc runwithibmjvm = sp.getProperty("runwithibmjvm");
458         if (runwithibmjvm != null)
459             suiteProperties.put("runwithibmjvm", runwithibmjvm);
460         String JavaDoc excludeJCC = sp.getProperty("excludeJCC");
461         if (excludeJCC != null)
462             suiteProperties.put("excludeJCC", excludeJCC);
463         String JavaDoc keep = sp.getProperty("keepfiles");
464         if (keep != null)
465             suiteProperties.put("keepfiles", keep);
466         String JavaDoc outd = sp.getProperty("outputdir");
467         if (outd != null)
468         {
469             outputdir = outd;
470             suiteProperties.put("outputdir", outputdir);
471         }
472         String JavaDoc canond = sp.getProperty("canondir");
473         if (canond != null)
474         {
475             canondir = canond;
476             suiteProperties.put("canondir", canondir);
477         }
478         String JavaDoc j9bootcp = sp.getProperty("bootcp");
479         if (j9bootcp != null)
480         {
481             bootcp = j9bootcp;
482             suiteProperties.put("bootcp", bootcp);
483         }
484         String JavaDoc hostname = sp.getProperty("hostName");
485         if (hostname != null)
486             suiteProperties.put("hostName", hostname);
487         String JavaDoc serverJvm = sp.getProperty("serverJvm");
488         if (serverJvm != null)
489             suiteProperties.put("serverJvm", serverJvm);
490         String JavaDoc cmlTestEncoding = sp.getProperty("derbyTesting.encoding");
491         if (cmlTestEncoding != null)
492             suiteProperties.put("derbyTesting.encoding", cmlTestEncoding);
493                 String JavaDoc upgradejarpath = sp.getProperty("derbyTesting.jar.path");
494                 if (upgradejarpath != null)
495                     suiteProperties.put("derbyTesting.jar.path", upgradejarpath);
496         String JavaDoc testout = sp.getProperty("testoutname");
497         if (testout != null)
498             suiteProperties.put("testoutname", testout); // toursDemo
499
String JavaDoc mtdir = sp.getProperty("mtestdir"); // used by multi tests
500
if (mtdir != null)
501             suiteProperties.put("mtestdir", mtdir);
502         String JavaDoc usepr = sp.getProperty("useprocess");
503         if (usepr != null)
504         {
505             // Some platforms cannot handle process exec
506
usepr = usepr.toLowerCase();
507             if (usepr.equals("false"))
508             {
509                 useprocess = false;
510                 suiteProperties.put("useprocess", usepr);
511             }
512         }
513         
514         String JavaDoc nosed = sp.getProperty("skipsed");
515         if (nosed != null)
516         {
517             // in some cases (like locales, we may want to skip the Sed)
518
nosed = nosed.toLowerCase();
519             if (nosed.equals("true"))
520             {
521                 skipsed = true;
522                 suiteProperties.put("skipsed", nosed);
523             }
524         }
525         
526         String JavaDoc sysdiff = sp.getProperty("systemdiff");
527         if (sysdiff != null)
528         {
529             // Use system diff if set to true
530
sysdiff = sysdiff.toLowerCase();
531             if (sysdiff.equals("true"))
532                 suiteProperties.put("systemdiff", "true");
533         }
534         String JavaDoc defrespckg = sp.getProperty("ij.defaultResourcePackage");
535         if (defrespckg != null)
536             suiteProperties.put("ij.defaultResourcePackage", defrespckg);
537         String JavaDoc outcpy = sp.getProperty("outcopy");
538         if (outcpy != null)
539             suiteProperties.put("outcopy", outcpy);
540         String JavaDoc topsuite = sp.getProperty("suitename");
541         if (topsuite != null)
542             suiteProperties.put("suitename", topsuite);
543         else
544             suiteProperties.put("suitename", topSuiteName);
545         String JavaDoc dbug = sp.getProperty("verbose");
546         if (dbug != null)
547             suiteProperties.put("verbose", dbug);
548         String JavaDoc reporterr = sp.getProperty("reportstderr");
549         if (reporterr != null)
550             suiteProperties.put("reportstderr", reporterr);
551         String JavaDoc tout = sp.getProperty("timeout");
552         if (tout != null)
553             suiteProperties.put("timeout", tout);
554     }
555
556     private static void setOutput(String JavaDoc suiteName)
557         throws ClassNotFoundException JavaDoc, FileNotFoundException JavaDoc, IOException JavaDoc
558     {
559         boolean status = false;
560         // Use the defined output directory or user.dir by default
561
File JavaDoc tmpoutDir;
562         if ( (outputdir == null) || (outputdir.length()==0) )
563         {
564             tmpoutDir =
565                 new File JavaDoc((new File JavaDoc(userdir)).getCanonicalPath());
566         }
567         else
568         {
569             tmpoutDir =
570                 new File JavaDoc((new File JavaDoc(outputdir)).getCanonicalPath());
571         }
572         outDir = tmpoutDir;
573         outDir.mkdir();
574         
575         // runDir is where the suites/tests are run and where
576
// any support files or scripts will be expected to live
577
runDir =
578             new File JavaDoc((new File JavaDoc(userdir)).getCanonicalPath());
579             
580         // Set the suite property outputdir
581
suiteProperties.put("outputdir", outDir.getCanonicalPath());
582
583         // Define the final suite summary file file
584
outFile = new File JavaDoc(outDir, suiteName + ".sum");
585         if (outFile.exists())
586             status = outFile.delete();
587  
588         // Define the suite.pass file
589
File JavaDoc passFile = new File JavaDoc(outDir, suiteName + ".pass");
590         if (passFile.exists())
591             status = passFile.delete();
592
593         // Define the suite.fail file
594
File JavaDoc failFile = new File JavaDoc(outDir, suiteName + ".fail");
595         if (failFile.exists())
596             status = failFile.delete();
597
598         // Create a PrintWriter for writing env and test info to the diff file
599
pwOut = new PrintWriter JavaDoc
600             (new BufferedWriter JavaDoc(new FileWriter JavaDoc(outFile.getPath()), 4096), true);
601     }
602 }
603
Popular Tags