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 sp...@apache.org on 2009/11/24 12:27:11 UTC
svn commit: r883669 [4/6] - in
/incubator/kato/trunk/org.apache.kato/kato.tck: ./ src/test/ant/
src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/kato/
src/test/java/org/apache/kato/tck/ src/test/java/org/apache/kato/tck/tests/
src/...
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime_getHeapRoots.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime_getHeapRoots.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime_getHeapRoots.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime_getHeapRoots.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,345 @@
+/*******************************************************************************
+ * 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.kato.tck.tests.javaruntime;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.tools.diagnostics.image.CorruptData;
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.MemoryAccessException;
+import javax.tools.diagnostics.runtime.java.JavaClass;
+import javax.tools.diagnostics.runtime.java.JavaClassLoader;
+import javax.tools.diagnostics.runtime.java.JavaField;
+import javax.tools.diagnostics.runtime.java.JavaObject;
+import javax.tools.diagnostics.runtime.java.JavaReference;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+import javax.tools.diagnostics.runtime.java.JavaThread;
+
+import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
+import org.apache.kato.tck.scenario142.javaruntime.SetupJavaRuntime_getHeapRoots;
+import org.apache.kato.tck.scenario142.javaruntime.SetupJavaRuntime_getHeapRoots.HeapRoot;
+import org.apache.kato.tck.tests.javaruntime.TestJavaStackFrame_getHeapRoots.HeapRootsTestLocalVariable;
+import org.apache.kato.tck.tests.javaruntime.TestJavaStackFrame_getHeapRoots.HeapRootsTestParam;
+
+
+public class TestJavaRuntime_getHeapRoots extends TCKJavaRuntimeTestcase {
+
+ private SetupJavaRuntime_getHeapRoots setup=new SetupJavaRuntime_getHeapRoots();
+
+ private static JavaClass javaLangString = null;
+
+ public static Map rootsCheckList = null;
+
+
+
+ public void testSystemClassRoots() {
+ if (rootsCheckList == null) {
+ rootsCheckList = getRootsCheckList();
+ }
+ assertTrue("Found system classes not reported as roots.", checkSystemClasses(rootsCheckList));
+ }
+
+ public void testThreadRoot() {
+ if (rootsCheckList == null) {
+ rootsCheckList = getRootsCheckList();
+ }
+ HeapRoot[] roots = searchRootByClassName(rootsCheckList, "HeapRootsTestThread", JavaReference.HEAP_ROOT_THREAD);
+ assertTrue("Found thread not reported as root.", roots.length != 0);
+ }
+
+ public void testClassloaderRoot() {
+ if (rootsCheckList == null) {
+ rootsCheckList = getRootsCheckList();
+ }
+ HeapRoot[] roots = searchRootByClassName(rootsCheckList, "HeapRootsTestClassLoader", JavaReference.HEAP_ROOT_CLASSLOADER);
+ assertTrue("Found classloader not reported as root.", roots.length != 0);
+ }
+
+ public void testUnfinalizedRoot() {
+ if (rootsCheckList == null) {
+ rootsCheckList = getRootsCheckList();
+ }
+ HeapRoot[] roots = searchRootByClassName(rootsCheckList, "HeapRootsTestUnfinalized", JavaReference.HEAP_ROOT_UNFINALIZED_OBJ);
+ assertTrue("Found unfinalized object not reported as root.", roots.length != 0);
+
+ }
+
+ public void testFinalizableRoot() {
+ if (rootsCheckList == null) {
+ rootsCheckList = getRootsCheckList();
+ }
+
+ HeapRoot[] roots = searchRootByClassName(rootsCheckList, "HeapRootsTestFinalizable", JavaReference.HEAP_ROOT_FINALIZABLE_OBJ);
+ assertTrue("Found finalizable object not reported as root.", roots.length != 0);
+
+ }
+
+ public void testStringTableRoot() {
+ if (rootsCheckList == null) {
+ rootsCheckList = getRootsCheckList();
+ }
+ HeapRoot[] roots = searchRootByClassName(rootsCheckList, "", JavaReference.HEAP_ROOT_STRINGTABLE);
+ HeapRoot currentRoot = null;
+
+ JavaField countField = null;
+ JavaField valueField = null;
+ Iterator fields = javaLangString.getDeclaredFields().iterator();
+ while (fields.hasNext()) {
+ Object next = fields.next();
+ if (next instanceof JavaField) {
+ JavaField field = (JavaField) next;
+ try {
+ if (field.getName().equals("value")) {
+ valueField = field;
+ } else if (field.getName().equals("count")) {
+ countField = field;
+ }
+ } catch (CorruptDataException e) {
+ assertNotNull(e.getCorruptData());
+ }
+ }
+ }
+
+ boolean found = false;
+ for (int i=0; i<roots.length; i++) {
+ currentRoot = roots[i];
+ Object rootObject = currentRoot.getRoot();
+ if (!(rootObject instanceof JavaObject)) {
+ continue;
+ }
+ JavaObject root = (JavaObject)rootObject;
+
+ try {
+ int length = countField.getInt(root);
+ char[] contents = new char[length];
+ Object valueObj = valueField.get(root);
+ if (valueObj instanceof JavaObject) {
+ JavaObject value = (JavaObject)valueObj;
+ value.arraycopy(0, contents, 0, length);
+
+ }
+ String currentString = new String(contents);
+ if (SetupJavaRuntime_getHeapRoots.DTFJ_STRING_TABLE_ROOT_TEST.equals(currentString)) {
+ found = true;
+ break;
+ }
+ } catch (CorruptDataException e) {
+ assertNotNull(e.getCorruptData());
+ e.printStackTrace();
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ e.printStackTrace();
+ }
+
+ }
+ assertTrue("Found stringtable not reported as root.", found);
+ }
+
+
+/* to be moved to the JavaStackFrame#getHeapRoots()
+ public void testJavaParameters() {
+
+ if (rootsCheckList == null) {
+ rootsCheckList = getRootsCheckList();
+ }
+ assertTrue("Found local variable not reported as root.", checkRoot(rootsCheckList, "HeapRootsTestLocalVariableClass"));
+ }
+
+ public void testJavaLocalVariables() {
+
+ if (rootsCheckList == null) {
+ rootsCheckList = getRootsCheckList();
+ }
+ assertTrue("Found local variable not reported as root.", checkRoot(rootsCheckList, "HeapRootsTestLocalVariableClass"));
+ }
+*/
+
+ private Map getRootsCheckList() {
+ JavaRuntime runtime = getJavaRuntime();
+ Map rootsCheckList = new HashMap();
+ Iterator roots = runtime.getHeapRoots().iterator();
+ while (roots.hasNext()) {
+ Object next = roots.next();
+ if (next instanceof CorruptData) {
+ continue;
+ }
+ JavaReference r = (JavaReference)next;
+ try {
+ Object root = r.getTarget();
+ int type = r.getRootType();
+ HeapRoot rootObject = new HeapRoot(root, type);
+ rootsCheckList.put(rootObject, Boolean.FALSE);
+ //System.out.println("Adding " + rootObject + " to rootCheckList" );
+ } catch (DataUnavailable du) {
+ } catch (CorruptDataException cde) {
+ assertNotNull(cde.getCorruptData());
+ }
+ }
+ return rootsCheckList;
+ }
+
+ /** Tests whether all the system classes are correctly reported as roots */
+ // need to ignore primitive types
+ private boolean checkSystemClasses(Map rootsCheckList) {
+ JavaClassLoader systemClassLoader = getBootClassLoader();
+ Iterator systemClasses = systemClassLoader.getDefinedClasses().iterator();
+ boolean passed = true;
+ String systemClassName = null;
+ while (systemClasses.hasNext()) {
+ Object next = systemClasses.next();
+ if (next instanceof CorruptData) {
+ continue;
+ }
+ JavaClass systemClass = (JavaClass)next;
+ try {
+ systemClassName = systemClass.getName();
+ } catch (CorruptDataException e) {
+ assertNotNull(e.getCorruptData());
+ e.printStackTrace();
+ }
+
+ if (systemClassName.equals("java/lang/String")) {
+ javaLangString = systemClass; // to be used later on
+ }
+
+ // primitive types are reported as loaded by the System classloader,
+ // so they can be found, but they are not scanned as roots
+ if (!(systemClassName.equals("void")
+ || systemClassName.equals("boolean")
+ || systemClassName.equals("byte")
+ || systemClassName.equals("char")
+ || systemClassName.equals("short")
+ || systemClassName.equals("int")
+ || systemClassName.equals("long")
+ || systemClassName.equals("float")
+ || systemClassName.equals("double")))
+ {
+ Object rootClass = rootsCheckList.get(new HeapRoot(systemClass,JavaReference.HEAP_ROOT_SYSTEM_CLASS));
+ if (rootClass == null) {
+ System.out.println("Found a class loaded by the system classloader which is NOT a root:" + systemClassName);
+ passed = false;
+ } else {
+ //System.out.println("Found root object for system class: " + systemClassName);
+ rootsCheckList.put(rootClass, Boolean.TRUE);
+ }
+ }
+ }
+ return passed;
+ }
+
+ private HeapRoot[] searchRootByClassName(Map rootCheckList, String classNameToSearch) {
+ return searchRootByClassName(rootCheckList, classNameToSearch, 0);
+ }
+
+
+ private HeapRoot[] searchRootByClassName(Map rootCheckList, String classNameToSearch, int type) {
+ String className;
+ ArrayList roots = new ArrayList();
+ Iterator i = rootsCheckList.keySet().iterator();
+ while (i.hasNext()) {
+ Object next = i.next();
+ if (!(next instanceof HeapRoot)) {
+ continue;
+ }
+ HeapRoot rootObject = (HeapRoot)next;
+ Object root = rootObject.getRoot();
+ int rootType = rootObject.getType();
+ if (type != 0 && type != rootType) {
+ continue;
+ }
+ try {
+ if (root instanceof JavaObject) {
+ className = ((JavaObject)root).getJavaClass().getName();
+ } else if (root instanceof JavaClass) {
+ className = ((JavaClass)root).getName();
+ } else {
+ continue;
+ }
+
+// System.out.println("Checking root object of class: "+ className + " root type: " + HeapRoot.getRootTypeDescription(rootType));
+ if (className.endsWith(classNameToSearch)) {
+// System.out.println("Found root object of class: "+ className + " root type: " + HeapRoot.getRootTypeDescription(rootType));
+ roots.add(rootObject);
+ }
+ } catch (CorruptDataException e) {
+ assertNotNull(e.getCorruptData());
+ continue;
+ }
+ }
+ //System.out.println("Root object of type " + classNameToSearch + " not found.");
+ HeapRoot[] heapRoots = (HeapRoot[])roots.toArray(new HeapRoot[0]);
+ return heapRoots;
+ }
+
+ /**
+ * This test applies only to JVMs whose thread roots only appear with the rest of the roots,
+ * and not in JavaStackFrames because of conservative garbage collection.
+ */
+ public void testJavaThreadRoots() throws Exception {
+ JavaThread thread = null;
+
+ // Find the thread to match as a root source.
+ Iterator threads = getJavaRuntime().getThreads().iterator();
+ while(threads.hasNext()) {
+ JavaThread candidateThread = (JavaThread) threads.next();
+ if (setup.javaLocalRootsthreadName.equals(candidateThread.getName())) {
+ thread = candidateThread;
+ break;
+ }
+ }
+
+ assertNotNull("Couldn't find thread "+setup.javaLocalRootsthreadName, thread);
+
+ // Set up a set of JavaObject class names to look for.
+ Set roots = new HashSet();
+
+ roots.add(HeapRootsTestLocalVariable.class.getName().replace('.', '/'));
+ roots.add(HeapRootsTestParam.class.getName().replace('.', '/'));
+
+ // Find all JavaObject heaproots that have our test thread as a source
+ // Remove their class names from our set of expected names.
+ Iterator rootIterator = getJavaRuntime().getHeapRoots().iterator();
+ while(rootIterator.hasNext()) {
+ JavaReference reference = (JavaReference) rootIterator.next();
+
+ if (thread.equals(reference.getSource())) {
+ if(reference.getTarget() instanceof JavaObject) {
+ JavaObject target = (JavaObject) reference.getTarget();
+ roots.remove(target.getJavaClass().getName());
+ }
+ }
+
+ }
+
+ // Create error string of missing object.
+ String remainingRoots="";
+ // uh-oh, we should have found all our roots
+ if(roots.size()>0) {
+ Iterator rootsLeft = roots.iterator();
+
+ while(rootsLeft.hasNext()) {
+ remainingRoots += " " + ((String) rootsLeft.next());
+ }
+ }
+
+ assertFalse("Thread roots not found: " + remainingRoots, roots.size() >0);
+ }
+
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaStackFrame_getHeapRoots.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaStackFrame_getHeapRoots.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaStackFrame_getHeapRoots.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaStackFrame_getHeapRoots.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,198 @@
+/*******************************************************************************
+ * 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.kato.tck.tests.javaruntime;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.tools.diagnostics.image.CorruptData;
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.runtime.java.JavaClass;
+import javax.tools.diagnostics.runtime.java.JavaLocation;
+import javax.tools.diagnostics.runtime.java.JavaObject;
+import javax.tools.diagnostics.runtime.java.JavaReference;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+import javax.tools.diagnostics.runtime.java.JavaStackFrame;
+import javax.tools.diagnostics.runtime.java.JavaThread;
+
+import org.apache.kato.tck.api.ICheckpoint;
+import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
+import org.apache.kato.tck.scenario142.javaruntime.SetupJavaRuntime_getHeapRoots.HeapRoot;
+
+
+
+public class TestJavaStackFrame_getHeapRoots extends TCKJavaRuntimeTestcase {
+
+
+ class HeapRootsTestParam {}
+ class HeapRootsTestLocalVariable {}
+
+ public static final String threadName = "org.apache.kato.tck.tests.javaruntime.TestJavaStackFrame_getHeapRoots#configureJavaLocalsRoots";
+ private JavaStackFrame frame = null;
+ private Map rootsCheckList = new HashMap();
+
+// public String[] jvmDisableJIT()
+// {
+// System.out.println("Disabling JIT...");
+// return new String[]{"-Xint"};
+// }
+
+
+
+ public void setUp () {
+ JavaRuntime runtime = getJavaRuntime();
+ Iterator threads = runtime.getThreads().iterator();
+ JavaThread contrivedThread = null;
+ while (threads.hasNext()) {
+ Object next = threads.next();
+
+ if (next instanceof JavaThread) {
+ JavaThread thread = (JavaThread) next;
+ try {
+ //System.out.println("Thread: " + thread.getName());
+ if (threadName.equals( thread.getName())) {
+// System.out.println("Thread " + thread.getName() + " found!");
+ contrivedThread = thread;
+ break;
+ }
+ } catch (CorruptDataException e) {
+ assertNotNull(e.getCorruptData());
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ if (contrivedThread == null) {
+ fail("Couldn't find thread "+threadName);
+ }
+
+ Iterator frames = contrivedThread.getStackFrames().iterator();
+ JavaStackFrame currentFrame = null;
+ while (frames.hasNext() && frame == null) {
+ Object next = frames.next();
+
+ if (next instanceof JavaStackFrame) {
+ currentFrame = (JavaStackFrame) next;
+ try {
+ JavaLocation location = currentFrame.getLocation();
+ String methodName = location.getMethod().getName();
+// System.out.println("Method is: " + methodName + " "+ location.getFilename() + "@" + location.getLineNumber());
+ if ("methodA".equals(methodName)) {
+ frame = currentFrame;
+ }
+ } catch (Exception e) {
+ //e.printStackTrace();
+ }
+ }
+ }
+
+ if (null == frame) {
+ fail("Couldn't find stack frame for methodA");
+ }
+
+ Iterator roots = frame.getHeapRoots().iterator();
+ while (roots.hasNext()) {
+ Object next = roots.next();
+ if (next instanceof CorruptData) {
+ continue;
+ }
+ JavaReference r = (JavaReference)next;
+ try {
+ Object root = r.getTarget();
+ int type = r.getRootType();
+ HeapRoot rootObject = new HeapRoot(root, type);
+ rootsCheckList.put(rootObject, Boolean.FALSE);
+ //System.out.println("Adding " + rootObject + " to rootCheckList" );
+ } catch (DataUnavailable du) {
+ } catch (CorruptDataException cde) {
+ assertNotNull(cde.getCorruptData());
+ }
+ }
+
+
+ }
+
+
+ public void configureJavaLocalsRoots(ICheckpoint cp) {
+ HeapRootsTestParam param = new HeapRootsTestParam();
+ methodA(cp, param);
+ }
+
+ private void methodA(ICheckpoint cp, HeapRootsTestParam param) {
+ HeapRootsTestLocalVariable localVariable = new HeapRootsTestLocalVariable();
+ cp.checkpoint();
+ System.out.println(param);
+ System.out.println(localVariable);
+ }
+
+ private HeapRoot[] searchRootByClassName(Map rootCheckList, String classNameToSearch) {
+ return searchRootByClassName(rootCheckList, classNameToSearch, 0);
+ }
+
+
+ private HeapRoot[] searchRootByClassName(Map rootCheckList, String classNameToSearch, int type) {
+ String className;
+ ArrayList roots = new ArrayList();
+ Iterator i = rootsCheckList.keySet().iterator();
+ while (i.hasNext()) {
+ Object next = i.next();
+ if (!(next instanceof HeapRoot)) {
+ continue;
+ }
+ HeapRoot rootObject = (HeapRoot)next;
+ Object root = rootObject.getRoot();
+ int rootType = rootObject.getType();
+ if (type != 0 && type != rootType) {
+ continue;
+ }
+ try {
+ if (root instanceof JavaObject) {
+ className = ((JavaObject)root).getJavaClass().getName();
+ } else if (root instanceof JavaClass) {
+ className = ((JavaClass)root).getName();
+ } else {
+ continue;
+ }
+ if (className.endsWith(classNameToSearch)) {
+ //System.out.println("Found root object of class: "+ className + " root type: " + HeapRoot.getRootTypeDescription(rootType));
+// synchronized (root) {
+// rootsCheckList.put(root, Boolean.TRUE);
+// }
+ roots.add(rootObject);
+ }
+ } catch (CorruptDataException e) {
+ assertNotNull(e.getCorruptData());
+ continue;
+ }
+ }
+ //System.out.println("Root object of type " + classNameToSearch + " not found.");
+ HeapRoot[] heapRoots = (HeapRoot[])roots.toArray(new HeapRoot[0]);
+ return heapRoots;
+ }
+
+
+ public void testJavaLocalRoots() throws Exception {
+ HeapRoot[] roots = searchRootByClassName(rootsCheckList, "HeapRootsTestLocalVariable", JavaReference.HEAP_ROOT_STACK_LOCAL);
+ assertTrue("Found Local Variable object not reported as root.", roots.length != 0);
+ }
+
+ public void testParameterRoots() throws Exception {
+ HeapRoot[] roots = searchRootByClassName(rootsCheckList, "HeapRootsTestParam", JavaReference.HEAP_ROOT_STACK_LOCAL);
+ assertTrue("Found Local Variable object not reported as root.", roots.length != 0);
+ }
+
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaThreadInspection.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaThreadInspection.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaThreadInspection.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaThreadInspection.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * 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.kato.tck.tests.javaruntime;
+
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.MemoryAccessException;
+import javax.tools.diagnostics.runtime.java.JavaField;
+import javax.tools.diagnostics.runtime.java.JavaObject;
+import javax.tools.diagnostics.runtime.java.JavaThread;
+
+import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
+
+
+/**
+ * Tests to ensure that valid Thread objects get reported correctly
+ *
+ */
+public class TestJavaThreadInspection extends TCKJavaRuntimeTestcase{
+
+
+private JavaObject[] threadDumpInstances=null;
+
+
+ /**
+ * Locate special holder
+ * @throws CorruptDataException
+ * @throws MemoryAccessException
+ */
+ public void setUp() throws CorruptDataException, MemoryAccessException {
+
+ JavaObject thisTestInstanceInDump=getScenerioReference();
+ assertNotNull(thisTestInstanceInDump);
+
+
+ Iterator i=thisTestInstanceInDump.getJavaClass().getDeclaredFields().iterator();
+ assertNotNull("declared fields iterator is null",i);
+
+ while(i.hasNext()) {
+ Object o=i.next();
+ if(o instanceof JavaField) {
+ JavaField field=(JavaField) o;
+ String name=field.getName();
+ if(name.equals("configThreadInstances")) {
+ JavaObject obj=(JavaObject) field.get(thisTestInstanceInDump);
+ // found field
+
+ int arraySize=obj.getArraySize();
+ assertEquals(3,arraySize);
+ threadDumpInstances=new JavaObject[arraySize];
+ obj.arraycopy(0,threadDumpInstances,0,arraySize);
+ return;
+ }
+
+ }
+ }
+
+ fail("unable to locate thread instances field in testcase instance in dump");
+
+ }
+
+ /**
+ * Test that the contents of a thread created using new Thread() can be
+ * retrieved
+ */
+ public void testSimpleThreadCreation() throws Exception {
+ assertNotNull(threadDumpInstances);
+ JavaObject o1=threadDumpInstances[0];
+
+ Thread t=new Thread();
+ JavaThread jt;
+
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaThread_getName.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaThread_getName.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaThread_getName.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaThread_getName.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * 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.kato.tck.tests.javaruntime;
+
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.CorruptData;
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+import javax.tools.diagnostics.runtime.java.JavaThread;
+
+import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
+import org.apache.kato.tck.scenario142.javaruntime.SetupJavaThread_getName;
+
+
+public class TestJavaThread_getName extends TCKJavaRuntimeTestcase {
+
+
+ public void testJavaThread()
+ {
+ boolean foundThread = false;
+
+ JavaRuntime runtime=getJavaRuntime();
+
+ Iterator threads = runtime.getThreads().iterator();
+
+ while (threads.hasNext()) {
+ Object next = threads.next();
+
+ if (next instanceof CorruptData) {
+ System.err.println("returned CorruptData `" + next + "'");
+ break;
+ }
+
+ JavaThread thread = (JavaThread) next;
+
+ try {
+ if (0==SetupJavaThread_getName.threadName.compareTo(thread.getName())){
+ foundThread=true;
+ }
+ } catch (CorruptDataException e) {
+ assertNotNull(e.getCorruptData());
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ assertTrue(foundThread);
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaThread_getStackFrames.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaThread_getStackFrames.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaThread_getStackFrames.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaThread_getStackFrames.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * 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.kato.tck.tests.javaruntime;
+
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.runtime.java.JavaLocation;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+import javax.tools.diagnostics.runtime.java.JavaStackFrame;
+import javax.tools.diagnostics.runtime.java.JavaThread;
+
+import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
+import org.apache.kato.tck.scenario142.javaruntime.SetupJavaThread_getStackFrames;
+
+
+/**
+ *
+ * Tests JavaThread.getStackFrames(). Configures a thread with a known stack in
+ * the live JVM. Finds the thread, by name, in the dump and then retrieves it's
+ * JavaStackFrames and checks that the expected methods are there in the correct
+ * order. Ignores possible spurious methods inbetween the methods it does expect
+ * for implementation specifics.
+ *
+ */
+public class TestJavaThread_getStackFrames extends TCKJavaRuntimeTestcase {
+ public void setUp () {
+ JavaRuntime runtime = getJavaRuntime();
+ Iterator threads = runtime.getThreads().iterator();
+
+ while (threads.hasNext()) {
+ Object next = threads.next();
+
+ if (next instanceof JavaThread) {
+ JavaThread thread = (JavaThread) next;
+
+ try {
+ if (SetupJavaThread_getStackFrames.threadName.equals( thread.getName())) {
+ contrivedThread = thread;
+ break;
+ }
+ } catch (CorruptDataException e) {
+ assertNotNull(e.getCorruptData());
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ if (contrivedThread == null) {
+ fail("Couldn't find thread "+SetupJavaThread_getStackFrames.threadName);
+ }
+ }
+
+ private JavaThread contrivedThread;
+
+ public void testGetStackFrames() throws Exception {
+ Iterator frames = contrivedThread.getStackFrames().iterator();
+ int methodIndex = 0;
+
+ while (frames.hasNext()) {
+ Object next = frames.next();
+
+ if (next instanceof JavaStackFrame) {
+ JavaStackFrame frame = (JavaStackFrame) next;
+
+ JavaLocation location = frame.getLocation();
+
+ if ((methodIndex < SetupJavaThread_getStackFrames.methodNames.length)
+ && SetupJavaThread_getStackFrames.methodNames[methodIndex].equals(location.getMethod().getName())) {
+ methodIndex++;
+ }
+
+ }
+ }
+
+ assertEquals("Didn't find all expected methods name. Couldn't find "
+ + ((methodIndex < SetupJavaThread_getStackFrames.methodNames.length) ? SetupJavaThread_getStackFrames.methodNames[methodIndex] : ""), SetupJavaThread_getStackFrames.methodNames.length, methodIndex);
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/TestEnvironmentVariables.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/TestEnvironmentVariables.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/TestEnvironmentVariables.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/TestEnvironmentVariables.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * 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.kato.tck.tests.process;
+
+import java.util.Iterator;
+import java.util.Properties;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.Image;
+import javax.tools.diagnostics.image.ImageAddressSpace;
+import javax.tools.diagnostics.image.ImageProcess;
+import org.apache.kato.tck.harness.TCKProcessTestcase;
+import org.apache.kato.tck.scenario142.process.SetupEnvironmentVariables;
+
+
+public class TestEnvironmentVariables extends TCKProcessTestcase {
+
+
+ /**
+ * Tests that provided environmental variable is in dump and has
+ * correct value
+ * @throws CorruptDataException
+ * @throws DataUnavailable
+ */
+ public void testEnvironmentVariableRetrievedKeyValuePair() throws DataUnavailable, CorruptDataException {
+
+
+ // get image process
+
+
+ ImageProcess process=getProcess();
+
+ // get environment
+
+ Properties properties=process.getEnvironment();
+ String value=properties.getProperty(SetupEnvironmentVariables.KEY1);
+ assertEquals(SetupEnvironmentVariables.VALUE,value);
+
+
+
+ }
+ /**
+ * Tests that provided environmental variable is in dump and has
+ * correct value
+ * @throws CorruptDataException
+ * @throws DataUnavailable
+ */
+ public void testEnvironmentVariableRetrievedKeyOnly() throws DataUnavailable, CorruptDataException {
+
+
+ // get image process
+
+
+ ImageProcess process=getProcess();
+
+ // get environment
+
+ Properties properties=process.getEnvironment();
+ String value=properties.getProperty(SetupEnvironmentVariables.KEY2);
+ assertEquals("key2 value should be empty String","",value);
+
+
+
+ }
+ /**
+ * Tests that provided environmental variable is in dump and has
+ * correct value
+ * @throws CorruptDataException
+ * @throws DataUnavailable
+ */
+ public void testEnvironmentVariableRetrievedKeyNoValue() throws DataUnavailable, CorruptDataException {
+
+
+ // get image process
+
+
+ ImageProcess process=getProcess();
+
+ // get environment
+
+ Properties properties=process.getEnvironment();
+ String value=properties.getProperty(SetupEnvironmentVariables.KEY3);
+ System.out.println("KEY3 "+SetupEnvironmentVariables.KEY3+" value \""+value+"\"");
+ assertNull(value);
+
+
+
+ }
+ private ImageProcess getProcess() {
+
+ Image image=getImage();
+ Iterator addressIterator=image.getAddressSpaces().iterator();
+ ImageAddressSpace addressSpace=(ImageAddressSpace) addressIterator.next();
+ ImageProcess process=addressSpace.getCurrentProcess();
+ return process;
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/TestImage.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/TestImage.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/TestImage.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/TestImage.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.kato.tck.tests.process;
+
+import javax.tools.diagnostics.image.Image;
+import org.apache.kato.tck.harness.TCKProcessTestcase;
+
+
+/**
+ * Image Tests
+ *
+ *
+ */
+public class TestImage extends TCKProcessTestcase{
+
+ /**
+ * Simple test that image exists
+ */
+ public void testImageExists() {
+
+ Image image=getImage();
+ assertNotNull(image);
+
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageAddressSpace.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageAddressSpace.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageAddressSpace.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageAddressSpace.java Tue Nov 24 12:27:01 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 org.apache.kato.tck.tests.process.image;
+
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.CorruptData;
+import javax.tools.diagnostics.image.Image;
+import javax.tools.diagnostics.image.ImageAddressSpace;
+import org.apache.kato.tck.harness.TCKProcessTestcase;
+
+
+/**
+ * ImageAddressSpace
+ *
+ */
+public class TestImageAddressSpace extends TCKProcessTestcase{
+
+ /**
+ *
+ */
+ public void testAddressSpace() {
+
+ Image image=getImage();
+ Iterator addressSpaces = image.getAddressSpaces().iterator();
+
+ while (addressSpaces.hasNext()) {
+ Object nextAddressSpace = addressSpaces.next();
+ if (nextAddressSpace instanceof CorruptData) {
+ System.err.println("returned CorruptData `" + nextAddressSpace + "'");
+ break;
+ }
+
+ ImageAddressSpace anAddressSpace = (ImageAddressSpace) nextAddressSpace;
+
+ assertNotNull(anAddressSpace);
+ }
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetCreationTime.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetCreationTime.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetCreationTime.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetCreationTime.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.kato.tck.tests.process.image;
+
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.Image;
+import org.apache.kato.tck.harness.TCKProcessTestcase;
+
+
+public class TestImageGetCreationTime extends TCKProcessTestcase{
+
+
+
+ public void testGetCreationTime() throws Exception {
+
+ Image image=getImage();
+ long theCreationTime=0;
+ try {
+ theCreationTime = image.getCreationTime();
+ assertTrue(0!=theCreationTime);
+ } catch (DataUnavailable du) {
+ //allowed by the specification
+ }
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetHostName.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetHostName.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetHostName.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetHostName.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * 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.kato.tck.tests.process.image;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.Image;
+import org.apache.kato.tck.harness.TCKProcessTestcase;
+
+
+public class TestImageGetHostName extends TCKProcessTestcase{
+
+ /**
+ *
+ */
+ public void testGetHostName() {
+
+ Image image=getImage();
+ String theHostName=null;
+ try {
+ theHostName = image.getHostName();
+ } catch (CorruptDataException e) {
+ // allowed by the specification
+ return;
+ } catch (DataUnavailable e) {
+ // allowed by the specification
+ return;
+ }
+
+ assertNotNull(theHostName);
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetIPAddresses.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetIPAddresses.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetIPAddresses.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetIPAddresses.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * 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.kato.tck.tests.process.image;
+
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.CorruptData;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.Image;
+import org.apache.kato.tck.harness.TCKProcessTestcase;
+
+
+public class TestImageGetIPAddresses extends TCKProcessTestcase{
+
+ /**
+ *
+ */
+ public void testGetIPAddresses() {
+
+ Image image=getImage();
+ Iterator IPAdresses;
+ try {
+ IPAdresses = image.getIPAddresses();
+ while (IPAdresses.hasNext()) {
+ Object nextIPAddress = IPAdresses.next();
+ if (nextIPAddress instanceof CorruptData) {
+ System.err.println("returned CorruptData `" + nextIPAddress + "'");
+ break;
+ }
+ else
+ {
+ return;
+ }
+ }
+
+ } catch (DataUnavailable e) {
+ //this is acceptable
+ return;
+ }
+ assertTrue(false);
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetInstalledMemory.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetInstalledMemory.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetInstalledMemory.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetInstalledMemory.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * 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.kato.tck.tests.process.image;
+
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.Image;
+import org.apache.kato.tck.harness.TCKProcessTestcase;
+
+
+public class TestImageGetInstalledMemory extends TCKProcessTestcase{
+
+ /*
+ *
+ */
+ public void testGetInstalledMemory() {
+
+ Image image=getImage();
+ long theMemory=0;
+ try {
+ theMemory = image.getInstalledMemory();
+ // TODO test range is acceptable
+ assertTrue(0!=theMemory);
+ } catch (DataUnavailable e) {
+ // DataUnavailable is an acceptable return from getInstalledMemory()
+ }
+
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetProcessorCount.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetProcessorCount.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetProcessorCount.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetProcessorCount.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * 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.kato.tck.tests.process.image;
+
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.Image;
+import org.apache.kato.tck.harness.TCKProcessTestcase;
+
+
+public class TestImageGetProcessorCount extends TCKProcessTestcase{
+
+ /**
+ * @throws DataUnavailable
+ *
+ * @tck
+ */
+ public void testGet() throws DataUnavailable {
+
+ Image image=getImage();
+ long theValue=0;
+
+ theValue = image.getProcessorCount();
+ System.out.println("theValue "+theValue);
+ assertTrue(0!=theValue);
+
+
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetProcessorSubType.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetProcessorSubType.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetProcessorSubType.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetProcessorSubType.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.kato.tck.tests.process.image;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.Image;
+import org.apache.kato.tck.harness.TCKProcessTestcase;
+
+
+
+public class TestImageGetProcessorSubType extends TCKProcessTestcase{
+
+ /**
+ * @throws CorruptDataException
+ * @throws DataUnavailable
+ *
+ */
+ public void testGet() throws DataUnavailable, CorruptDataException {
+
+ Image image=getImage();
+ String theValue=image.getProcessorSubType();
+ assertNotNull("Processor subType is null",theValue);
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetProcessorType.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetProcessorType.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetProcessorType.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetProcessorType.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.kato.tck.tests.process.image;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.Image;
+import org.apache.kato.tck.harness.TCKProcessTestcase;
+
+
+
+public class TestImageGetProcessorType extends TCKProcessTestcase{
+
+ /**
+ * @throws CorruptDataException
+ * @throws DataUnavailable
+ *
+ */
+ public void testGetProcessorType() throws DataUnavailable, CorruptDataException {
+
+ Image image=getImage();
+ String theValue=image.getProcessorType();
+ assertNotNull("Processor type is null",theValue);
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetSystemSubType.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetSystemSubType.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetSystemSubType.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetSystemSubType.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.kato.tck.tests.process.image;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.Image;
+import org.apache.kato.tck.harness.TCKProcessTestcase;
+
+
+
+public class TestImageGetSystemSubType extends TCKProcessTestcase{
+
+ /**
+ * @throws CorruptDataException
+ * @throws DataUnavailable
+ *
+ */
+ public void testGetSystemSubType() throws DataUnavailable, CorruptDataException {
+
+ Image image=getImage();
+ String theValue=image.getSystemSubType();
+ assertNotNull("System subtype is null",theValue);
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetSystemType.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetSystemType.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetSystemType.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/process/image/TestImageGetSystemType.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * 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.kato.tck.tests.process.image;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.Image;
+import org.apache.kato.tck.harness.TCKProcessTestcase;
+
+
+
+public class TestImageGetSystemType extends TCKProcessTestcase {
+
+ /**
+ * @throws CorruptDataException
+ * @throws DataUnavailable
+ *
+ */
+ public void testGet() throws DataUnavailable, CorruptDataException {
+
+ Image image = getImage();
+ String theValue = null;
+ theValue = image.getSystemType();
+ assertNotNull("SystemType is null",theValue);
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/AbstractImageTestcase.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/AbstractImageTestcase.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/AbstractImageTestcase.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/AbstractImageTestcase.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,270 @@
+/*******************************************************************************
+ * 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.kato.tests.junit;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.tools.diagnostics.image.CorruptData;
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.Image;
+import javax.tools.diagnostics.image.ImageAddressSpace;
+import javax.tools.diagnostics.image.ImageFactory;
+import javax.tools.diagnostics.image.ImageModule;
+import javax.tools.diagnostics.image.ImageProcess;
+import javax.tools.diagnostics.image.ImageThread;
+import javax.tools.diagnostics.runtime.java.JavaClass;
+import javax.tools.diagnostics.runtime.java.JavaClassLoader;
+import javax.tools.diagnostics.runtime.java.JavaHeap;
+import javax.tools.diagnostics.runtime.java.JavaMethod;
+import javax.tools.diagnostics.runtime.java.JavaObject;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+import javax.tools.diagnostics.runtime.java.JavaThread;
+
+import org.apache.kato.tck.harness.TCKProcessTestcase;
+import org.apache.kato.tests.junit.ImageLoaderHelper.Capabilities;
+
+
+public abstract class AbstractImageTestcase extends TCKProcessTestcase {
+
+ private static Capabilities capabilities = null;
+
+ public ImageProcess defaultImageProcess() {
+ if(_proc==null) _proc= defaultAddressSpace().getCurrentProcess();
+ return _proc;
+ }
+
+ public ImageAddressSpace defaultAddressSpace() {
+ Image image = defaultTestingImage();
+
+ //TODO: come up with a good way to test each address space. For now we will just grab the first one
+ return (ImageAddressSpace) image.getAddressSpaces().get(0);
+ }
+
+ /**
+ * Returns the Image for testing, creating it if necessary
+ * @return The default testing image
+ */
+ public Image defaultTestingImage() {
+
+
+ try {
+ if (null == capabilities) {
+ capabilities=new ImageLoaderHelper().getCapabilities();
+ }
+ } catch (Throwable t) {
+ t.printStackTrace();
+ fail();
+ }
+ return capabilities.image;
+ }
+
+
+ private ImageProcess _proc = null;
+ private ImageModule _module = null;
+
+
+
+ public ImageModule defaultImageModule() {
+
+ if(_module!=null) return _module;
+
+ ImageProcess proc = defaultImageProcess();
+ List it = null;
+
+ try {
+ it = proc.getLibraries();
+ } catch (DataUnavailable e) {
+ //ok
+ } catch (CorruptDataException e) {
+ //ok
+ }
+ if (null == it) {
+ //we have nothing to test so throw unimplemented so we know it isn't a real bug
+ throw new TestNotImplementedException();
+ }
+ _module=(ImageModule) it.get(0);
+ return _module;
+ }
+
+ public ImageFactory getFactory() {
+ return capabilities.factory;
+ }
+
+ public JavaRuntime defaultJavaRuntime() {
+ JavaRuntime runtime = null;
+ Iterator it = defaultImageProcess().getRuntimes().iterator();
+
+ assertFalse(null == it);
+ while ((null == runtime) && (it.hasNext())) {
+ Object maybeRuntime = it.next();
+ if (maybeRuntime instanceof JavaRuntime) {
+ runtime = (JavaRuntime) maybeRuntime;
+ } else {
+ throw new TestNotImplementedException();
+ }
+ }
+ assertNotNull(runtime);
+ return runtime;
+ }
+
+ public JavaThread defaultJavaThread() {
+ JavaRuntime time = defaultJavaRuntime();
+ assertNotNull(time);
+ Iterator it = time.getThreads().iterator();
+ assertNotNull(it);
+ assertTrue(it.hasNext());
+ //threads without stack frames aren't very useful for testing so ignore them
+ // unless they are the only ones
+ JavaThread candidate = null;
+ do {
+ candidate = (JavaThread) it.next();
+ } while ((it.hasNext()) && (!candidate.getStackFrames().iterator().hasNext()));
+ return candidate;
+ }
+
+ public JavaClassLoader defaultJavaClassLoader() {
+ Iterator loaders = defaultJavaRuntime().getJavaClassLoaders().iterator();
+ assertTrue(loaders.hasNext());
+ JavaClassLoader loader = (JavaClassLoader) loaders.next();
+ Iterator i=loader.getDefinedClasses().iterator();
+ while ((!i.hasNext()) && (loaders.hasNext())) {
+ loader = (JavaClassLoader) loaders.next();
+ }
+ return loader;
+ }
+
+ public JavaClass defaultJavaClass() {
+ // Choose a class loader
+ JavaClassLoader loader = defaultJavaClassLoader();
+
+ // Choose a class which has a superclass
+ try {
+ for (Iterator iter = loader.getDefinedClasses().iterator(); iter.hasNext();) {
+ JavaClass clazz = (JavaClass) iter.next();
+ if ( !clazz.getName().equals("java/lang/Object") &&
+ !clazz.getName().equals("boolean" ) &&
+ !clazz.getName().equals("byte" ) &&
+ !clazz.getName().equals("char" ) &&
+ !clazz.getName().equals("double" ) &&
+ !clazz.getName().equals("float" ) &&
+ !clazz.getName().equals("int" ) &&
+ !clazz.getName().equals("long" ) &&
+ !clazz.getName().equals("short" ) &&
+ !clazz.getName().equals("void" ) &&
+ !clazz.isArray() ) {
+ return clazz;
+ }
+ }
+ } catch (CorruptDataException e) {
+ //allowed by the spec
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ return null;
+ }
+
+ public JavaHeap defaultJavaHeap() {
+ JavaRuntime runtime = defaultJavaRuntime();
+ Iterator it = runtime.getHeaps().iterator();
+ assertNotNull(it);
+ assertTrue(it.hasNext());
+ JavaHeap heap = (JavaHeap) it.next();
+
+ // This should use Middleware Heap as default
+ // move on to Middleware Heap
+ if (heap.getName().equalsIgnoreCase("System Heap")){
+ heap = (JavaHeap) it.next();
+ if (heap.getName().equalsIgnoreCase("Transient Heap")){
+ heap = (JavaHeap) it.next();
+ }
+ }
+
+ return (JavaHeap) heap;
+ }
+
+ public JavaObject defaultJavaObject(boolean isArray) {
+ JavaObject foundObject = null;
+ JavaHeap heap = defaultJavaHeap();
+ Iterator objects = heap.getObjects().iterator();
+
+ while ((null == foundObject) && (objects.hasNext())) {
+ JavaObject oneObject = (JavaObject) objects.next();
+
+ try {
+ if (isArray) {
+ // We need any array object with at least one element
+ if (oneObject.isArray()) {
+ if (oneObject.getArraySize() > 0) {
+ foundObject = oneObject;
+ }
+ }
+ } else {
+ // We need a non-array, non-trivial object with at least two declared fields
+ if ( (!oneObject.isArray()) && (!oneObject.getJavaClass().getName().equals("java/lang/Object"))) {
+ Iterator declaredFields=oneObject.getJavaClass().getDeclaredFields().iterator();
+ if (declaredFields.hasNext()) {
+ declaredFields.next();
+ if (declaredFields.hasNext()) {
+ foundObject = oneObject;
+ }
+ }
+ }
+ }
+ } catch (CorruptDataException e) {
+ //just ignore this one
+ }
+ }
+ return foundObject;
+ }
+
+ public ImageThread defaultImageThread() {
+ Iterator it = defaultImageProcess().getThreads().iterator();
+
+ assertNotNull(it);
+ assertTrue(it.hasNext());
+
+ ImageThread thread = null;
+ while (null == thread && it.hasNext()) {
+ Object next = it.next();
+ if (next instanceof CorruptData)
+ continue;
+ thread = (ImageThread) next;
+ }
+
+ if (null == thread)
+ throw new TestNotImplementedException();
+
+ return thread;
+ }
+
+ public JavaMethod defaultJavaMethod() {
+ JavaRuntime runtime = defaultJavaRuntime();
+ Iterator it = runtime.getCompiledMethods().iterator();
+ if (it.hasNext()) {
+ return (JavaMethod) it.next();
+ } else {
+ System.err.println("Warning: No compiled methods found! This core must have been without JIT!");
+ throw new TestNotImplementedException();
+ }
+ }
+
+ protected void setUp() throws Exception {
+
+ if(capabilities==null) capabilities=new ImageLoaderHelper().getCapabilities();
+ }
+
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/AllTests.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/AllTests.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/AllTests.java Tue Nov 24 12:27:01 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 org.apache.kato.tests.junit;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Test for org.apache.kato.tests.junit");
+ //$JUnit-BEGIN$
+ suite.addTestSuite(JavaRuntimeTest.class);
+ suite.addTestSuite(ImageProcessTest.class);
+ suite.addTestSuite(ImageTest.class);
+ suite.addTestSuite(ImageAddressSpaceTest.class);
+ suite.addTestSuite(ImageModuleTest.class);
+ suite.addTestSuite(JavaThreadTest.class);
+ suite.addTestSuite(ImageThreadTest.class);
+ suite.addTestSuite(JavaStackFrameTest.class);
+ suite.addTestSuite(JavaMonitorTest.class);
+ suite.addTestSuite(JavaMethodTest.class);
+ suite.addTestSuite(ImageSectionTest.class);
+ suite.addTestSuite(JavaHeapTest.class);
+ suite.addTestSuite(JavaClassLoaderTest.class);
+ suite.addTestSuite(JavaClassTest.class);
+ suite.addTestSuite(JavaObjectTest.class);
+ suite.addTestSuite(ImagePointerTest.class);
+ suite.addTestSuite(ImageRegisterTest.class);
+ suite.addTestSuite(ImageStackFrameTest.class);
+ suite.addTestSuite(ImageSymbolTest.class);
+ suite.addTestSuite(JavaFieldTest.class);
+ suite.addTestSuite(JavaLocationTest.class);
+ suite.addTestSuite(ImageFactoryTest.class);
+ //$JUnit-END$
+ return suite;
+ }
+
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageAddressSpaceTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageAddressSpaceTest.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageAddressSpaceTest.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageAddressSpaceTest.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * 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.kato.tests.junit;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.tools.diagnostics.image.CorruptData;
+import javax.tools.diagnostics.image.ImageAddressSpace;
+import javax.tools.diagnostics.image.ImageSection;
+
+
+public class ImageAddressSpaceTest extends AbstractImageTestcase {
+ private ImageAddressSpace _space = null;
+ public static final long TEST_ADDRESS = 0x7FFFFFFF; //TODO: don't test with this specific value
+
+ protected void setUp() throws Exception {
+ _space = defaultAddressSpace();
+ super.setUp();
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageAddressSpace.getCurrentProcess()'
+ *
+ * Ensures that the process is non-null
+ */
+ public void testGetCurrentProcess() {
+ assertNotNull(_space.getCurrentProcess());
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageAddressSpace.getProcesses()'
+ *
+ * Ensures that the process iterator is non-null and has at least one process
+ */
+ public void testGetProcesses() {
+ List it = _space.getProcesses();
+
+ assertNotNull(it);
+ assertFalse(it.isEmpty());
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageAddressSpace.getPointer(long)'
+ *
+ * Ensures that pointers can be created which point at entities within the address space.
+ * TODO: this needs to be tested in a less arbitrary way.
+ */
+ public void testGetPointer() {
+ assertNotNull(_space.getPointer(TEST_ADDRESS));
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageAddressSpace.getImageSections()'
+ *
+ * Ensures that there is at least one section and it is of type ImageSection
+ */
+ public void testGetImageSections()
+ {
+ Iterator it = _space.getImageSections().iterator();
+ assertTrue(it.hasNext());
+ // empty iterator is a valid return from getImageSections
+ while (it.hasNext()) {
+ Object section = it.next();
+ assertTrue((section instanceof ImageSection) || (section instanceof CorruptData));
+ }
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageFactoryTest.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageFactoryTest.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageFactoryTest.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * 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.kato.tests.junit;
+
+import javax.tools.diagnostics.image.ImageFactory;
+
+public class ImageFactoryTest extends AbstractImageTestcase
+{
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageFactory.getDTFJMajorVersion()'
+ *
+ * Ensures that the major version is at least 1
+ */
+ public void testGetDTFJMajorVersion()
+ {
+ assertTrue(getFactory().getMajorVersion() >= 1);
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageFactory.getDTFJMinorVersion()'
+ *
+ * Ensures that the minor version is at least 0
+ */
+ public void testGetDTFJMinorVersion()
+ {
+ assertTrue(getFactory().getMinorVersion() >= 0);
+ }
+
+ /**
+ * Test that the modification level is greater than or equal to 0
+ */
+
+ public void testGetDTFJModificationLevel()
+ {
+ assertTrue(getFactory().getModificationLevel() >= 0);
+ }
+
+ /**
+ * Test that the modification level matches the implementation build no
+ * Note that the existence of the implementation version string is tested
+ * in the TestPackageInformation class
+ */
+
+ public void testGetDTFJModificationLevelAsBuildNo()
+ {
+ String implementationVersion=ImageFactory.class.getPackage().getImplementationVersion();
+ int buildNumber=0;
+ try {
+ buildNumber=Integer.parseInt(implementationVersion);
+ } catch(NumberFormatException nfe) {
+ buildNumber=-1;
+ }
+ assertTrue(getFactory().getModificationLevel()==buildNumber);
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageLoaderHelper.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageLoaderHelper.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageLoaderHelper.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageLoaderHelper.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * 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.kato.tests.junit;
+
+
+import javax.tools.diagnostics.image.Image;
+import javax.tools.diagnostics.image.ImageFactory;
+
+import org.apache.kato.tck.api.IImageCreator;
+
+
+public class ImageLoaderHelper {
+
+
+
+ public Capabilities getCapabilities() throws Exception {
+
+
+ IImageCreator creator=null;
+
+ Capabilities c=new Capabilities();
+
+ c.image=creator.createProcessImage();
+
+ return c;
+
+ }
+
+
+
+
+
+
+
+ public class Capabilities {
+ public Image image=null;
+ public ImageFactory factory=null;
+ public boolean hasRootSupport=false;
+ public Exception loadError=null;
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageModuleTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageModuleTest.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageModuleTest.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImageModuleTest.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * 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.kato.tests.junit;
+
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+
+
+public class ImageModuleTest extends AbstractImageTestcase {
+
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageModule.getName()'
+ *
+ * Ensures that the name is non-null
+ */
+ public void testGetName() {
+ try {
+ assertNotNull(defaultImageModule().getName());
+ } catch (CorruptDataException e) {
+ //acceptable
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageModule.getSections()'
+ *
+ * Ensures that the sections iterator is non-null and non-empty
+ */
+ public void testGetSections() {
+ List it = defaultImageModule().getSections();
+
+ assertNotNull(it);
+ assertFalse(it.isEmpty());
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageModule.getSymbols()'
+ *
+ * Ensures that symbols exist in the module
+ *
+ */
+ public void testGetSymbols() {
+ List it = defaultImageModule().getSymbols();
+
+ assertNotNull(it);
+ assertFalse(it.isEmpty());
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImageModule.getProperties()'
+ *
+ * Ensures that the module has a properties structure
+ */
+ public void testGetProperties() {
+ Properties props = null;
+
+ try {
+ props = defaultImageModule().getProperties();
+ } catch (CorruptDataException e) {
+ assertTrue(false);
+ }
+ assertNotNull(props);
+ }
+
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImagePointerTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImagePointerTest.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImagePointerTest.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tests/junit/ImagePointerTest.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,259 @@
+/*******************************************************************************
+ * 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.kato.tests.junit;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.ImageAddressSpace;
+import javax.tools.diagnostics.image.ImagePointer;
+import javax.tools.diagnostics.image.MemoryAccessException;
+
+public class ImagePointerTest extends AbstractImageTestcase
+{
+ private static ImageAddressSpace _parent; //used for comparisons
+ private static long _address; //used for comparisons
+ private static final long OFFSET = 0x100;
+ private ImagePointer _testPointer;
+
+ public ImagePointer defaultImagePointer()
+ {
+ _parent = defaultAddressSpace();
+ _address = ImageAddressSpaceTest.TEST_ADDRESS;
+
+ return _parent.getPointer(_address);
+ }
+
+ protected void setUp() throws Exception
+ {
+ _testPointer = defaultImagePointer();
+ super.setUp();
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImagePointer.getAddress()'
+ *
+ * Ensure that the address is what we created it with
+ */
+ public void testGetAddress()
+ {
+ assertTrue(_address == _testPointer.getAddress());
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImagePointer.getAddressSpace()'
+ *
+ * Ensures that the parent address space is equal to the one we used to create it
+ */
+ public void testGetAddressSpace()
+ {
+ assertTrue(_parent.equals(_testPointer.getAddressSpace()));
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImagePointer.add(long)'
+ *
+ * Ensures that adding an offset yields a pointer at the expected address
+ */
+ public void testAdd()
+ {
+ ImagePointer newPointer = _testPointer.add(OFFSET);
+ assertTrue(newPointer.getAddress() == (_testPointer.getAddress() + OFFSET));
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImagePointer.isExecutable()'
+ *
+ * Ensures that the method can be called
+ */
+ public void testIsExecutable()
+ {
+ try {
+ _testPointer.isExecutable();
+ } catch (DataUnavailable e) {
+ //accepted by spec
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImagePointer.isReadOnly()'
+ *
+ * Ensures that the method can be called
+ */
+ public void testIsReadOnly()
+ {
+ try {
+ _testPointer.isReadOnly();
+ } catch (DataUnavailable e) {
+ //accepted by spec
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImagePointer.isShared()'
+ *
+ * Ensures that the method can be called
+ */
+ public void testIsShared()
+ {
+ try {
+ _testPointer.isShared();
+ } catch (DataUnavailable e) {
+ //accepted by spec
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImagePointer.getPointerAt(long)'
+ *
+ * Ensure that we can read a pointer at the given address without throwing anything unexpected
+ */
+ public void testGetPointerAt()
+ {
+ try {
+ _testPointer.getPointerAt(0);
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ //accepted by spec
+ } catch (CorruptDataException e) {
+ //accepted by spec
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImagePointer.getLongAt(long)'
+ *
+ * Ensure that we can read a long at the given address without throwing anything unexpected
+ */
+ public void testGetLongAt()
+ {
+ try {
+ _testPointer.getLongAt(0);
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ //accepted by spec
+ } catch (CorruptDataException e) {
+ //accepted by spec
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImagePointer.getIntAt(long)'
+ *
+ * Ensure that we can read an int at the given address without throwing anything unexpected
+ */
+ public void testGetIntAt()
+ {
+ try {
+ _testPointer.getIntAt(0);
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ //accepted by spec
+ } catch (CorruptDataException e) {
+ //accepted by spec
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImagePointer.getShortAt(long)'
+ *
+ * Ensure that we can read a short at the given address without throwing anything unexpected
+ */
+ public void testGetShortAt()
+ {
+ try {
+ _testPointer.getShortAt(0);
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ //accepted by spec
+ } catch (CorruptDataException e) {
+ //accepted by spec
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImagePointer.getByteAt(long)'
+ *
+ * Ensure that we can read a byte at the given address without throwing anything unexpected
+ */
+ public void testGetByteAt()
+ {
+ try {
+ _testPointer.getByteAt(0);
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ //accepted by spec
+ } catch (CorruptDataException e) {
+ //accepted by spec
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImagePointer.getFloatAt(long)'
+ *
+ * Ensure that we can read a float at the given address without throwing anything unexpected
+ */
+ public void testGetFloatAt()
+ {
+ try {
+ _testPointer.getFloatAt(0);
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ //accepted by spec
+ } catch (CorruptDataException e) {
+ //accepted by spec
+ }
+ }
+
+ /**
+ * Test method for 'javax.tools.diagnostics.image.ImagePointer.getDoubleAt(long)'
+ *
+ * Ensure that we can read a double at the given address without throwing anything unexpected
+ */
+ public void testGetDoubleAt()
+ {
+ try {
+ _testPointer.getDoubleAt(0);
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ //accepted by spec
+ } catch (CorruptDataException e) {
+ //accepted by spec
+ }
+ }
+
+ /**
+ * Verify that the equals call doesn't throw
+ */
+ public void testEquals()
+ {
+ try{
+ assertTrue(_testPointer.equals(_testPointer));
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Verify that hashCode() doesn't throw and returns non-zero (technically zero is ok but it will be
+ * flagged here to ensure that we aren't doing anything bad to create the hashcode)
+ */
+ public void testHashCode()
+ {
+ try {
+ assertTrue(0 != _testPointer.hashCode());
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+}