KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.harness.RunList
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.FileWriter JavaDoc;
31 import java.io.FileInputStream JavaDoc;
32 import java.io.FileOutputStream JavaDoc;
33 import java.io.BufferedOutputStream JavaDoc;
34 import java.io.BufferedWriter JavaDoc;
35 import java.io.FileWriter JavaDoc;
36 import java.io.PrintWriter JavaDoc;
37 import java.io.PrintStream JavaDoc;
38 import java.io.IOException JavaDoc;
39 import java.io.FileNotFoundException JavaDoc;
40 import java.lang.ClassNotFoundException JavaDoc;
41 import java.lang.reflect.Method JavaDoc;
42 import java.util.Enumeration JavaDoc;
43 import java.util.Properties JavaDoc;
44 import java.util.Vector JavaDoc;
45 import java.util.StringTokenizer JavaDoc;
46 import java.sql.DriverManager JavaDoc;
47 import java.sql.SQLException JavaDoc;
48
49 import org.apache.derbyTesting.functionTests.util.TestUtil;
50
51
52 public class RunList
53 {
54
55     static String JavaDoc jvmName = "currentjvm";
56     static String JavaDoc javaCmd = "java";
57     static String JavaDoc javaArgs;
58     static jvm jvm;
59     static String JavaDoc javaVersion; // System.getProperty("java.version")
60
static String JavaDoc majorVersion;
61     static String JavaDoc minorVersion;
62     static String JavaDoc jversion; // to pass jvm to RunTest as -Djvm=1.2 etc.
63
static int iminor;
64     static int imajor;
65     static boolean skip = false;
66     static boolean driverNotFound = false;
67     static boolean needSync = false;
68     static boolean needJdk12 = false;
69     static boolean needJdk12ext = false;
70     static boolean excludedFromJCC = false;
71     static String JavaDoc clientExclusionMessage;
72     static Boolean JavaDoc needIBMjvm = null;
73     static boolean needEncryption = false;
74     static String JavaDoc jvmflags;
75     static String JavaDoc testJavaFlags;
76     static String JavaDoc classpath;
77     static String JavaDoc classpathServer;
78     static String JavaDoc framework;
79     static String JavaDoc usesystem;
80     static String JavaDoc upgradetest;
81     static String JavaDoc jarfile;
82     static String JavaDoc useoutput;
83     static String JavaDoc keepfiles = "false";
84     static String JavaDoc encryption;
85     static String JavaDoc testEncryptionProvider;
86     static String JavaDoc testEncryptionAlgorithm;
87     static String JavaDoc jdk12test;
88     static String JavaDoc jdk12exttest;
89     static String JavaDoc runwithibmjvm = null;
90     static String JavaDoc runwithj9;
91     static String JavaDoc runwithjvm;
92     static String JavaDoc excludeJCC;
93     static boolean useprocess = true;
94     static String JavaDoc skipsed = "false";
95     static boolean fw_set = false;
96     static String JavaDoc systemdiff = "false";
97     static String JavaDoc suiteName = "";
98     static String JavaDoc fullsuiteName = "";
99     static String JavaDoc topSuiteName = ""; // The very top suite creating RunLists
100
static String JavaDoc topParentSuite = ""; // The "subparent" of the very top suite
101
static String JavaDoc topSpecialProps = ""; // special properties at the top suite
102
static String JavaDoc otherSpecialProps = ""; // special properties (individual suite)
103
static String JavaDoc ijdefaultResourcePackage; // for ij tests, the package resource
104
static String JavaDoc outcopy; // cases where copyfiles should go to outDir
105
static String JavaDoc userdir; // current user directory
106
static String JavaDoc mtestdir; // required by multi tests
107
static boolean verbose = false; // for debug output
108
static String JavaDoc reportstderr;
109     static String JavaDoc timeout;
110     static String JavaDoc shutdownurl;
111     static PrintWriter JavaDoc pwOut; // for writing suite output
112
static String JavaDoc outputdir; // location of output (default is userdir)
113
static String JavaDoc topsuitedir; // for nested suites, need top output location
114
static String JavaDoc topreportdir; // where to place the .pass and .fail files
115
static String JavaDoc canondir; // location of masters (default is master)
116
static String JavaDoc bootcp; // for j9 bootclasspath
117
static String JavaDoc serverJvm; // for starting another jvm for networkserver, j9 default.
118
static String JavaDoc serverJvmName; // for starting another jvm for networkserver, j9_22 default.
119
static File JavaDoc outDir; // test out dir
120
static File JavaDoc outFile; // suite output file
121
static File JavaDoc runDir; // location of suite.runall (list of tests)
122
static File JavaDoc runFile; // suite.runall file
123
static Properties JavaDoc suiteProperties;
124     static Properties JavaDoc specialProperties; // for testSpecialProps
125
static BufferedReader JavaDoc runlistFile;
126     static String JavaDoc hostName;
127     static String JavaDoc testEncoding; // Encoding used for child jvm and to read the test output
128
static String JavaDoc upgradejarpath; // Encoding used for child jvm and to read the test output
129
static String JavaDoc derbyTestingXaSingle;// Run junit test cases with under
130
// single branck xa transaction
131

132     static String JavaDoc [] clientExclusionKeywords = new String JavaDoc [] {
133         "at-or-before:", "at-or-after:", "when-at-or-before:jdk",
134         "when-at-or-after:jdk", "when:jdk"
135     };
136
137     public RunList()
138     {
139     }
140
141     /**
142     * RunList
143     * suitesToRun: a Vector of suites from RunSuite
144     * outDir: The output directory for the suite(s)
145     * pwOut: The output for writing suite and test results
146     * suiteProperties: From RunSuite for the top suite
147     * (individual suites in the vector may have their own
148     * properties which must also be located and applied)
149     */

150
151     public RunList(Vector JavaDoc suitesToRun,
152         File JavaDoc runDir, File JavaDoc outDir, PrintWriter JavaDoc pwOut,
153         Properties JavaDoc suiteProperties,
154         Properties JavaDoc specialProperties,
155         String JavaDoc topParentSuite)
156         throws ClassNotFoundException JavaDoc, IOException JavaDoc, Exception JavaDoc
157     {
158         this.runDir = runDir;
159         this.outDir = outDir;
160         this.pwOut = pwOut;
161         this.suiteProperties = suiteProperties; // usual suite props
162
this.specialProperties = specialProperties; // for special test Flags
163
this.topSuiteName = suiteProperties.getProperty("suitename");
164         //System.out.println("----------------------------------------");
165
//System.out.println("RunList topSuiteName= " + topSuiteName);
166
this.topParentSuite = topParentSuite;
167         //System.out.println("topParentSuite= " + topParentSuite);
168

169         // Run the suites
170
runSuites(suitesToRun);
171     }
172
173     private static void runSuites(Vector JavaDoc suitesToRun)
174         throws ClassNotFoundException JavaDoc,
175         FileNotFoundException JavaDoc, IOException JavaDoc, Exception JavaDoc
176     {
177         // For each suite, locate its properties and runall files
178
// which should be in the "suites" dir or user.dir
179
String JavaDoc suiteName = "";
180         userdir = System.getProperty("user.dir");
181         //System.out.println("Number of suites in list = " + suitesToRun.size());
182
Properties JavaDoc p = null;
183
184         // First get the top level suiteProperties since some
185
// special properties might need to be used by all sub-suites
186
setTopSuiteProperties();
187         // Now set the properties for the topParentSuite (a sub-parent of the top)
188
Properties JavaDoc topParentSuiteProps =
189             locateSuiteProperties(topParentSuite, suiteProperties, true, true);
190         setSuiteProperties(topParentSuiteProps, topParentSuite, suiteProperties, true, true);
191
192         // Now handle the list of child suites under this parent
193
for (int i = 0; i < suitesToRun.size(); i++)
194         {
195             /* Note: nesting of suites can be complex, especially if the
196              subsuites of the top suite also contain subsuites; we must take
197              care in setting of special properties like framework which may
198              need to propagate to its subsuites, but not back to the very top
199             */

200             Properties JavaDoc subProps = null;
201             fullsuiteName = (String JavaDoc)suitesToRun.elementAt(i);
202             //System.out.println("fullsuiteName: " + fullsuiteName);
203
String JavaDoc subSuite = fullsuiteName.substring(0,fullsuiteName.lastIndexOf(":"));
204             //System.out.println("subSuite: " + subSuite);
205
if ( !subSuite.equals(topParentSuite) )
206             {
207                 subProps = locateSuiteProperties(subSuite, topParentSuiteProps, true, false);
208             }
209             else
210             {
211                 // reset in case a previous subsuite had set framework, etc
212
subProps = topParentSuiteProps;
213             }
214             setSuiteProperties(subProps, subSuite, topParentSuiteProps, true, false);
215
216             // Now handle the child suite of this subSuite
217
suiteName = fullsuiteName.substring(fullsuiteName.lastIndexOf(":")+1);
218             //System.out.println("child suiteName: " + suiteName);
219

220             p = locateSuiteProperties(suiteName, subProps, false, false);
221             setSuiteProperties(p, suiteName, subProps, false, false);
222
223             // Now locate the suite runall file containing the tests
224
String JavaDoc runfile = "suites" + '/' + suiteName + ".runall";
225
226             InputStream JavaDoc is = org.apache.derbyTesting.functionTests.harness.RunTest.loadTestResource(runfile);
227             if (is == null)
228             {
229                 // Look in userdir
230
is = org.apache.derbyTesting.functionTests.harness.RunTest.loadTestResource(userdir + '/' + suiteName + ".runall");
231             }
232             if (is == null)
233             {
234                 System.out.println("Suite runall file not found for " + suiteName);
235                 continue;
236             }
237
238             // Create a BufferedReader to read the list of tests to run
239
runlistFile = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(is, "UTF-8"));
240             if (runlistFile == null)
241             {
242                 System.out.println("The suite runall file could not be read.");
243             }
244             else
245             {
246                 String JavaDoc startTime = CurrentTime.getTime();
247                 pwOut.println("**** Start SubSuite: " + fullsuiteName +
248                     " jdk" + javaVersion +
249                     " " + startTime + " ****");
250                 if ( (framework != null) && (framework.length()>0) )
251                 {
252                     pwOut.println("Framework: " + framework);
253                 }
254                 else
255                     pwOut.println("Framework: No special framework.");
256
257                 // Create the file to list the suites that get skipped
258
File JavaDoc f = new File JavaDoc(outDir, topSuiteName);
259                 File JavaDoc skipFile = new File JavaDoc(f, topSuiteName+".skip");
260
261             //we catch an IOException here to work around a jvm bug on the Psion.
262
PrintStream JavaDoc ps = null;
263             try { ps = new PrintStream JavaDoc
264                     ( new FileOutputStream JavaDoc(skipFile.getCanonicalPath(),true) ); }
265             catch (IOException JavaDoc e) {
266             FileWriter JavaDoc fw = new FileWriter JavaDoc(skipFile);
267             fw.close();
268             ps = new PrintStream JavaDoc
269                 ( new FileOutputStream JavaDoc(skipFile.getCanonicalPath(),true) );
270             }
271
272                 // Due to autoloading of JDBC drivers introduced in JDBC4
273
// (see DERBY-930) the embedded driver and Derby engine
274
// might already have been loaded. To ensure that the
275
// embedded driver and engine used by the tests run in
276
// this suite are configured to use the correct
277
// property values we try to unload the embedded driver
278
if (useprocess == false) {
279                     unloadEmbeddedDriver();
280                 }
281
282                 System.out.println("Now run the suite's tests");
283                 //System.out.println("shutdownurl: " + shutdownurl);
284

285                 if (skip) // Skip a suite under certain environments
286
{
287                     addToSkipFile(topSuiteName+":"+fullsuiteName, ps);
288                     if(driverNotFound)
289                         pwOut.println("Cannot run the suite, framework driver not found");
290                     else if(needSync)
291                         pwOut.println("Cannot run the suite, sync product not found");
292                     else if(needJdk12ext)
293                         pwOut.println("Cannot run the suite, requires jdk12 or higher with extensions");
294                     else if(needJdk12)
295                         pwOut.println("Cannot run the suite, requires jdk12 or higher, have jdk" + javaVersion);
296                     else if(excludedFromJCC)
297                         pwOut.println(clientExclusionMessage);
298                     else if((needIBMjvm == null || needIBMjvm.booleanValue() == false))
299                         pwOut.println("Cannot run the suite, requires IBM jvm, jvm vendor is " + System.getProperty("java.vendor"));
300                     else
301                         pwOut.println("Cannot run the suite, have jdk" + javaVersion);
302                  }
303                 else
304                 {
305                     System.out.println("Run the tests...");
306                     // Unjar any jarfile define for an upgrade suite
307
//System.out.println("jarfile: " + jarfile);
308
if (jarfile != null)
309                     {
310                         //System.out.println("unjar jar file...");
311
UnJar uj = new UnJar();
312                         uj.unjar(jarfile, outDir.getCanonicalPath(), true);
313                         if ( (upgradetest.equals("true")) && (suiteName.startsWith("convert")) )
314                         {
315                             // need to rename the directory
316
// such as kimono -- rename to convertKimono
317
String JavaDoc tmpname = jarfile.substring(0, jarfile.indexOf("JAR"));
318                             File JavaDoc tmp = new File JavaDoc(outDir, tmpname);
319                 File JavaDoc convert = new File JavaDoc(outDir, usesystem);
320                             boolean renamed = tmp.renameTo(convert);
321                             //System.out.println("renamed: " + renamed);
322
}
323                     }
324
325                     // Run the tests for this suite
326
runTests(p, fullsuiteName);
327                 }
328
329                 String JavaDoc endTime = CurrentTime.getTime();
330                 pwOut.println("**** End SubSuite: " + fullsuiteName +
331                     " jdk" + javaVersion +
332                     " " + endTime + " ****");
333                 //System.out.println("--------------------------------------");
334
ps.close();
335             }
336         }
337     }
338
339
340     private static void runTests(Properties JavaDoc suiteProps, String JavaDoc suite)
341         throws IOException JavaDoc, Exception JavaDoc
342     {
343         // save a copy of the system properties at this point; when runing with
344
// java threads we need to reset the system properties to this list;
345
// otherwise we start to accumulate extraneous properties from
346
// individual tests (does not happen with exec (useprocess==true)
347
// because each test case has its own fresh VM
348
ManageSysProps.saveSysProps();
349
350         // Build command string for RunTest()
351
StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
352         jvm = jvm.getJvm(jvmName);
353         Vector JavaDoc jvmProps = new Vector JavaDoc();
354         if ((javaCmd.length()>0) )
355         {
356             jvm.setJavaCmd(javaCmd);
357             jvmProps.addElement("javaCmd=" + javaCmd);
358         }
359         if ( (testJavaFlags != null) && (testJavaFlags.length()>0) )
360             jvmProps.addElement("testJavaFlags=" + testJavaFlags);
361         if (classpath != null)
362             jvmProps.addElement("classpath=" + classpath);
363         if (classpathServer != null)
364             jvmProps.addElement("classpathServer=" + classpathServer);
365         if (jversion != null)
366             jvmProps.addElement("jvm=" + jversion);
367         if (framework != null)
368             jvmProps.addElement("framework=" + framework);
369         if (usesystem != null)
370             jvmProps.addElement("usesystem=" + usesystem);
371         if (shutdownurl != null)
372             jvmProps.addElement("shutdownurl=" + shutdownurl);
373         if (upgradetest != null)
374             jvmProps.addElement("upgradetest=" + upgradetest);
375         if (outcopy != null)
376             jvmProps.addElement("outcopy=" + outcopy);
377         if (useoutput != null)
378             jvmProps.addElement("useoutput=" + useoutput);
379         if (verbose == true)
380             jvmProps.addElement("verbose=true");
381         if ( (reportstderr != null) && (reportstderr.length()>0) )
382             jvmProps.addElement("reportstderr=" + reportstderr);
383
384         if ( (jvmflags != null) && (jvmflags.length()>0) )
385         {
386             // We want to pass this down to RunTest so it will
387
// run an individual test with jvmflags like -nojit
388
jvmProps.addElement("jvmflags=" + jvmflags);
389         }
390
391         if ( (timeout != null) && (timeout.length()>0) )
392         {
393             if (useprocess)
394             {
395                 jvmProps.addElement("timeout=" + timeout);
396             }
397             else
398             {
399                 org.apache.derbyTesting.functionTests.harness.RunTest.timeoutStr = timeout;
400             }
401         }
402         if (Boolean.getBoolean("listOnly"))
403             jvmProps.addElement("listOnly=true");
404
405         if (encryption != null)
406             jvmProps.addElement("encryption=" + encryption);
407         if (testEncryptionProvider != null)
408             jvmProps.addElement("testEncryptionProvider=" + testEncryptionProvider);
409         if (testEncryptionAlgorithm != null)
410             jvmProps.addElement("testEncryptionAlgorithm=" + testEncryptionAlgorithm);
411         if (jdk12test != null)
412             jvmProps.addElement("jdk12test=" + jdk12test);
413         if (jdk12exttest != null)
414             jvmProps.addElement("jdk12exttest=" + jdk12exttest);
415         if (keepfiles != null)
416             jvmProps.addElement("keepfiles=" + keepfiles);
417         if ( (outputdir != null) && (outputdir.length()>0) )
418         {
419             jvmProps.addElement("outputdir=" + outputdir);
420         }
421         if ( (topsuitedir != null) && (topsuitedir.length()>0) )
422             jvmProps.addElement("topsuitedir=" + topsuitedir);
423         else
424             jvmProps.addElement("topsuitedir=" + outputdir);
425         if (topreportdir != null)
426             jvmProps.addElement("topreportdir=" + topreportdir);
427         else
428             jvmProps.addElement("topreprtdir=" + topsuitedir);
429         if ( (runDir != null) && (runDir.exists()) )
430             jvmProps.addElement("rundir=" + runDir.getCanonicalPath());
431         if ( (bootcp != null) && (bootcp.length()>0) )
432             jvmProps.addElement("bootcp=" + bootcp);
433         if ( (serverJvm != null) && (serverJvm.length()>0) )
434             jvmProps.addElement("serverJvm=" + serverJvm);
435         if ( (serverJvmName != null) && (serverJvmName.length()>0) )
436             jvmProps.addElement("serverJvmName=" + serverJvmName);
437         if (testEncoding != null)
438             jvmProps.addElement("derbyTesting.encoding=" + testEncoding);
439         if (upgradejarpath != null)
440             jvmProps.addElement("derbyTesting.jar.path=" + upgradejarpath);
441         if ( (hostName != null) && (hostName.length()>0) )
442             jvmProps.addElement("hostName=" + hostName);
443         if ( useprocess == false )
444             jvmProps.addElement("useprocess=false");
445         if ( skipsed.equals("true") )
446             jvmProps.addElement("skipsed=true");
447         if ( systemdiff != null )
448             jvmProps.addElement("systemdiff=" + systemdiff);
449         if ( ijdefaultResourcePackage != null )
450             jvmProps.addElement("ij.defaultResourcePackage=" + ijdefaultResourcePackage);
451         if ( mtestdir != null )
452             jvmProps.addElement("mtestdir=" + mtestdir);
453         if (topSpecialProps.length()>0)
454         {
455             jvmProps.addElement("testSpecialProps=" + topSpecialProps +
456             ((otherSpecialProps.length()>0)?
457              ("^" + otherSpecialProps)
458              :"")
459             );
460         }
461         else if (otherSpecialProps.length()>0)
462             jvmProps.addElement("testSpecialProps=" + otherSpecialProps);
463             
464         if (derbyTestingXaSingle != null)
465             jvmProps.addElement ("derbyTesting.xa.single=" + derbyTestingXaSingle);
466         
467         // Ensure any properties that define the default connection
468
// for the tests to use a DataSource are passed from the
469
// command line onto the RunTest invoked. These properties are
470
//
471
// ij.dataSource=<classname of datasource>
472
//
473
// any number of
474
// ij.dataSource.<datasource property>=<value>
475

476         Properties JavaDoc sysProps = System.getProperties();
477         for (Enumeration JavaDoc e = sysProps.keys(); e.hasMoreElements(); )
478         {
479             String JavaDoc key = (String JavaDoc) e.nextElement();
480             if (key.startsWith("ij.dataSource"))
481                 jvmProps.addElement(key + "=" + sysProps.getProperty(key));
482         }
483
484         jvmProps.addElement("suitename=" + suite);
485
486         if ( (topSuiteName != null) && (topSuiteName.length()>0) )
487             jvmProps.addElement("topsuitename=" + topSuiteName);
488
489         if (classpath != null)
490             jvm.setClasspath(classpath);
491
492         jvm.setD(jvmProps);
493         Vector JavaDoc v = jvm.getCommandLine();
494         v.addElement("org.apache.derbyTesting.functionTests.harness.RunTest");
495
496         String JavaDoc str = "";
497         String JavaDoc lastTest = null;
498         String JavaDoc skipTo = System.getProperties().getProperty("skipToFile");
499         String JavaDoc stopAfter = System.getProperties().getProperty("stopAfterFile");
500         // Read the individual tests
501
// Example: "lang/avg.sql" or "conn/resultset.java"
502
while ( (str = runlistFile.readLine()) != null )
503         {
504             // skip tests if specified
505
if (skipTo != null && !str.equals(skipTo))
506                 continue;
507             else
508                 skipTo = null;
509             if (stopAfter != null && lastTest != null && lastTest.equals(stopAfter)) break;
510             // Create the command for RunTest
511
// Create a string array from the vector
512
String JavaDoc testCmd[] = new String JavaDoc[v.size() + 1];
513             StringBuffer JavaDoc verboseSb = new StringBuffer JavaDoc();
514             int i = 0;
515             for (i = 0; i < v.size(); i++)
516             {
517                 testCmd[i] = (String JavaDoc)v.elementAt(i);
518                 verboseSb.append(testCmd[i] + " ");
519             }
520             testCmd[i++] = str;
521             verboseSb.append(str + " ");
522             //if (verbose)
523
//System.out.println("Execute command: " + verboseSb.toString());
524

525             String JavaDoc uc = System.getProperties().getProperty("useCommonDB");
526             if (uc == null) uc = "false";
527             if ( useprocess == true && uc.equals("true")==false)
528             {
529                 System.out.println("Execute command: " + verboseSb.toString());
530
531                 // Now execute the command to run the test
532
Process JavaDoc pr = null;
533                 try
534                 {
535                     pr = Runtime.getRuntime().exec(testCmd);
536
537                     // We need the process inputstream to capture into the output file
538
BackgroundStreamDrainer stdout =
539                         new BackgroundStreamDrainer(pr.getInputStream(), null);
540                     BackgroundStreamDrainer stderr =
541                         new BackgroundStreamDrainer(pr.getErrorStream(), null);
542
543                     pr.waitFor();
544
545                     String JavaDoc result = HandleResult.handleResult(pr.exitValue(),
546                         stdout.getData(), stderr.getData(), pwOut, testEncoding);
547                     pr.destroy();
548                 }
549                 catch(Throwable JavaDoc t)
550                 {
551                     System.out.println("Process exception: " + t.getMessage());
552                     if (pr != null)
553                     {
554                         pr.destroy();
555                         pr = null;
556                     }
557                 }
558             }
559             else
560             {
561                 // if useprocess=false, we cannot pass properties on a commandline,
562
// instead we pass absolutely necessary properties directly to RunTest.
563
// At the very minimum, we need to know:
564
// 0. the test
565
// 1. resourcepackage - the base for loading functionTests Resources
566
// 2. whether or not to use a specific system & the usesystem flag (like for nist)
567
// 3. useprocess flag
568
// 4. shutdown url
569
// 5. name of the suite
570
// 6. the framework, or subsuites might default back to embedded
571
// if a test needs a jvm process started with more/other properties than these,
572
// it will not run well with useprocess=false or not in the same way as with
573
// useprocess=true
574
String JavaDoc[] args = new String JavaDoc[7];
575                 args[0] = str; // the test name
576
if ( ijdefaultResourcePackage != null )
577                     args[1] = ijdefaultResourcePackage;
578                 else
579                     args[1] = "/org/apache/derbyTesting/functionTests/";
580                 if ( usesystem != null )
581                     args[2] = usesystem;
582                 else
583                     args[2] = "";
584                 args[3] = "noprocess";
585                 if ( shutdownurl != null)
586                     args[4] = shutdownurl;
587                 else
588                     args[4] = "";
589                 args[5] = suite;
590                 args[6] = framework;
591                 org.apache.derbyTesting.functionTests.harness.RunTest.main(args);
592                 // Write any diff to the suite's output
593
String JavaDoc tmp = str.substring(str.indexOf("/") + 1, str.lastIndexOf("."));
594                 String JavaDoc diffname = tmp + "." + "diff";
595                 File JavaDoc diffFile = new File JavaDoc(outDir, diffname);
596                 if ( (diffFile != null) && (diffFile.exists()) )
597                 {
598                     BufferedReader JavaDoc inFile =
599                         new BufferedReader JavaDoc(new FileReader JavaDoc(diffFile));
600                     String JavaDoc diffLine = "";
601                     while ( (diffLine = inFile.readLine()) != null )
602                     {
603                         pwOut.println(diffLine);
604                     }
605                 }
606
607             }
608         // reset the system properties to prevent confusion
609
// when running with java threads
610
ManageSysProps.resetSysProps();
611         lastTest = str;
612         }
613
614         // If useprocess is false, and this is a networkserver test,
615
// we can speed up the test run by not starting and stopping networkserver
616
// for every test (and waiting for it to be up), as we're using the same
617
// directory for all test files (instead of creating each test's files in a new dir).
618
// NetworkServer will get started through RunTest if it's not running, but
619
// at the end of a suite run, we need to make sure we shutdown network server
620
if ((!useprocess) && ((framework !=null) && (framework.startsWith("DerbyNet"))))
621         {
622             try
623             {
624                 String JavaDoc stopCmd = javaCmd +
625                    " org.apache.derby.drda.NetworkServerControl shutdown";
626                 Process JavaDoc prstop = Runtime.getRuntime().exec(stopCmd);
627             } catch (Exception JavaDoc e) {} // ignore
628
}
629     }
630
631     /**
632     * Locate the suite's properties file
633     */

