You are viewing a plain text version of this content. The canonical link for it is here.
Posted to kato-commits@incubator.apache.org by cc...@apache.org on 2009/03/16 16:42:15 UTC
svn commit: r754944 [2/4] - in
/incubator/kato/trunk/import/org.apache.kato.tck.harness: ./ .settings/
META-INF/ launchers/ lib/ slave-configs/ slave-configs/hornet/ src/
src/com/ src/com/ibm/ src/com/ibm/dtfj/ src/com/ibm/dtfj/tck/
src/com/ibm/dtfj/tc...
Added: incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/BuildVersionHelper.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/BuildVersionHelper.java?rev=754944&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/BuildVersionHelper.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/BuildVersionHelper.java Mon Mar 16 16:42:12 2009
@@ -0,0 +1,192 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.tck.harness;
+
+
+public class BuildVersionHelper {
+
+
+ private static final String JAVA_SPECIFICATION_VERSION = "java.specification.version";
+ private static final String JAVA_VENDOR = "java.vendor";
+ private static final String JAVA_RUNTIME_VERSION = "java.runtime.version";
+
+ /**
+ *
+ * @return jvm build version in the form version.subversion.subversion.subversion...
+ */
+
+ public static String getBuildVersion() {
+
+
+
+ String version=getProperty(JAVA_SPECIFICATION_VERSION);
+ String vendor=getProperty(JAVA_VENDOR).toLowerCase();
+
+
+ if(vendor.indexOf("sun")>=0) {
+
+ return getSunBuildVersion(getProperty("java.runtime.version"));
+ }
+ else if(vendor.indexOf("ibm")>=0) {
+ if(version.equals("1.4")) {
+
+ return getIBM142Version(getProperty("java.fullversion"));
+ }
+ if(version.equals("1.5")) {
+
+ return getIBM150Version(getProperty("java.runtime.version"));
+ }
+ if(version.equals("1.6")) {
+
+ return getIBM160Version(getProperty("java.runtime.version"));
+ }
+ else throw new IllegalArgumentException("unable to handle IBM Java version "+version);
+
+ }
+
+ for(int i=2000;i<2050;i++) {
+ String id=""+i;
+ int loc=version.indexOf(id);
+ if(loc<0) {
+ continue;
+ }
+ else {
+ String year=version.substring(loc,loc+4);
+ String month=version.substring(loc+4,loc+6);
+ String day=version.substring(loc+6,loc+8);
+ return year+"/"+month+"/"+day;
+
+ }
+ }
+
+ return null;
+ }
+
+
+ public static String getIBM160Version(String fullversion) {
+ int eyecatcher=fullversion.indexOf("-");
+ if(eyecatcher<0) throw new IllegalArgumentException("cannot locate IBM 1.6.0 version info from "+fullversion);
+
+ int us=fullversion.indexOf("_",eyecatcher);
+
+ String datestamp=fullversion.substring(eyecatcher+1,us);
+ String sr=fullversion.substring(us+1);
+
+ // get service refresh number if available
+
+
+ String result="1.6.0."+sr+"."+datestamp;
+
+
+ return result;
+
+ }
+ public static String getIBM150Version(String fullversion) {
+ int eyecatcher=fullversion.indexOf("-");
+ if(eyecatcher<0) throw new IllegalArgumentException("cannot locate IBM 1.5.0 version info from "+fullversion);
+
+ // now expect date + month + day etc
+ int space=fullversion.indexOf(' ', eyecatcher);
+ String datestamp=fullversion.substring(eyecatcher+1,space);
+
+ // get service refresh number if available
+
+ String sr=null;
+
+ // find first open bracket
+
+ int ob=fullversion.indexOf("(",space);
+ if(ob>eyecatcher) {
+ int cb=fullversion.indexOf(")",space);
+ sr=fullversion.substring(ob+1,cb);
+ }
+
+ String result="1.5.0";
+ if(sr!=null) result=result+"."+sr+"."+datestamp;
+ else result=result+".0."+datestamp;
+
+
+ return result;
+ }
+ public static String getIBM142Version(String fullversion) {
+
+ int eyecatcher=fullversion.indexOf("-");
+ if(eyecatcher<0) throw new IllegalArgumentException("cannot locate IBM 1.4.2 version info from "+fullversion);
+
+ // now expect date + month + day etc
+ int space=fullversion.indexOf(' ', eyecatcher);
+ String datestamp=fullversion.substring(eyecatcher+1,space);
+
+ // get service refresh number if available
+
+ String sr=null;
+
+ // find first open bracket
+
+ int ob=fullversion.indexOf("(",space);
+ if(ob>eyecatcher) {
+ int cb=fullversion.indexOf(")",space);
+ sr=fullversion.substring(ob+1,cb);
+ }
+
+ String result="1.4.2";
+ if(sr!=null) result=result+"."+sr+"."+datestamp;
+ else result=result+".0."+datestamp;
+
+
+ return result;
+ }
+
+ private static String getProperty(String id) {
+ String result=System.getProperty(id);
+ if(result==null) throw new IllegalArgumentException("cannot location required system property "+id);
+ return result;
+ }
+
+
+
+ public static String getSunBuildVersion(String version) {
+ char chars[]=version.toCharArray();
+
+ for(int i=0;i<chars.length;i++) {
+ char c=chars[i];
+
+ if(Character.isDigit(c)) continue;
+ if(c=='_' || c=='-' || c=='.') {
+ chars[i]='.';
+ continue;
+ }
+ chars[i]=0;
+ }
+
+ StringBuffer results=new StringBuffer();
+ char last=0;
+ for(int i=0;i<chars.length;i++) {
+ char c=chars[i];
+ if(c==0) continue; // skip null char
+
+ if(Character.isDigit(c)) {
+ results.append(c);
+ last=c;
+ }
+ else {
+ if(last=='.') continue; // duplicate dots - skip
+ results.append(c);
+ last=c;
+ }
+ }
+
+ return new String(results);
+ }
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/Configure.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/Configure.java?rev=754944&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/Configure.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/Configure.java Mon Mar 16 16:42:12 2009
@@ -0,0 +1,274 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.tck.harness;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import com.ibm.dtfj.anttasks.tcklistbuilder.TCKDefinition;
+import com.ibm.dtfj.anttasks.tcklistbuilder.TCKDefinition.TCKClassDefinition;
+import com.ibm.dtfj.tck.api.DumpDefinition;
+import com.ibm.dtfj.tck.api.ICheckPointHandler;
+import com.ibm.dtfj.tck.api.ICheckpoint;
+import com.ibm.dtfj.tck.api.IDumpCreator;
+
+public class Configure extends AbstractLauncher {
+
+ private static Set anchor=new HashSet();
+
+ public static void main(String[] args) {
+
+
+ Configure c=new Configure();
+ try {
+ if(args!=null && args.length>0) {
+ c.setUserConfiguration(new File(args[0]));
+ }
+ DumpDefinition def=c.configure();
+ if(def==null) {
+ System.exit(-2);
+ }
+ else {
+ File workingDir = c.getConfig().getWorkingDirectory();
+ File dumpconfig=new File(workingDir,"dumpdef.properties");
+ FileOutputStream fos=new FileOutputStream(dumpconfig);
+ Properties p=def.getProperties();
+ p.store(fos,"dump definition");
+ fos.close();
+
+ }
+ System.exit(0); // force end of JVM.
+ } catch (Throwable e) {
+
+ e.printStackTrace();
+ }
+
+ System.exit(-1);
+ }
+
+ private DumpDefinition configure() throws IOException {
+
+ log("configure started");
+
+ // locate and instantiate the dump generator
+
+ IDumpCreator creator=loadDumpCreator();
+
+
+ // create situation
+ VisitStatistics stats=buildSystem();
+ log("system built");
+ log("Testcase roots scanned = "+stats.roots);
+ log(" of which archives = "+stats.archiveRoots);
+ log(" of which directories = "+stats.directoryRoots);
+ log(" of which files = "+stats.fileRoots);
+ log("Testcases found = "+stats.testcasesFound);
+ log(" of which accepted = "+stats.testcaseClassesAccepted);
+ log(" of which failed to int = "+stats.testcaseInstantiationFailures);
+ log("End of Stats");
+ // run it
+ DumpDefinition handle=creator.createDump();
+ if(handle==null) {
+ log("dump not created - no handle returned");
+ }
+ else {
+ log("dump created (jvm builddate="+handle.getJvmBuildDate()+")");
+ }
+ return handle;
+
+
+ }
+
+ private VisitStatistics buildSystem() {
+
+
+
+
+ // set up check point handler
+
+
+ final ICheckPointHandler handler=new CheckPointHandler();
+
+ // visit all the testcases
+
+ TCKDefinition def=getConfig().getTestcaseConfiguration();
+
+
+ VisitStatistics stats=visitFiles(def,handler);
+
+ // wait for any outstanding threads to complete
+
+ if(handler.hasOutstandingThreads()) {
+
+ log("Waiting for "+handler.outstandingThreads()+ " oustanding threads to reach checkpoint");
+
+ while(handler.hasOutstandingThreads()) {
+
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ log("any outstanding threads reached checkpoint");
+ }
+
+ log("Definition date = "+def.getCreatedDate());
+
+ return stats;
+
+ }
+
+ private VisitStatistics visitFiles( TCKDefinition def,ICheckPointHandler handler
+ ) {
+
+ VisitStatistics stats=new VisitStatistics();
+
+ Iterator classes=def.classIterator();
+ while(classes.hasNext()) {
+ TCKClassDefinition clazz=(TCKClassDefinition) classes.next();
+ String qualifedName=clazz.getQualifedClassName();
+ Class realClass;
+ try {
+ realClass = Class.forName(qualifedName);
+ stats.classesFound++;
+ } catch (ClassNotFoundException e) {
+ stats.classesNotFound++;
+ System.err.println("cannot find class "+qualifedName+" on classpath");
+ continue;
+ }
+
+ if(TestCase.class.isAssignableFrom(realClass)) {
+ if(AbstractTCKTestcase.class.isAssignableFrom(realClass)) {
+ stats.testcasesFound++;
+ AbstractTCKTestcase instance;
+ try {
+ instance = (AbstractTCKTestcase) realClass.newInstance();
+ anchor.add(instance);
+ instance.configure(handler);
+
+ } catch (Exception e) {
+ stats.testcaseInstantiationFailures++;
+ System.err.println("Error instantiating "+qualifedName);
+ e.printStackTrace(System.err);
+ continue;
+ }
+
+ }
+ }
+ else {
+
+ System.err.println("During Configure a class "+qualifedName+" that is not a Junit Testcase was discovered");
+ }
+
+ }
+
+ return stats;
+ }
+
+ class CheckPointRunner implements Runnable {
+
+ private Method method=null;
+ private AbstractTCKTestcase testcase=null;
+ private ICheckPointHandler handler=null;
+
+ public CheckPointRunner(ICheckPointHandler checkPointHandler, Method method, AbstractTCKTestcase testcase) {
+ this.method=method;
+ this.testcase=testcase;
+ this.handler=checkPointHandler;
+ }
+
+ public void run() {
+
+ // run method
+ ICheckpoint checkpoint=new ICheckpoint(){
+
+ public void checkpoint() {
+ handler.checkpoint(method);
+ while (true) {
+ try {
+ Thread.sleep(10000);
+ } catch (InterruptedException e) {
+ }
+ }
+ }};
+
+ try {
+ method.invoke(testcase, new Object[]{checkpoint});
+// Thread.sleep(10000);
+ } catch (IllegalArgumentException e) {
+ checkpoint.checkpoint();
+
+ } catch (IllegalAccessException e) {
+ checkpoint.checkpoint();
+ } catch (InvocationTargetException e) {
+ checkpoint.checkpoint();
+ }
+
+
+ }
+
+ }
+
+ class CheckPointHandler implements ICheckPointHandler {
+
+ private HashSet startedThreads=new HashSet();
+
+ /**
+ * Handle new testcase configure method
+ *
+ * Do this by creating a thread to run the method
+ *
+ */
+ public void handle(Method method, AbstractTCKTestcase testcase) {
+ CheckPointRunner runner=new CheckPointRunner(this,method,testcase);
+ startedThreads.add(method); // keep track of it
+ log("started configure thread "+method);
+ Thread t=new Thread(runner,method.getDeclaringClass().getName()+ "#"+method.getName());
+ t.start();
+
+ }
+
+
+ public boolean hasOutstandingThreads() {
+ return startedThreads.size()>0;
+ }
+
+
+ /**
+ * Thread reached completion point..
+ *
+ */
+ public void checkpoint(Method method) {
+
+ log("method checkpointed "+method);
+ startedThreads.remove(method);
+ }
+
+
+ public int outstandingThreads() {
+ return startedThreads.size();
+ }
+
+ }
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/ConsoleOutputConstants.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/ConsoleOutputConstants.java?rev=754944&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/ConsoleOutputConstants.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/ConsoleOutputConstants.java Mon Mar 16 16:42:12 2009
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.tck.harness;
+
+public interface ConsoleOutputConstants {
+
+ public static final String TCK_TEST_SUITE_EXECUTION_BEGINS = "TCK Test Suite Execution begins";
+ public static final String TCK_TEST_SUITE_EXECUTION_ENDS = "TCK Test Suite Execution ends";
+ public static final String TCK_TEST_ERROR = "TCK Test error ";
+ public static final String TCK_TEST_FAILED = "TCK Test failed ";
+ public static final String TCK_TEST_PASSED = "TCK Test passed ";
+ public static final String BUILD = "build ";
+ public static final String ARCH = "arch ";
+ public static final String OS = "os ";
+ public static final String TESTSUITE = "testsuite ";
+ public static final String VMTYPE = "vmtype ";
+ public static final String VENDOR = "vendor ";
+ public static final String DUMPTYPE = "dumptype ";
+ public static final String DATE = "date ";
+ public static final String VERSION = "version ";
+ public static final String WORDSIZE = "wordsize ";
+ public static final String STACK_TRACE_END = "STACK TRACE END";
+ public static final String STACK_TRACE_START = "STACK TRACE START";
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/ITestCaseVisitor.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/ITestCaseVisitor.java?rev=754944&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/ITestCaseVisitor.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/ITestCaseVisitor.java Mon Mar 16 16:42:12 2009
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.tck.harness;
+
+
+public interface ITestCaseVisitor {
+
+ void fileMissing(String filePath);
+
+ void error(Throwable t, String absolutePath);
+
+ boolean visit(AbstractTCKTestcase base);
+ boolean visit(Class clazz);
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/JRESystemPropertyRetriever.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/JRESystemPropertyRetriever.java?rev=754944&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/JRESystemPropertyRetriever.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/JRESystemPropertyRetriever.java Mon Mar 16 16:42:12 2009
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.tck.harness;
+
+import java.util.Properties;
+
+/**
+ * Outputs the specified properties to the system console
+ *
+ */
+public class JRESystemPropertyRetriever {
+
+
+ public static void main(String[] args) {
+ if(args==null || args.length==0) return;
+
+ Properties props=System.getProperties();
+
+ for(int i=0;i<args.length;i++) {
+ String key=args[i];
+ if(props.containsKey(key)) {
+ String value=props.getProperty(key);
+ System.out.println(key+"="+value);
+ }
+ }
+
+
+ }
+
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/MapCollector.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/MapCollector.java?rev=754944&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/MapCollector.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/MapCollector.java Mon Mar 16 16:42:12 2009
@@ -0,0 +1,151 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.tck.harness;
+
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import com.ibm.dtfj.tck.api.TCKException;
+
+public class MapCollector {
+
+ private Map variables=new TreeMap();
+
+ /**
+ * Create collector with provided initial values
+ *
+ * @param environmentalVariables
+ */
+ public MapCollector(List environmentalVariables) {
+ Iterator i=environmentalVariables.iterator();
+ while(i.hasNext()) {
+ String value=(String) i.next();
+ collect(value,null);
+ }
+ }
+ public MapCollector() {
+
+ }
+
+
+ /**
+ * Collects variable key/value settings
+ *
+ * If a method registers a conflicting requirement
+ * a TCK exception is thrown.
+ *
+ * @param var - variable to record (assumes that key and value are
+ * seperated by an '='
+ * @param method - method doing the recording
+ *
+ */
+ public void collect(String var, Method method) {
+
+
+ String key=null;
+ String value=null;
+
+ String[] separateVar=splitEnvVar(var);
+
+
+ collect(separateVar[0],separateVar[1],method);
+
+
+ }
+
+ public static String[] splitEnvVar(String var) {
+
+ String key=null;
+ String value=null;
+ int eq=var.indexOf('=');
+
+ if(eq<0) {
+ key=var;
+ }
+ else {
+ key=var.substring(0,eq);
+ value=var.substring(eq+1);
+
+ }
+ return new String[]{key,value};
+
+ }
+ public void collect(String key, String value, Method method) {
+
+ if(variables.containsKey(key)==false) {
+ CollectionValue v=new CollectionValue();
+ v.recorder=method;
+ v.value=value;
+ variables.put(key,v);
+ }
+ else {
+ // key clash
+ CollectionValue original=(CollectionValue) variables.get(key);
+
+ if(original.value==null) {
+ if( value==null) return; // matching ultimate value (both null)
+ }
+ else {
+ if( value!=null) {
+ // both not null. same value?
+ if(original.equals(value)) return; // same value
+ }
+ }
+
+ String originator="<intial setup>";
+ if(original.recorder!=null) originator=original.recorder.toString();
+ throw new TCKException("unable to register key "+key+" for "+method+" value conflicts with previously registered value from "+originator);
+ }
+ }
+
+ class CollectionValue {
+ Method recorder=null;
+ String value=null;
+ }
+
+ public List asList() {
+
+ List list=new LinkedList();
+ Iterator i=variables.keySet().iterator();
+ while(i.hasNext()) {
+ Object key=i.next();
+ CollectionValue value=(CollectionValue) variables.get(key);
+ String keyValue=key.toString();
+ if(value.value==null) list.add(keyValue);
+ else list.add(keyValue+"="+value.value);
+ }
+
+ return list;
+ }
+
+ public Iterator keyIterator() {
+ return variables.keySet().iterator();
+ }
+
+ public String getValue(String key) {
+ CollectionValue value=(CollectionValue) variables.get(key);
+ if(value==null) return null;
+ return value.value;
+ }
+
+ public int size() {
+ return variables.size();
+ }
+
+
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/ProcessLauncher.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/ProcessLauncher.java?rev=754944&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/ProcessLauncher.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/ProcessLauncher.java Mon Mar 16 16:42:12 2009
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.tck.harness;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.util.LinkedList;
+import java.util.List;
+
+public class ProcessLauncher {
+
+ private List standardEnvVars = new LinkedList();
+ private String suffix = "";
+ private TCKReporter reporter=null;
+
+ public ProcessLauncher() {
+ reporter=new TCKReporter();
+ }
+ public ProcessLauncher(TCKReporter reporter) {
+ this.reporter=reporter;
+ }
+ public int launch(File workingDir, List envvars, List list)
+ throws IOException {
+
+ List myEnvars = new LinkedList();
+ myEnvars.addAll(standardEnvVars);
+ myEnvars.addAll(envvars);
+
+ int size = list.size();
+ String[] parms = (String[]) list.toArray(new String[size]);
+ String[] vars = (String[]) myEnvars
+ .toArray(new String[myEnvars.size()]);
+
+ return launch(workingDir, vars, parms, null);
+ }
+
+ public int launch(File workingDir, String[] parms) throws IOException {
+ List myEnvars = new LinkedList();
+ myEnvars.addAll(standardEnvVars);
+ String[] vars = (String[]) myEnvars
+ .toArray(new String[myEnvars.size()]);
+ return launch(workingDir, vars, parms, null);
+ }
+
+ private int launch(File workingDir, String[] vars, String[] parms,
+ File output) throws IOException {
+
+ // TODO - should make configurable
+
+ for (int i = 0; i < parms.length; i++) {
+ reporter.report(suffix+" init parm " + i + " =" + parms[i]);
+ }
+ for (int i = 0; i < vars.length; i++) {
+ reporter.report(suffix+" init vars " + i + " =" + vars[i]);
+ }
+ Runtime r = Runtime.getRuntime();
+
+ Process p;
+
+ // if the env var list is empty we chuck it away so that envs are
+ // inheritied
+ if (vars != null && vars.length == 0) {
+ vars = null;
+ }
+ p = r.exec(parms, vars, workingDir);
+
+ PrintStream out = null;
+ PrintStream err = null;
+ FileOutputStream fos = null;
+
+ TextStreamRedirector rdr1=null;
+ TextStreamRedirector rdr2=null;
+ InputStream stdIn=p.getInputStream();
+ InputStream errIn=p.getErrorStream();
+
+ if (output != null) {
+
+ fos = new FileOutputStream(output);
+ PrintStream ps = new PrintStream(fos);
+ rdr1 = new TextStreamRedirector(stdIn,ps);
+ rdr2 = new TextStreamRedirector(errIn,ps);
+
+
+ } else {
+ // no specific file set.
+ // if we have an reporter we can use it
+ if(reporter!=null) {
+ rdr1 = new TextStreamRedirector(stdIn,reporter);
+ rdr2 = new TextStreamRedirector(errIn,reporter);
+ }
+ else {
+ rdr1 = new TextStreamRedirector(stdIn,System.out);
+ rdr2 = new TextStreamRedirector(errIn,System.err);
+ }
+ }
+
+
+ rdr1.setPrefix(suffix);
+ rdr2.setPrefix(suffix);
+ rdr1.start();
+ rdr2.start();
+
+ try {
+ p.waitFor();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ if (fos != null)
+ fos.close();
+
+ return p.exitValue();
+
+ }
+
+ public void launch(File workingDir, List list) throws IOException {
+ launch(workingDir, new LinkedList(), list);
+
+ }
+
+ public String getSuffix() {
+ return suffix;
+ }
+
+ public void setSuffix(String suffix) {
+ this.suffix = suffix;
+ }
+
+ public void launch(File workingDir, List list, File results)
+ throws IOException {
+ launch(workingDir, new String[0], (String[]) list
+ .toArray(new String[list.size()]), results);
+
+ }
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/PropertyStoreXMLWriter.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/PropertyStoreXMLWriter.java?rev=754944&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/PropertyStoreXMLWriter.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/PropertyStoreXMLWriter.java Mon Mar 16 16:42:12 2009
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.tck.harness;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Date;
+import java.util.Iterator;
+
+import com.ibm.dtfj.tck.api.PropertyStore;
+
+public class PropertyStoreXMLWriter {
+
+
+ private PropertyStore store=null;
+
+ public PropertyStoreXMLWriter(PropertyStore store) {
+ this.store=store;
+ }
+
+ /**
+ * Writes the contents of the store to a properties file keys with null
+ * values are written with blank values
+ *
+ * @param store
+ * @param outfile
+ * @throws IOException
+ */
+ public void write(File outfile)
+ throws IOException {
+
+ FileWriter fw = new FileWriter(outfile);
+ PrintWriter pw = new PrintWriter(fw);
+
+ pw.println("<tckconfig created=\"" + new Date()+"\">");
+
+ PropertyStore s=store;
+ while(s!=null) {
+ writeStoreConfig(s,pw);
+ s=s.getParent();
+ }
+
+ pw.println("</tckconfig>");
+ pw.close();
+
+ }
+
+ private void writeStoreConfig(PropertyStore pstore,PrintWriter pw) {
+
+ pw.println("<store source=\""+pstore.getSource()+"\">");
+
+ Iterator keyIterator = pstore.iterator();
+
+ while (keyIterator.hasNext()) {
+ String key = (String) keyIterator.next();
+ pw.print("<key name=\""+key+"\" ");
+
+ String resolvedValue = store.getProperty(key);
+ String value=pstore.getPropertyAsIs(key);
+ if(value!=null) {
+ pw.print("value=\""+value+"\" " );
+ }
+
+ if(resolvedValue!=null) {
+ pw.print("resolvedvalue=\""+resolvedValue+"\" " );
+ }
+
+ pw.println(" />");
+
+ }
+ pw.println("</store>");
+ }
+
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/SetupCollector.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/SetupCollector.java?rev=754944&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/SetupCollector.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/SetupCollector.java Mon Mar 16 16:42:12 2009
@@ -0,0 +1,181 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.tck.harness;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import com.ibm.dtfj.anttasks.tcklistbuilder.TCKDefinition;
+import com.ibm.dtfj.anttasks.tcklistbuilder.TCKDefinition.TCKClassDefinition;
+import com.ibm.dtfj.tck.api.TCKConfiguration;
+
+/**
+ *TCK Harness Launcher
+ *
+ *Launches the setup process.
+ *
+ */
+public class SetupCollector extends AbstractLauncher {
+
+
+ /**
+ * Main entry point
+ *
+ */
+
+ public static void main(String[] args) {
+
+
+
+
+ try {
+ SetupCollector collector = new SetupCollector();
+ if(args!=null && args.length>0) {
+ collector.setUserConfiguration(new File(args[0]));
+ }
+ collector.collect();
+ } catch (Throwable e) {
+
+ e.printStackTrace();
+ System.exit(-1);
+ }
+
+ }
+
+
+
+ public void extractRuntimeData(MapCollector envVars,
+ ValueCollector jvmArgs, AbstractTCKTestcase base) {
+ base.getEnvironmentArguments(envVars);
+ base.getJVMArguments(jvmArgs);
+ }
+
+ public void collect() throws IOException {
+
+ System.out.println("Collecter started");
+
+ List testcaseAnchor=new LinkedList();
+
+ TCKConfiguration config=getConfig();
+
+ MapCollector envVars = new MapCollector(config.getEnvironmentalVariables());
+ ValueCollector jvmArgs = new ValueCollector(config.getJVMArguments());
+
+ TCKDefinition def = config.getTestcaseConfiguration();
+ log("Definition date = "+def.getCreatedDate());
+
+ // gather and launch testcases
+ VisitStatistics stats=visitFiles(testcaseAnchor, def, envVars, jvmArgs);
+
+
+ log("Classes found = "+stats.classesFound);
+ log("Classes not found = "+stats.classesNotFound);
+ log("Testcases found = "+stats.testcasesFound);
+ log("End of Stats");
+
+ if(stats.testcasesFound==0) raiseError("No testcases found");
+ // write results
+
+ File envlist=config.getEnvironmentalVariablesReportFile();
+ File jvmlist=config.getJVMArgumentsReportFile();
+
+ log("writing env vars to "+envlist);
+ PrintWriter envWriter=new PrintWriter(new FileOutputStream(envlist));
+ writeData(envWriter, envVars.asList());
+ envWriter.close();
+
+ PrintWriter argWriter=null;
+ if(jvmlist!=null) {
+ log("writing jvm args to "+jvmlist);
+ argWriter=new PrintWriter(new FileOutputStream(jvmlist));
+ writeData(argWriter, jvmArgs.asList());
+ argWriter.close();
+ }
+
+
+
+
+
+ }
+
+
+
+
+
+ private VisitStatistics visitFiles(final List anchor, TCKDefinition def,
+ final MapCollector envVars, final ValueCollector jvmArgs) {
+
+ VisitStatistics stats=new VisitStatistics();
+
+ Iterator classes=def.classIterator();
+ while(classes.hasNext()) {
+ TCKClassDefinition clazz=(TCKClassDefinition) classes.next();
+ String qualifedName=clazz.getQualifedClassName();
+ Class realClass;
+ try {
+ realClass = Class.forName(qualifedName);
+ stats.classesFound++;
+ } catch (ClassNotFoundException e) {
+ stats.classesNotFound++;
+ System.err.println("cannot find class "+qualifedName+" on classpath");
+ continue;
+ }
+
+
+ if(TestCase.class.isAssignableFrom(realClass)) {
+ stats.testcasesFound++;
+ TestCase instance;
+ try {
+ instance = (TestCase) realClass.newInstance();
+
+ } catch (Exception e) {
+ stats.testcaseInstantiationFailures++;
+ System.err.println("Error instantiating "+qualifedName);
+ e.printStackTrace(System.err);
+ continue;
+ }
+ if(instance instanceof AbstractTCKTestcase) {
+ extractRuntimeData(envVars, jvmArgs,(AbstractTCKTestcase) instance);
+ anchor.add(realClass);
+ }
+ }
+ else {
+ System.err.println("class "+qualifedName+" is not a Junit TestCase class");
+ }
+
+ }
+
+ return stats;
+ }
+
+ private void writeData(PrintWriter writer, List list) {
+
+
+ Iterator i=list.iterator();
+ while(i.hasNext()) {
+ String entry=(String) i.next();
+ writer.println(entry);
+ }
+
+
+
+ }
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKJavaRuntimeTestcase.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKJavaRuntimeTestcase.java?rev=754944&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKJavaRuntimeTestcase.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKJavaRuntimeTestcase.java Mon Mar 16 16:42:12 2009
@@ -0,0 +1,286 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.tck.harness;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import com.ibm.dtfj.image.CorruptData;
+import com.ibm.dtfj.image.CorruptDataException;
+import com.ibm.dtfj.java.JavaClass;
+import com.ibm.dtfj.java.JavaClassLoader;
+import com.ibm.dtfj.java.JavaField;
+import com.ibm.dtfj.java.JavaHeap;
+import com.ibm.dtfj.java.JavaObject;
+import com.ibm.dtfj.java.JavaRuntime;
+import com.ibm.dtfj.tck.api.IJavaRuntimeCreator;
+
+public abstract class TCKJavaRuntimeTestcase extends AbstractTCKTestcase {
+
+ private static JavaRuntime runtime=null;
+ private static IJavaRuntimeCreator creator=null;
+
+
+ /**
+ * Convert an address to a 0x hex number
+ * @param address
+ * @return A string representing the address
+ */
+ public static String format(long address) {
+ return "0x"+Long.toHexString(address);
+ }
+
+ /**
+ * Retrieves a field from a JavaClass by name.
+ *
+ * @param javaClass JavaClass to get field from
+ * @param fieldName name of field to retrieve.
+ * @return JavaField found, or null if not found.
+ * @throws CorruptDataException
+ */
+ public static JavaField getJavaField(JavaClass javaClass, String fieldName)
+ throws CorruptDataException {
+ JavaField foundField = null;
+
+ for(Iterator fields = javaClass.getDeclaredFields(); fields.hasNext();) {
+ Object nextField = fields.next();
+
+ if (nextField instanceof CorruptData) {
+ continue;
+ }
+
+ JavaField field = (JavaField) nextField;
+
+ if (field.getName().equals(fieldName)) {
+ foundField = field;
+ break;
+ }
+ }
+
+ return foundField;
+ }
+
+ /**
+ * Retrieve a JavaField by name from a JavaObject.
+ * You must use the JavaField on the passed JavaObject
+ * to get the actual field contents though.
+ *
+ * @param javaObject JavaObject to retrieve the JavaField from.
+ * @param fieldName The name of the JavaField to retrieve
+ * @return JavaField or null if not found.
+ * @throws CorruptDataException
+ */
+ public static JavaField getJavaField(JavaObject javaObject, String fieldName)
+ throws CorruptDataException {
+ return getJavaField(javaObject.getJavaClass(), fieldName);
+ }
+
+ public JavaRuntime getJavaRuntime()
+ {
+ if(runtime==null) {
+ IJavaRuntimeCreator creator=getJavaRuntimeCreator();
+ try {
+
+ runtime=creator.createJavaRuntime(getConfiguration());
+ } catch (IOException e) {
+ report(e,"unable to create Java runtime image from dump");
+ }
+ if(runtime==null) report("unable to create Java runtime image from dump");
+ }
+ return runtime;
+ }
+
+
+ protected IJavaRuntimeCreator getJavaRuntimeCreator() {
+ if(creator!=null) return creator;
+
+ String className=getConfiguration().getImageCreatorClassName();
+
+ Class clazz=null;
+ try {
+ clazz = Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ report(e,"cannot locate JavaRuntime creator class "+className);
+
+ }
+ try {
+ creator=(IJavaRuntimeCreator) clazz.newInstance();
+ } catch (Exception e) {
+ report(e,"unable to instantiate JavaRuntime creator class "+className);
+ }
+ return creator;
+ }
+
+ /**
+ * Returns the system classloader for runtime.
+ * @return the JavaClassLoader object representing the system classloader.
+ */
+
+ protected JavaClassLoader getBootClassLoader() {
+
+ JavaRuntime run = getJavaRuntime();
+
+ // Find the bootstrap loader using the idea that it it the only loader to have loaded itself
+ JavaClassLoader bootLoader = null;
+ HashMap loaders = new HashMap();
+ for (Iterator i = run.getJavaClassLoaders(); i.hasNext();) {
+ Object next = i.next();
+ if (next instanceof CorruptData) {
+ continue;
+ }
+ JavaClassLoader jcl = (JavaClassLoader)next;
+ try {
+ JavaObject loaderObject = jcl.getObject();
+ // Remember the class loader
+ loaders.put(loaderObject, jcl);
+ if (loaderObject == null) {
+ // Potential boot loader
+ System.out.println("Found class loader with null Java object "+jcl);
+ bootLoader = jcl;
+ break;
+ } else if (loaderObject.getJavaClass().getName().equals("*System*")) {
+ System.out.println("Found class loader of type *System* "+jcl);
+ bootLoader = jcl;
+ break;
+ } else {
+ JavaClass loadObjectClass = loaderObject.getJavaClass();
+ System.out.println("Found class loader "+loadObjectClass.getName()+" at "+format(loaderObject.getID().getAddress()));
+ JavaClassLoader jcl2 = getClassLoader(loadObjectClass);
+ if (jcl.equals(jcl2)) {
+ System.out.println("Found boot class loader "+loadObjectClass.getName()+" at "+format(loaderObject.getID().getAddress()));
+ bootLoader = jcl;
+ break;
+ }
+ }
+ } catch (CorruptDataException e) {
+ }
+ }
+ return bootLoader;
+
+ }
+
+ /**
+ * Basic class loader finder - copes with arrays not having a loader, use component type loader instead
+ * @param j2
+ * @param listener TODO
+ *
+ * @throws CorruptDataException
+ */
+ private JavaClassLoader getClassLoader1(JavaClass j2) throws CorruptDataException {
+ JavaClassLoader load;
+ // Fix up possible problem with arrays not having a class loader
+ // Use the loader of the component type instead
+ for (JavaClass j3 = j2; ; j3 = j3.getComponentType()) {
+ load = j3.getClassLoader();
+ if (load != null) break;
+ }
+ return load;
+ }
+
+ /**
+ * General class loader finder
+ * @param j1
+ * @param listener TODO
+ *
+ * @throws CorruptDataException
+ */
+ private JavaClassLoader getClassLoader(JavaClass j1) throws CorruptDataException {
+ try {
+ return getClassLoader1(j1);
+ } catch (CorruptDataException e) {
+ JavaClassLoader load = getClassLoader2(j1);
+ if (load != null) return load;
+ throw e;
+ }
+ }
+
+ /**
+ * @param j1
+ *
+ * @throws CorruptDataException
+ */
+ private JavaClassLoader getClassLoader2(JavaClass j1) throws CorruptDataException {
+ JavaClassLoader load = null;
+ JavaRuntime run = getJavaRuntime();
+ for (Iterator i = run.getJavaClassLoaders(); i.hasNext();) {
+ Object next = i.next();
+ if (next instanceof CorruptData) {
+ continue;
+ }
+ JavaClassLoader jcl = (JavaClassLoader)next;
+ for (Iterator j = jcl.getDefinedClasses();j.hasNext();) {
+ Object next2 = j.next();
+ if (next2 instanceof CorruptData) {
+ continue;
+ }
+ JavaClass j2 = (JavaClass)next2;
+ if (j2.equals(j1)) {
+ return jcl;
+ }
+ }
+ }
+ return load;
+ }
+
+
+ private JavaObject thisJavaObject = null;
+ /**
+ * Finds the JavaObject in the DTFJ Dump that corresponds with this
+ * testcase.
+ *
+ * @return The dead version of the test, or null.
+ */
+ public JavaObject getThis() {
+ String testName = this.getClass().getName().replace('.', '/');
+ if (thisJavaObject == null) {
+ return thisJavaObject = getJavaObjectByClassname(testName);
+ }
+
+ return null;
+ }
+
+ public JavaObject getJavaObjectByClassname(String className) {
+ JavaRuntime run = getJavaRuntime();
+
+ for(Iterator heaps = run.getHeaps(); heaps.hasNext();) {
+ Object nextHeap = heaps.next();
+
+ if (nextHeap instanceof CorruptData) {
+ continue;
+ }
+
+ JavaHeap heap = (JavaHeap) nextHeap;
+
+ for(Iterator objects = heap.getObjects(); objects.hasNext();) {
+ Object nextObject = objects.next();
+
+ if (nextObject instanceof CorruptData) {
+ continue;
+ }
+
+ JavaObject object = (JavaObject) nextObject;
+
+ try {
+ if (className.equals(object.getJavaClass().getName())) {
+ return object;
+ }
+ } catch (CorruptDataException e) {
+ // Ignore, it might be a following object.
+ }
+ }
+ }
+ return null;
+ }
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKLauncher.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKLauncher.java?rev=754944&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKLauncher.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKLauncher.java Mon Mar 16 16:42:12 2009
@@ -0,0 +1,542 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.tck.harness;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.util.LinkedList;
+import java.util.List;
+
+import com.ibm.dtfj.anttasks.tcklistbuilder.TCKDefinition;
+import com.ibm.dtfj.anttasks.tcklistbuilder.TCKDefinitionXMLReader;
+import com.ibm.dtfj.tck.api.IDumpCreator;
+import com.ibm.dtfj.tck.api.IImageCreator;
+import com.ibm.dtfj.tck.api.PropertyStore;
+import com.ibm.dtfj.tck.api.TCKConfiguration;
+import com.ibm.dtfj.tck.api.TCKException;
+
+/**
+ * This class has a main method that is the entry point for TCK execution via
+ * the TCK.jar directly
+ *
+ *
+ * command line options are listed below. They are all optional
+ *
+ * -testconfig the name of the properties file that contains the required information for executing the a
+ * testcase suite. If not specified then the program just uses the default config which is
+ * ${user.home}/tck.properties.
+ *
+ * The configuration used by this program is a tiered collection of properties from potentially four
+ * sources. At the lowest level is that provided by the default configuration held by the tck itself
+ * followed by ${user.home}/tck.properties , test config file, and finally system properties
+ * Any property set at a logically higher level overrides any from those below
+ *
+ * -dumponly this option prevents the execution of testcases. The dump creation phase is executed only
+ *
+ * -testonly this option inhibits the dump creation phase of the tck process. It is assumed that the dump
+ * has already been produced and that it exists in the expected location (default is ${user.home}/kato.output/tck.output)
+ *
+ * -output this option allows the user to specify a file to which all console output will be directed
+ *
+ * -tckconfig the name of a config file which contains the xml that defines testcase execution and expected results
+ *
+ */
+public class TCKLauncher {
+
+ private TCKConfiguration config = null;
+ private String classPath = null;
+ private TCKReporter reporter=null;
+
+ public TCKLauncher(TCKReporter reporter,TCKConfiguration config) {
+ this.config = config;
+ this.reporter=reporter;
+
+ // create fully qualified class path for use by the launchers
+
+ classPath = config.getFullyQualifiedClasspath();
+
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+
+
+ TCKReporter reporter=new TCKReporter();
+
+ TCKLauncherConfigurator configurator=new TCKLauncherConfigurator(args);
+
+ if(configurator.isValid()==false) {
+
+ String errorMessage=configurator.getErrorMessage();
+ if(errorMessage!=null) {
+ reporter.report(errorMessage);
+ }
+ usage(reporter);
+ return;
+ }
+
+ File outputLocation=configurator.getOutputLocation();
+
+ // was a alternative output provided?
+ if(outputLocation!=null) {
+ try {
+ TCKReporter newReporter=new TCKReporter(outputLocation);
+ reporter=newReporter;
+ } catch (IOException e) {
+
+ e.printStackTrace();
+ reporter.report("error setting output");
+ return;
+ }
+ }
+
+ // if a tck config is provided then set the system properties to suit
+ File tckConfigFile=configurator.getTCKConfigFile();
+ if(tckConfigFile!=null) {
+ System.getProperties().setProperty(TCKConfiguration.TCK_TESTCONFIG,tckConfigFile.getAbsolutePath());
+ }
+
+
+ // build a property store to bring config files together
+
+ TCKConfiguration config =null;
+
+ File testConfigFile=configurator.getTestConfigFile();
+
+ if(testConfigFile!=null) {
+ config = TCKConfiguration.getConfiguration(testConfigFile);
+ }
+ else {
+ config=TCKConfiguration.getConfiguration();
+ }
+
+
+
+
+ TCKLauncher launcher1 = new TCKLauncher(reporter,config);
+
+ if(launcher1.validateConfiguration()==false) {
+ return; // error already written
+ }
+
+ File workingDir = config.getWorkingDirectory();
+
+
+ // if producing a dump clear the output dir
+
+ if(configurator.isRunDump()) {
+ launcher1.clearOuputDir(workingDir);
+ }
+
+ // setup output directory
+ // copy in the test config file
+
+ launcher1.setup(workingDir,testConfigFile);
+
+
+
+
+ // now we run create the dump
+
+ try {
+ if(configurator.isRunDump()) {
+ launcher1.runCollector(testConfigFile,workingDir);
+ launcher1.createDump(testConfigFile);
+ }
+ if(configurator.isRunTests()) launcher1.runTests();
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ reporter.report("error creating dump");
+ return;
+ }
+
+ }
+
+
+
+ /**
+ * Copy file to new location
+ * @param testConfigFile
+ * @param file
+ * @throws IOException
+ */
+ private static void copyFile(File in, File out) throws IOException {
+
+
+ InputStream inStream=new FileInputStream(in);
+ PrintStream outStream=new PrintStream(new FileOutputStream(out));
+
+ TextStreamRedirector redirector=new TextStreamRedirector(inStream,outStream);
+ redirector.run();
+ inStream.close();
+ outStream.close();
+
+ }
+
+ private void setup( File workingDir,File testConfigFile) {
+
+
+ // write out a diagnostics file to show configuration
+
+ File configOut = new File(workingDir, "tck.config.xml");
+ try {
+ PropertyStoreXMLWriter writer=new PropertyStoreXMLWriter(config.getStore());
+ writer.write(configOut);
+ } catch (IOException e) {
+ e.printStackTrace();
+ reporter.report("error writing configuration setup to "
+ + configOut.getAbsolutePath());
+
+ }
+
+ if(testConfigFile!=null) {
+ try {
+ copyFile(testConfigFile,new File(workingDir,"tck.properties"));
+ } catch(IOException ioe) {
+ reporter.report("error copying testconfig", ioe);
+ throw new TCKException("error copying testconfig", ioe);
+ }
+
+ }
+ }
+
+ private void clearOuputDir(File workingDir) {
+ // clear out working directory
+ clearDir(workingDir);
+
+ // ensure output dir exists
+
+ workingDir.mkdir();
+ }
+
+ /**
+ * Removes all files in the specified directory and any child directories
+ * in unix terms is equivilant to "rm -rf"
+ *
+ * @param file
+ */
+ private static void clearDir(File file) {
+
+ if (file.exists()) {
+ if (file.isDirectory()) {
+ File[] kids = file.listFiles();
+ if (kids != null && kids.length > 0) {
+ for (int k = 0; k < kids.length; k++) {
+ clearDir(kids[k]);
+ }
+ }
+ } else {
+ file.delete();
+ }
+ }
+
+ }
+
+ /**
+ * Checks that required parameters are
+ * present and valid.
+ *
+ *
+ */
+ private boolean validateConfiguration() {
+
+ if(validateTCKConfig()==false) return false;
+
+ PropertyStore store=config.getStore();
+
+ // check dump creator class exists and is valid
+
+ String dumpCreator = store
+ .getRequiredProperty(TCKConfiguration.TCK_DUMPCREATOR_CLASS);
+ Class dumpCreatorClass = getClass(dumpCreator);
+ if (dumpCreatorClass.isAssignableFrom(IDumpCreator.class)) {
+ reporter.report("dump creator class does not implement "
+ + IDumpCreator.class.getCanonicalName());
+ return false;
+ }
+ // check image creator class exists and is valid
+
+ String imageCreator = store
+ .getRequiredProperty("tck.imagecreator.class");
+ Class imageCreatorClass = getClass(imageCreator);
+ if (imageCreatorClass.isAssignableFrom(IImageCreator.class)) {
+ reporter.report("image creator class does not implement "
+ + IImageCreator.class.getCanonicalName());
+ return false;
+ }
+
+ // check that a valid java launcher exists
+
+ String dumpCreatorLauncher = store
+ .getRequiredProperty(TCKConfiguration.TCK_DUMPCREATOR_LAUNCHER);
+ File launcher = new File(dumpCreatorLauncher);
+ if (launcher.exists() == false) {
+ reporter.report("launcher [" + launcher.getAbsolutePath()
+ + "] specified in property ["
+ + TCKConfiguration.TCK_DUMPCREATOR_LAUNCHER
+ + "] does not exist");
+ return false;
+ }
+ if (launcher.isFile() == false) {
+ reporter.report("launcher [" + launcher.getAbsolutePath()
+ + "] specified in property ["
+ + TCKConfiguration.TCK_DUMPCREATOR_LAUNCHER
+ + "] is not a file");
+ return false;
+ }
+
+ return true;
+ }
+
+ private boolean validateTCKConfig() {
+ PropertyStore store = config.getStore();
+
+ // test tck config option is correct by loading it.
+
+ String testsuite = store.getProperty(TCKConfiguration.TCK_TESTCONFIG);
+ if(testsuite!=null) {
+ File testSuiteFile=new File(testsuite);
+ if(testSuiteFile.exists()==false) {
+ reporter.report("tck config file " + testsuite + " does not exist");
+ return false;
+ }
+ if(testSuiteFile.isDirectory()) {
+ reporter.report("tck config file " + testsuite + " is not a file");
+ return false;
+ }
+ // load it..
+ TCKDefinitionXMLReader reader=new TCKDefinitionXMLReader();
+ try {
+ TCKDefinition def=reader.load(testSuiteFile);
+ } catch (Exception e) {
+
+ reporter.report("unable to load testsuite file "+testSuiteFile.getAbsolutePath(), e);
+ return false;
+ }
+ // no errors!
+ }
+ else {
+ // look for the "standard" config. This is relative to a testcase in the testsuite
+ Class testClazz=null;
+ try {
+ testClazz=Class.forName("com.ibm.dtfj.tck.tests.tagvalidation.TestValidateWindowsClassTag");
+ } catch (ClassNotFoundException e) {
+ String cp=System.getProperty("java.class.path");
+
+ reporter.report("unable to locate a TCK testcase in classpath "+cp,e);
+ return false;
+ }
+
+ InputStream in=testClazz.getResourceAsStream("/tck-definition.xml");
+ if(in==null) {
+ reporter.report("unable to locate TCK definition file");
+ return false;
+ }
+ // load it
+ TCKDefinitionXMLReader reader=new TCKDefinitionXMLReader();
+ try {
+ TCKDefinition def=reader.load(in);
+ in.close();
+ } catch (Exception e) {
+ reporter.report("unable to load standard testsuite file ", e);
+ return false;
+ }
+
+ }
+ return true;
+ }
+
+ private void runCollector(File testConfig, File outputdir) {
+
+ List envvars = config.getEnvironmentalVariables();
+ String bootclasspath = config.getDumpCreatorBootclassPath();
+
+ ProcessLauncher processlauncher = new ProcessLauncher(reporter);
+ processlauncher.setSuffix("collect: ");
+ List list = new LinkedList();
+ list.add(config.getJavaExecutablePath());
+
+ if (bootclasspath != null) {
+ list.add("-Xbootclasspath/p:" + bootclasspath);
+ }
+
+ list.add("-cp");
+ list.add(classPath);
+ list.add("com.ibm.dtfj.tck.harness.SetupCollector");
+ if(testConfig!=null) list.add(testConfig.getAbsolutePath());
+
+ try {
+ int result = processlauncher.launch(outputdir, envvars, list);
+ reporter.report("Configure Process completed rc=" + result);
+
+ } catch (IOException e) {
+ reporter.report("error during config process", e);
+ throw new TCKException("error during config process", e);
+ }
+
+ }
+
+
+ private Class getClass(String className) {
+
+ try {
+ Class clazz = Class.forName(className);
+ return clazz;
+ } catch (ClassNotFoundException e) {
+ reporter.report("cannot locate class " + className,e);
+ throw new TCKException("cannot locate class " + className);
+ }
+
+ }
+
+
+
+ private static void usage(TCKReporter reporter) {
+ reporter.report("Usage:");
+ reporter.report("[-testconfig configfile] [-output outfile] [-dumponly] [-testonly]");
+
+ }
+
+ private List getJVMArguments() throws IOException {
+ File args = config.getJVMArgumentsReportFile();
+ List list = new LinkedList();
+ if (args != null && args.exists()) {
+ list = loadFileAsList(args);
+ }
+ return list;
+
+ }
+
+ private List getEnvironmentalVariables() throws IOException {
+ File args = config.getEnvironmentalVariablesReportFile();
+ List list = new LinkedList();
+ list = loadFileAsList(args);
+ return list;
+
+ }
+
+ private List loadFileAsList(File args) throws IOException {
+ List list = new LinkedList();
+
+ FileReader fr = new FileReader(args);
+ BufferedReader br = new BufferedReader(fr);
+ while (true) {
+ String line = br.readLine();
+ if (line == null)
+ break;
+ list.add(line);
+ }
+
+ return list;
+ }
+
+ public void createDump(File userConfig) throws IOException {
+
+ File workingDir = config.getWorkingDirectory();
+ workingDir.mkdirs();
+
+ String bootclasspath = config.getDumpCreatorBootclassPath();
+
+ if (workingDir.exists() == false) {
+
+ workingDir.mkdirs();
+ }
+ List envvars = getEnvironmentalVariables();
+ List jvmArgs = getJVMArguments();
+
+ ProcessLauncher launcher = new ProcessLauncher(reporter);
+ launcher.setSuffix("config: ");
+ List list = new LinkedList();
+ list.add(config.getJavaExecutablePath());
+
+ if (bootclasspath != null) {
+ list.add("-Xbootclasspath/p:" + bootclasspath);
+ }
+ // add args
+ list.addAll(jvmArgs);
+
+ list.add("-cp");
+ list.add(classPath);
+ list.add("com.ibm.dtfj.tck.harness.Configure");
+ if(userConfig!=null) list.add(userConfig.getAbsolutePath());
+ launcher.launch(workingDir, envvars, list);
+
+ // log("dump created");
+ }
+
+ private void runTests() throws IOException {
+
+ File workingDir = config.getWorkingDirectory();
+ String classPath = config.getFullyQualifiedClasspath();
+ String bootclasspath = config.getImageCreatorBootclassPath();
+ String launcherPath = config.getJavaTestExecutablePath();
+ String junitRunner=config.getTestCaseRunner();
+
+ log("running tests: jre is " + launcherPath);
+ log("running tests: working dir is " + workingDir);
+ log("running tests: classpath is " + classPath);
+ log("running tests: boot classpath is " + bootclasspath);
+ log("running tests: runner is " + junitRunner);
+
+ boolean emmaCoverage = config.getStore().getPropertyAsBoolean(
+ "tck.emma.coverage", false);
+ String emmaOutputDir = config.getStore().getProperty("tck.emma.output",
+ ".");
+
+ log("emma state: format=" + emmaCoverage + " dir=" + emmaOutputDir);
+
+ List envvars = config.getEnvironmentalVariables();
+
+ ProcessLauncher launcher = new ProcessLauncher(reporter);
+
+ launcher.setSuffix("test: ");
+ List list = new LinkedList();
+
+ list.add(launcherPath);
+
+ if (bootclasspath != null) {
+ list.add("-Xbootclasspath/p:" + bootclasspath);
+ }
+
+ list.add("-cp");
+ list.add(classPath);
+
+ if (emmaCoverage) {
+ list.add("-Demma.coverage.out.file=" + emmaOutputDir);
+ list.add("-Dverbosity.level=verbose");
+ log("emma coverage enabled");
+ } else {
+ log("no emma coverage");
+ }
+ list.add(junitRunner);
+ list.add("com.ibm.dtfj.tck.harness.TCKTestCaseSuiteBuilder");
+
+ launcher.launch(workingDir, envvars, list);
+
+ }
+
+ private void log(String string) {
+ reporter.report(string);
+
+ }
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKLauncherConfigurator.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKLauncherConfigurator.java?rev=754944&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKLauncherConfigurator.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKLauncherConfigurator.java Mon Mar 16 16:42:12 2009
@@ -0,0 +1,176 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.tck.harness;
+
+import java.io.File;
+
+public class TCKLauncherConfigurator {
+
+ private String[] args=null;
+ private String error=null;
+ private boolean runTests=true;
+ private boolean runDump=true;
+ private File testConfigFile = null;
+ private File outputLocation = null;
+ private File tckConfigFile=null;
+
+ public TCKLauncherConfigurator(String[] args) {
+ this.args=args;
+ }
+ public String getErrorMessage() {
+ return error;
+ }
+ public boolean isValid() {
+
+
+ if (args == null || args.length == 0) {
+ return false;
+ }
+
+ Boolean dumponly=null;
+ Boolean testonly=null;
+
+
+ for (int i = 0; i < args.length; i++) {
+
+ String arg = args[i];
+ if (arg.equalsIgnoreCase("-testonly")) {
+ if(testonly!=null) {
+ error="-testonly can only be specified once";
+ return false;
+ }
+ testonly=new Boolean(true);
+ }
+ else if (arg.equalsIgnoreCase("-dumponly")) {
+ if(dumponly!=null) {
+ error="-dumponly can only be specified once";
+ return false;
+ }
+ dumponly=new Boolean(true);
+ }
+ else if (arg.equalsIgnoreCase("-tckconfig")) {
+ if (tckConfigFile != null) {
+ error="-tckconfig can only be specified once";
+ return false;
+ }
+ if ((i + 1) >= args.length) {
+ error="-tckconfig requires a filename";
+ return false;
+ }
+ i++;
+ String nextArg=args[i];
+ if(nextArg.startsWith("-")) {
+ error="-tckconfig requires a filename";
+ return false;
+ }
+
+ tckConfigFile = new File(nextArg);
+
+ if (tckConfigFile.exists()==false) {
+ error="testsuite file "+tckConfigFile.getAbsolutePath()+" does not exist";
+ return false;
+ }
+
+ if (tckConfigFile.isDirectory()) {
+ error="TCK config file "+tckConfigFile.getAbsolutePath()+" is a directory";
+ return false;
+ }
+
+ }
+ else if (arg.equalsIgnoreCase("-output")) {
+ if (outputLocation != null) {
+ error="-output can only be specified once";
+ return false;
+ }
+ if ((i + 1) >= args.length) {
+ error="-output requires a filename";
+ return false;
+ }
+ i++;
+ String nextArg=args[i];
+ if(nextArg.startsWith("-")) {
+ error="-output requires a filename";
+ return false;
+ }
+
+ outputLocation = new File(nextArg);
+
+ if (outputLocation.exists() && outputLocation.isDirectory()) {
+ error="output location "
+ + outputLocation.getAbsolutePath()
+ + " is a directory";
+ return false;
+ }
+
+ }
+ else if (arg.equalsIgnoreCase("-testconfig")) {
+ if (testConfigFile != null) {
+ error="-testconfig can only be specified once";
+ return false;
+ }
+ if ((i + 1) >= args.length) {
+ error="-testconfig requires a filename";
+ return false;
+ }
+ i++;
+ String nextArg=args[i];
+ if(nextArg.startsWith("-")) {
+ error="-testconfig requires a filename";
+ return false;
+ }
+ testConfigFile = new File(nextArg);
+ if (testConfigFile.exists() == false) {
+ error="testconfig file "
+ + testConfigFile.getAbsolutePath()
+ + " does not exist";
+ return false;
+ }
+ if (testConfigFile.isFile() == false) {
+ error="testconfig file "
+ + testConfigFile.getAbsolutePath()
+ + " is not a file";
+ return false;
+ }
+
+ } else {
+ error="argument " + arg + " is not understood";
+
+ return false;
+ }
+ }
+
+ if(testonly==null) testonly=new Boolean(false);
+ if(dumponly==null) dumponly=new Boolean(false);
+
+ runTests=!dumponly.booleanValue();
+ runDump=!testonly.booleanValue();
+
+ return true;
+ }
+ public File getTestConfigFile() {
+ return testConfigFile;
+ }
+ public File getOutputLocation() {
+ return outputLocation;
+ }
+ public boolean isRunTests() {
+ return runTests;
+ }
+ public boolean isRunDump() {
+ return runDump;
+ }
+ public File getTCKConfigFile() {
+ return tckConfigFile;
+ }
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKProcessTestcase.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKProcessTestcase.java?rev=754944&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKProcessTestcase.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKProcessTestcase.java Mon Mar 16 16:42:12 2009
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.tck.harness;
+
+import com.ibm.dtfj.image.Image;
+import com.ibm.dtfj.tck.api.IImageCreator;
+
+public abstract class TCKProcessTestcase extends AbstractTCKTestcase{
+
+ private static Image image=null;
+
+ private static IImageCreator imageCreator=null;
+
+ protected Image getImage()
+ {
+ if(image==null) {
+ IImageCreator creator=getImageCreator();
+
+ try {
+ image=creator.createProcessImage(getConfiguration());
+ } catch (Exception e) {
+
+ report(e,"unable to create process image from dump");
+ }
+ if(image==null) report("unable to create process image from dump");
+ }
+ return image;
+ }
+
+ private IImageCreator getImageCreator()
+ {
+
+
+ if(imageCreator!=null) return imageCreator;
+
+ String className=getConfiguration().getImageCreatorClassName();
+
+ Class clazz=null;
+ try {
+ clazz = Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ report(e,"cannot locate Image generator class "+className);
+
+ }
+ try {
+ imageCreator=(IImageCreator) clazz.newInstance();
+ } catch (Exception e) {
+ report(e,"unable to instantiate Image creator class "+className);
+ }
+ return imageCreator;
+ }
+
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKReporter.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKReporter.java?rev=754944&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKReporter.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKReporter.java Mon Mar 16 16:42:12 2009
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.tck.harness;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+
+public class TCKReporter {
+
+ private PrintWriter out=null;
+
+ public TCKReporter(PrintWriter out) {
+ this.out=out;
+ }
+ public TCKReporter(PrintStream out) {
+ this.out=new PrintWriter(out);
+ }
+ public TCKReporter() {
+ this(System.out);
+ }
+ public TCKReporter(File output) throws IOException {
+ FileWriter fw=new FileWriter(output);
+ this.out=new PrintWriter(fw);
+ }
+ public void report(String message) {
+ out.println(message);
+ out.flush();
+ }
+ public void report(String text, Throwable e) {
+ out.println(text);
+ out.flush();
+ e.printStackTrace(out);
+
+ }
+
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKTestCaseSuiteBuilder.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKTestCaseSuiteBuilder.java?rev=754944&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKTestCaseSuiteBuilder.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKTestCaseSuiteBuilder.java Mon Mar 16 16:42:12 2009
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.tck.harness;
+
+import java.io.File;
+import java.util.Iterator;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import com.ibm.dtfj.anttasks.tcklistbuilder.TCKDefinition;
+import com.ibm.dtfj.anttasks.tcklistbuilder.TCKDefinition.TCKClassDefinition;
+
+public class TCKTestCaseSuiteBuilder extends AbstractLauncher {
+
+ public TCKTestCaseSuiteBuilder() {
+
+ File workingDir=getConfig().getWorkingDirectory();
+ setUserConfiguration(new File(workingDir,"tck.properties"));
+
+ }
+
+ public static Test suite() {
+
+
+ final TCKTestCaseSuiteBuilder builder=new TCKTestCaseSuiteBuilder();
+ final TestSuite suite = new TestSuite();
+
+
+ // load classes
+ TCKDefinition def=builder.getConfig().getTestcaseConfiguration();
+ builder.log("Definition date = "+def.getCreatedDate());
+ VisitStatistics stats=builder.visitFiles(suite,def);
+
+ builder.log("Testcase roots scanned = "+stats.roots);
+ builder.log(" of which archives = "+stats.archiveRoots);
+ builder.log(" of which directories = "+stats.directoryRoots);
+ builder.log(" of which files = "+stats.fileRoots);
+ builder.log("Testcases found = "+stats.testcasesFound);
+ builder.log("End of Stats");
+
+ return suite;
+ }
+
+ private VisitStatistics visitFiles(TestSuite suite,TCKDefinition def) {
+
+ VisitStatistics stats=new VisitStatistics();
+
+ Iterator classes=def.classIterator();
+ while(classes.hasNext()) {
+ TCKClassDefinition clazz=(TCKClassDefinition) classes.next();
+ String qualifedName=clazz.getQualifedClassName();
+ Class realClass;
+ try {
+ realClass = Class.forName(qualifedName);
+ stats.classesFound++;
+ } catch (ClassNotFoundException e) {
+ stats.classesNotFound++;
+ System.err.println("cannot find class "+qualifedName+" on classpath");
+ continue;
+ }
+
+
+ if(TestCase.class.isAssignableFrom(realClass)) {
+ stats.testcasesFound++;
+ suite.addTestSuite(realClass);
+ }
+ else {
+ System.err.println("class "+qualifedName+" is not a TestCase class");
+ }
+
+ }
+
+ return stats;
+ }
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKTestcaseRunner.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKTestcaseRunner.java?rev=754944&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKTestcaseRunner.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.harness/src/com/ibm/dtfj/tck/harness/TCKTestcaseRunner.java Mon Mar 16 16:42:12 2009
@@ -0,0 +1,338 @@
+/*******************************************************************************
+ * 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 com.ibm.dtfj.tck.harness;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.LinkedList;
+import java.util.List;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestFailure;
+import junit.framework.TestResult;
+import junit.textui.ResultPrinter;
+import junit.textui.TestRunner;
+
+import com.ibm.dtfj.tck.api.TCKConfiguration;
+import com.ibm.dtfj.tck.results.reporter.TCKResultSet;
+import com.ibm.dtfj.tck.results.reporter.TestExecutionConfig;
+import com.ibm.dtfj.tck.results.reporter.TestcaseResult;
+import com.ibm.dtfj.tck.results.reporter.TestcaseResultError;
+import com.ibm.dtfj.tck.results.reporter.TestcaseResultFailure;
+import com.ibm.dtfj.tck.results.reporter.TestcaseResultPass;
+
+public class TCKTestcaseRunner {
+
+
+
+ public static void main(String args[]) {
+ TestRunner runner= new TestRunner();
+
+
+ TestExecutionConfig config=new TestExecutionConfig();
+ TCKResultSet set=new TCKResultSet(config,new Date().toString(),null);
+
+ PrintStream oldOut=System.out;
+ PrintStream oldErr=System.err;
+
+
+
+ runner.setPrinter(new TCKTestResultPrinter(set));
+
+ int returncode=0;
+
+ try {
+
+ TestResult r= runner.start(args);
+ System.setErr(oldErr);
+ System.setOut(oldOut);
+
+
+ if(r.wasSuccessful()==false) {
+
+ returncode=-1;
+ }
+
+ } catch (Exception e) {
+ System.setErr(oldErr);
+ System.setOut(oldOut);
+ returncode=-2;
+ e.printStackTrace();
+
+ }
+ System.out.println("===============================");
+ System.out.println("run "+set.getTestcaseCount()+" failures "+set.getFailureCount()+" errors " + set.getErrorCount());
+ System.out.println(ConsoleOutputConstants.TCK_TEST_SUITE_EXECUTION_ENDS);
+
+ System.exit(returncode);
+ }
+
+
+}
+
+ class TCKTestResultPrinter extends ResultPrinter implements ConsoleOutputConstants {
+
+
+
+ TCKConfiguration config=TCKConfiguration.getConfiguration();
+ ByteArrayOutputStream stdstore=null;
+ ByteArrayOutputStream errstore=null;
+ PrintStream stdout=null;
+ PrintStream stderr=null;
+ boolean prologWritten=false;
+
+ PrintStream consoleOut=System.out;
+ PrintStream consoleErr=System.err;
+
+ private TCKResultSet resultSet=null;
+ TestcaseResult currenttest=null;
+
+
+ public TCKTestResultPrinter(TCKResultSet set) {
+ super(System.out);
+ resultSet=set;
+ }
+
+
+
+ public void addError(Test test, Throwable t) {
+
+ if(currenttest==null) return; // not for us
+
+ if(test instanceof TestCase) {
+ stderr.println(STACK_TRACE_START);
+ t.printStackTrace(stderr);
+ stderr.println(STACK_TRACE_END);
+ TestCase testcase=(TestCase) test;
+ currenttest=new TestcaseResultError(testcase.getClass().getName(),testcase.getName(),0,"",t);
+
+ }
+ else {
+
+ consoleOut.println("!! "+test.toString());
+ t.printStackTrace(consoleOut);
+ }
+
+
+ }
+
+ public void addFailure(Test test, AssertionFailedError t) {
+
+ if(currenttest==null) return; // not for us
+
+ if(test instanceof TestCase) {
+ stderr.println(STACK_TRACE_START);
+ t.printStackTrace(stderr);
+ stderr.println(STACK_TRACE_END);
+ TestCase testcase=(TestCase) test;
+ currenttest=new TestcaseResultFailure(testcase.getClass().getName(),testcase.getName(),0,"",t);
+
+ }
+ else {
+
+ consoleOut.println("!! "+test.toString());
+ t.printStackTrace(consoleOut);
+ }
+ }
+
+
+
+
+ public void endTest(Test test) {
+
+
+ if(currenttest!=null) {
+
+
+ // get std err etc
+
+ System.out.flush();
+ System.err.flush();
+ stdout.flush();
+ stderr.flush();
+ String[] standardoutput;
+ String[] erroutput;
+ try {
+ standardoutput = loadData(stdstore.toByteArray());
+ stdstore=null;
+ erroutput = loadData(errstore.toByteArray());
+ errstore=null;
+ } catch (IOException e) {
+ e.printStackTrace(consoleErr);
+ throw new RuntimeException("error loading output for "+test,e);
+ }
+
+ // write out results
+ int lines=standardoutput.length+erroutput.length;
+
+
+ if(currenttest instanceof TestcaseResultPass) {
+ consoleOut.println(TCK_TEST_PASSED+test+" "+lines);
+
+ }
+ else if(currenttest instanceof TestcaseResultFailure) {
+ consoleOut.println(TCK_TEST_FAILED+test+" "+lines);
+
+ }
+ else {
+ consoleOut.println(TCK_TEST_ERROR+test+" "+lines);
+
+ }
+ // save results
+
+ resultSet.addTestcaseResult(currenttest);
+ currenttest.setOutput(standardoutput);
+ currenttest.setError(erroutput);
+
+
+ if(lines>0) writeLog(currenttest);
+ currenttest=null;
+ }
+
+ if(stdout!=null) stdout.close();
+ if(stderr!=null) stderr.close();
+ }
+
+ private void writeLog(TestcaseResult test) {
+
+ writeArray(test.getOutput());
+ writeArray(test.getError());
+
+
+ }
+
+
+
+ private void writeArray(String[] data) {
+ if(data==null || data.length==0) return;
+ for(int i=0;i<data.length;i++) {
+ consoleOut.println(data[i]);
+ }
+ }
+
+
+
+ private String[] loadData(byte[] array) throws IOException {
+
+ ByteArrayInputStream bis=new ByteArrayInputStream(array);
+ InputStreamReader isr=new InputStreamReader(bis);
+ BufferedReader br=new BufferedReader(isr);
+ List data=new LinkedList();
+ while(true) {
+ String line=br.readLine();
+ if(line==null) break;
+ data.add(line);
+ }
+
+ br.close();
+
+
+ return (String[]) data.toArray(new String[0]);
+
+ }
+
+ public void printDefect(TestFailure booBoo, int count) {
+ }
+
+ protected void printDefectHeader(TestFailure booBoo, int count) {
+
+ }
+
+ protected void printDefects(Enumeration booBoos, int count, String type) {
+
+ }
+
+ protected void printDefectTrace(TestFailure booBoo) {
+ }
+
+ protected void printErrors(TestResult result) {
+
+ }
+
+ protected void printFailures(TestResult result) {
+
+ }
+
+ protected void printFooter(TestResult result) {
+
+ }
+
+ protected void printHeader(long runTime) {
+
+ }
+
+ public void startTest(Test test) {
+
+
+ if(prologWritten==false) {
+ writeProlog();
+ }
+ currenttest=null;
+
+ if(test instanceof TestCase) {
+ TestCase testcase=(TestCase) test;
+ currenttest=new TestcaseResultPass(testcase.getClass().getName(),testcase.getName(),0);
+
+ stdstore=new ByteArrayOutputStream();
+ stdout=new PrintStream(stdstore);
+ errstore=new ByteArrayOutputStream();
+ stderr=new PrintStream(errstore);
+ System.setErr(stderr);
+ System.setOut(stdout);
+
+ }
+ else {
+
+ consoleOut.println("!! "+test.toString());
+
+ }
+
+
+ }
+
+
+ /**
+ * write test meta data to console.
+ * Warning - the sequence of this output is depended upon by
+ * the ConsoleOutputResultsReader class
+ */
+ private void writeProlog() {
+ consoleOut.println("\n"+TCK_TEST_SUITE_EXECUTION_BEGINS);
+ consoleOut.println("===============================");
+ consoleOut.println(DUMPTYPE+config.getDumpType());
+ consoleOut.println(VENDOR+config.getVendor());
+ consoleOut.println(VMTYPE+config.getVMType());
+ consoleOut.println(VERSION+config.getVersion());
+ consoleOut.println(WORDSIZE+config.getWordSize());
+ consoleOut.println(TESTSUITE+config.getTestcaseType());
+ consoleOut.println(OS+config.getOSName());
+ consoleOut.println(ARCH+config.getArchitecture());
+ consoleOut.println(BUILD+config.getStore().getProperty("buildname"));
+ consoleOut.println(DATE+new Date());
+ consoleOut.println("===============================");
+
+ prologWritten=true;
+ }
+
+
+ }
+