📄 runtest.java
字号:
/* Derby - Class org.apache.derbyTesting.functionTests.harness.RunTest Copyright 1999, 2004 The Apache Software Foundation or its licensors, as applicable. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */package org.apache.derbyTesting.functionTests.harness;import org.apache.derby.tools.sysinfo;import org.apache.derby.tools.ij;import org.apache.derby.iapi.reference.Attribute;import java.io.File;import java.io.InputStream;import java.io.InputStreamReader;import java.io.ByteArrayInputStream;import java.io.BufferedReader;import java.io.FileReader;import java.io.FileWriter;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.BufferedOutputStream;import java.io.BufferedWriter;import java.io.FileWriter;import java.io.PrintWriter;import java.io.PrintStream;import java.io.IOException;import java.io.FileNotFoundException;import java.lang.ClassNotFoundException;import java.lang.ClassFormatError;import java.lang.Thread;import java.lang.reflect.Method;import java.util.Enumeration;import java.util.Vector;import java.sql.Timestamp;import java.sql.Connection;import java.sql.SQLException;import java.sql.DriverManager;import java.util.Properties;import java.util.StringTokenizer;import java.net.URL;public class RunTest{ // For printing debug info static boolean verbose=false; // Under some circumstances, we may need to skip the test static boolean skiptest = false; static StringBuffer skiptestReason = new StringBuffer(); //java requires / to look into jars, irrespective of OS static final String testResourceHome = "/org/apache/derbyTesting/functionTests/"; // Framework support static String[] validFrameworks = {"embedded","", "DerbyNet","DerbyNetClient", "DB2jcc", "DB2app"}; static NetServer ns; static boolean frameworkInitialized = false; static boolean jvmnet = false; // switch to see if we need have client & server in a different jvm static String jvmnetjvm; // string for class name of server jvm if different from client jvm static String driverName; static String dbName; // Test properties static String jvmName = "currentjvm"; static String javaCmd; static String javaVersion; // System.getProperty("java.version") static String majorVersion; static String minorVersion; static int jccMajor; static int jccMinor; static int imajor; static int iminor; static boolean isjdk12test = false; static String classpath = ""; static String classpathServer = ""; static String framework = "embedded"; public static String J9_STATEMENTCACHESIZE = "20"; static String usesystem = ""; static String searchCP = ""; static boolean useCommonDB = false; static boolean keepfiles = false; static boolean useprocess = true; static boolean systemdiff = false; // can set true if there is a system diff static boolean upgradetest = false; static boolean encryption = false; // requires jdk12ext plus encryptionProtocol static boolean jdk12exttest = false; // requires jdk12ext static String runningdir = ""; // where the tests are run and suppfiles placed static String outputdir = ""; // user can specify as a property (optional) static String canondir; // optional (to specify other than "master") static String bootcp; // for j9 bootclasspath static String canonpath; // special full path (will be platform dependent) static String mtestdir = ""; // for MultiTest user must specify testdir static String testSpecialProps = ""; // any special suite properties static String testJavaFlags = ""; // special command line flags static String jvmflags; // java special flags static boolean reportstderr = true; static int timeout = -1; // in case tests are hanging public static String timeoutStr; static String jarfile; // some tests have jar files (like upgrade) static boolean skipsed = false; static String commonDBHome = "testCSHome"; static boolean dbIsNew = true; static String runwithjvm="true"; static boolean startServer=true; // should test harness start the server // Other test variables for directories, files, output static String scriptName = ""; // testname as passed in static String scriptFileName; // testname with extension static String testDirName = ""; // test directory name static String defaultPackageName = "/org/apache/derbyTesting/"; static String javaPath = "org.apache.derbyTesting."; // for java tests static String testType; // sql, java, unit, etc. static String testBase; // testname without extension static String testOutName; // output name without path or extension (optional) static String passFileName; // file listing passed tests static String failFileName; // file listing failed tests static String tempMasterName; //file name for JCC corrected/local encoded master static File passFile; static File failFile; static String shutdownurl = ""; static boolean useOutput; // use output or assume .tmp file is produced? static boolean outcopy; // copy support files to outDir rather than runDir static String userdir; // current user directory static char fileSep; // file separator for the system static PrintWriter printWriter = null; // used to write test output to .tmp static PrintWriter pwDiff = null; // for writing test output and info static File script; // The file created for test files other than java tests static File baseDir; // the DB base system dir static boolean deleteBaseDir; // the DB base system dir static File outDir; // test out dir static File runDir; // where test is run and where support files are expected static File canonDir; // allows setting master dir other than default static File tmpOutFile; // tmp output file (before sed) static File tempMasterFile; // master file processed for JCC/local encoding static File stdOutFile; // for tests with useoutput false static File finalOutFile; // final output file (after sed) static File appPropFile; // testname_app.properties or default static File clPropFile; // testname_derby.properties or default static File diffFile; // To indicate diffs static File tsuiteDir; // Final output dir for suite(s) static File rsuiteDir; // Where to report .pass and .fail for suite(s) static File extInDir; //Where all external test input files exist. static File extOutDir; //Where all external test input files exist. static File extInOutDir; //Where all external test input files exist. // This test may be part of a suite // (RunTest may need to know this is a suite to avoid dup output like sysinfo) static String topsuitedir = ""; // in case of nested suites static String topsuiteName = ""; static String topreportdir = ""; static String suiteName = ""; static boolean isSuiteRun = false; static boolean lastTestFailed = false; static boolean isI18N = false; static InputStream isSed = null; // For test_sed.properties // Cliff public static void main(String[] args) throws Exception { skiptestReason.setLength(0); // 0 out for useprocess // Determine the test type if (args.length == 0) { // No script name provided System.out.println("no test name provided"); System.exit(1); } scriptName = args[0]; if (Boolean.getBoolean("listOnly")) { System.out.println("LISTONLY :" + scriptName); return; } if ( (scriptName == null) || (scriptName.equals("")) ) { System.out.println("Null or blank test script name."); System.exit(1); } if (args.length == 6) { defaultPackageName = args[1]; usesystem = args[2]; useprocess = false; shutdownurl = args[4]; isSuiteRun = true; suiteName = args[5]; //System.out.println("suiteName: " + suiteName); } testType = scriptName.substring(scriptName.lastIndexOf(".") + 1); verifyTestType(); // Get the properties for the test Properties sp = System.getProperties(); // For useprocess=false, some system wide properties need to be reset if (useprocess == false) { sp.put("useprocess", "false"); // Reset maximumDisplayWidth because some tests set this in app properties // and when running in same process, can cause extra long lines and diffs if ( sp.getProperty("maximumDisplayWidth") == null ) sp.put("maximumDisplayWidth", "128"); if ( sp.getProperty("ij.defaultResourcePackage") != null ) sp.put("ij.defaultResourcePackage", defaultPackageName); System.setProperties(sp); } getProperties(sp); // Setup the directories for the test and test output setDirectories(scriptName,sp); // Check for properties files, including derby.properties // and if needed, build the -p string to pass to the test String propString = createPropString(); if ( (isSuiteRun == false) && (useprocess) ) { SysInfoLog sysLog = new SysInfoLog(); sysLog.exec(jvmName, javaCmd, classpath, framework, pwDiff, useprocess); } String startTime = CurrentTime.getTime(); StringBuffer sb = new StringBuffer(); sb.append("*** Start: " + testBase + " jdk" + javaVersion + " "); if ( (framework.length()>0) && (!framework.startsWith("embedded")) ) sb.append(framework + " "); if ( (suiteName != null) && (suiteName.length()>0) ) sb.append(suiteName + " "); sb.append(startTime + " ***"); System.out.println(sb.toString()); pwDiff.println(sb.toString()); // Run the Server if needed if ((driverName != null) && (!skiptest) ) { System.out.println("Initialize for framework: "+ framework ); if (jvmnet && framework.startsWith("DerbyNet")) { // first check to see if properties were set to use a different jvm for server/client String jvmnetjvm = System.getProperty("serverJvmName"); if (jvmnetjvm == null) { // default to the latest one we know jvmnetjvm = "j9_22"; } ns = new NetServer(baseDir, jvmnetjvm, classpathServer, null, jvmflags,framework, startServer); } else ns = new NetServer(baseDir, jvmName, classpathServer, javaCmd, jvmflags,framework, startServer); ns.start(); frameworkInitialized = true; } // If the test has a jar file (such as upgrade) unjar it if (jarfile != null) { UnJar uj = new UnJar(); uj.unjar(jarfile, outDir.getCanonicalPath(), true); } // Run the actual test (unless skiptest was set to true) if (skiptest == false) { testRun(propString, sp); } else { if (skiptestReason.length() == 0) addSkiptestReason("Test skipped: skiptest set without setting skiptestReason, please fix RunTest.java..."); pwDiff.println(skiptestReason); System.out.println(skiptestReason); doCleanup(javaVersion); return; } // Stop the Network server if necessary if (frameworkInitialized) { ns.stop(); } // Do "sed" to strip some unwanted stuff from the output file // unless flag skipsed is set to true (for special cases) String outName = finalOutFile.getPath(); if (testDirName.startsWith("i18n")) { isI18N=true; } if (skipsed) { tmpOutFile.renameTo(finalOutFile); } else { try { Sed sed = new Sed(); sed.exec(tmpOutFile,finalOutFile, isSed, NetServer.isClientConnection(framework), isI18N); } catch (ClassFormatError cfe) { if (verbose) System.out.println("SED Error: " + cfe.getMessage()); } } // Now do a diff between the out and the master files // Use the system's diff if systemdiff is true String frameworkMaster = framework; if (framework.startsWith("embedded")) frameworkMaster = ""; FileCompare diff = new FileCompare(); if (verbose) { System.out.println( "About to execute: diff.exec(" + " outName = " + outName + ",outDir = " + outDir + ",pwDiff = " + pwDiff + ",testOutName = " + testOutName + ",frameworkMaster = " + frameworkMaster + ",jvmName = " + jvmName + ",iminor = " + iminor + ",useprocess = " + useprocess + ",systemdiff = " + systemdiff + ",canondir = " + canondir + ",canonpath = " + canonpath + ")\n"); } boolean status; // allow for server jvmName to be different from client jvmName if (jvmnet) { // first check to see if properties were set to use a different jvm for server/client
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -