File: RunSuite.java

package info (click to toggle)
derby 10.14.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 78,896 kB
  • sloc: java: 691,930; sql: 42,686; xml: 20,511; sh: 3,373; sed: 96; makefile: 60
file content (607 lines) | stat: -rw-r--r-- 22,461 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
/* 

   Derby - Class org.apache.derbyTesting.functionTests.harness.RunSuite

   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

 */

package org.apache.derbyTesting.functionTests.harness;

import org.apache.derby.tools.sysinfo;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.lang.ClassNotFoundException;
import java.sql.Timestamp;
import java.util.Enumeration;
import java.util.Properties;
import java.util.Vector;
import java.util.StringTokenizer;

public class RunSuite
{

    static final boolean verbose=true;

    static String suites; // list of subsuites in this suite
    static Vector<String> suitesToRun; // Vector of suites to run

    // Properties which may be specified
	static String jvmName = "";
	static String javaCmd = "java";
	static String jvmflags = ""; // jvm flags as one string
	static String javaVersion;
	static String classpath;
	static String classpathServer;
	static String testJavaFlags = ""; // formerly systest_javaflags
	static String testSpecialProps = ""; 
	static String userdir;
	static String framework;
	static String runwithibmjvm;
	static String excludeJCC;
	static boolean useprocess = true;
	static boolean skipsed = false;
	static String systemdiff = "false";
	static String topSuiteName = "";
	static String outputdir; // location of output (default is userdir)
	static String outcopy = "false"; // true if support files should go to outDir
	static String canondir; // location of master dir (default is master)
	static String bootcp; //  path for j9 bootclasspath setting
	static String serverJvm; //  path for j9 bootclasspath setting
	static String hostName; // needs to be settable for IPV6 testing; localhost otherwise. 
	static String testEncoding; // setting the encoding.
	static String ijdefaultResourcePackage; // for ij tests only
	static String debug; // for setting verbose mode to pass down to RunTest
    static String timeout; // to allow killing a hanging test
    static String shutdownurl; //used mainly by useprocess=false tests
	static String reportstderr; // can set to disable (to turn off JIT errors, etc.)
	static Properties suiteProperties;
	static Properties specialProperties;

	// Output variables
    static PrintWriter pwOut = null; // for writing suite output
    static File outDir; // test out dir
    static File runDir; // where the suite/tests are run
    static File outFile; // suite output file

	public static void main(String[] args) throws Exception
	{
		if ((System.getProperty("java.vm.name") != null) && System.getProperty("java.vm.name").equals("J9"))
		{
		 		javaCmd = "j9";
				String javaHome = System.getProperty("java.home");
		}
		String j9config = System.getProperty("com.ibm.oti.configuration");
		if (j9config != null) 
			if (j9config.equals("foun10")) 
				jvmName="j9_foundation";
			else if (j9config.equals("foun11")) 
				jvmName="j9_foundation11";
			else if (j9config.equals("max"))
				jvmName="j9_13";
			else if (j9config.equals("dee"))
				jvmName="j9dee15";

	    String suiteName = args[0];
	    if ( suiteName == null )
	    {
	        System.out.println("No suite name argument.");
	        System.exit(1);
	    }
	    topSuiteName = suiteName;
	    System.out.println("Top suite: " + suiteName);

	    // suiteName may be one suite or a list of suites
        suitesToRun = new Vector<String>();

        // Get properties set in the suite's properties file
		suiteProperties = getSuiteProperties(suiteName, true);

		// There may be system properties which will override
		// the suiteProperties. This will make it easier when you
		// do not want to edit the suite props for a special case
		getSystemProperties();

        // Get any special properties that are not the usual
        // expected properties (we separate these from suiteProperties
        // to avoid conflicts)
        specialProperties =
            SpecialFlags.getSpecialProperties(suiteProperties);

        // Setup the initial output
        setOutput(suiteName);

        // Get the current time to write a timestamp
        String startTime = CurrentTime.getTime();

        pwOut.println("******* Start Suite: " + suiteName +
            " " + startTime + " *******");

        // Write sysinfo to the output file
        if (useprocess) // doesn't work on Mac
        {
            SysInfoLog sysLog= new SysInfoLog();
            sysLog.exec(jvmName, javaCmd, classpath, framework, pwOut, useprocess);
        }
            
        getSuitesList(suiteName, true);
        
        // Get the current time to write a timestamp
        String endTime = CurrentTime.getTime();
        pwOut.println("******* End Suite: " + suiteName +
            " " + endTime + " *******");
        pwOut.close();
        
		String genrep = System.getProperty("genrep");
		boolean isGenrep = true;
		if (genrep!=null) isGenrep = "true".equalsIgnoreCase(genrep);
		if (isGenrep) 
		{
		    String[] genargs = new String[6];
		    genargs[0] = args[0];
		    genargs[1] = jvmName;
		    genargs[2] = javaCmd;
		    genargs[3] = classpath;
		    genargs[4] = framework;
		    if (useprocess)
		        genargs[5] = "true";
		    else
		        genargs[5] = "false";
		    GenerateReport.main(genargs);
		}
	}

    static void getSuitesList(String topparent, boolean isTop)
        throws Exception, ClassNotFoundException, IOException
    {
		// Get the suite properties if it exists
        Properties p;
        if ( (suites == null) || (suites.length()==0) )
        {
            // There is a single suite, not a list, just add it
            if (verbose) System.out.println("Suite to run: " + topparent+":"+topparent);
            suitesToRun.addElement(topparent+":"+topparent);
            // Use RunList class to issue the RunTest commands
            if (verbose) System.out.println("Now do RunList");
            //System.out.println("skipsed: " + skipsed);
            RunList rl = new RunList(suitesToRun, runDir, outDir, pwOut,
                suiteProperties, specialProperties, topparent);
            suitesToRun.removeAllElements();
        }
        else
        {
            isTop = false;
            // Build the Vector from suites string
	        StringTokenizer st = new StringTokenizer(suites);
	        String subparent = "";
            while (st.hasMoreTokens())
            {
                subparent = st.nextToken();
                p = getSuiteProperties(subparent, isTop);
                if ( (p.getProperty("suites") == null) || (subparent.equals(topparent)) )
                {
                    suitesToRun.addElement(topparent+":"+subparent);
                    //System.out.println("Add to suitesToRun: " + topparent+":"+subparent);
                    // Use RunList class to issue the RunTest commands
                    if (verbose) System.out.println("Now do RunList");
                    //System.out.println("skipsed: " + skipsed);
                    RunList rl = new RunList(suitesToRun, runDir, outDir, pwOut,
                        suiteProperties, specialProperties, topparent);
                    suitesToRun.removeAllElements();
                }
                else // This suite also has nested suites
                {
                    String sublist = p.getProperty("suites");
                    //System.out.println("list for this SubSuite= " + sublist);
                    BuildSuitesVector(subparent, sublist);
                    // Use RunList class to issue the RunTest commands
                    if (verbose) System.out.println("Now do RunList");
                    //System.out.println("skipsed: " + skipsed);
                    RunList rl = new RunList(suitesToRun, runDir, outDir, pwOut,
                        suiteProperties, specialProperties, subparent);
                    suitesToRun.removeAllElements();                    
                }
            }
        }
    }
    