634     public static Properties JavaDoc locateSuiteProperties(String JavaDoc suiteName,
635         Properties JavaDoc parentProps, boolean isParent, boolean isTop)
636         throws ClassNotFoundException JavaDoc, IOException JavaDoc, Exception JavaDoc
637     {
638         // Check for suite properties
639
//System.out.println("Checking for suite properties");
640
String JavaDoc suitePropsName = "suites" + '/' + suiteName + ".properties";
641
642         InputStream JavaDoc is = org.apache.derbyTesting.functionTests.harness.RunTest.loadTestResource(suitePropsName);
643         if (is == null)
644         {
645             // Look in userdir
646
suitePropsName = userdir + '/' + suiteName + ".properties";
647             is = org.apache.derbyTesting.functionTests.harness.RunTest.loadTestResource(suitePropsName);
648         }
649         Properties JavaDoc p = new Properties JavaDoc();
650         // Reset these properties
651
if (isParent)
652         {
653             usesystem = null;
654             upgradetest = null;
655             jarfile = null;
656             outcopy = null;
657             useoutput = null;
658             mtestdir = null;
659             skipsed = "false";
660             //outputdir = outDir.getCanonicalPath();
661
}
662         if (is != null)
663         {
664             p.load(is);
665             is = null;
666         }
667         else
668         {
669             // Reset framework to the parent suite's framework, if any
670
// because framework may have been set by previous suite
671
testEncoding = parentProps.getProperty("derbyTesting.encoding");
672             upgradejarpath = parentProps.getProperty("derbyTesting.jar.path");
673             framework = parentProps.getProperty("framework");
674             serverJvm = parentProps.getProperty("serverJvm");
675             serverJvmName = parentProps.getProperty("serverJvmName");
676             // Do the same for ij.defaultResourcePackage
677
ijdefaultResourcePackage =
678                 parentProps.getProperty("ij.defaultResourcePackage");
679             // And do the same for encryption
680
encryption = parentProps.getProperty("encryption");
681             testEncryptionProvider = parentProps.getProperty("testEncryptionProvider");
682             testEncryptionAlgorithm = parentProps.getProperty("testEncryptionAlgorithm");
683             // And do the same for jdk12test
684
jdk12test = parentProps.getProperty("jdk12test");
685             jdk12exttest = parentProps.getProperty("jdk12exttest");
686             runwithj9 = parentProps.getProperty("runwithj9");
687             runwithibmjvm = parentProps.getProperty("runwithibmjvm");
688             String JavaDoc testJVM = jvmName;
689             if (jvmName.startsWith("j9"))
690                 testJVM = (jvmName.equals("j9_foundation") ? "foundation" : "j9");
691             runwithjvm = parentProps.getProperty("runwith" + testJVM);
692             excludeJCC = parentProps.getProperty("excludeJCC");
693         }
694         return p;
695     }
696
697
698     /**
699     * Properties which may be defined for all suites
700     * at the top level suite (such as "nightly")
701     */

