1 21 22 package org.apache.derbyTesting.functionTests.harness; 23 24 import org.apache.derby.tools.sysinfo; 25 import org.apache.derby.tools.ij; 26 import org.apache.derby.iapi.reference.Attribute; 27 28 import java.io.File ; 29 import java.io.InputStream ; 30 import java.io.InputStreamReader ; 31 import java.io.ByteArrayInputStream ; 32 import java.io.BufferedReader ; 33 import java.io.FileReader ; 34 import java.io.FileWriter ; 35 import java.io.FileInputStream ; 36 import java.io.FileOutputStream ; 37 import java.io.BufferedOutputStream ; 38 import java.io.BufferedWriter ; 39 import java.io.FileWriter ; 40 import java.io.OutputStreamWriter ; 41 import java.io.PrintWriter ; 42 import java.io.PrintStream ; 43 import java.io.IOException ; 44 import java.io.FileNotFoundException ; 45 import java.lang.ClassNotFoundException ; 46 import java.lang.ClassFormatError ; 47 import java.lang.Thread ; 48 import java.lang.reflect.Method ; 49 import java.util.Enumeration ; 50 import java.util.Locale ; 51 import java.util.Vector ; 52 import java.sql.Timestamp ; 53 import java.sql.Connection ; 54 import java.sql.SQLException ; 55 import java.sql.DriverManager ; 56 import java.util.Properties ; 57 import java.util.StringTokenizer ; 58 import java.net.URL ; 59 60 import junit.framework.TestSuite; 61 62 public class RunTest 63 { 64 65 static boolean verbose=false; 67 static boolean skiptest = false; 69 static StringBuffer skiptestReason = new StringBuffer (); 70 71 static final String testResourceHome = "/org/apache/derbyTesting/functionTests/"; 73 74 static String [] validFrameworks = {"embedded","", 76 "DerbyNet","DerbyNetClient", "DB2jcc", 77 "DB2app"}; 78 static NetServer ns; 79 static boolean serverNeedsStopping = false; static boolean jvmnet = false; static String jvmnetjvm; static String driverName; 83 static String dbName; 84 85 static String jvmName = "currentjvm"; 87 static String javaCmd; 88 static String javaVersion; static String majorVersion; 90 static String minorVersion; 91 static int jccMajor; 92 static int jccMinor; 93 static int imajor; 94 static int iminor; 95 static boolean isjdk12test = false; 96 static String classpath = ""; 97 static String classpathServer = ""; 98 public static String framework = "embedded"; 99 public static String J9_STATEMENTCACHESIZE = "20"; 100 101 static String usesystem = ""; 102 static String searchCP = ""; 103 static boolean useCommonDB = false; 104 static boolean keepfiles = false; 105 static boolean useprocess = true; 106 static boolean systemdiff = false; static boolean upgradetest = false; 108 static boolean encryption = false; static boolean jdk12exttest = false; static boolean generateUTF8Out = false; static String runningdir = ""; static String outputdir = ""; static String canondir; static String bootcp; static String canonpath; static String mtestdir = ""; static String testSpecialProps = ""; static String testJavaFlags = ""; static String jvmflags; static boolean reportstderr = true; 121 static int timeout = -1; public static String timeoutStr; 123 static String jarfile; static boolean skipsed = false; 125 static String commonDBHome = "testCSHome"; 126 static boolean dbIsNew = true; 127 static String runwithjvm="true"; 128 static boolean startServer=true; static String hostName; static String testEncoding; static String upgradejarpath; static boolean replacePolicyFile=false; 134 static String scriptName = ""; static String scriptFileName; static String testDirName = ""; static String defaultPackageName = "/org/apache/derbyTesting/"; 139 static String javaPath = "org.apache.derbyTesting."; static String testType; static String testBase; static String testOutName; static String passFileName; static String failFileName; static String UTF8OutName; static String tempMasterName; static File passFile; 148 static File failFile; 149 static String shutdownurl = ""; 150 static boolean useOutput; static boolean outcopy; static String userdir; static char fileSep; static PrintWriter printWriter = null; static PrintWriter pwDiff = null; static File script; static File baseDir; static boolean deleteBaseDir; static File outDir; static File runDir; static File canonDir; static File tmpOutFile; static File tempMasterFile; static File stdOutFile; static File finalOutFile; static File UTF8OutFile; static File appPropFile; static File clPropFile; static File diffFile; static File tsuiteDir; static File rsuiteDir; static File extInDir; static File extOutDir; static File extInOutDir; 176 static String topsuitedir = ""; static String topsuiteName = ""; 180 static String topreportdir = ""; 181 static String suiteName = ""; 182 static boolean isSuiteRun = false; 183 static boolean lastTestFailed = false; 184 185 static boolean isI18N = false; 186 188 static String codeset = null; 189 static boolean junitXASingle = false; 190 191 197 static boolean runWithoutSecurityManager; 198 199 static InputStream isSed = null; 201 public static void main(String [] args) 202 throws Exception 203 { 204 Locale.setDefault(Locale.US); 205 skiptestReason.setLength(0); if (args.length == 0) 208 { 209 System.out.println("no test name provided"); 211 System.exit(1); 212 } 213 scriptName = args[0]; 214 215 if (Boolean.getBoolean("listOnly")) 216 { 217 System.out.println("LISTONLY :" + scriptName); 218 return; 219 } 220 221 if ( (scriptName == null) || (scriptName.equals("")) ) 222 { 223 System.out.println("Null or blank test script name."); 224 System.exit(1); 225 } 226 if (args.length == 7) 228 { 229 defaultPackageName = args[1]; 230 usesystem = args[2]; 231 useprocess = false; 232 shutdownurl = args[4]; 233 isSuiteRun = true; 234 suiteName = args[5]; 235 framework=args[6]; 237 startServer=true; 240 } 241 242 testType = scriptName.substring(scriptName.lastIndexOf(".") + 1); 243 244 verifyTestType(); 245 246 Properties sp = System.getProperties(); 248 249 if (useprocess == false) 251 { 252 sp.put("useprocess", "false"); 253 if ( sp.getProperty("maximumDisplayWidth") == null ) 256 sp.put("maximumDisplayWidth", "128"); 257 if ( sp.getProperty("ij.defaultResourcePackage") != null ) 258 sp.put("ij.defaultResourcePackage", defaultPackageName); 259 System.setProperties(sp); 260 } 261 262 JavaVersionHolder jvhs = getProperties(sp); 263 boolean isJDBC4 = jvhs.atLeast( 1, 6 ); 264 265 setDirectories(scriptName,sp); 267 268 if (testDirName.startsWith("i18n")) { 269 isI18N=true; 270 } 271 272 String propString = createPropString(); 275 if ( (isSuiteRun == false) && (useprocess) ) 276 { 277 SysInfoLog sysLog = new SysInfoLog(); 278 sysLog.exec(jvmName, javaCmd, classpath, framework, pwDiff, useprocess); 279 } 280 281 String startTime = CurrentTime.getTime(); 282 StringBuffer sb = new StringBuffer (); 283 sb.append("*** Start: " + testBase + " jdk" + javaVersion + " "); 284 if ( (framework.length()>0) && (!framework.startsWith("embedded")) ) 285 sb.append(framework + " "); 286 if ( (suiteName != null) && (suiteName.length()>0) ) 287 sb.append(suiteName + " "); 288 sb.append(startTime + " ***"); 289 System.out.println(sb.toString()); 290 pwDiff.println(sb.toString()); 291 292 if ((driverName != null) && (!skiptest) ) 294 { 295 composePolicyFile(); 298 String spacedJvmFlags = jvmflags; 299 if ((jvmflags != null) && (jvmflags.indexOf("^")>0)) 301 { 302 spacedJvmFlags = spaceJvmFlags(jvmflags); 303 } 304 305 System.out.println("Initialize for framework: "+ framework ); 306 if (jvmnet && framework.startsWith("DerbyNet")) 307 { 308 String jvmnetjvm = System.getProperty("serverJvmName"); 310 if (jvmnetjvm == null) 311 { 312 jvmnetjvm = "j9_22"; 314 } 315 316 ns = new NetServer(baseDir, jvmnetjvm, classpathServer, null, 317 spacedJvmFlags,framework, startServer); 318 } 319 else 320 ns = new NetServer(baseDir, jvmName, classpathServer, 321 javaCmd, spacedJvmFlags,framework, startServer); 322 323 if ((!useprocess) && (isSuiteRun)) 337 { 338 boolean started = false; 339 try 340 { 341 started = ns.testNetworkServerConnection(); 342 } 343 catch (Exception e) {} if (!started && startServer) 345 ns.start(); if (started && !startServer) 347 ns.stop(); 348 } 349 else 350 { 351 ns.start(); 352 serverNeedsStopping = true; 353 } 354 } 355 356 357 358 if (jarfile != null) 360 { 361 UnJar uj = new UnJar(); 362 uj.unjar(jarfile, outDir.getCanonicalPath(), true); 363 } 364 365 if (skiptest == false) 367 { 368 testRun(propString, sp); 369 } 370 else 371 { 372 if (skiptestReason.length() == 0) 373 addSkiptestReason("Test skipped: skiptest set without setting skiptestReason, please fix RunTest.java..."); 374 pwDiff.println(skiptestReason); 375 System.out.println(skiptestReason); 376 doCleanup(javaVersion); 377 return; 378 } 379 380 if (serverNeedsStopping) 382 { 383 ns.stop(); 384 } 385 386 389 String outName = finalOutFile.getPath(); 390 391 if (skipsed) 392 { 393 tmpOutFile.renameTo(finalOutFile); 394 } 395 else 396 { 397 try 398 { 399 Sed sed = new Sed(); 400 sed.exec(tmpOutFile,finalOutFile, isSed, 401 NetServer.isClientConnection(framework), isI18N, isJDBC4); 402 } 403 catch (ClassFormatError cfe) 404 { 405 if (verbose) System.out.println("SED Error: " + cfe.getMessage()); 406 } 407 } 408 String frameworkMaster = framework; 411 if (framework.startsWith("embedded")) 412 frameworkMaster = ""; 413 FileCompare diff = new FileCompare(); 414 415 if (verbose) 416 { 417 System.out.println( 418 "About to execute: diff.exec(" + 419 " outName = " + outName + 420 ",outDir = " + outDir + 421 ",pwDiff = " + pwDiff + 422 ",testOutName = " + testOutName + 423 ",frameworkMaster = " + frameworkMaster + 424 ",jvmName = " + jvmName + 425 ",iminor = " + iminor + 426 ",useprocess = " + useprocess + 427 ",systemdiff = " + systemdiff + 428 ",canondir = " + canondir + 429 ",canonpath = " + canonpath + 430 ")\n"); 431 } 432 433 boolean status; 434 435 if (jvmnet) 437 { 438 if (jvmnetjvm == null) 440 { 441 jvmnetjvm = "j9_22"; 443 } 444 status = diff.exec(outName, outDir, pwDiff, testOutName, 445 frameworkMaster, jvmName, iminor, useprocess, systemdiff, canondir, 446 canonpath, jvmnetjvm); 447 } 448 else 449 status = diff.exec(outName, outDir, pwDiff, testOutName, 450 frameworkMaster, jvmName, iminor, useprocess, systemdiff, canondir, 451 canonpath, null); 452 453 if (status == true) 454 { 455 lastTestFailed = true; 456 pwDiff.println("Test Failed."); 457 System.out.println("Test Failed."); 458 keepfiles = true; 459 addToFailures(scriptName); 460 if (useCommonDB) { 461 status = baseDir.delete(); 462 } 464 } 465 else 466 { 467 addToSuccesses(scriptName); 468 pwDiff.flush(); 469 } 470 471 generateUTF8OutFile(finalOutFile); 472 473 doCleanup(javaVersion); 475 } 476 477 private static void testRun(String propString, Properties sysProp) 478 throws FileNotFoundException , IOException , Exception 479 { 480 String systemHome = baseDir.getPath(); 481 String scriptPath = null; 482 if (testType.startsWith("sql")) 483 scriptPath = script.getPath(); 484 485 if (useCommonDB == true 487 && (usesystem == null || usesystem == "") 488 && (testType.equals("sql") || testType.equals("java") 489 || testType.equals("sql2"))) { 490 dbcleanup.doit(dbIsNew); 491 } 492 493 494 if ( useprocess ) 496 { 497 String [] testCmd = 499 buildTestCommand(propString, systemHome, scriptPath); 500 execTestProcess(testCmd); 501 } 502 else 503 { 504 execTestNoProcess(sysProp, systemHome, propString, scriptPath); 505 } 506 } 507 508 512 private static void setDirectories(String scriptName, Properties sp) 513 throws ClassNotFoundException , FileNotFoundException , IOException 514 { 515 userdir = sp.getProperty("user.dir"); 517 518 if (useprocess == false) 520 defaultPackageName = "/org/apache/derbyTesting/"; 521 522 if (useCommonDB == true) 524 { 525 defaultPackageName = "/org/apache/derbyTesting/"; 526 } 527 528 String resourceName = defaultPackageName + "functionTests/tests/"; 531 int index = scriptName.lastIndexOf('/'); 535 if (index == -1) { 537 if ( (!testType.equals("sql")) && (!testType.equals("java")) && (!testType.equals("junit"))) 538 { 539 System.out.println("Test argument should be of the form: <dir>/<test>.<ext>"); 540 System.exit(1); 541 } 542 else 543 { 544 scriptFileName = scriptName; resourceName += scriptName; } 547 } 548 else { 550 testDirName = (index==0)?"":scriptName.substring(0,index); 551 scriptFileName = scriptName.substring(index+1, scriptName.length()); 553 if (testType.equals("multi")) 555 defaultPackageName = defaultPackageName + "functionTests/multi/" + testDirName + "/"; 556 else 557 defaultPackageName = defaultPackageName + "functionTests/tests/" + testDirName + "/"; 558 resourceName = defaultPackageName + scriptFileName; 560 } 562 563 564 testBase = scriptFileName.substring(0, scriptFileName.lastIndexOf("."+testType)); 566 567 if (testType.equals("java") || testType.equals("junit")) 568 { 569 String tmp = defaultPackageName.replace('/', '.'); 571 int tl = tmp.length()-1; 572 javaPath = (tl==0)?"":tmp.substring(1, tl); 573 } 574 575 if ( (runningdir != null) && (runningdir.length()>0) ) 577 { 578 if (File.separatorChar == '\\') 579 { 580 String runningdirWin = convertPathForWin(runningdir); 582 runDir = new File ((new File (runningdirWin)).getCanonicalPath()); 583 } 584 else 585 { 586 runDir = new File ((new File (runningdir)).getCanonicalPath()); 587 } 588 } 589 590 File tmpoutDir; 592 String userdirWin = null; 593 594 if ( (outputdir == null) || (outputdir.length()==0) ) 595 { 596 if (File.separatorChar == '\\') 597 { 598 userdirWin = convertPathForWin(userdir); 600 tmpoutDir = new File ((new File (userdirWin)).getCanonicalPath()); 601 } 602 else 603 { 604 tmpoutDir = 605 new File ((new File (userdir)).getCanonicalPath()); 606 } 607 } 608 else 609 { 610 if (File.separatorChar == '\\') 611 { 612 String outputdirWin = convertPathForWin(outputdir); 613 tmpoutDir = 614 new File ((new File (outputdirWin)).getCanonicalPath()); 615 } 616 else 617 { 618 tmpoutDir = 619 new File ((new File (outputdir)).getCanonicalPath()); 620 } 621 } 622 623 if ( (!isSuiteRun) && (!framework.startsWith("embedded")) ) 628 { 629 runDir = tmpoutDir; 630 outDir = new File (tmpoutDir, framework); 631 outDir.mkdir(); 632 } 633 else { 635 outDir = tmpoutDir; 636 outDir.mkdir(); 637 if ( (topsuitedir != null) && (topsuitedir.length()>0) ) 638 { 639 if (File.separatorChar == '\\') 640 { 641 String topsuitedirWin = convertPathForWin(topsuitedir); 642 tsuiteDir = 643 new File ((new File (topsuitedirWin)).getCanonicalPath()); 644 } 645 else 646 { 647 tsuiteDir = new File ((new File (topsuitedir)).getCanonicalPath()); 648 } 649 } 650 else 651 { 652 tsuiteDir = outDir; 653 } 654 tsuiteDir.mkdir(); 655 if ( (topreportdir != null) && (topreportdir.length()>0) ) 656 { 657 if (File.separatorChar == '\\') 658 { 659 String topreportdirWin = convertPathForWin(topreportdir); 660 rsuiteDir = 661 new File ((new File (topreportdirWin)).getCanonicalPath()); 662 } 663 else 664 { 665 rsuiteDir = 666 new File ((new File (topreportdir)).getCanonicalPath()); 667 } 668 } 669 else 670 { 671 rsuiteDir = outDir; 672 } 673 rsuiteDir.mkdir(); 674 } 675 676 fileSep = File.separatorChar; 677 678 if ( testType.equals("multi") ) 681 if ( (mtestdir == null) || (mtestdir.length()==0) ) 682 mtestdir = outDir.getPath(); 684 685 if ( (!testType.equals("java")) && 688 (!testType.equals("junit")) && 689 (!testType.equals("unit")) && 690 (!testType.equals("multi")) ) 691 { 692 InputStream is = 695 loadTestResource("tests/" + testDirName + "/" + scriptFileName); 696 697 if (is == null) 698 { 699 System.out.println("Could not locate " + scriptName); 700 addToFailures(scriptName); 701 throw new FileNotFoundException (resourceName); 702 } 703 704 BufferedReader in = new BufferedReader (new InputStreamReader (is, "UTF-8")); 707 if (upgradetest) 708 709 try { script = new File ((new File (userdir, scriptFileName)).getCanonicalPath()); } 712 catch (IOException e) { 713 File f = new File (userdir, scriptFileName); 714 FileWriter fw = new FileWriter (f); 715 fw.close(); 716 script = new File (f.getCanonicalPath()); 717 } 718 else 720 try { script = new File ((new File (outDir, scriptFileName)).getCanonicalPath()); } 721 catch (IOException e) { 722 File f = new File (outDir, scriptFileName); 723 FileWriter fw = new FileWriter (f); 724 fw.close(); 725 script = new File (f.getCanonicalPath()); 726 } 727 728 PrintWriter pw = null; 729 pw = new PrintWriter ( new BufferedWriter 730 (new FileWriter (script.getPath()), 10000), true ); 731 732 String str = ""; 733 while ( (str = in.readLine()) != null ) 734 { 735 pw.println(str); 736 } 737 pw.close(); 738 pw = null; 739 in = null; 740 } 741 742 baseDir = null; 744 745 if (useCommonDB == true) 746 { 747 if (File.separatorChar == '\\') 748 { 749 String commonDBHomeWin = convertPathForWin(commonDBHome); 750 baseDir = new File (userdirWin, commonDBHomeWin); 751 } 752 else 753 { 754 baseDir = new File (userdir, commonDBHome); 755 } 756 } 757 else if ( (!useprocess) && isSuiteRun && ((usesystem==null) || (usesystem.length()<=0)) ) 758 { 759 String suite = (suiteName.substring(0,suiteName.indexOf(':'))); 760 if (File.separatorChar == '\\') 761 { 762 String useprWin = convertPathForWin(suite); 763 baseDir = new File (outDir, useprWin); 764 } 765 else 766 { 767 baseDir = new File (outDir, suite); 768 } 769 } 770 else if ( (usesystem != null) && (usesystem.length()>0) ) 771 { 772 if (File.separatorChar == '\\') 773 { 774 String usesystemWin = convertPathForWin(usesystem); 775 if (upgradetest == true) 776 baseDir = new File (userdirWin, usesystemWin); 777 else 778 baseDir = new File (outDir, usesystemWin); 779 } 780 else 781 { 782 if (upgradetest == true) 783 baseDir = new File (userdir, usesystem); 784 else 785 baseDir = new File (outDir, usesystem); 786 } 787 } 788 else 789 { 790 if (File.separatorChar == '\\') 791 { 792 String testBaseWin = convertPathForWin(testBase); 793 baseDir = new File (outDir, testBaseWin); 794 } 795 else 796 { 797 baseDir = new File (outDir, testBase); 798 } 799 } 800 801 if (baseDir.exists()) 808 { 809 if (useCommonDB == false || lastTestFailed == true) { 810 cleanupBaseDir(baseDir); 811 lastTestFailed = false; 812 } 813 else if (useCommonDB == true) 814 dbIsNew = false; } 816 else { 817 818 boolean created = baseDir.mkdir(); 819 dbIsNew = true; } 821 822 if ( (usesystem == null) || (usesystem.length()<=0) ) 824 deleteBaseDir = true; else 826 deleteBaseDir = false; 828 829 if ( testOutName == null ) 832 { 833 if (testType.equals("demo")) 834 testOutName = testBase.substring(testBase.indexOf(".")+1); 835 else 836 testOutName = testBase; 837 } 838 839 tmpOutFile = new File (outDir, testOutName + ".tmp"); 841 tempMasterName = testOutName+".tmpmstr"; 844 UTF8OutName = testOutName+".utf8out"; 845 finalOutFile = new File (outDir, testOutName + ".out"); 847 848 diffFile = new File (outDir, testOutName + ".diff"); 850 stdOutFile = new File (outDir, testOutName + ".std"); 851 852 if ( isSuiteRun ) 854 { 855 String sname = suiteName.substring(0,suiteName.indexOf(":")); 856 passFileName = sname+".pass"; 859 passFile = new File (rsuiteDir, passFileName); 860 failFileName = sname+".fail"; 861 failFile = new File (rsuiteDir, failFileName); 862 } 863 else 864 { 865 passFileName=testBase+".pass"; 866 passFile = new File (outDir, passFileName); 867 failFileName=testBase+".fail"; 868 failFile = new File (outDir, failFileName); 869 } 870 boolean status = true; 872 873 if (tmpOutFile.exists()) 875 status = tmpOutFile.delete(); 876 tempMasterFile = new File (outDir, tempMasterName); 877 if (tempMasterFile.exists()) 878 status = tempMasterFile.delete(); 879 if (finalOutFile.exists()) 880 status = finalOutFile.delete(); 881 if (diffFile.exists()) 882 status = diffFile.delete(); 883 if (stdOutFile.exists()) 884 status = stdOutFile.delete(); 885 UTF8OutFile = new File (outDir, UTF8OutName); 886 if (UTF8OutFile.exists()) 887 status = UTF8OutFile.delete(); 888 889 if (!isSuiteRun) 891 { 892 if (failFile.exists()) 893 status = failFile.delete(); 894 if (passFile.exists()) 895 status = passFile.delete(); 896 } 897 898 if (status == false) 899 System.out.println("Unable to delete tmp, out and/or diff files to start"); 900 901 pwDiff = new PrintWriter 903 (new BufferedWriter (new FileWriter (diffFile.getPath()), 4096), true); 904 } 905 906 private static JavaVersionHolder getProperties(Properties sp) 907 throws Exception 908 { 909 911 if ((jvmflags != null) && (jvmflags.length() > 0)) 914 { 915 StringTokenizer st = new StringTokenizer (jvmflags,"^"); 916 while (st.hasMoreTokens()) 917 { 918 String tmpstr = st.nextToken(); 919 if ((tmpstr.indexOf("=")> 0) && (tmpstr.startsWith("-D"))) 920 { 921 String key = tmpstr.substring(2, tmpstr.indexOf("=")); 923 String value = tmpstr.substring((tmpstr.indexOf("=") +1), tmpstr.length()); 924 sp.put(key, value); 925 } 926 } 927 } 928 929 searchCP = sp.getProperty("ij.searchClassPath"); 930 String frameworkp = sp.getProperty("framework"); 931 if (frameworkp != null) 932 framework = frameworkp; 933 if (framework == null) 934 framework = "embedded"; 935 if (!verifyFramework(framework)) 936 framework = ""; 937 else 938 driverName = NetServer.getDriverName(framework); 939 String junitXAProp = sp.getProperty ("derbyTesting.xa.single"); 940 if (junitXAProp != null && junitXAProp.equals ("true")) { 941 junitXASingle = true; 942 } 943 hostName = sp.getProperty("hostName"); 944 if (hostName == null) 946 hostName="localhost"; 947 948 String generateUTF8OutProp = sp.getProperty("generateUTF8Out"); 949 if (generateUTF8OutProp != null && generateUTF8OutProp.equals("true")) 950 generateUTF8Out = true; 951 952 String skipFile = framework + ".exclude"; 955 if (!framework.equals("")) 956 { 957 skiptest = (SkipTest.skipIt(skipFile, scriptName)); 958 if (!skiptest) 961 { 962 if (!hostName.equals("localhost")) 963 { 964 skipFile = framework + "Remote.exclude"; 965 skiptest = (SkipTest.skipIt(skipFile, scriptName)); 966 } 967 } 968 if (skiptest) addSkiptestReason("Test skipped: listed in " + skipFile + 970 " file, skipping test: " + scriptName); 971 } 972 973 jvmName = sp.getProperty("jvm"); 974 975 if ( (jvmName == null) || (jvmName.length()==0) || (jvmName.equals("jview"))) 977 { 978 javaVersion = System.getProperty("java.version"); 979 } 981 else 982 javaVersion = jvmName; 983 984 String javavmVersion; 986 if (sp.getProperty("java.vm.name").equals("J9")) 987 javavmVersion = (sp.getProperty("java.vm.version")); 988 else 989 javavmVersion = javaVersion; 990 991 992 JavaVersionHolder jvh = new JavaVersionHolder(javavmVersion); 993 majorVersion = jvh.getMajorVersion(); 994 minorVersion = jvh.getMinorVersion(); 995 iminor = jvh.getMinorNumber(); 996 imajor = jvh.getMajorNumber(); 997 998 if ( (jvmName == null) || (!jvmName.equals("jview")) ) 999 { 1000 if ( (iminor < 2) && (imajor < 2) ) 1001 jvmName = "currentjvm"; 1002 else 1003 { 1004 if (System.getProperty("java.vm.vendor").startsWith("IBM")) 1005 { 1006 if (System.getProperty("java.vm.name").equals("J9")) 1007 { 1008 if (System.getProperty("com.ibm.oti.configuration").equals("foun10")) 1009 { 1010 jvmName = "j9_foundation"; 1011 } 1012 else 1013 { 1014 javaVersion = javaVersion + " - " + majorVersion + "." + minorVersion; 1016 if ((imajor <= 2) && (iminor < 2)) 1019 { 1020 majorVersion = "1"; 1021 minorVersion = "3"; 1022 imajor = 1; 1023 iminor = 3; 1024 } 1025 jvmName = "j9_" + majorVersion + minorVersion; 1026 } 1027 } 1028 else 1029 jvmName = "ibm" + majorVersion + minorVersion; 1030 } 1031 else 1032 jvmName = "jdk" + majorVersion + minorVersion; 1033 } 1034 } 1035 1036 String specversion = (sp.getProperty("java.specification.version")); 1039 JavaVersionHolder jvhs = new JavaVersionHolder(specversion); 1040 1041 testEncoding = sp.getProperty("derbyTesting.encoding"); 1042 upgradejarpath = sp.getProperty("derbyTesting.jar.path"); 1043 if ((testEncoding != null) && (!jvmName.equals("jdk15"))) 1044 { 1045 skiptest = true; 1046 addSkiptestReason("derbyTesting.encoding can only be used with jdk15, skipping test"); 1047 } 1048 1049 String replace_policy = sp.getProperty("derbyTesting.replacePolicyFile"); 1050 if ((replace_policy != null) && (replace_policy.equals("true"))) 1051 replacePolicyFile=true; 1052 else 1053 replacePolicyFile=false; 1054 1055 javaCmd = sp.getProperty("javaCmd"); 1056 bootcp = sp.getProperty("bootcp"); 1057 jvmflags = sp.getProperty("jvmflags"); 1058 testJavaFlags = sp.getProperty("testJavaFlags"); 1059 classpath = sp.getProperty("classpath"); 1060 classpathServer = sp.getProperty("classpathServer"); 1062 if ( (classpathServer == null) || (classpathServer.startsWith("${")) ) 1063 classpathServer = classpath; 1064 jarfile = sp.getProperty("jarfile"); 1066 String upg = sp.getProperty("upgradetest"); 1067 if (upg != null) 1068 { 1069 upg = upg.toLowerCase(); 1070 if (upg.equals("true")) 1071 upgradetest = true; 1072 } 1073 1074 if ( framework.equals("DerbyNet") && (! jvmName.equals("j9_foundation"))) 1075 { 1076 1077 Class c = null; 1078 Method m = null; 1079 Object o = null; 1080 Integer i = null; 1081 try 1082 { 1083 c = Class.forName("com.ibm.db2.jcc.DB2Driver"); 1084 o = c.newInstance(); 1085 m = c.getMethod("getMajorVersion", null); 1086 i = (Integer )m.invoke(o, null); 1087 jccMajor = i.intValue(); 1088 m = c.getMethod("getMinorVersion", null); 1089 i = (Integer )m.invoke(o, null); 1090 jccMinor = i.intValue(); 1091 } catch (ClassNotFoundException e) {} 1092 1093 String excludeJcc = sp.getProperty("excludeJCC"); 1094 try { 1095 RunList.checkClientExclusion(excludeJcc, "JCC", jccMajor, jccMinor, javaVersion); 1096 } catch (Exception e) { 1097 skiptest = true; 1098 addSkiptestReason(e.getMessage()); 1099 } 1100 } 1101 1102 String sysdiff = sp.getProperty("systemdiff"); 1103 if (sysdiff != null) 1104 { 1105 sysdiff = sysdiff.toLowerCase(); 1106 if (sysdiff.equals("true")) 1107 systemdiff = true; 1108 } 1109 String keep = sp.getProperty("keepfiles"); 1110 if (keep != null) 1111 { 1112 keep = keep.toLowerCase(); 1113 if (keep.equals("true")) 1114 keepfiles = true; 1115 } 1116 String encrypt = sp.getProperty("encryption"); 1117 if ( (encrypt != null) && (encrypt.equalsIgnoreCase("true")) ) 1118 encryption = true; 1119 String jdk12ext = sp.getProperty("jdk12exttest"); 1120 if ( (jdk12ext != null) && (jdk12ext.equalsIgnoreCase("true")) ) 1121 jdk12exttest = true; if ( encryption || jdk12exttest ) 1123 { 1124 if ( iminor < 2 ) { 1127 skiptest = true; 1128 addSkiptestReason("Test skipped: encryption or jdk12exttest requires jdk12 or higher; this is jdk1"+iminor+", skipping test: " + scriptFileName); 1129 } 1130 else { 1132 try 1133 { 1134 Class jtaClass = Class.forName("javax.transaction.xa.Xid"); 1135 } 1136 catch (ClassNotFoundException cnfe) 1137 { 1138 skiptest = true; 1140 addSkiptestReason("Test skipped: javax.transaction.xa.Xid not found, skipping test: " + scriptFileName); 1141 } 1142 try 1143 { 1144 Class jdbcClass = Class.forName("javax.sql.RowSet"); 1145 } 1146 catch (ClassNotFoundException cnfe2) 1147 { 1148 skiptest = true; 1150 addSkiptestReason("Test skipped: javax.sql.RowSet not found, skipping test: " + scriptFileName); 1151 } 1152 } 1153 } 1154 runningdir = sp.getProperty("rundir"); 1155 if (runningdir == null) 1156 runningdir = ""; 1157 outputdir = sp.getProperty("outputdir"); 1158 if (outputdir == null) 1159 outputdir = ""; 1160 1161 canondir = sp.getProperty("canondir"); 1162 canonpath = sp.getProperty("canonpath"); 1163 1164 testOutName = sp.getProperty("testoutname"); 1165 useOutput = new Boolean (sp.getProperty("useoutput","true")).booleanValue(); 1166 outcopy = new Boolean (sp.getProperty("outcopy","false")).booleanValue(); 1167 mtestdir = sp.getProperty("mtestdir"); if (mtestdir == null) 1169 mtestdir = ""; 1170 1171 String usepr = sp.getProperty("useprocess"); 1172 if (usepr != null) 1173 { 1174 usepr = usepr.toLowerCase(); 1175 if (usepr.equals("false")) 1176 useprocess = false; 1177 else 1178 useprocess = true; 1179 } 1180 else 1181 useprocess = true; 1182 1183 1184 if (!hostName.equals("localhost")) 1188 { 1189 startServer=false; 1190 } 1191 1192 String nosed = sp.getProperty("skipsed"); 1193 if (nosed != null) 1194 { 1195 nosed = nosed.toLowerCase(); 1196 if (nosed.equals("true")) 1197 skipsed = true; 1198 } 1199 1200 1201 String dbug = sp.getProperty("verbose"); 1202 if (dbug != null) 1203 { 1204 dbug = dbug.toLowerCase(); 1205 if (dbug.equals("true")) 1206 verbose = true; 1207 } 1208 String rstderr = sp.getProperty("reportstderr"); 1209 if (rstderr != null) 1210 { 1211 rstderr = rstderr.toLowerCase(); 1212 if (rstderr.equals("false")) 1213 reportstderr = false; 1214 } 1215 1216 if (timeoutStr == null) 1218 { 1219 timeoutStr = sp.getProperty("timeout", "-1"); 1220 } 1222 else 1223 { 1224 } 1226 1227 try 1228 { 1229 timeout = Integer.parseInt(timeoutStr); 1230 } 1231 catch (NumberFormatException nfe) 1232 { 1233 timeout = -1; 1234 } 1235 1236 1238 testSpecialProps = sp.getProperty("testSpecialProps"); 1239 1240 if (useprocess) 1241 { 1242 String defrespckg = sp.getProperty("ij.defaultResourcePackage"); 1243 if (defrespckg != null) { 1245 defaultPackageName = defrespckg; 1246 if (!defaultPackageName.endsWith("/")) 1247 defaultPackageName += "/"; 1248 } 1249 usesystem = sp.getProperty("usesystem"); 1250 } 1251 1252 if ((jvmName.startsWith("j9")) && (!jvmName.equals("j9_foundation")) && testType.equals("junit")) 1255 { 1256 skiptest = true; 1257 addSkiptestReason("Test skipped: cannot run junit test with j9 jvms because of security manager issue in the jvm"); 1258 } 1259 1260 1261 if (!useprocess && !skiptest ) 1264 { 1265 String tsuiteName = null; 1266 if (suiteName != null) 1267 tsuiteName = suiteName; 1268 else 1269 tsuiteName = sp.getProperty("suitename"); 1270 if ( (tsuiteName != null) && (tsuiteName.length()>0) ) 1271 { 1272 skipFile = framework + "Useprocess.exclude"; 1273 if (!framework.equals("")) 1274 { 1275 skiptest = (SkipTest.skipIt(skipFile, scriptName)); 1276 if (skiptest) 1277 { 1278 skiptest=true; 1279 addSkiptestReason("Test " + scriptName + " skipped, " + 1280 "listed in " + framework + "Useprocess.exclude file."); 1281 } 1282 } 1283 } 1284 } 1285 1286 if ( (useprocess) || (suiteName == null) ) 1287 { 1288 if (useprocess) 1289 suiteName = sp.getProperty("suitename"); 1290 if ( (suiteName != null) && (suiteName.length()>0) ) 1291 { 1292 isSuiteRun = true; 1294 if (useprocess) 1295 topsuiteName = sp.getProperty("topsuitename"); 1297 topsuitedir = sp.getProperty("topsuitedir"); 1298 topreportdir = sp.getProperty("topreportdir"); 1299 } 1300 } 1301 String uscdb = sp.getProperty("useCommonDB"); 1302 if (uscdb != null && uscdb.equals("true")) 1303 useCommonDB = true; 1304 1305 return jvhs; 1306 } 1307 1308 private static String createPropString() 1309 throws ClassNotFoundException , FileNotFoundException , IOException 1310 { 1311 String propString = ""; 1315 1316 BufferedReader in = null; 1318 BufferedOutputStream bos = null; 1319 BufferedOutputStream bos2 = null; 1320 String str = ""; 1321 1322 InputStream isCl = null; InputStream isClDef = null; InputStream isAp = null; InputStream isApDef = null; 1328 String clDefProp = "tests/" + testDirName + "/" + "default_derby.properties"; 1330 String apDefProp = null; 1331 if (useCommonDB) 1332 apDefProp = "tests/" + testDirName + "/" + "commonDB_app.properties"; 1333 else 1334 apDefProp = "tests/" + testDirName + "/" + "default_app.properties" ; 1335 1336 Properties clp = new Properties (); 1338 Properties ap = new Properties (); 1339 1340 Properties ijProps = new Properties (); 1343 Properties srvProps = new Properties (); 1344 if ( (testSpecialProps != null) && (testSpecialProps.length()>0)) 1345 { 1346 SpecialFlags.parse(testSpecialProps, ijProps, srvProps); 1347 } 1348 1349 1352 1353 isClDef = loadTestResource(clDefProp); 1355 isCl = loadTestResource("tests/" + testDirName + "/" + testBase + "_derby.properties"); 1357 1362 if (isCl != null) { 1365 clp.load(isCl); 1366clp.list(System.out); 1367 } 1368 else if (isClDef != null) 1370 { 1371 clp.load(isClDef); 1372 } 1373 1374 if (jvmName.startsWith("j9")) 1377 { 1378 if (clp.getProperty("derby.language.statementCacheSize")==null) 1379 clp.put("derby.language.statementCacheSize", J9_STATEMENTCACHESIZE); 1380 } 1381 1382 if ( clp.isEmpty() ) 1385 { 1386 if ( !srvProps.isEmpty() ) 1388 clp = srvProps; 1389 } 1390 else 1391 { 1392 if ( !srvProps.isEmpty() ) 1394 { 1395 for (Enumeration e = srvProps.propertyNames(); e.hasMoreElements();) 1396 { 1397 String key = (String )e.nextElement(); 1398 String value = srvProps.getProperty(key); 1399 if (key.equals("derby.debug.true")) { 1401 String cval = clp.getProperty("derby.debug.true"); 1402 if (cval != null) 1405 { 1406 if (cval.length() != 0) { 1407 value = value + "," + cval; 1409 } else { 1410 value = ""; 1413 } 1414 } 1415 } 1416 clp.put(key,value); 1417 } 1418 } 1419 } 1420 1421 if ( !clp.isEmpty() ) 1422 { 1423 1425 try { clPropFile = new File ((new File (baseDir, "derby.properties")).getCanonicalPath()); } 1428 catch (IOException e) { 1429 File f = new File (baseDir, "derby.properties"); 1430 FileWriter fw = new FileWriter (f); 1431 fw.close(); 1432 clPropFile = new File (f.getCanonicalPath()); 1433 } 1434 1435 bos = new BufferedOutputStream (new FileOutputStream (clPropFile)); 1437 clp.store(bos, "Derby Properties"); 1438 bos.close(); 1439 } 1440 1441 1452 if ( testType.equals("multi") ) 1453 isSed = loadTestResource("multi/stress/" + testBase + "_sed.properties"); 1454 else 1455 isSed = loadTestResource("tests/" + testDirName + "/" + testBase + "_sed.properties"); 1456 1462 Properties dp = new Properties (); 1466 String testPropName = null; 1467 String testPropSDName = null; if (useCommonDB) testPropName = "CDB" + testBase + "_app.properties"; 1469 else testPropName = testBase + "_app.properties"; 1470 1471 isApDef = loadTestResource(apDefProp); 1473 1474 1476 if ( testType.equals("multi") ) 1477 isAp = loadTestResource("multi/" + testDirName + "/" + testBase + "_app.properties"); 1478 else 1479 isAp = loadTestResource("tests/" + testDirName + "/" + testBase + "_app.properties"); 1480 1485 1486 if ( isAp != null ) 1489 { 1490 ap.load(isAp); 1491 for (Enumeration e = ap.propertyNames(); e.hasMoreElements(); ) 1493 { 1494 String key = (String )e.nextElement(); 1495 String value = ap.getProperty(key); 1496 if ( (key.equals("usedefaults")) && (value.equals("true")) ) 1497 { 1498 if ( isApDef != null ) 1500 { 1501 dp.load(isApDef); 1502 mergeProps(ap, dp); 1503 break; 1504 } 1505 } 1506 } 1507 } 1508 else 1509 { 1510 if ( isApDef != null ) 1512 ap.load(isApDef); 1513 } 1514 1515 if ( ap.isEmpty() ) 1517 { 1518 if ( !ijProps.isEmpty() ) 1519 ap = ijProps; 1520 } 1521 else 1522 { 1523 if ( !ijProps.isEmpty() ) 1525 { 1526 for (Enumeration e = ijProps.propertyNames(); e.hasMoreElements();) 1527 { 1528 String key = (String )e.nextElement(); 1529 String value = ijProps.getProperty(key); 1530 ap.put(key,value); 1531 } 1532 } 1533 } 1534 1535 if ( !ap.isEmpty() ) 1536 { 1537 try 1541 { 1542 appPropFile = new File ((new File (baseDir, testPropName)).getCanonicalPath()); 1543 } 1544 catch (IOException e) 1545 { 1546 File f = new File (baseDir, testPropName); 1547 FileWriter fw = new FileWriter (f); 1548 fw.close(); 1549 appPropFile = new File (f.getCanonicalPath()); 1550 } 1551 1552 String conEnc = System.getProperty("console.encoding"); 1558 String fileEnc = System.getProperty("file.encoding"); 1559 1560 if (ap.getProperty("derby.ui.codeset") != null) { 1561 codeset = ap.getProperty("derby.ui.codeset"); 1563 } else if (isI18N) { 1564 ap.put("derby.ui.codeset", "UTF-8"); 1565 } else if ((conEnc != null) && (fileEnc != null ) && 1566 conEnc.startsWith("Cp850")) 1567 { 1568 ap.put("derby.ui.codeset",fileEnc); 1569 } 1570 1571 if (verbose) 1572 System.out.println("console.encoding:" + conEnc + 1573 " file.encoding:" + fileEnc + 1574 " derby.ui.codeset: " + ap.getProperty("derby.ui.codeset")); 1575 1576 if (System.getProperty("ij.dataSource") != null) 1582 { 1583 ap.remove("ij.database"); 1584 ap.remove("ij.protocol"); 1585 } 1586 1587 bos = new BufferedOutputStream (new FileOutputStream (appPropFile)); 1589 ap.store(bos, "App Properties"); 1590 bos.close(); 1591 1592 String apppropsjvmflags = ap.getProperty("jvmflags"); 1597 if (apppropsjvmflags != null) 1598 { 1599 if (jvmflags != null) 1600 jvmflags = apppropsjvmflags + "^" + jvmflags; 1601 else 1602 jvmflags = apppropsjvmflags; 1603 } 1604 if ((jvmflags != null) && (jvmflags.length() > 0)) 1607 { 1608 StringTokenizer st = new StringTokenizer (jvmflags,"^"); 1609 while (st.hasMoreTokens()) 1610 { 1611 1612 String tmpstr = st.nextToken(); 1613 if ((tmpstr.indexOf("=")> 0) && (tmpstr.startsWith("-D"))) 1614 { 1615 String key = tmpstr.substring(2, tmpstr.indexOf("=")); 1617 String value = tmpstr.substring((tmpstr.indexOf("=")+1), tmpstr.length()); 1618 ap.put(key, value); 1619 } 1620 } 1621 } 1622 1623 if ( (framework.length()>0) || (encryption) ) 1625 { 1626 try 1627 { 1628 if (!framework.equals("") && 1629 !framework.equals("embedded")) 1630 frameworkProtocol(ap); 1631 else if (encryption) 1632 encryptionProtocol(ap); 1633 } 1634 catch(Exception e) 1635 { 1636 System.out.println("Exception: " + e.getMessage()); 1637 e.printStackTrace(); 1638 } 1639 1640 appPropFile = new File (baseDir, testBase + "_app.properties"); 1642 try 1643 { 1644 bos = new BufferedOutputStream (new FileOutputStream (appPropFile)); 1645 ap.store(bos, "Test Properties"); 1646 bos.close(); 1647 } 1648 catch(IOException ioe) 1649 { 1650 System.out.println("IOException creating prop file: " + ioe.getMessage()); 1651 } 1652 } 1653 } 1654 1655 if ( (appPropFile != null) && (appPropFile.exists()) ) 1656 { 1657 propString = appPropFile.getPath(); 1659 1660 shutdownurl = ap.getProperty("shutdown"); 1662 1663 String jdk12test = ap.getProperty("jdk12test"); 1665 if (jdk12test != null) 1668 { 1669 if (jdk12test.toLowerCase().equals("true")) 1670 { 1671 isjdk12test = true; 1672 if (jvmName.equals("currentjvm")) { skiptest = true; 1675 addSkiptestReason("Test skipped: test needs jdk12, jvm is reporting currentjvm; skipping test: " + scriptFileName); 1676 } 1677 } 1678 } 1679 1680 String srvJvm = System.getProperty("serverJvm"); 1681 if (srvJvm !=null) 1682 jvmnet = true; 1683 1684 String excludeJcc = ap.getProperty("excludeJCC"); 1685 if ( framework.equals("DerbyNet") ) 1686 { 1687 try { 1688 RunList.checkClientExclusion(excludeJcc, "JCC", jccMajor, jccMinor, javaVersion); 1689 } catch (Exception e) { 1690 skiptest = true; 1691 addSkiptestReason(e.getMessage()); 1692 } 1693 } 1694 1695 String testJVM = jvmName; 1699 if (jvmName.startsWith("j9")) 1700 { 1701 if (jvmName.equals("j9_foundation")) 1702 testJVM = "foundation"; 1703 else 1704 testJVM = "j9"; 1705 } 1706 runwithjvm = ap.getProperty("runwith" + testJVM); 1707 if ((runwithjvm != null) && (runwithjvm.equalsIgnoreCase("false"))) 1708 { 1709 skiptest = true; 1710 addSkiptestReason("Test skipped: test cannot run with jvm: " + 1711 jvmName + ". " + scriptFileName); 1712 } 1713 String startServerProp = ap.getProperty("startServer"); 1716 if (startServerProp != null && 1717 startServerProp.equalsIgnoreCase("false")) 1718 startServer =false; 1719 1720 if(testEncoding == null) { 1722 testEncoding = ap.getProperty("derbyTesting.encoding"); 1723 if ((jvmName.equals("jdk15")) && (testEncoding != null)) 1725 { 1726 jvmflags = (jvmflags==null?"":jvmflags+" ") 1727 + "-Dfile.encoding=" + testEncoding; 1728 ap.put("file.encoding",testEncoding); 1729 } 1730 } 1731 1732 if(!replacePolicyFile) 1733 { 1734 String replace_policy = ap.getProperty("derbyTesting.replacePolicyFile"); 1735 if (replace_policy != null && replace_policy.equals("true")) 1736 replacePolicyFile = true; 1737 else 1738 replacePolicyFile = false; 1739 1740 } 1741 1742 1743 if (NetServer.isJCCConnection(framework) 1744 || "true".equalsIgnoreCase(ap.getProperty("noSecurityManager"))) 1745 runWithoutSecurityManager = true; 1746 1747 String suppFiles = ap.getProperty("supportfiles"); 1749 boolean copySupportFiles = ((suppFiles != null) && (suppFiles.length()>0)); 1750 boolean createExtDirs= new Boolean (ap.getProperty("useextdirs","false")).booleanValue(); 1751 if (copySupportFiles || createExtDirs) 1752 { 1753 File copyOutDir = null; 1754 1755 if (testType.equals("sql2")) 1756 { 1757 if ( (isSuiteRun) || (framework.length()>0) ) 1758 copyOutDir = outDir; 1759 else if ( (runDir != null) && (runDir.exists()) ) 1760 copyOutDir = runDir; 1761 else 1762 copyOutDir = outDir; 1763 } 1764 else if ( testType.equals("multi") ) 1765 { 1766 if ( (isSuiteRun) || (mtestdir == null) || (mtestdir.length()==0) ) 1767 { 1768 copyOutDir = outDir; 1769 } 1770 else 1771 { 1772 File multiDir = new File (mtestdir); 1773 copyOutDir = multiDir; 1774 } 1775 } 1776 else if ( outcopy == true ) 1777 copyOutDir = outDir; 1778 else if ( (runDir != null) && (runDir.exists()) ) 1779 { 1780 copyOutDir = runDir; 1781 } 1782 else 1783 copyOutDir = outDir; 1784 1785 if(createExtDirs) 1786 { 1787 extInDir = copyOutDir; 1788 extInDir = new File (copyOutDir , "extin"); 1790 if(!extInDir.exists()) 1791 extInDir.mkdirs(); 1792 extOutDir = new File (copyOutDir , "extout"); 1794 if(!extOutDir.exists()) 1795 extOutDir.mkdirs(); 1796 extInOutDir = new File (copyOutDir , "extinout"); 1798 if(!extInOutDir.exists()) 1799 extInOutDir.mkdirs(); 1800 copyOutDir = extInDir; 1801 } 1802 if(copySupportFiles) 1803 CopySuppFiles.copyFiles(copyOutDir, suppFiles); 1804 } 1805 else 1806 { 1807 extInDir = null; 1810 extOutDir = null; 1811 extInOutDir = null; 1812 } 1813 } 1814 return propString; 1815 } 1816 1817 public static String setTestJavaFlags(String tflags) 1818 { 1819 StringBuffer sb = new StringBuffer (); 1820 if (verbose) System.out.println("testJavaflags: " + tflags); 1821 String dintro = "-D"; 1822 try 1823 { 1824 dintro = jvm.getJvm(jvmName).getDintro(); 1825 } 1826 catch (Exception e) 1827 { 1828 System.out.println("Problem getting jvm "+jvmName+" Dintro: "); 1829 e.printStackTrace(System.out); 1830 System.exit(1); 1831 } 1832 StringTokenizer st = new StringTokenizer (tflags,"^"); 1834 while (st.hasMoreTokens()) 1835 { 1836 String token = st.nextToken(); 1837 if (! (token.startsWith("-"))) { sb.append(dintro); } 1838 sb.append(token); 1839 sb.append(" "); 1840 } 1841 if (verbose) System.out.println("setTestJavaFlags returning: " + sb.toString()); 1842 return sb.toString(); 1843 } 1844 1845 private static void loadProps(Properties p, File f) throws Exception 1846 { 1847 if (f.canRead()) 1848 { 1849 FileInputStream fis = new FileInputStream (f); 1850 p.load(fis); 1851 fis.close(); 1852 } 1853 } 1854 1855 private static void mergeProps(Properties to, Properties from) 1856 { 1857 for (Enumeration e = from.propertyNames(); e.hasMoreElements(); ) 1858 { 1859 String key = (String )e.nextElement(); 1860 to.put(key, from.getProperty(key)); 1861 } 1862 } 1863 1864 1865 1866 private static void frameworkProtocol(Properties p) throws Exception 1867 { 1868 1869 if (p == null) 1870 { 1871 return; 1873 } 1874 for (Enumeration e = p.propertyNames(); e.hasMoreElements(); ) 1875 { 1876 String key = (String )e.nextElement(); 1877 String value = p.getProperty(key); 1878 1879 if (key.equals("driver") || key.equals("ij.driver") || key.equals("jdbc.drivers")) 1880 { 1881 p.put(key, driverName); 1882 } 1883 else if (key.startsWith("ij.protocol") || key.equals("protocol")) 1884 { 1885 value = NetServer.alterURL(framework,value); 1886 p.put(key, value); 1887 } 1888 else if (key.equals("database") || key.equals("ij.database") || key.startsWith("ij.connection") || key.equals("jdbc.url")) 1889 { 1890 dbName = value.substring(value.lastIndexOf(':') + 1 , 1891 value.length()); 1892 value = NetServer.alterURL(framework,value); 1893 p.put(key, value); 1894 } 1895 else p.put(key, value); 1897 1898 } 1899 1900 1901 if (NetServer.isJCCConnection(framework)) 1905 { 1906 String user = System.getProperty("ij.user"); 1907 if (user == null) user = "APP"; 1908 p.put("ij.user",user); 1909 } 1910 1911 if (NetServer.isClientConnection(framework)) 1913 { 1914 String password = System.getProperty("ij.password"); 1915 if (password == null) password = "APP"; 1916 p.put("ij.password",password); 1917 } 1918 1919 if (NetServer.isJCCConnection(framework)) 1920 { 1921 p.put("ij.retrieveMessagesFromServerOnGetMessage","true"); 1923 } 1924 1925 if (driverName != null) 1928 p.put("ij.driver",driverName); 1929 } 1930 1931 1932 private static void encryptionProtocol(Properties p) throws Exception 1933 { 1934 String encryptUrl = "dataEncryption=true;bootPassword=Thursday"; 1935 1936 if (p == null) 1937 { 1938 return; 1940 } 1941 1942 String v = p.getProperty("testEncryptionAlgorithm"); 1944 if (v != null) 1945 encryptUrl += ";" + Attribute.CRYPTO_ALGORITHM + "=" + v; 1946 v = p.getProperty("testEncryptionProvider"); 1947 if (v != null) 1948 encryptUrl += ";" + Attribute.CRYPTO_PROVIDER + "=" + v; 1949 1950 for (Enumeration e = p.propertyNames(); e.hasMoreElements(); ) 1951 { 1952 String key = (String )e.nextElement(); 1953 String value = p.getProperty(key); 1954 1955 if (key.equals("database") || key.equals("ij.database") || key.startsWith("ij.connection") || key.equals("jdbc.url")) 1956 { 1957 int index = value.indexOf(encryptUrl); 1959 if ( index == -1) 1960 { 1961 value = value + ";" + encryptUrl; 1962 } 1963 p.put(key, value); 1964 } 1965 else if (key.equals("testEncryptionAlgorithm") || key.equals("testEncryptionProvider")) 1966 {} else p.put(key, value); 1969 } 1970 } 1971 1972 private static void cleanupBaseDir(File baseDir) 1973 { 1974 boolean okToDelete = false; 1976 1977 if ( (usesystem == null) || (usesystem.length()==0) ) 1978 okToDelete = true; 1979 else if (usesystem.equals("nist")) 1980 { 1981 if (testBase.equals("schema1")) 1982 okToDelete = true; 1983 } 1984 else if (usesystem.equals("puzzles")) 1985 { 1986 if (testBase.equals("puzzleschema")) 1987 okToDelete = true; 1988 } 1989 1990 if (useCommonDB) okToDelete = false; 1991 1992 if (okToDelete == true) 1993 { 1994 deleteFile(baseDir); 1996 if (baseDir.exists()) 1997 System.out.println("baseDir did not get deleted which could cause test failures"); 1998 else 1999 baseDir.mkdir(); 2000 } 2001 } 2002 2003 private static void doCleanup(String javaVersion) 2004 throws IOException 2005 { 2006 boolean status = true; 2007 2014 if ( !(script == null) && (script.exists()) && (!keepfiles) ) 2016 { 2017 status = script.delete(); 2018 } 2020 2021 String endTime = CurrentTime.getTime(); 2022 StringBuffer sbend = new StringBuffer (); 2023 sbend.append("*** End: " + testBase + " jdk" + javaVersion + " "); 2024 if ( (framework.length()>0) && (!framework.startsWith("embedded")) ) 2025 sbend.append(framework + " "); 2026 if ( (suiteName != null) && (suiteName.length()>0) ) 2027 sbend.append(suiteName + " "); 2028 sbend.append(endTime + " ***"); 2029 System.out.println(sbend.toString()); 2030 pwDiff.println(sbend.toString()); 2031 pwDiff.flush(); 2032 pwDiff.close(); 2033 pwDiff = null; 2034 2035 if (keepfiles == false) 2037 { 2038 status = tmpOutFile.delete(); 2040 if (status == false) 2041 tmpOutFile = null; 2042 status = finalOutFile.delete(); 2043 if (skiptest == false) 2044 status = diffFile.delete(); 2045 tempMasterFile = new File (outDir, tempMasterName); 2047 status = tempMasterFile.delete(); 2048 UTF8OutFile = new File (outDir, UTF8OutName); 2049 status = UTF8OutFile.delete(); 2050 File defaultPolicyFile = new File (userdir, "derby_tests.policy"); 2051 if (defaultPolicyFile.exists()) 2052 status = defaultPolicyFile.delete(); 2053 if (deleteBaseDir) 2054 { 2055 if (useCommonDB == false) 2056 { 2057 deleteFile(baseDir); 2059 } 2060 else 2061 { 2062 status = appPropFile.delete(); 2063 } 2069 2070 if (extInDir!=null) deleteFile(extInDir); 2073 if (extOutDir!=null) deleteFile(extOutDir); 2074 if (extInOutDir!=null) deleteFile(extInOutDir); 2075 } 2076 } 2077 keepfiles = false; 2087 2088 } 2089 2090 2094 public static void deleteFile(File f) 2095 { 2096 boolean status = true; 2097 if (f == null) 2098 { 2099 System.out.println(f.getName() + " is null"); 2100 return; 2101 } 2102 if (!f.exists()) 2103 { 2104 System.out.println(f.getName() + " does not exist; harness error"); 2105 return; 2106 } 2107 2108 status = f.delete(); 2110 2111 if (status == true) 2112 return; 2113 else 2114 { 2115 if (!f.isDirectory()) 2117 { 2118 System.out.println("Could not delete file " + f.getName() + ", going on"); 2119 return; 2120 } 2121 String [] files = f.list(); 2123 for (int i = 0; i < files.length; i++) 2124 { 2125 File sub = new File (f.getPath(), files[i]); 2126 if (sub == null) 2127 continue; 2128 status = sub.delete(); 2130 if (status != true) 2131 { 2132 if ( sub.isDirectory() ) 2134 { 2135 deleteFile(sub); 2137 status = sub.delete(); 2139 } 2141 } 2145 } 2146 } 2147 status = f.delete(); 2149 if (status == false) 2150 { 2151 System.out.println("Warning: Cleanup failed on baseDir: " + f.getPath()); 2152 } 2153 } 2154 2155 static void addToFailures(String testName) throws IOException 2156 { 2157 if (failFileName==null) 2158 { 2159 if (isSuiteRun) failFileName = suiteName+".fail"; 2160 else failFileName=testBase+".fail"; 2161 } 2162 addToListFile(failFileName,testName); 2163 } 2164 2165 static void addToSuccesses(String testName) throws IOException 2166 { 2167 if (passFileName==null) 2168 { 2169 if (isSuiteRun) passFileName = suiteName+".pass"; 2170 else passFileName=testBase+".pass"; 2171 } 2172 addToListFile(passFileName,testName); 2173 } 2174 2175 static void addToListFile(String fileName, String testName) throws IOException 2176 { 2177 File f; 2178 if (isSuiteRun) 2179 f = new File (rsuiteDir,fileName); 2180 else 2181 f = new File (outDir,fileName); 2182 PrintStream ps = null; 2183 2184 try { ps = new PrintStream ( new FileOutputStream (f.getCanonicalPath(),true) ); } 2187 catch (IOException e) { 2188 FileWriter fw = new FileWriter (f); 2189 fw.close(); 2190 ps = new PrintStream ( new FileOutputStream (f.getCanonicalPath(),true) ); 2191 } 2192 2193 ps.println(testName); 2194 ps.flush(); 2195 ps.close(); 2196 } 2197 2198 static void appendStderr(BufferedOutputStream bos, InputStream is) 2199 throws IOException 2200 { 2201 PrintWriter tmpPw = new PrintWriter (bos); 2202 BufferedReader errReader = new BufferedReader (new InputStreamReader (is, "UTF-8")); 2204 String s = null; 2205 int lines = 0; 2206 while ((s = errReader.readLine()) != null) 2207 { 2208 tmpPw.println(s); 2209 } 2210 errReader.close(); 2211 tmpPw.flush(); 2212 } 2213 2214 static void verifyTestType() 2215 throws ClassNotFoundException , FileNotFoundException , IOException 2216 { 2217 InputStream is = 2219 loadTestResource("harness/testtypes.properties"); 2220 Properties p = new Properties (); 2221 p.load(is); 2222 String testtypes = p.getProperty("testtypes"); 2223 StringTokenizer st = new StringTokenizer (testtypes,","); 2224 String ttype = ""; 2225 while (st.hasMoreTokens()) 2226 { 2227 ttype = st.nextToken(); 2228 if ( testType.equals(ttype) ) 2229 return; 2230 } 2231 System.out.println("Unknown test type: " + testType); 2233 System.exit(1); 2234 } 2235 2236 public static void 2237 addStandardTestJvmProps(Vector testJvmProps,String derbySystemHome, 2238 String userDirName, jvm jvm) 2239 { 2240 if (derbySystemHome==null || derbySystemHome.length() == 0) 2241 derbySystemHome = userDirName; 2242 testJvmProps.addElement("derby.system.home=" + derbySystemHome); 2243 testJvmProps.addElement("derby.infolog.append=true "); 2244 } 2248 2249 private static String [] buildTestCommand(String propString, 2250 String systemHome, String scriptPath) 2251 throws FileNotFoundException , IOException , Exception 2252 { 2253 composePolicyFile(); 2254 2255 String ij = ""; 2257 if (testType.equals("sql")) 2259 ij = "ij"; 2260 jvm jvm = null; jvm = jvm.getJvm(jvmName); 2262 if (javaCmd != null) 2263 jvm.setJavaCmd(javaCmd); 2264 2265 if ( (classpath != null) && (classpath.length()>0) ) 2266 jvm.setClasspath(classpath); 2267 2268 Vector jvmProps = new Vector (); 2269 if ( testType.equals("java") || testType.equals("demo") ) 2270 addStandardTestJvmProps(jvmProps,systemHome, 2271 outDir.getCanonicalPath(),null); 2272 else if ( (runDir != null) && (runDir.exists()) ) 2273 addStandardTestJvmProps(jvmProps,systemHome, 2274 runDir.getCanonicalPath(),jvm); 2275 else 2276 addStandardTestJvmProps(jvmProps,systemHome, 2277 outDir.getCanonicalPath(),jvm); 2278 2279 if ( (testJavaFlags != null) && (testJavaFlags.length()>0) ) 2280 { 2281 String parsedFlags = setTestJavaFlags(testJavaFlags); 2282 StringTokenizer st = new StringTokenizer (parsedFlags," "); 2283 while (st.hasMoreTokens()) 2284 { 2285 jvmflags = (jvmflags==null?"":jvmflags) + " " + st.nextToken(); 2286 } 2287 } 2288 2289 if ( ij.startsWith("ij") ) 2290 jvmProps.addElement("ij.defaultResourcePackage=" + 2291 defaultPackageName); 2292 2293 if ( (framework != null) ) 2294 { 2295 jvmProps.addElement("framework=" + framework); 2296 if ((hostName != null) && (!hostName.equals("localhost"))) 2297 jvmProps.addElement("hostName=" + hostName); 2298 } 2299 2300 if (junitXASingle) 2301 jvmProps.addElement ("derbyTesting.xa.single=true"); 2302 2303 if ((testEncoding != null) && (jvmName.equals("jdk15"))) 2305 { 2306 jvmProps.addElement("derbyTesting.encoding=" + testEncoding); 2307 jvmProps.addElement("file.encoding=" + testEncoding); 2308 jvmflags = (jvmflags==null?"":jvmflags+" ") 2309 + "-Dfile.encoding=" + testEncoding; 2310 } else if (isI18N) { 2311 jvmProps.addElement("file.encoding=UTF-8"); 2315 jvmflags = (jvmflags==null ? "" : jvmflags + " ") + 2316 "-Dfile.encoding=UTF-8"; 2317 } 2318 2319 if (upgradejarpath != null) 2320 jvmProps.addElement("derbyTesting.jar.path=" + upgradejarpath); 2321 2322 if ( (jvmflags != null) && (jvmflags.length()>0) ) 2323 { 2324 if (jvmflags.indexOf("^")>0) 2326 { 2327 jvmflags = spaceJvmFlags(jvmflags); 2328 } 2329 jvm.setFlags(jvmflags); 2330 } 2331 2332 2333 if (testType.equals("multi")) 2334 { 2335 if ( (jvmflags != null) && (jvmflags.indexOf("mx") == -1) && (jvmflags.indexOf("Xmx") == -1)) 2336 jvm.setMx(64*1024*1024); 2338 jvmProps.addElement("encryption="+encryption); 2341 Properties props = new Properties (); 2342 SpecialFlags.parse(testSpecialProps, props, new Properties ()); 2344 String encryptionAlgorithm = props.getProperty("testEncryptionAlgorithm"); 2345 if(encryptionAlgorithm != null) 2346 jvmProps.addElement("encryptionAlgorithm=\""+ Attribute.CRYPTO_ALGORITHM 2347 +"="+encryptionAlgorithm+"\""); 2348 } 2349 jvm.setD(jvmProps); 2350 2351 if (!runWithoutSecurityManager) 2353 jvm.setSecurityProps(); 2354 else 2355 System.out.println("-- SecurityManager not installed --"); 2356 2357 Vector v = jvm.getCommandLine(); 2358 if ( ij.startsWith("ij") ) 2359 { 2360 String isNotAscii = System.getProperty("platform.notASCII"); 2367 if (isI18N) { 2368 v.addElement("-Dconsole.encoding=UTF-8"); 2371 } else if ((isNotAscii == null) || (isNotAscii.equals("false"))) { 2372 v.addElement("-Dconsole.encoding=Cp1252" ); 2373 } 2374 v.addElement("org.apache.derby.tools." + ij); 2375 if (ij.equals("ij")) 2376 { 2377 v.addElement("-f"); 2381 v.addElement(outDir.toString() + File.separatorChar + scriptFileName); 2382 } 2383 v.addElement("-p"); 2384 v.addElement(propString); 2385 } 2386 else if ( testType.equals("java") ) 2387 { 2388 if (javaPath.length() > 0) 2389 v.addElement(javaPath + "." + testBase); 2390 else 2391 v.addElement(testBase); 2392 if (propString.length() > 0) 2393 { 2394 v.addElement("-p"); 2395 v.addElement(propString); 2396 } 2397 } 2398 else if (testType.equals("unit")) 2399 { 2400 v.addElement("org.apache.derbyTesting.unitTests.harness.UnitTestMain"); 2401 v.addElement("-p"); 2402 v.addElement(propString); 2403 } 2404 else if (testType.equals("junit")) 2405 { 2406 v.addElement("junit.textui.TestRunner"); 2407 if (javaPath.length() > 0) { 2408 v.addElement(javaPath + "." + testBase); 2409 } else { 2410 v.addElement(testBase); 2411 } 2412 } 2413 else if ( testType.equals("multi") ) 2414 { 2415 System.out.println("scriptiflename is: " + scriptFileName); 2416 v.addElement("org.apache.derbyTesting.functionTests.harness.MultiTest"); 2417 v.addElement(scriptFileName); 2418 v.addElement("-i"); 2419 v.addElement(mtestdir); 2420 v.addElement("-o"); 2421 v.addElement(outDir.getPath()); 2422 v.addElement("-p"); 2423 v.addElement(propString); 2424 } 2425 2426 String [] sCmd = new String [v.size()]; 2428 for (int i = 0; i < v.size(); i++) 2429 { 2430 sCmd[i] = (String )v.elementAt(i); 2431 } 2432 2433 return sCmd; 2434 } 2435 2436 public static String spaceJvmFlags(String caretedJvmFlags) 2437 { 2438 String spacedJvmFlags = ""; 2439 StringTokenizer st = new StringTokenizer (jvmflags,"^"); 2441 while (st.hasMoreTokens()) 2442 { 2443 spacedJvmFlags += st.nextToken() + " "; 2444 } 2445 spacedJvmFlags = spacedJvmFlags.substring(0,spacedJvmFlags.length() -1); 2446 return spacedJvmFlags; 2447 } 2448 2449 public static void composePolicyFile() throws ClassNotFoundException 2450 { 2451 try{ 2452 2454 String default_policy = "util/derby_tests.policy"; 2456 2457 if (!replacePolicyFile) 2461 { 2462 File userDirHandle = new File (userdir); 2463 CopySuppFiles.copyFiles(userDirHandle, default_policy); 2464 } 2465 if ((isSuiteRun) && (suiteName!=null)) 2467 { 2468 InputStream newpolicy = loadTestResource("suites/" + 2469 suiteName.substring(0,suiteName.indexOf(':')) + 2470 ".policy"); 2471 writePolicyFile(newpolicy); 2472 } 2473 2474 if (!useprocess) 2477 { 2478 InputStream newpolicy = loadTestResource("util/" + "useprocessfalse.policy"); 2479 writePolicyFile(newpolicy); 2480 } 2481 2482 InputStream newpolicy = 2484 loadTestResource("tests/" + testDirName + "/" + testBase + ".policy"); 2485 writePolicyFile(newpolicy); 2486 } catch (IOException ie) { 2487 System.out.println("Exception trying to create policy file: "); 2488 ie.printStackTrace(); 2489 } 2490 } 2491 2492 public static void writePolicyFile(InputStream newpolicy) 2493 { 2494 try{ 2495 if (newpolicy != null) 2496 { 2497 File oldpolicy = new File (runDir,"derby_tests.policy"); 2498 if (verbose && oldpolicy.exists()) System.out.println("Appending to derby_tests.policy"); 2499 BufferedReader policyadd = new BufferedReader (new InputStreamReader (newpolicy, "UTF-8")); 2500 FileWriter policyfw = new FileWriter (oldpolicy.getPath(), true); 2501 PrintWriter policypw = new PrintWriter ( new BufferedWriter (policyfw, 10000), true ); 2502 String str = ""; 2503 while ( (str = policyadd.readLine()) != null ) { policypw.println(str); } 2504 policypw.close(); 2505 policyadd.close(); 2506 policypw= null; 2507 newpolicy = null; 2508 } 2509 } catch (IOException ie) { 2510 System.out.println("Exception trying to create policy file: "); 2511 ie.printStackTrace(); 2512 } 2513 } 2514 2515 private static void execTestProcess(String [] testCmd) 2516 throws Exception 2517 { 2518 Process pr = null; 2520 try 2521 { 2522 ProcessStreamResult prout = null; 2524 ProcessStreamResult prerr = null; 2525 FileOutputStream fos = null; 2526 BufferedOutputStream bos = null; 2527 2528 StringBuffer sb = new StringBuffer (); 2529 2530 for (int i = 0; i < testCmd.length; i++) 2531 { 2532 sb.append(testCmd[i] + " "); 2533 } 2534 if (verbose) System.out.println(sb.toString()); 2535 pr = Runtime.getRuntime().exec(testCmd); 2536 2537 String inEncoding = null; 2538 String outEncoding = null; 2539 if (isI18N) { 2540 inEncoding = "UTF-8"; 2543 outEncoding = inEncoding; 2544 } 2545 2546 if (codeset != null) { 2547 inEncoding = codeset; 2550 } 2551 2552 if (testEncoding != null) { 2553 inEncoding = testEncoding; 2554 } 2555 2556 if (useOutput) 2557 { 2558 fos = new FileOutputStream (tmpOutFile); 2559 } 2560 else 2561 { 2562 fos = new FileOutputStream (stdOutFile); 2563 } 2564 bos = new BufferedOutputStream (fos, 1024); 2565 prout = 2566 new ProcessStreamResult(pr.getInputStream(), bos, 2567 timeoutStr, 2568 inEncoding, outEncoding); 2569 prerr = 2570 new ProcessStreamResult(pr.getErrorStream(), bos, 2571 timeoutStr, 2572 inEncoding, outEncoding); 2573 2574 if (framework != null && ! framework.equals("")) 2575 if (verbose) System.out.println("The test should be running..."); 2576 2577 if (timeout != -1) { 2578 TimedProcess tp = new TimedProcess(pr); 2579 tp.waitFor(timeout*60); 2580 pr = null; 2581 } 2582 2583 boolean outInterrupt = prout.Wait(); 2585 boolean errInterrupt = prerr.Wait(); 2586 2587 if ( (errInterrupt) || (outInterrupt) ) 2588 { 2589 pwDiff.println("The test timed out..."); 2590 System.out.println("Test timed out..."); 2591 pr.destroy(); 2592 pr = null; 2593 } 2594 2595 fos.close(); 2596 bos.close(); 2597 if (pr != null) 2600 { 2601 pr.destroy(); 2602 pr = null; 2603 } 2604 } 2605 catch(IOException ioe) 2606 { 2607 System.out.println("IOException: " + ioe.getMessage()); 2608 } 2609 catch(Throwable t) 2610 { 2611 pwDiff.println("Process exception: " + t); 2612 System.out.println("Process exception: " + t.getMessage()); 2613 t.printStackTrace(); 2614 if (pr != null) 2615 { 2616 pr.destroy(); 2617 pr = null; 2618 } 2619 } 2620 } 2621 2622 private static void execTestNoProcess(Properties sysProp, 2623 String systemHome, String propString, String scriptPath) 2624 throws Exception 2625 { 2626 Properties ptmp = System.getProperties(); 2628 ptmp.put("derby.system.home", systemHome); 2629 ptmp.put("derby.infolog.append", "true"); 2630 if (framework.startsWith("DerbyNet")) 2633 ptmp.put("hostName=", hostName); 2634 System.setProperties(ptmp); 2635 2636 String pathStr = ""; 2637 2638 try 2641 { 2642 pathStr = tmpOutFile.getCanonicalPath().replace(File.separatorChar,fileSep); 2643 } 2644 catch (IOException e) 2645 { 2646 FileWriter fw = new FileWriter (tmpOutFile); 2647 fw.close(); 2648 pathStr = tmpOutFile.getCanonicalPath().replace(File.separatorChar,fileSep); 2649 } 2650 2651 2652 PrintStream ps = new PrintStream (new FileOutputStream (pathStr), true); 2653 2654 composePolicyFile(); 2656 boolean installedSecurityManager = installSecurityManager(); 2657 if (testType.equals("sql")) 2658 { 2659 String [] ijarg = new String [3]; 2660 ijarg[0] = "-p"; 2661 ijarg[1] = propString; 2662 ijarg[2] = scriptPath; 2663 PrintStream stdout = System.out; 2665 PrintStream stderr = System.err; 2666 System.setOut(ps); 2667 System.setErr(ps); 2668 RunIJ ij = new RunIJ(ijarg); 2669 Thread ijThread = new Thread (ij); 2670 try 2671 { 2672 ijThread.start(); 2673 if (timeout < 0) 2674 { 2675 ijThread.join(); 2676 } 2677 else 2678 { 2679 ijThread.join(timeout * 60 * 1000); 2680 } 2681 } 2682 catch (Exception e) 2683 { 2684 System.out.println("Aiiie! Got some kind of exception " + e); 2685 } 2686 2687 if (shutdownurl != null) 2689 { 2690 String [] sdargs = new String [2]; 2691 sdargs[0] = systemHome; 2692 sdargs[1] = shutdownurl; 2693 shutdown.main(sdargs); 2694 } 2695 ptmp = System.getProperties(); 2697 ptmp.put("ij.defaultResourcePackage", "/org/apache/derbyTesting/"); 2698 ptmp.put("usesystem", ""); 2699 System.setProperties(ptmp); 2700 System.setOut(stdout); 2702 System.setErr(stderr); 2703 } 2704 else if (testType.equals("java")) 2705 { 2706 if (javaPath == null) 2707 javaPath = "org.apache.derbyTesting.functionTests.tests." + testDirName; 2708 2709 String [] args = new String [2]; 2710 args[0] = "-p"; 2711 args[1] = propString; 2712 Class [] classArray = new Class [1]; 2713 classArray[0] = args.getClass(); 2714 String testName = javaPath + "." + testBase; 2715 Class JavaTest = Class.forName(testName); 2716 PrintStream stdout = System.out; 2717 PrintStream stderr = System.err; 2718 System.setOut(ps); 2719 System.setErr(ps); 2720 Method testMain = JavaTest.getMethod("main", classArray); 2722 Object [] argObj = new Object [1]; 2723 argObj[0] = args; 2724 RunClass testObject = new RunClass(testMain, argObj); 2725 Thread testThread = new Thread (testObject); 2726 try 2727 { 2728 testThread.start(); 2729 if (timeout < 0) 2730 { 2731 testThread.join(); 2732 } 2733 else 2734 { 2735 testThread.join(timeout * 60 * 1000); 2736 } 2737 } 2738 catch(Exception e) 2739 { 2740 System.out.println("Exception upon invoking test..." + e); 2741 e.printStackTrace(); 2742 } 2743 2744 try 2745 { 2746 java.sql.DriverManager.getConnection("jdbc:derby:;shutdown=true"); 2747 } 2748 catch (java.sql.SQLException e) 2749 { 2750 } 2752 System.setOut(stdout); 2754 System.setErr(stderr); 2755 } 2756 else if (testType.equals("multi")) 2757 { 2758 System.out.println("scriptiflename is: later " + scriptFileName); 2759 String [] args = new String [5]; 2767 args[0] = scriptFileName; 2768 args[1] = "-i"; 2769 args[2] = mtestdir; 2770 args[3] = "-o"; 2771 args[4] = outDir.getPath(); 2772 System.out.println("Try running MultiTest.main"); 2773 for (int i = 0; i < args.length; i++) 2774 System.out.println("args: " + args[i]); 2775 System.exit(1); 2776 org.apache.derbyTesting.functionTests.harness.MultiTest.main(args); 2777 } 2778 else if (testType.equals("unit")) 2779 { 2780 PrintStream stdout = System.out; 2782 PrintStream stderr = System.err; 2783 System.setOut(ps); 2784 System.setErr(ps); 2785 System.out.println("Unit tests not implemented yet with useprocess=false"); 2786 System.setOut(stdout); 2788 System.setErr(stderr); 2789 System.out.println("Unit tests not implemented yet with useprocess=false"); 2791 2798 } 2799 else if (testType.equals("junit")) 2800 { 2801 PrintStream stdout = System.out; 2802 PrintStream stderr = System.err; 2803 System.setOut(ps); 2804 System.setErr(ps); 2805 if (javaPath == null) { 2806 javaPath = "org.apache.derbyTesting.functionTests.tests." + testDirName; 2807 } 2808 String testName = javaPath + "." + testBase; 2809 2810 2813 2816 2826 Class testClass = Class.forName(testName); 2828 2829 TestSuite junitTestSuite = null; 2830 2831 try{ 2832 Method suiteMethod = testClass.getMethod("suite", null); 2834 junitTestSuite = (TestSuite) suiteMethod.invoke(null, null); 2839 } catch(Exception ex){ 2840 junitTestSuite = new TestSuite(testClass); 2845 } 2846 2847 if(junitTestSuite != null){ 2848 junit.textui.TestRunner.run(junitTestSuite); 2850 } 2851 else{ 2852 System.out.println("Not able to extract JUnit TestSuite from " + 2853 "test class " + testName); 2854 } 2855 2856 System.setOut(stdout); 2858 System.setErr(stderr); 2859 } 2860 ps.close(); 2861 if (installedSecurityManager) 2862 { 2863 System.setSecurityManager(null); 2864 2865 } 2866 } 2867 2868 static void addSkiptestReason(String reason) { 2869 if (skiptestReason.length() > 0) 2870 skiptestReason.append(System.getProperty("line.separator","\n")); 2871 skiptestReason.append(reason); 2872 } 2873 2874 static boolean verifyFramework (String framework) { 2875 String validFmString = ""; 2876 for (int i = 0 ; i < validFrameworks.length; i++) 2877 { 2878 validFmString += " " + validFrameworks[i]; 2879 if (validFrameworks[i].equals(framework)) 2880 return true; 2881 } 2882 System.err.println("Invalid framework: " + framework); 2883 2884 System.err.println("Valid frameworks are: " + 2885 validFmString); 2886 return false; 2887 2888 } 2889 2890 2895 public static InputStream loadTestResource(String loc) { 2896 return new Object ().getClass().getResourceAsStream(testResourceHome + loc); 2897 } 2898 2899 2904 private static String convertPathForWin(String path) 2905 { 2906 String tmp = "a" + path +"a"; 2907 int i = tmp.indexOf('/'); 2908 while (i != -1) 2909 { 2910 tmp = tmp.substring(0, i) + "\\\\" + tmp.substring(i+1); 2912 i = tmp.indexOf('/'); 2913 } 2914 tmp = tmp.substring(1, tmp.length()-1); 2916 2918 return tmp; 2919 } 2920 2921 2928 private static boolean installSecurityManager() throws ClassNotFoundException , IOException 2929 { 2930 if (jvmName.startsWith("j9")) 2933 return false; 2934 2935 boolean installedSecurityManager = false; 2936 boolean haveSecurityManagerAlready = System.getSecurityManager() != null; 2938 if (runWithoutSecurityManager) 2939 { 2940 if (haveSecurityManagerAlready) 2943 System.out.println( 2944 "noSecurityManager=true,useProcess=false but SecurityManager installed by previous test"); 2945 else 2946 System.out.println("-- SecurityManager not installed --"); 2947 } 2948 else if (!haveSecurityManagerAlready) 2949 { 2950 Vector propList = jvm.getSecurityProps(null); 2953 for (Enumeration e = propList.elements(); e.hasMoreElements();) 2954 { 2955 String dashDOpt = (String ) e.nextElement(); 2956 if ("java.security.manager".equals(dashDOpt)) 2957 continue; 2958 2959 int eq = dashDOpt.indexOf("="); 2960 String key = dashDOpt.substring(0, eq); 2961 String value = dashDOpt.substring(eq + 1); 2962 2963 System.setProperty(key, value); 2964 2965 } 2966 System.setSecurityManager(new SecurityManager ()); 2967 installedSecurityManager = true; 2968 } 2969 2970 return installedSecurityManager; 2971 } 2972 2973 private static void generateUTF8OutFile(File FinalOutFile) throws IOException 2977 { 2978 if (generateUTF8Out) 2979 { 2980 keepfiles=true; 2981 File UTF8OutFile = new File (UTF8OutName); 2982 2983 BufferedReader inFile = new BufferedReader (new FileReader (FinalOutFile)); 2985 FileOutputStream fos = new FileOutputStream (UTF8OutFile); 2986 BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (fos, "UTF-8")); 2987 int c; 2988 while ((c = inFile.read()) != -1) 2989 bw.write(c); 2990 bw.flush(); 2991 bw.close(); 2992 fos.close(); 2993 } 2994 } 2995 2996} 2997 2998 2999 | Popular Tags |