    static void BuildSuitesVector(String parent, String subsuites)
        throws ClassNotFoundException, IOException
    {
        Properties p;
        StringTokenizer st = new StringTokenizer(subsuites);
        String child = "";
        while (st.hasMoreTokens())
        {
            child = st.nextToken();
            if (child.equals(parent))
            {
                suitesToRun.addElement(parent+":"+child);
                //System.out.println("Add this: " + parent+":"+child);
            }
            else
            {
                p = getSuiteProperties(child, false);
                if ( p.getProperty("suites") == null )
                {
                    suitesToRun.addElement(parent+":"+child);
                    //System.out.println("Add this: " + parent+":"+child);
                }
                else
                {
                    String moresuites = p.getProperty("suites");
                    BuildSuitesVector(child, moresuites);
                }
            }
        }
    }
            
    
    static Properties getSuiteProperties(String suiteName, boolean isTop)
        throws ClassNotFoundException, IOException
    {
        // Locate the suite's config file and get the properties
        // The file should be in the harness dir or user.dir
        String suiteProps = "suites" + '/' + suiteName + ".properties";
        userdir = System.getProperty("user.dir");

        InputStream is = RunTest.loadTestResource(suiteProps);
        if (is == null)
        {
            // Look in userdir
            suiteProps = userdir + '/' + suiteName + ".properties";
            is = RunTest.loadTestResource(suiteProps);
        }
        Properties p = new Properties();
        if (is == null)
            return p;

        p.load(is);
        // The top level suite may have special properties
        // which get propagated to any subsuites
        if (isTop == true)
        {
			String tmpjvmName=jvmName;	
            jvmName = p.getProperty("jvm");
		    if ( (jvmName == null) || (jvmName.length()==0) )
		    {
		        javaVersion = System.getProperty("java.version");
		    }
		    else
		        javaVersion = jvmName;

            // for j9, we cannot just use java.version.
            String javavmVersion;
            if (System.getProperty("java.vm.name").equals("J9"))
                javavmVersion = (System.getProperty("java.vm.version"));
            else
                javavmVersion = javaVersion;
    		    
		    JavaVersionHolder jvh = new JavaVersionHolder(javavmVersion);
		    String majorVersion = jvh.getMajorVersion();
		    String minorVersion = jvh.getMinorVersion();
            int iminor = jvh.getMinorNumber();
            int imajor = jvh.getMajorNumber();
    		
		    if ( (iminor < 2) && (imajor < 2) )
		        jvmName = "currentjvm";
		    else
		        jvmName = "jdk" + majorVersion + minorVersion;
		if ( tmpjvmName != null)
			jvmName= tmpjvmName;
            javaCmd = p.getProperty("javaCmd");
            jvmflags = p.getProperty("jvmflags");
            testJavaFlags = p.getProperty("testJavaFlags");
            testSpecialProps = p.getProperty("testSpecialProps");
            classpath = p.getProperty("classpath");
            classpathServer = p.getProperty("classpathServer");
            framework = p.getProperty("framework");
		    String usepr = p.getProperty("useprocess");
		    if (usepr != null)
		    {
		        usepr = usepr.toLowerCase();
		        if (usepr.equals("false"))
		            useprocess = false;
		        else
		            useprocess = true;
		    }
		    else
		        useprocess = true;

            String nosed = p.getProperty("skipsed");
            if (nosed != null)
            {
                nosed = nosed.toLowerCase();
                if (nosed.equals("true"))
                    skipsed = true;
                else
                    skipsed = false;
            }
            else
                skipsed = false;
                
            outputdir = p.getProperty("outputdir");
            canondir = p.getProperty("canondir");
            bootcp = p.getProperty("bootcp");
            hostName = p.getProperty("hostName");
            serverJvm = p.getProperty("serverJvm");
            systemdiff = p.getProperty("systemdiff");
            ijdefaultResourcePackage = p.getProperty("ij.defaultResourcePackage");
            outcopy = p.getProperty("outcopy");
            debug = p.getProperty("verbose");
            reportstderr = p.getProperty("reportstderr");
            timeout = p.getProperty("timeout");
            shutdownurl = p.getProperty("shutdownurl");
            testEncoding = p.getProperty("derbyTesting.encoding");
        }
        suites = p.getProperty("suites");
		return p;
    }