702     private static void setTopSuiteProperties()
703         throws ClassNotFoundException JavaDoc, IOException JavaDoc
704     {
705         framework = suiteProperties.getProperty("framework");
706         
707         jversion = suiteProperties.getProperty("jversion");
708         //System.out.println("RunList top jversion= " + jversion);
709

710         jvmName = suiteProperties.getProperty("jvm");
711         String JavaDoc j9config = System.getProperty("com.ibm.oti.configuration");
712         if (j9config != null)
713             if (j9config.equals("foun10"))
714                 jvmName="j9_foundation";
715             else if (j9config.equals("max"))
716                 jvmName="j9_13";
717         if (jversion == null)
718             javaVersion = System.getProperty("java.version");
719         else
720             javaVersion = jversion;
721             
722         //System.out.println("RunList setTopSuiteProperties javaVersion: " + javaVersion);
723

724         javaCmd = suiteProperties.getProperty("javaCmd");
725         if (javaCmd == null)
726             javaCmd = "java";
727         else if (javaCmd.equals("jview"))
728             jvmName = "jview";
729
730         // if j9, we need to check further
731
String JavaDoc javavmVersion;
732         if (System.getProperty("java.vm.name").equals("J9"))
733             javavmVersion = (System.getProperty("java.vm.version"));
734         else
735             javavmVersion = javaVersion;
736
737
738         JavaVersionHolder jvh = new JavaVersionHolder(javavmVersion);
739         majorVersion = jvh.getMajorVersion();
740         minorVersion = jvh.getMinorVersion();
741         iminor = jvh.getMinorNumber();
742         imajor = jvh.getMajorNumber();
743
744         if ( (jvmName == null) || (jvmName.equals("jview")) )
745         {
746             if ( (iminor < 2) && (imajor < 2) )
747                 jvmName = "currentjvm";
748             else
749                 jvmName = "jdk" + majorVersion + minorVersion;
750         }
751     
752         if (jvmName.equals("j9_13"))
753         {
754             javaVersion = javaVersion + " - " + majorVersion + "." + minorVersion;
755             System.out.println("javaVersion now: " + javaVersion);
756             // up to j9 2.1 (jdk 1.3.1. subset) the results are the same for all versions, or
757
// we don't care about it anymore. So switch back to 1.3 (java.version values).
758
if ((imajor <= 2) && (iminor < 2))
759             {
760                 majorVersion = "1";
761                 minorVersion = "3";
762                 imajor = 1;
763                 iminor = 3;
764             }
765             else
766                 jvmName = "j9_" + majorVersion + minorVersion;
767         }
768
769         jvmflags = suiteProperties.getProperty("jvmflags");
770         testJavaFlags = suiteProperties.getProperty("testJavaFlags");
771         classpath = suiteProperties.getProperty("classpath");
772         classpathServer = suiteProperties.getProperty("classpathServer");
773         usesystem = suiteProperties.getProperty("usesystem");
774         upgradetest = suiteProperties.getProperty("upgradetest");
775         outcopy = suiteProperties.getProperty("outcopy");
776         useoutput = suiteProperties.getProperty("useoutput");
777         encryption = suiteProperties.getProperty("encryption");
778         testEncryptionProvider = suiteProperties.getProperty("testEncryptionProvider");
779         testEncryptionAlgorithm = suiteProperties.getProperty("testEncryptionAlgorithm");
780         jdk12test = suiteProperties.getProperty("jdk12test");
781         jdk12exttest = suiteProperties.getProperty("jdk12exttest");
782         runwithibmjvm = suiteProperties.getProperty("runwithibmjvm");
783         runwithj9 = suiteProperties.getProperty("runwithj9");
784                 derbyTestingXaSingle = suiteProperties.getProperty("derbyTesting.xa.single");
785         String JavaDoc testJVM = jvmName;
786         if (jvmName.startsWith("j9"))
787             testJVM = (jvmName.equals("j9_foundation") ? "foundation" : "j9");
788         runwithjvm = suiteProperties.getProperty("runwith" + testJVM);
789         excludeJCC = suiteProperties.getProperty("excludeJCC");
790         keepfiles = suiteProperties.getProperty("keepfiles");
791         systemdiff = suiteProperties.getProperty("systemdiff");
792         outputdir = suiteProperties.getProperty("outputdir");
793         if (outputdir == null)
794             outputdir = userdir;
795         topsuitedir = suiteProperties.getProperty("topsuitedir");
796         if (topsuitedir == null)
797             topsuitedir = outputdir;
798         bootcp = suiteProperties.getProperty("bootcp");
799         serverJvm = suiteProperties.getProperty("serverJvm");
800         serverJvmName = suiteProperties.getProperty("serverJvmName");
801         hostName = suiteProperties.getProperty("hostName");
802         testEncoding = suiteProperties.getProperty("derbyTesting.encoding");
803         upgradejarpath = suiteProperties.getProperty("derbyTesting.jar.path");
804         canondir = suiteProperties.getProperty("canondir");
805         mtestdir = suiteProperties.getProperty("mtestdir");
806         String JavaDoc usepr = suiteProperties.getProperty("useprocess");
807         if ( (usepr != null) && (usepr.equals("false")) )
808             useprocess = false;
809         skipsed = suiteProperties.getProperty("skipsed");
810         String JavaDoc dbug = suiteProperties.getProperty("verbose");
811         if ( (dbug != null) && (dbug.equals("true")) )
812             verbose = true;
813         reportstderr = suiteProperties.getProperty("reportstderr");
814         timeout = suiteProperties.getProperty("timeout");
815         shutdownurl = suiteProperties.getProperty("shutdownurl");
816         topSuiteName = suiteProperties.getProperty("suitename");
817         ijdefaultResourcePackage =
818             suiteProperties.getProperty("ij.defaultResourcePackage");
819         // The top level suiteProperties may have special
820
// properties which need to be added to testSpecialProps
821
if ( (specialProperties != null) && (!specialProperties.isEmpty()) )
822         {
823             //System.out.println("Top suite has special props");
824
setSpecialProps(specialProperties, true);
825         }
826     }
827
828     /**
829     * Properties for nested suites
830     */

