1 21 22 package org.apache.derbyTesting.functionTests.harness; 23 24 import java.io.File ; 26 import java.io.InputStream ; 27 import java.io.InputStreamReader ; 28 import java.io.BufferedReader ; 29 import java.io.FileReader ; 30 import java.io.FileWriter ; 31 import java.io.FileInputStream ; 32 import java.io.FileOutputStream ; 33 import java.io.BufferedOutputStream ; 34 import java.io.BufferedWriter ; 35 import java.io.FileWriter ; 36 import java.io.PrintWriter ; 37 import java.io.PrintStream ; 38 import java.io.IOException ; 39 import java.io.FileNotFoundException ; 40 import java.lang.ClassNotFoundException ; 41 import java.lang.reflect.Method ; 42 import java.util.Enumeration ; 43 import java.util.Properties ; 44 import java.util.Vector ; 45 import java.util.StringTokenizer ; 46 import java.sql.DriverManager ; 47 import java.sql.SQLException ; 48 49 import org.apache.derbyTesting.functionTests.util.TestUtil; 50 51 52 public class RunList 53 { 54 55 static String jvmName = "currentjvm"; 56 static String javaCmd = "java"; 57 static String javaArgs; 58 static jvm jvm; 59 static String javaVersion; static String majorVersion; 61 static String minorVersion; 62 static String jversion; 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 clientExclusionMessage; 72 static Boolean needIBMjvm = null; 73 static boolean needEncryption = false; 74 static String jvmflags; 75 static String testJavaFlags; 76 static String classpath; 77 static String classpathServer; 78 static String framework; 79 static String usesystem; 80 static String upgradetest; 81 static String jarfile; 82 static String useoutput; 83 static String keepfiles = "false"; 84 static String encryption; 85 static String testEncryptionProvider; 86 static String testEncryptionAlgorithm; 87 static String jdk12test; 88 static String jdk12exttest; 89 static String runwithibmjvm = null; 90 static String runwithj9; 91 static String runwithjvm; 92 static String excludeJCC; 93 static boolean useprocess = true; 94 static String skipsed = "false"; 95 static boolean fw_set = false; 96 static String systemdiff = "false"; 97 static String suiteName = ""; 98 static String fullsuiteName = ""; 99 static String topSuiteName = ""; static String topParentSuite = ""; static String topSpecialProps = ""; static String otherSpecialProps = ""; static String ijdefaultResourcePackage; static String outcopy; static String userdir; static String mtestdir; static boolean verbose = false; static String reportstderr; 109 static String timeout; 110 static String shutdownurl; 111 static PrintWriter pwOut; static String outputdir; static String topsuitedir; static String topreportdir; static String canondir; static String bootcp; static String serverJvm; static String serverJvmName; static File outDir; static File outFile; static File runDir; static File runFile; static Properties suiteProperties; 124 static Properties specialProperties; static BufferedReader runlistFile; 126 static String hostName; 127 static String testEncoding; static String upgradejarpath; static String derbyTestingXaSingle; 132 static String [] clientExclusionKeywords = new String [] { 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 150 151 public RunList(Vector suitesToRun, 152 File runDir, File outDir, PrintWriter pwOut, 153 Properties suiteProperties, 154 Properties specialProperties, 155 String topParentSuite) 156 throws ClassNotFoundException , IOException , Exception 157 { 158 this.runDir = runDir; 159 this.outDir = outDir; 160 this.pwOut = pwOut; 161 this.suiteProperties = suiteProperties; this.specialProperties = specialProperties; this.topSuiteName = suiteProperties.getProperty("suitename"); 164 this.topParentSuite = topParentSuite; 167 169 runSuites(suitesToRun); 171 } 172 173 private static void runSuites(Vector suitesToRun) 174 throws ClassNotFoundException , 175 FileNotFoundException , IOException , Exception 176 { 177 String suiteName = ""; 180 userdir = System.getProperty("user.dir"); 181 Properties p = null; 183 184 setTopSuiteProperties(); 187 Properties topParentSuiteProps = 189 locateSuiteProperties(topParentSuite, suiteProperties, true, true); 190 setSuiteProperties(topParentSuiteProps, topParentSuite, suiteProperties, true, true); 191 192 for (int i = 0; i < suitesToRun.size(); i++) 194 { 195 200 Properties subProps = null; 201 fullsuiteName = (String )suitesToRun.elementAt(i); 202 String subSuite = fullsuiteName.substring(0,fullsuiteName.lastIndexOf(":")); 204 if ( !subSuite.equals(topParentSuite) ) 206 { 207 subProps = locateSuiteProperties(subSuite, topParentSuiteProps, true, false); 208 } 209 else 210 { 211 subProps = topParentSuiteProps; 213 } 214 setSuiteProperties(subProps, subSuite, topParentSuiteProps, true, false); 215 216 suiteName = fullsuiteName.substring(fullsuiteName.lastIndexOf(":")+1); 218 220 p = locateSuiteProperties(suiteName, subProps, false, false); 221 setSuiteProperties(p, suiteName, subProps, false, false); 222 223 String runfile = "suites" + '/' + suiteName + ".runall"; 225 226 InputStream is = org.apache.derbyTesting.functionTests.harness.RunTest.loadTestResource(runfile); 227 if (is == null) 228 { 229 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 runlistFile = new BufferedReader (new InputStreamReader (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 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 File f = new File (outDir, topSuiteName); 259 File skipFile = new File (f, topSuiteName+".skip"); 260 261 PrintStream ps = null; 263 try { ps = new PrintStream 264 ( new FileOutputStream (skipFile.getCanonicalPath(),true) ); } 265 catch (IOException e) { 266 FileWriter fw = new FileWriter (skipFile); 267 fw.close(); 268 ps = new PrintStream 269 ( new FileOutputStream (skipFile.getCanonicalPath(),true) ); 270 } 271 272 if (useprocess == false) { 279 unloadEmbeddedDriver(); 280 } 281 282 System.out.println("Now run the suite's tests"); 283 285 if (skip) { 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 if (jarfile != null) 309 { 310 UnJar uj = new UnJar(); 312 uj.unjar(jarfile, outDir.getCanonicalPath(), true); 313 if ( (upgradetest.equals("true")) && (suiteName.startsWith("convert")) ) 314 { 315 String tmpname = jarfile.substring(0, jarfile.indexOf("JAR")); 318 File tmp = new File (outDir, tmpname); 319 File convert = new File (outDir, usesystem); 320 boolean renamed = tmp.renameTo(convert); 321 } 323 } 324 325 runTests(p, fullsuiteName); 327 } 328 329 String endTime = CurrentTime.getTime(); 330 pwOut.println("**** End SubSuite: " + fullsuiteName + 331 " jdk" + javaVersion + 332 " " + endTime + " ****"); 333 ps.close(); 335 } 336 } 337 } 338 339 340 private static void runTests(Properties suiteProps, String suite) 341 throws IOException , Exception 342 { 343 ManageSysProps.saveSysProps(); 349 350 StringBuffer sb = new StringBuffer (); 352 jvm = jvm.getJvm(jvmName); 353 Vector jvmProps = new Vector (); 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 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 476 Properties sysProps = System.getProperties(); 477 for (Enumeration e = sysProps.keys(); e.hasMoreElements(); ) 478 { 479 String key = (String ) 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 v = jvm.getCommandLine(); 494 v.addElement("org.apache.derbyTesting.functionTests.harness.RunTest"); 495 496 String str = ""; 497 String lastTest = null; 498 String skipTo = System.getProperties().getProperty("skipToFile"); 499 String stopAfter = System.getProperties().getProperty("stopAfterFile"); 500 while ( (str = runlistFile.readLine()) != null ) 503 { 504 if (skipTo != null && !str.equals(skipTo)) 506 continue; 507 else 508 skipTo = null; 509 if (stopAfter != null && lastTest != null && lastTest.equals(stopAfter)) break; 510 String testCmd[] = new String [v.size() + 1]; 513 StringBuffer verboseSb = new StringBuffer (); 514 int i = 0; 515 for (i = 0; i < v.size(); i++) 516 { 517 testCmd[i] = (String )v.elementAt(i); 518 verboseSb.append(testCmd[i] + " "); 519 } 520 testCmd[i++] = str; 521 verboseSb.append(str + " "); 522 525 String 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 Process pr = null; 533 try 534 { 535 pr = Runtime.getRuntime().exec(testCmd); 536 537 BackgroundStreamDrainer stdout = 539 new BackgroundStreamDrainer(pr.getInputStream(), null); 540 BackgroundStreamDrainer stderr = 541 new BackgroundStreamDrainer(pr.getErrorStream(), null); 542 543 pr.waitFor(); 544 545 String result = HandleResult.handleResult(pr.exitValue(), 546 stdout.getData(), stderr.getData(), pwOut, testEncoding); 547 pr.destroy(); 548 } 549 catch(Throwable 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 String [] args = new String [7]; 575 args[0] = str; 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 String tmp = str.substring(str.indexOf("/") + 1, str.lastIndexOf(".")); 594 String diffname = tmp + "." + "diff"; 595 File diffFile = new File (outDir, diffname); 596 if ( (diffFile != null) && (diffFile.exists()) ) 597 { 598 BufferedReader inFile = 599 new BufferedReader (new FileReader (diffFile)); 600 String diffLine = ""; 601 while ( (diffLine = inFile.readLine()) != null ) 602 { 603 pwOut.println(diffLine); 604 } 605 } 606 607 } 608 ManageSysProps.resetSysProps(); 611 lastTest = str; 612 } 613 614 if ((!useprocess) && ((framework !=null) && (framework.startsWith("DerbyNet")))) 621 { 622 try 623 { 624 String stopCmd = javaCmd + 625 " org.apache.derby.drda.NetworkServerControl shutdown"; 626 Process prstop = Runtime.getRuntime().exec(stopCmd); 627 } catch (Exception e) {} } 629 } 630 631 634 public static Properties locateSuiteProperties(String suiteName, 635 Properties parentProps, boolean isParent, boolean isTop) 636 throws ClassNotFoundException , IOException , Exception 637 { 638 String suitePropsName = "suites" + '/' + suiteName + ".properties"; 641 642 InputStream is = org.apache.derbyTesting.functionTests.harness.RunTest.loadTestResource(suitePropsName); 643 if (is == null) 644 { 645 suitePropsName = userdir + '/' + suiteName + ".properties"; 647 is = org.apache.derbyTesting.functionTests.harness.RunTest.loadTestResource(suitePropsName); 648 } 649 Properties p = new Properties (); 650 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 } 662 if (is != null) 663 { 664 p.load(is); 665 is = null; 666 } 667 else 668 { 669 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 ijdefaultResourcePackage = 678 parentProps.getProperty("ij.defaultResourcePackage"); 679 encryption = parentProps.getProperty("encryption"); 681 testEncryptionProvider = parentProps.getProperty("testEncryptionProvider"); 682 testEncryptionAlgorithm = parentProps.getProperty("testEncryptionAlgorithm"); 683 jdk12test = parentProps.getProperty("jdk12test"); 685 jdk12exttest = parentProps.getProperty("jdk12exttest"); 686 runwithj9 = parentProps.getProperty("runwithj9"); 687 runwithibmjvm = parentProps.getProperty("runwithibmjvm"); 688 String 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 702 private static void setTopSuiteProperties() 703 throws ClassNotFoundException , IOException 704 { 705 framework = suiteProperties.getProperty("framework"); 706 707 jversion = suiteProperties.getProperty("jversion"); 708 710 jvmName = suiteProperties.getProperty("jvm"); 711 String 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 724 javaCmd = suiteProperties.getProperty("javaCmd"); 725 if (javaCmd == null) 726 javaCmd = "java"; 727 else if (javaCmd.equals("jview")) 728 jvmName = "jview"; 729 730 String 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 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 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 usepr = suiteProperties.getProperty("useprocess"); 807 if ( (usepr != null) && (usepr.equals("false")) ) 808 useprocess = false; 809 skipsed = suiteProperties.getProperty("skipsed"); 810 String 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 if ( (specialProperties != null) && (!specialProperties.isEmpty()) ) 822 { 823 setSpecialProps(specialProperties, true); 825 } 826 } 827 828 831 private static void setSuiteProperties(Properties p, String suiteName, 832 Properties parentProperties, boolean isParent, boolean isTop) 833 throws ClassNotFoundException , IOException 834 { 835 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 String totaljvmflags = jvmflags; 857 String subjvmflags = p.getProperty("jvmflags"); 858 String 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 if ( parentProperties.getProperty("framework") != null ) 891 p.put("framework", framework); 892 else 893 framework = p.getProperty("framework"); 894 895 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 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 if ( parentProperties.getProperty("encryption") != null ) 923 p.put("encryption", encryption); 924 else 925 encryption = p.getProperty("encryption"); 926 927 if ( parentProperties.getProperty("testEncryptionProvider") != null ) 929 p.put("testEncryptionProvider", testEncryptionProvider); 930 else 931 testEncryptionProvider = p.getProperty("testEncryptionProvider"); 932 933 if ( parentProperties.getProperty("testEncryptionAlgorithm") != null ) 935 p.put("testEncryptionAlgorithm", testEncryptionAlgorithm); 936 else 937 testEncryptionAlgorithm = p.getProperty("testEncryptionAlgorithm"); 938 939 if ( parentProperties.getProperty("jdk12test") != null ) 941 p.put("jdk12test", jdk12test); 942 else 943 jdk12test = p.getProperty("jdk12test"); 944 945 if ( parentProperties.getProperty("jdk12exttest") != null ) 947 p.put("jdk12exttest", jdk12exttest); 948 else 949 jdk12exttest = p.getProperty("jdk12exttest"); 950 951 if ( parentProperties.getProperty("runwithibmjvm") != null ) 953 p.put("runwithibmjvm", runwithibmjvm); 954 else 955 runwithibmjvm = p.getProperty("runwithibmjvm"); 956 957 String 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 if ( parentProperties.getProperty("runwithj9") != null ) 968 p.put("runwithj9", runwithj9); 969 else 970 runwithj9 = p.getProperty("runwithj9"); 971 972 if ( parentProperties.getProperty("excludeJCC") != null ) 974 p.put("excludeJCC", excludeJCC); 975 else 976 excludeJCC = p.getProperty("excludeJCC"); 977 978 String 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 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 1005 String 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 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 = p.getProperty("outcopy"); 1032 1033 useoutput = p.getProperty("useoutput"); 1035 1036 1037 mtestdir = p.getProperty("mtestdir"); 1039 1040 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 setSuiteDir(suiteName, isParent, isTop); 1052 1053 otherSpecialProps = ""; 1056 Properties specialProps = SpecialFlags.getSpecialProperties(p); 1057 if ( (specialProps != null) && (!specialProps.isEmpty()) ) 1058 setSpecialProps(specialProps, false); 1060 } 1061 1062 1071 private static boolean shouldSkipTest() 1072 { 1073 boolean result = false; 1074 1075 boolean isJdk12 = false; 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 1088 driverNotFound = false; 1090 needSync = false; 1091 needJdk12 = false; 1092 needJdk12ext = false; 1093 excludedFromJCC = false; 1094 needIBMjvm = null; 1095 1096 1097 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 (runwithibmjvm != null) 1106 { 1107 if (runwithibmjvm.equals("")) { needIBMjvm = null; } 1108 else { needIBMjvm = new Boolean (runwithibmjvm); } 1109 } 1110 if (runwithibmjvm == null) { needIBMjvm = null; } 1111 if (needIBMjvm != null) 1112 { 1113 boolean needsibm = needIBMjvm.booleanValue(); 1114 boolean ibmjvm = false; 1115 String 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 try { 1132 Class.forName("org.apache.derby.drda.NetworkServerControl"); 1133 } catch (ClassNotFoundException cnfe) { 1134 driverNotFound = true; 1135 result = true; 1136 } 1137 1138 try { 1142 Class.forName("com.ibm.db2.jcc.DB2Driver"); 1143 } catch (ClassNotFoundException cnfe) { 1144 driverNotFound = true; 1145 result = true; 1146 } catch (NoClassDefFoundError err) { 1147 driverNotFound = true; 1148 result = true; 1149 } 1150 } 1151 } 1152 1153 if (result) return true; 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 if (!isJdk12) 1164 { 1165 if ( (isEncryption) || (isJdk12Test) || (isJdk12ExtTest) ) 1166 { 1167 needJdk12 = true; 1168 result = true; } 1170 if (result) return true; } 1172 1173 if ( (isEncryption) || (isJdk12ExtTest) ) 1175 { 1176 needJdk12ext = true; 1177 try 1179 { 1180 Class jtaClass = Class.forName("javax.transaction.xa.Xid"); 1181 Class jdbcClass = Class.forName("javax.sql.RowSet"); 1182 } 1183 catch (ClassNotFoundException cnfe) 1184 { 1185 result = true; } 1188 if (result) return true; } 1190 1191 if (isEncryption) { 1193 needEncryption = true; 1194 try 1195 { 1196 Class jceClass = Class.forName("javax.crypto.Cipher"); 1197 } 1198 catch (ClassNotFoundException cnfe) 1199 { 1200 result = true; 1201 } 1202 if (result) return true; 1203 } 1204 1205 if (excludeJCC != null) 1206 { 1207 Class c = null; 1208 Method m = null; 1209 Object o = null; 1210 Integer 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 )m.invoke(o, null); 1219 jccMajor = i.intValue(); 1220 m = c.getMethod("getMinorVersion", null); 1221 i = (Integer )m.invoke(o, null); 1222 jccMinor = i.intValue(); 1223 } catch (Exception 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 e) { 1230 excludedFromJCC = true; 1231 clientExclusionMessage = e.getMessage(); 1232 return true; 1233 } 1234 } 1235 1236 return result; } 1238 1239 1240 public static void setSuiteDir(String suiteName, boolean isParent, boolean isTop) 1241 throws IOException 1242 { 1243 if (isTop) { 1245 if ( (topsuitedir == null) || (topsuitedir.length() == 0) ) 1247 { 1248 topsuitedir = userdir; 1249 outputdir = topsuitedir; 1250 } 1251 else 1252 outputdir = topsuitedir; 1253 1254 File topdir = new File (outputdir, topSuiteName); 1256 topdir.mkdir(); 1257 if (!topParentSuite.equals(topSuiteName)) 1258 { 1259 File topparent = new File (topdir, topParentSuite); 1260 topparent.mkdir(); 1261 outputdir = topparent.getCanonicalPath(); 1262 } 1263 else 1264 outputdir = topdir.getCanonicalPath(); 1265 topreportdir = outputdir; 1266 1270 if ( (framework != null) && (framework.length()>0) ) 1272 { 1273 File f = new File (outputdir, framework); 1274 f.mkdir(); 1275 outputdir = f.getCanonicalPath(); 1276 fw_set = true; } 1279 topsuitedir = outputdir; 1280 } 1281 else if (isParent) { 1283 outputdir = topsuitedir; 1284 if (!suiteName.equals(topParentSuite)) 1286 { 1287 File suitedir = new File (outputdir, suiteName); 1288 suitedir.mkdir(); 1289 outputdir = suitedir.getCanonicalPath(); 1290 } 1291 if (!fw_set) 1293 { 1294 if ( (framework != null) && (framework.length()>0) ) 1295 { 1296 File f = new File (outputdir, framework); 1297 f.mkdir(); 1298 outputdir = f.getCanonicalPath(); 1299 } 1300 } 1301 } 1302 1303 else if ( upgradetest == null ) { 1305 File suitedir = new File (outputdir, suiteName); 1306 suitedir.mkdir(); 1307 outputdir = suitedir.getCanonicalPath(); 1308 } 1310 } 1311 1312 private static void setSpecialProps(Properties p, boolean isTop) 1313 { 1314 String tmp = ""; 1319 for (Enumeration e = p.propertyNames(); e.hasMoreElements(); ) 1320 { 1321 String key = (String )e.nextElement(); 1322 tmp += key + "=" + p.getProperty(key) + "^"; 1325 } 1326 if (tmp.length()>0) 1327 { 1328 if ( isTop == true ) topSpecialProps = tmp.substring(0, tmp.lastIndexOf('^')); 1330 else otherSpecialProps = tmp.substring(0, tmp.lastIndexOf('^')); 1332 } 1333 } 1334 1335 static void addToSkipFile(String suiteName, PrintStream ps) throws IOException 1336 { 1337 ps.println(suiteName); 1338 ps.flush(); 1339 } 1340 1341 1357 public static void checkClientExclusion(String exclusion, 1358 String clientName, int clientMajor, int clientMinor, 1359 String javaVersion) throws Exception 1360 { 1361 1362 if (exclusion == null) 1363 return; 1365 1366 int clientComparisonType = 0; 1371 int jvmComparisonType = 0; 1372 1373 exclusion = exclusion.toLowerCase(); 1374 String clientVersion = null; 1375 1376 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 e) { 1386 System.out.println("exclusion property poorly formatted: " + exclusion); 1387 return; 1388 } 1389 1390 boolean jvmDependent; 1392 if (comma == -1) 1393 jvmDependent = false; 1394 else { 1395 jvmDependent = true; 1396 String jvmVersion = exclusion.substring(comma+6); 1399 try { 1400 jvmComparisonType = getVersionCompareType(jvmVersion); 1401 } catch (Exception e) { 1402 System.out.println("exclusion property poorly formatted: " + exclusion); 1403 return; 1404 } 1405 } 1406 1407 int [] excludeInfo = null; 1412 try { 1413 excludeInfo = getVersionArray(exclusion, 5); 1414 } catch (Exception e) { 1415 System.out.println("Unexpected text in exclusion property: " + e.getMessage()); 1416 return; 1417 } 1418 1419 if (versionExcluded(new int [] {clientMajor, clientMinor}, 0, 1422 excludeInfo, 0, 2, clientComparisonType)) 1423 { 1424 1425 if (!jvmDependent) { 1426 throw new Exception ("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 int [] jvmInfo = null; 1435 try { 1436 jvmInfo = getVersionArray(javaVersion, 3); 1437 } catch (Exception 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 ("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 1477 private static int [] getVersionArray(String versionString, int resultSize) 1478 throws Exception 1479 { 1480 1481 if (versionString == null) 1482 versionString = ""; 1485 1486 int [] result = new int[resultSize]; 1487 1488 String tok = null; 1489 String text = null; 1490 StringTokenizer st = new StringTokenizer (versionString, ".,_"); 1491 for (int i = 0; i < resultSize; i++) { 1492 1493 if (!st.hasMoreTokens()) { 1494 result[i] = -1; 1496 continue; 1497 } 1498 1499 tok = st.nextToken(); 1501 int pos = 0; 1502 for (; !Character.isDigit(tok.charAt(pos)); pos++); 1503 text = tok.substring(0, pos); 1504 1505 if ((text.length() > 0) && !isClientExclusionKeyword(text)) 1508 throw new Exception (text); 1509 1510 tok = tok.substring(pos); 1512 if (tok.length() == 0) { 1513 i--; 1515 continue; 1516 } 1517 1518 result[i] = Integer.parseInt(tok); 1519 1520 } 1521 1522 return result; 1523 1524 } 1525 1526 1540 private static int getVersionCompareType(String versionString) 1541 throws Exception 1542 { 1543 1544 if (versionString == null) 1545 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 ("bad exclusion property format"); 1556 } 1557 1558 return -1; 1559 1560 } 1561 1562 1589 private static boolean versionExcluded(int [] vActual, int offset1, 1590 int [] vTarget, int offset2, int numParts, int comparisonType) 1591 { 1592 1593 int compareLen = (vActual.length >= vTarget.length ? vTarget.length : vActual.length); 1598 compareLen = (compareLen <= numParts ? compareLen : numParts); 1599 1600 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 1619 if (compareLen == numParts) 1620 return true; 1622 1623 return (comparisonType * vActual.length > comparisonType * vTarget.length); 1624 1625 } 1626 1627 1634 private static boolean isClientExclusionKeyword(String 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 1653 private static void unloadEmbeddedDriver() { 1654 if (TestUtil.HAVE_DRIVER_CLASS) 1657 try { 1658 DriverManager.getConnection("jdbc:derby:;shutdown=true"); 1659 } catch (SQLException se) { 1660 } 1662 1663 System.gc(); 1666 } 1667} 1668 1669 | Popular Tags |