    private static void getSystemProperties()
    {
        // Get any properties specified on the command line
        // which may not have been specified in the suite prop file
        Properties sp = System.getProperties();
        String searchCP = sp.getProperty("ij.searchClassPath");
        if (searchCP != null)
            suiteProperties.put("ij.searchClassPath", searchCP);
		String frm = sp.getProperty("framework");
		if ( (frm != null) && (!frm.equals("embedded")) )
		{
		    framework = frm;
		    suiteProperties.put("framework", framework);
		}
		String j = sp.getProperty("jvm");
		if (j != null)
		    suiteProperties.put("jversion", j);
		
		String jcmd = sp.getProperty("javaCmd");
		if ((System.getProperty("java.vm.name") != null) && System.getProperty("java.vm.name").equals("J9"))
			jcmd = "j9";
		if (jcmd != null)
		{
		    javaCmd = jcmd;
		    suiteProperties.put("javaCmd", javaCmd);
		}
		// get System properties for jvmflags, and put them to the end, thus
		// when the time comes to have this converted into actual jvm flags
		// the ones given at the command line will overwrite whatever's in the suite
		String jflags = sp.getProperty("jvmflags");
		if (jvmflags != null && jvmflags.length() > 0)
		{
		  //DERBY-4680 Make sure ^ does not get appended to jvmflags
		    if (jflags != null && jflags.length() > 0)
		    		suiteProperties.put("jvmflags", (jvmflags + "^" + jflags));
			else
		    		suiteProperties.put("jvmflags", jvmflags);
		}
		else
		{
			if (jflags != null && jflags.length() >0)
		    		suiteProperties.put("jvmflags", jflags);
		}
		String testflags = sp.getProperty("testJavaFlags");
		if (testflags != null)
		{
		    if (testJavaFlags == null || testJavaFlags.length() == 0)
		        testJavaFlags = testflags;
		    else // add to testJavaFlags
		        testJavaFlags = testJavaFlags + "^" + testflags;
		    suiteProperties.put("testJavaFlags", testJavaFlags);
		}
		String testprops = sp.getProperty("testSpecialProps");
		if (testprops != null)
		{
		    if (testSpecialProps == null || testSpecialProps.length() == 0)
		        testSpecialProps = testprops;
		    else // add to testSpecialProps
		        testSpecialProps = testSpecialProps + "^" + testprops;
		    suiteProperties.put("testSpecialProps", testSpecialProps);
		}
		String clpth = sp.getProperty("classpath");
		if (clpth != null)
		{
		    classpath = clpth;
		    suiteProperties.put("classpath", classpath);
		}
		String clsrv = sp.getProperty("classpathServer");
		if ( (clsrv != null) && (!clsrv.startsWith("${")) )
		{
		    classpathServer = clsrv;
		    suiteProperties.put("classpathServer", clsrv);
		}
		String usesys = sp.getProperty("usesystem");
		if (usesys != null)
		    suiteProperties.put("usesystem", usesys);
		String jarf = sp.getProperty("jarfile");
		if (jarf != null)
		    suiteProperties.put("jarfile", jarf);
		String upgtest = sp.getProperty("upgradetest");
		if (upgtest != null)
		    suiteProperties.put("upgradetest", upgtest);
		String rep = sp.getProperty("replication");
		if (rep != null)
		    suiteProperties.put("replication", rep);
		String encrypt = sp.getProperty("encryption");
		if (encrypt != null)
		    suiteProperties.put("encryption", encrypt);
		String encryptAlgorithm = sp.getProperty("testEncryptionAlgorithm");
		if (encryptAlgorithm != null)
		    suiteProperties.put("testEncryptionAlgorithm", encryptAlgorithm);
		String jdk12test = sp.getProperty("jdk12test");
		if (jdk12test != null)
		    suiteProperties.put("jdk12test", jdk12test);
		String jdk12ex = sp.getProperty("jdk12exttest");
		if (jdk12ex != null)
		    suiteProperties.put("jdk12exttest", jdk12ex);
		String runwithibmjvm = sp.getProperty("runwithibmjvm");
		if (runwithibmjvm != null)
		    suiteProperties.put("runwithibmjvm", runwithibmjvm);
		String excludeJCC = sp.getProperty("excludeJCC");
		if (excludeJCC != null)
		    suiteProperties.put("excludeJCC", excludeJCC);
		String keep = sp.getProperty("keepfiles");
		if (keep != null)
		    suiteProperties.put("keepfiles", keep);
		String outd = sp.getProperty("outputdir");
		if (outd != null)
		{
		    outputdir = outd;
		    suiteProperties.put("outputdir", outputdir);
		}
		String canond = sp.getProperty("canondir");
		if (canond != null)
		{
		    canondir = canond;
		    suiteProperties.put("canondir", canondir);
		}
		String j9bootcp = sp.getProperty("bootcp");
		if (j9bootcp != null)
		{
		    bootcp = j9bootcp;
		    suiteProperties.put("bootcp", bootcp);
		}
		String hostname = sp.getProperty("hostName");
		if (hostname != null)
			suiteProperties.put("hostName", hostname);
		String serverJvm = sp.getProperty("serverJvm");
		if (serverJvm != null)
		    suiteProperties.put("serverJvm", serverJvm);
		String cmlTestEncoding = sp.getProperty("derbyTesting.encoding");
		if (cmlTestEncoding != null)
		    suiteProperties.put("derbyTesting.encoding", cmlTestEncoding);
                String upgradejarpath = sp.getProperty("derbyTesting.jar.path");
                if (upgradejarpath != null)
                    suiteProperties.put("derbyTesting.jar.path", upgradejarpath);
		String testout = sp.getProperty("testoutname");
		if (testout != null)
		    suiteProperties.put("testoutname", testout);
		String mtdir = sp.getProperty("mtestdir"); // used by multi tests
		if (mtdir != null)
		    suiteProperties.put("mtestdir", mtdir);
		String usepr = sp.getProperty("useprocess");
		if (usepr != null)
		{
		    // Some platforms cannot handle process exec
		    usepr = usepr.toLowerCase();
		    if (usepr.equals("false"))
		    {
		        useprocess = false;
		        suiteProperties.put("useprocess", usepr);
		    }
		}
		
        String nosed = sp.getProperty("skipsed");
        if (nosed != null)
        {
            // in some cases (like locales, we may want to skip the Sed)
            nosed = nosed.toLowerCase();
            if (nosed.equals("true"))
            {
                skipsed = true;
                suiteProperties.put("skipsed", nosed);
            }
        }
		
		String sysdiff = sp.getProperty("systemdiff");
		if (sysdiff != null)
		{
		    // Use system diff if set to true
		    sysdiff = sysdiff.toLowerCase();
		    if (sysdiff.equals("true"))
		        suiteProperties.put("systemdiff", "true");
		}
		String defrespckg = sp.getProperty("ij.defaultResourcePackage");
		if (defrespckg != null)
		    suiteProperties.put("ij.defaultResourcePackage", defrespckg);
		String outcpy = sp.getProperty("outcopy");
		if (outcpy != null)
		    suiteProperties.put("outcopy", outcpy);
		String topsuite = sp.getProperty("suitename");
		if (topsuite != null)
		    suiteProperties.put("suitename", topsuite);
		else
		    suiteProperties.put("suitename", topSuiteName);
        String dbug = sp.getProperty("verbose");
		if (dbug != null)
		    suiteProperties.put("verbose", dbug);
		String reporterr = sp.getProperty("reportstderr");
		if (reporterr != null)
		    suiteProperties.put("reportstderr", reporterr);
		String tout = sp.getProperty("timeout");
		if (tout != null)
		    suiteProperties.put("timeout", tout);
    }