831     private static void setSuiteProperties(Properties JavaDoc p, String JavaDoc suiteName,
832         Properties JavaDoc parentProperties, boolean isParent, boolean isTop)
833         throws ClassNotFoundException JavaDoc, IOException JavaDoc
834     {
835         // Some properties may have been set by the top suite
836
// jvm, jvmflags, classpath, systemdiff, verbose, etc.
837
// In that case, these will be preserved for the rest
838
if (jversion != null)
839             p.put("jvm", jversion);
840         if ( jvmName == null )
841             jvmName = "currentjvm";
842         else
843             p.put("jvm", jvmName);
844
845         if ( javaCmd == null )
846             javaCmd = "java";
847         else
848             p.put("javaCmd", javaCmd);
849
850         // all jvmflags should get appended, with command line overwrite top suite
851
// properties overwrite lower level suite properties
852
// but we're letting the jvm handle that by putting the cmdline last.
853
// note that at this point, the parentproperties already should have appended the
854
// jvmflags from the command line and the top suite properties file
855
// only need to add the lower suite properties in the mix
856
String JavaDoc totaljvmflags = jvmflags;
857         String JavaDoc subjvmflags = p.getProperty("jvmflags");
858         String JavaDoc parentjvmflags = parentProperties.getProperty("jvmflags");
859         if ((subjvmflags != null) && (parentjvmflags != null) && (!subjvmflags.equals(parentjvmflags)))
860         {
861             totaljvmflags = subjvmflags + "^" + totaljvmflags;
862         }
863         if (totaljvmflags != null)
864         {
865             jvmflags= totaljvmflags;
866         }
867
868         if ( classpath != null )
869             p.put("classpath", classpath);
870         if ( classpathServer != null )
871             p.put("classpathServer", classpathServer);
872         if ( systemdiff != null )
873             p.put("systemdiff", systemdiff);
874         if ( verbose == true )
875             p.put("verbose", "true");
876         if ( bootcp != null )
877             p.put("bootcp", "bootcp");
878         if ( canondir != null )
879             p.put("canondir", canondir);
880
881         if ( (outputdir == null) || (outputdir.length() == 0) )
882         {
883             outputdir = p.getProperty("outputdir");
884             if (outputdir == null)
885                 outputdir = userdir;
886         }
887
888         // framework may be set at the top, or just
889
// set for individual suites
890
if ( parentProperties.getProperty("framework") != null )
891             p.put("framework", framework);
892         else
893             framework = p.getProperty("framework");
894
895         // same for serverJvm and serverJvmName
896
if ( parentProperties.getProperty("serverJvm") != null )
897             p.put("serverJvm", serverJvm);
898         else
899             serverJvm = p.getProperty("serverJvm");
900         if ( parentProperties.getProperty("serverJvmName") != null )
901             p.put("serverJvmName", serverJvmName);
902         else
903             serverJvmName = p.getProperty("serverJvmName");
904         
905         // derbyTesting.encoding may be set at the top, or just
906
// set for individual suites
907
if(parentProperties.getProperty("derbyTesting.encoding") != null)
908             p.put("derbyTesting.encoding", testEncoding);
909         else
910             testEncoding = p.getProperty("derbyTesting.encoding");
911
912         if(parentProperties.getProperty("derbyTesting.jar.path") != null)
913             p.put("derbyTesting.jar.path", upgradejarpath);
914         else
915             upgradejarpath = p.getProperty("derbyTesting.jar.path");
916
917         if ( hostName != null )
918             p.put("hostName", hostName);
919         else
920             p.put("hostName","localhost");
921         // Encryption may be set at the top or just for a subsuite
922
if ( parentProperties.getProperty("encryption") != null )
923             p.put("encryption", encryption);
924         else
925             encryption = p.getProperty("encryption");
926
927     // Encryption provider may be set at the top or just for a subsuite
928
if ( parentProperties.getProperty("testEncryptionProvider") != null )
929             p.put("testEncryptionProvider", testEncryptionProvider);
930         else
931             testEncryptionProvider = p.getProperty("testEncryptionProvider");
932
933     // Encryption algorithm may be set at the top or just for a subsuite
934
if ( parentProperties.getProperty("testEncryptionAlgorithm") != null )
935             p.put("testEncryptionAlgorithm", testEncryptionAlgorithm);
936         else
937             testEncryptionAlgorithm = p.getProperty("testEncryptionAlgorithm");
938
939         // jdk12test may be set at the top or just for a subsuite
940
if ( parentProperties.getProperty("jdk12test") != null )
941             p.put("jdk12test", jdk12test);
942         else
943             jdk12test = p.getProperty("jdk12test");
944
945         // jdk12exttest may be set at the top or just for a subsuite
946
if ( parentProperties.getProperty("jdk12exttest") != null )
947             p.put("jdk12exttest", jdk12exttest);
948         else
949             jdk12exttest = p.getProperty("jdk12exttest");
950
951         // runwithibmjvm may be set at the top or just for a subsuite
952
if ( parentProperties.getProperty("runwithibmjvm") != null )
953             p.put("runwithibmjvm", runwithibmjvm);
954         else
955             runwithibmjvm = p.getProperty("runwithibmjvm");
956
957         // runwithjvm may be set at the top or just for a subsuite
958
String JavaDoc testJVM = jvmName;
959         if (jvmName.startsWith("j9"))
960             testJVM = (jvmName.equals("j9_foundation") ? "foundation" : "j9");
961         if ( parentProperties.getProperty("runwith" + testJVM) != null )
962             p.put("runwith" + testJVM, runwithjvm);
963         else
964             runwithjvm = p.getProperty("runwith" + testJVM);
965
966         // runwithj9 may be set at the top or just for a subsuite
967
if ( parentProperties.getProperty("runwithj9") != null )
968             p.put("runwithj9", runwithj9);
969         else
970             runwithj9 = p.getProperty("runwithj9");
971
972         // excludeJCC may be set at the top or just for a subsuite
973
if ( parentProperties.getProperty("excludeJCC") != null )
974             p.put("excludeJCC", excludeJCC);
975         else
976             excludeJCC = p.getProperty("excludeJCC");
977
978         // useprocess may be set at the top or just for a subsuite
979
String JavaDoc upr = parentProperties.getProperty("useprocess");
980         if ( upr != null )
981             p.put("useprocess", upr);
982         else
983         {
984             upr = p.getProperty("useprocess");
985             if ( upr == null)
986                 useprocess = true;
987             else if (upr.equals("false"))
988                 useprocess = false;
989             else
990                 useprocess = true;
991         }
992         // properties specific to a single suite
993
usesystem = p.getProperty("usesystem");
994         shutdownurl = p.getProperty("shutdownurl");
995         upgradetest = p.getProperty("upgradetest");
996         jarfile = p.getProperty("jarfile");
997         skipsed = p.getProperty("skipsed");
998         if (skipsed == null)
999             skipsed = "false";
1000        if ( "true".equals(keepfiles) )
1001            p.put("keepfiles", keepfiles);
1002
1003        // testJavaFlags should get appended
1004

1005        String JavaDoc testflags = p.getProperty("testJavaFlags");
1006        if ( parentProperties.getProperty("testJavaFlags") != null )
1007        {
1008            if ( (testflags != null) && (!testflags.equals(testJavaFlags)) )
1009            {
1010                testJavaFlags = testJavaFlags + "^" + testflags;
1011            }
1012            p.put("testJavaFlags", testJavaFlags);
1013        }
1014        else
1015            testJavaFlags = p.getProperty("testJavaFlags");
1016
1017        // The following could change between suites or
1018
// may be set for the whole set of suites
1019

1020        if ( parentProperties.getProperty("reportstderr") != null )
1021            p.put("reportstderr", reportstderr);
1022        else
1023            reportstderr = p.getProperty("reportstderr");
1024
1025        if ( parentProperties.getProperty("timeout") != null )
1026            p.put("timeout", timeout);
1027        else
1028            timeout = p.getProperty("timeout");
1029
1030        // outcopy is very specific to a single suite
1031
outcopy = p.getProperty("outcopy");
1032
1033        // useoutput is very specific to a single suite
1034
useoutput = p.getProperty("useoutput");
1035
1036
1037        // mtestdir is very specific to a multi suite
1038
mtestdir = p.getProperty("mtestdir");
1039
1040        // ijdefaultResourcePackage is specific for a suite
1041
ijdefaultResourcePackage = p.getProperty("ij.defaultResourcePackage");
1042
1043        if ( topSuiteName == null )
1044            topSuiteName = p.getProperty("suitename");
1045        else
1046            p.put("suitename", topSuiteName);
1047
1048        skip = shouldSkipTest();
1049            
1050        // Set the suite subdir under top outputdir
1051
setSuiteDir(suiteName, isParent, isTop);
1052
1053        // This individual suite may also have special flags
1054
// Reset otherSpecialProps in case another suite had any set
1055
otherSpecialProps = "";
1056        Properties JavaDoc specialProps = SpecialFlags.getSpecialProperties(p);
1057        if ( (specialProps != null) && (!specialProps.isEmpty()) )
1058            // Add any special properties to suiteJavaFlags string
1059
setSpecialProps(specialProps, false);
1060    }
1061
1062    /**
1063        Determine if a test should be skipped or not.
1064        These are ad-hoc rules, see comments within for details.
1065        Examples of what is checked: JVM version, framework,
1066        encryption, jdk12test,
1067        Sets some global variables so that skip reporting is clearer.
1068
1069        @return true if test should not be run.
1070    */

1071    private static boolean shouldSkipTest()
1072    {
1073    boolean result = false;
1074
1075    // figure out if suite should be skipped ... adhoc rules
1076
boolean isJdk12 = false; // really now 'isJdk12orHigher'
1077
boolean isJdk118 = false;
1078    boolean isJdk117 = false;
1079    boolean isEncryption = false;
1080    boolean isJdk12Test = false;
1081    boolean isJdk12ExtTest = false;
1082    boolean isSyncTest = false;
1083    boolean isSyncProduct = false;
1084    boolean isExcludeJCC = false;
1085    // runwithibmjvm is really tri-state. null = run-anywhere,
1086
// true = only ibm jvms, false = only non-IBM jvms.
1087

1088    // reset skip reason parameters
1089
driverNotFound = false;
1090    needSync = false;
1091    needJdk12 = false;
1092    needJdk12ext = false;
1093    excludedFromJCC = false;
1094    needIBMjvm = null;
1095
1096
1097    // Determine if this is jdk12 or higher (with or without extensions)
1098
if (iminor >= 2) isJdk12 = true;
1099    if ( System.getProperty("java.version").startsWith("1.1.8") ) isJdk118 = true;
1100    if ( System.getProperty("java.version").startsWith("1.1.7") ) isJdk117 = true;
1101    
1102    // if a test needs an ibm jvm, skip if runwithibmjvm is true.
1103
// if a test needs to not run in an ibm jvm, skip if runwithibmjvm is false.
1104
// if null, continue in all cases.
1105
if (runwithibmjvm != null)
1106    {
1107        if (runwithibmjvm.equals("")) { needIBMjvm = null; }
1108        else { needIBMjvm = new Boolean JavaDoc(runwithibmjvm); }
1109    }
1110    if (runwithibmjvm == null) { needIBMjvm = null; }
1111    if (needIBMjvm != null)
1112    {
1113        boolean needsibm = needIBMjvm.booleanValue();
1114        boolean ibmjvm = false;
1115        String JavaDoc vendor = System.getProperty("java.vendor");
1116        if (vendor.startsWith("IBM")) { ibmjvm = true; }
1117        if (!needsibm && ibmjvm) { return true; }
1118        if (needsibm && !ibmjvm) { return true; }
1119    }
1120
1121    if (runwithjvm != null && runwithjvm.equals("false"))
1122    {
1123        return true;
1124    }
1125
1126        if ( (framework != null) && (framework.length()>0) )
1127    {
1128            if (framework.equals("DerbyNet"))
1129        {
1130        // skip if the derbynet.jar is not in the Classpath
1131
try {
1132            Class.forName("org.apache.derby.drda.NetworkServerControl");
1133        } catch (ClassNotFoundException JavaDoc cnfe) {
1134            driverNotFound = true;
1135            result = true;
1136        }
1137
1138        // skip if the IBM Universal JDBC Driver is not in the Classpath
1139
// note that that driver loads some javax.naming.* classes which may not
1140
// be present at runtime, and thus we need to catch a possible error too
1141
try {
1142            Class.forName("com.ibm.db2.jcc.DB2Driver");
1143        } catch (ClassNotFoundException JavaDoc cnfe) {
1144            driverNotFound = true;
1145            result = true;
1146        } catch (NoClassDefFoundError JavaDoc err) {
1147            driverNotFound = true;
1148            result = true;
1149        }
1150        }
1151    }
1152
1153    if (result) return true; // stop looking once know should skip
1154

1155        if ( (encryption != null) && (encryption.length()>0) )
1156            if ("true".equalsIgnoreCase(encryption)) isEncryption = true;
1157        if ( (jdk12test != null) && (jdk12test.length()>0) )
1158            if ("true".equalsIgnoreCase(jdk12test)) isJdk12Test = true;
1159        if ( (jdk12exttest != null) && (jdk12exttest.length()>0) )
1160            if ("true".equalsIgnoreCase(jdk12exttest)) isJdk12ExtTest = true;
1161        
1162        // Skip any suite if jvm is not jdk12 or higher for encryption, jdk12test or jdk12exttest
1163
if (!isJdk12)
1164        {
1165            if ( (isEncryption) || (isJdk12Test) || (isJdk12ExtTest) )
1166            {
1167                needJdk12 = true;
1168                result = true; // Can't run in this combination
1169
}
1170        if (result) return true; // stop looking once know should skip
1171
}
1172
1173    // Also require jdk12 extensions for encryption and jdk12exttest
1174
if ( (isEncryption) || (isJdk12ExtTest) )
1175    {
1176        needJdk12ext = true;
1177            // Check for extensions
1178
try
1179            {
1180                Class JavaDoc jtaClass = Class.forName("javax.transaction.xa.Xid");
1181                Class JavaDoc jdbcClass = Class.forName("javax.sql.RowSet");
1182            }
1183            catch (ClassNotFoundException JavaDoc cnfe)
1184            {
1185                // at least one of the extension classes was not found
1186
result = true; // skip this test
1187
}
1188        if (result) return true; // stop looking once know should skip
1189
}
1190
1191        if (isEncryption) // make sure encryption classes are available
1192
{
1193            needEncryption = true;
1194            try
1195            {
1196                Class JavaDoc jceClass = Class.forName("javax.crypto.Cipher");
1197            }
1198            catch (ClassNotFoundException JavaDoc cnfe)
1199            {
1200                result = true;
1201            }
1202            if (result) return true;
1203        }
1204
1205    if (excludeJCC != null)
1206    {
1207        Class JavaDoc c = null;
1208        Method JavaDoc m = null;
1209        Object JavaDoc o = null;
1210        Integer JavaDoc i = null;
1211        int jccMajor = 0;
1212        int jccMinor = 0;
1213        try
1214        {
1215        c = Class.forName("com.ibm.db2.jcc.DB2Driver");
1216        o = c.newInstance();
1217        m = c.getMethod("getMajorVersion", null);
1218        i = (Integer JavaDoc)m.invoke(o, null);
1219        jccMajor = i.intValue();
1220        m = c.getMethod("getMinorVersion", null);
1221        i = (Integer JavaDoc)m.invoke(o, null);
1222        jccMinor = i.intValue();
1223        } catch (Exception JavaDoc e) {
1224            if (verbose) System.out.println("Exception in shouldSkipTest: " + e);
1225            }
1226
1227        try {
1228            checkClientExclusion(excludeJCC, "JCC", jccMajor, jccMinor, javaVersion);
1229        } catch (Exception JavaDoc e) {
1230            excludedFromJCC = true;
1231            clientExclusionMessage = e.getMessage();
1232            return true;
1233        }
1234    }
1235
1236    return result; // last test result is returned
1237
}
1238
1239
1240    public static void setSuiteDir(String JavaDoc suiteName, boolean isParent, boolean isTop)
1241        throws IOException JavaDoc
1242    {
1243        if (isTop) // This is the very top suite for this RunList
1244
{
1245            // Here we want to set the topsuitedir
1246
if ( (topsuitedir == null) || (topsuitedir.length() == 0) )
1247            {
1248                topsuitedir = userdir;
1249                outputdir = topsuitedir;
1250            }
1251            else
1252                outputdir = topsuitedir;
1253            
1254            // Create the topsuite directory under the outputdir
1255
File JavaDoc topdir = new File JavaDoc(outputdir, topSuiteName);
1256            topdir.mkdir();
1257            if (!topParentSuite.equals(topSuiteName))
1258            {
1259                File JavaDoc topparent = new File JavaDoc(topdir, topParentSuite);
1260                topparent.mkdir();
1261                outputdir = topparent.getCanonicalPath();
1262            }
1263            else
1264                outputdir = topdir.getCanonicalPath();
1265            topreportdir = outputdir;
1266            //System.out.println("RunList topsuitedir: " + outputdir);
1267
//System.out.println("RunList outputdir: " + outputdir);
1268
//System.out.println("RunList topreportdir: " + topreportdir);
1269

1270            // Modify outputdir for special framework
1271
if ( (framework != null) && (framework.length()>0) )
1272            {
1273                File JavaDoc f = new File JavaDoc(outputdir, framework);
1274                f.mkdir();
1275                outputdir = f.getCanonicalPath();
1276                fw_set = true; // framework dir set at top level
1277
//System.out.println("RunList for framework outputdir: " + outputdir);
1278
}
1279            topsuitedir = outputdir;
1280        }
1281        else if (isParent) // reset outputdir to topsuitedir for a new parent
1282
{
1283            outputdir = topsuitedir;
1284            //System.out.println("outputdir reset for parent: " + outputdir);
1285
if (!suiteName.equals(topParentSuite))
1286            {
1287                File JavaDoc suitedir = new File JavaDoc(outputdir, suiteName);
1288                suitedir.mkdir();
1289                outputdir = suitedir.getCanonicalPath();
1290            }
1291            // Modify outputdir for special framework (if not already set)
1292
if (!fw_set)
1293            {
1294                if ( (framework != null) && (framework.length()>0) )
1295                {
1296                    File JavaDoc f = new File JavaDoc(outputdir, framework);
1297                    f.mkdir();
1298                    outputdir = f.getCanonicalPath();
1299                }
1300            }
1301        }
1302
1303        else if ( upgradetest == null ) // this is a child suite of a parent
1304
{
1305            File JavaDoc suitedir = new File JavaDoc(outputdir, suiteName);
1306            suitedir.mkdir();
1307            outputdir = suitedir.getCanonicalPath();
1308            //System.out.println("Child outputdir: " + outputdir);
1309
}
1310    }
1311
1312    private static void setSpecialProps(Properties JavaDoc p, boolean isTop)
1313    {
1314        // Just build string for RunTest to parse (^ is the separator)
1315
// and determine which special flags are for ij or for server
1316
// These special flags come from specialProperties, not from
1317
// the usual properties (RunSuite will give these for the top suite)
1318
String JavaDoc tmp = "";
1319        for (Enumeration JavaDoc e = p.propertyNames(); e.hasMoreElements(); )
1320        {
1321            String JavaDoc key = (String JavaDoc)e.nextElement();
1322            // Note: RunSuite will already have excluded
1323
// suites, useoutput, usesystem,keepfiles from these
1324
tmp += key + "=" + p.getProperty(key) + "^";
1325        }
1326        if (tmp.length()>0)
1327        {
1328            if ( isTop == true ) // This is the top level suite
1329
topSpecialProps = tmp.substring(0, tmp.lastIndexOf('^'));
1330            else // This is a nested suite, do not apply to all the suites
1331
otherSpecialProps = tmp.substring(0, tmp.lastIndexOf('^'));
1332        }
1333    }
1334    
1335    static void addToSkipFile(String JavaDoc suiteName, PrintStream JavaDoc ps) throws IOException JavaDoc
1336    {
1337        ps.println(suiteName);
1338        ps.flush();
1339    }
1340    
1341    /* ****
1342     * Look at the received exclusion property and use it to
1343     * figure out if this test/suite should be skipped based
1344     * on the actual client and JVM versions in question.
1345     * @param exclusion The harness property indicating the
1346     * rules for skipping this test. For example:
1347     * "at-or-before:2.0,when-at-or-after:jdk1.5.1".
1348     * @param clientName Name of the client being used.
1349     * @param clientMajor The 'major' part of the client version
1350     * that is actually being used for the test.
1351     * @param clientMinor The 'minor' part of the client version
1352     * that is actually being used for the test.
1353     * @param javaVersion JVM being used, as a string.
1354     * @return Exception is thrown if this test/suite should
1355     * be skipped; else we simply return.
1356     */