    private static void setOutput(String suiteName)
        throws ClassNotFoundException, FileNotFoundException, IOException
    {
        boolean status = false;
        // Use the defined output directory or user.dir by default
        File tmpoutDir;
        if ( (outputdir == null) || (outputdir.length()==0) )
        {
            tmpoutDir =
		        new File((new File(userdir)).getCanonicalPath());
		}
        else
        {
            tmpoutDir =
                new File((new File(outputdir)).getCanonicalPath());
		}
        outDir = tmpoutDir;
        outDir.mkdir();
        
		// runDir is where the suites/tests are run and where
		// any support files or scripts will be expected to live
		runDir =
		    new File((new File(userdir)).getCanonicalPath());
		    
        // Set the suite property outputdir
        suiteProperties.put("outputdir", outDir.getCanonicalPath());

        // Define the final suite summary file file
        outFile = new File(outDir, suiteName + ".sum");
        if (outFile.exists())
            status = outFile.delete();
 
        // Define the suite.pass file
        File passFile = new File(outDir, suiteName + ".pass");
        if (passFile.exists())
            status = passFile.delete();

        // Define the suite.fail file
        File failFile = new File(outDir, suiteName + ".fail");
        if (failFile.exists())
            status = failFile.delete();

        // Create a PrintWriter for writing env and test info to the diff file
        pwOut = new PrintWriter
            (new BufferedWriter(new FileWriter(outFile.getPath()), 4096), true);
    }
}