1357    public static void checkClientExclusion(String JavaDoc exclusion,
1358        String JavaDoc clientName, int clientMajor, int clientMinor,
1359        String JavaDoc javaVersion) throws Exception JavaDoc
1360    {
1361
1362        if (exclusion == null)
1363        // we already know the test isn't excluded.
1364
return;
1365
1366        // These tell us whether we want to 1) exclude version
1367
// numbers that are lower than the target version, or
1368
// 2) exclude version numbers that are higher than the
1369
// target version.
1370
int clientComparisonType = 0;
1371        int jvmComparisonType = 0;
1372
1373        exclusion = exclusion.toLowerCase();
1374        String JavaDoc clientVersion = null;
1375
1376        // Figure out what kind of comparison we need for the client version.
1377
int comma = exclusion.indexOf(",");
1378        if (comma != -1)
1379            clientVersion = exclusion.substring(0, comma);
1380        else
1381            clientVersion = exclusion;
1382
1383        try {
1384            clientComparisonType = getVersionCompareType(clientVersion);
1385        } catch (Exception JavaDoc e) {
1386            System.out.println("exclusion property poorly formatted: " + exclusion);
1387            return;
1388        }
1389
1390        // Figure out what kind of comparison we need for the JVM version.
1391
boolean jvmDependent;
1392        if (comma == -1)
1393            jvmDependent = false;
1394        else {
1395            jvmDependent = true;
1396            // "+6" in next line is length of ",when-", which is the
1397
// keyword used to begin the jvm exclusion string.
1398
String JavaDoc jvmVersion = exclusion.substring(comma+6);
1399            try {
1400                jvmComparisonType = getVersionCompareType(jvmVersion);
1401            } catch (Exception JavaDoc e) {
1402                System.out.println("exclusion property poorly formatted: " + exclusion);
1403                return;
1404            }
1405        }
1406
1407        // Load the client and JVM target versions. The "5" in the
1408
// next line means that we want to parse out 5 numbers from
1409
// the property: 2 numbers for the client version (ex. "2.0")
1410
// and 3 numbers for the JVM version (ex. "1.5.1").
1411
int [] excludeInfo = null;
1412        try {
1413            excludeInfo = getVersionArray(exclusion, 5);
1414        } catch (Exception JavaDoc e) {
1415            System.out.println("Unexpected text in exclusion property: " + e.getMessage());
1416            return;
1417        }
1418
1419        // Now check to see if this test/suite should be excluded.
1420
// First check the client version.
1421
if (versionExcluded(new int [] {clientMajor, clientMinor}, 0,
1422            excludeInfo, 0, 2, clientComparisonType))
1423        {
1424
1425            if (!jvmDependent) {
1426            // then skip it regardless of JVM.
1427
throw new Exception JavaDoc("This test/suite is excluded from running with " +
1428                    clientName + " versions at or " +
1429                    (clientComparisonType == -1 ? "before " : "after ") +
1430                    excludeInfo[0] + "." + excludeInfo[1] + ".");
1431            }
1432
1433            // Now check the JVM version.
1434
int [] jvmInfo = null;
1435            try {
1436                jvmInfo = getVersionArray(javaVersion, 3);
1437            } catch (Exception JavaDoc e) {
1438                System.out.println("Unexpected text in exclusion property: " + e.getMessage());
1439                return;
1440            }
1441
1442            if (versionExcluded(jvmInfo, 0, excludeInfo, 2, 3, jvmComparisonType)) {
1443                throw new Exception JavaDoc("This test/suite is excluded from running with " +
1444                    clientName + " versions at or " +
1445                    (clientComparisonType == -1 ? "before " : "after ") +
1446                    excludeInfo[0] + "." + excludeInfo[1] + " when JVM versions at or " +
1447                    (jvmComparisonType == -1 ? "before " : "after ") +
1448                    excludeInfo[2] + "." + excludeInfo[3] + "." + excludeInfo[4] +
1449                    " are being used.");
1450            }
1451        }
1452
1453    }
1454
1455    /* ****
1456     * Parses a versionString property and returns the specified
1457     * number of integers as found in that string. If the number
1458     * of integers requested is larger than the number of integers
1459     * found in the version string, -1 will be used as filler.
1460     *
1461     * An example versionString might be any of the following:
1462     * "2.4" or "at-or-after:2.4" or "when:jdk1.3.1" or
1463     * "when-at-or-after:jdk1.3.1", etc. In these examples,
1464     * the resultant int arrays would be:
1465     *
1466     * "2.4" ==> [2,4] // if resultSize == 2.
1467     * "at-or-after:2.4" ==> [2.4] // if resultSize == 2.
1468     * "when:jdk1.3.1" ==> [1,3,1] // if resultSize == 3.
1469     * "when-at-or-after:jdk1.3.1" ==> [1,3,1,-1] // if resultSize == 4.
1470     *
1471     * @param versionString The version string to parse.
1472     * @param resultSize The number of integers to parse out of the
1473     * received version string.
1474     * @return An integer array holding resultSize integers as parsed
1475     * from the version string (with -1 as a filler if needed).
1476     */

1477    private static int [] getVersionArray(String JavaDoc versionString, int resultSize)
1478        throws Exception JavaDoc
1479    {
1480
1481        if (versionString == null)
1482        // Use an empty string so that tokenizer will still work;
1483
// result will be an array of "-1" values.
1484
versionString = "";
1485
1486        int [] result = new int[resultSize];
1487
1488        String JavaDoc tok = null;
1489        String JavaDoc text = null;
1490        StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(versionString, ".,_");
1491        for (int i = 0; i < resultSize; i++) {
1492    
1493            if (!st.hasMoreTokens()) {
1494            // if we're out of integers, use -1 as a filler.
1495
result[i] = -1;
1496                continue;
1497            }
1498
1499            // Get the token and parse out an integer.
1500
tok = st.nextToken();
1501            int pos = 0;
1502            for (; !Character.isDigit(tok.charAt(pos)); pos++);
1503            text = tok.substring(0, pos);
1504
1505            // If we have text, make sure it's a valid keyword
1506
// and then move past it.
1507
if ((text.length() > 0) && !isClientExclusionKeyword(text))
1508                throw new Exception JavaDoc(text);
1509
1510            // Load the int.
1511
tok = tok.substring(pos);
1512            if (tok.length() == 0) {
1513            // no integer found, so don't count this iteration.
1514
i--;
1515                continue;
1516            }
1517
1518            result[i] = Integer.parseInt(tok);
1519
1520        }
1521
1522        return result;
1523
1524    }
1525
1526    /* ****
1527     * Looks at a version string and searches for an indication
1528     * of what kind of versions (lower or higher) need to be
1529     * excluded. This method just looks for the keywords
1530     * "at-or-before" and "at-or-after", and then returns
1531     * a corresponding value. If neither of those keywords
1532     * is found, the default is to exclude versions that are
1533     * lower (i.e. "at-or-before").
1534     * @param versionString The version string in question,
1535     * for example "2.4" or "jdk1.3.1" or "at-or-before:jdk1.3.1".
1536     * @return -1 if we want to exclude versions that come
1537     * before the target, 1 if we want to exclude versions
1538     * that come after the target. Default is -1.
1539     */

1540    private static int getVersionCompareType(String JavaDoc versionString)
1541        throws Exception JavaDoc
1542    {
1543
1544        if (versionString == null)
1545        // just return the default.
1546
return -1;
1547
1548        int colon = versionString.indexOf(":");
1549        if (colon != -1) {
1550            if (versionString.startsWith("at-or-before"))
1551                return -1;
1552            else if (versionString.startsWith("at-or-after"))
1553                return 1;
1554            else
1555                throw new Exception JavaDoc("bad exclusion property format");
1556        }
1557
1558        return -1;
1559
1560    }
1561
1562    /* ****
1563     * Takes two versions, each of which is an array of integers,
1564     * and determines whether or not the first (actual) version
1565     * should be excluded from running based on the second (target)
1566     * version and on the received comparisonType.
1567     *
1568     * For example, let vActual be [2,1] and vTarget be [2,4]. Then
1569     * if comparisonType indicates that versions "at or before" the
1570     * the target version (2.4) should be excluded, this method
1571     * would return true (because 2.1 is before 2.4); if comparisonType
1572     * indicates that versions "at or after" the target type should
1573     * be excluded, this method would return false (because 2.1 is
1574     * NOT at or after 2.4).
1575     *
1576     * @param vActual The actual version, as an int array.
1577     * @param vTarget The target version, as an int array.
1578     * @param offset1 Offset into vActual at which to start the
1579     * comparison.
1580     * @param offset2 Offset into vTarget at which to start the
1581     * comparison.
1582     * @param numParts The maximum number of integer parts to compare.
1583     * @param comparisonType -1 if we want to exclude versions
1584     * at or before the target; 1 if we want to exclude versions
1585     * at or after the target.
1586     * @return True if the actual version should be excluded from
1587     * running, false otherwise.
1588     */

1589    private static boolean versionExcluded(int [] vActual, int offset1,
1590        int [] vTarget, int offset2, int numParts, int comparisonType)
1591    {
1592
1593        // Figure out how many integer parts we can actually compare.
1594
// The max is "len", but if len is greater than the length of
1595
// either of the versions, then we have to compensate for
1596
// the shortest version.
1597
int compareLen = (vActual.length >= vTarget.length ? vTarget.length : vActual.length);
1598        compareLen = (compareLen <= numParts ? compareLen : numParts);
1599
1600        // Now do the comparison.
1601
for (int i = 0; i < compareLen; i++) {
1602
1603            if (comparisonType * vActual[offset1] > comparisonType * vTarget[offset2])
1604                return true;
1605
1606            if (comparisonType * vActual[offset1] < comparisonType * vTarget[offset2])
1607                return false;
1608
1609            offset1++;
1610            offset2++;
1611
1612        }
1613
1614        // If we get here, the two versions are the same thru
1615
// compareLen parts. If that's as far as we're supposed
1616
// to compare, then we treat them as equal. Else, we take
1617
// the version having more parts as the greater of the two.
1618

1619        if (compareLen == numParts)
1620        // treat them as equal.
1621
return true;
1622
1623        return (comparisonType * vActual.length > comparisonType * vTarget.length);
1624
1625    }
1626
1627    /* ****
1628     * Checks to see if the received string is a recognized
1629     * keyword for an exclusion property.
1630     * @param text The string in question.
1631     * @return True if the received text is a valid keyword
1632     * for exclusion properties; false otherwise.
1633     */

1634    private static boolean isClientExclusionKeyword(String JavaDoc text) {
1635
1636        for (int i = 0; i < clientExclusionKeywords.length; i++) {
1637            if (clientExclusionKeywords[i].equals(text))
1638                return true;
1639        }
1640
1641        return false;
1642
1643    }
1644
1645
1646    /**
1647     * Unloads the embedded JDBC driver and Derby engine in case
1648     * is has already been loaded.
1649     * The purpose for doing this is that using an embedded engine
1650     * that already is loaded makes it impossible to set new
1651     * system properties for each individual suite or test.
1652     */

1653    private static void unloadEmbeddedDriver() {
1654        // Attempt to unload the embedded driver and engine
1655
// but only if we're not having a J2ME configuration i.e. no DriverManager, so check...
1656
if (TestUtil.HAVE_DRIVER_CLASS)
1657        try {
1658            DriverManager.getConnection("jdbc:derby:;shutdown=true");
1659        } catch (SQLException JavaDoc se) {
1660            // Ignore any exception thrown
1661
}
1662
1663        // Call the garbage collector as spesified in the Derby doc
1664
// for how to get rid of the classes that has been loaded
1665
System.gc();
1666    }
1667}
1668
1669
Popular Tags