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 mo...@apache.org on 2009/11/23 15:54:15 UTC
svn commit: r883384 [32/47] - in /incubator/kato/trunk/org.apache.kato: ./
kato.anttasks/src/main/java/org/apache/kato/anttasks/
kato.anttasks/src/main/java/org/apache/kato/anttasks/sitebuilder/
kato.anttasks/src/main/java/org/apache/kato/anttasks/tck/...
Propchange: incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_arraycopy.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_getDeclaredFields_getName.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_getDeclaredFields_getName.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_getDeclaredFields_getName.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_getDeclaredFields_getName.java Mon Nov 23 15:53:48 2009
@@ -1,97 +1,97 @@
-/*******************************************************************************
- * 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.JavaClass;
-import javax.tools.diagnostics.runtime.java.JavaField;
-import javax.tools.diagnostics.runtime.java.JavaHeap;
-import javax.tools.diagnostics.runtime.java.JavaObject;
-import javax.tools.diagnostics.runtime.java.JavaRuntime;
-
-import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
-import org.apache.kato.tck.scenario142.javaruntime.SetupJavaObject_getDeclaredFields_getName;
-
-
-
-public class TestJavaObject_getDeclaredFields_getName extends TCKJavaRuntimeTestcase {
-
-
-
- /**
- *
- */
-public void testJavaObject_get()
- {
- boolean foundObject = false;
-
- JavaRuntime runtime=getJavaRuntime();
-
- Iterator heaps = runtime.getHeaps().iterator();
-
- while (heaps.hasNext()) {
- Object nextHeap = heaps.next();
- if (nextHeap instanceof CorruptData) {
- System.err.println("returned CorruptData `" + nextHeap + "'");
- break;
- }
-
- JavaHeap aJavaHeap = (JavaHeap) nextHeap;
- Iterator objects = aJavaHeap.getObjects().iterator();
-
- while (objects.hasNext()) {
- Object nextObject = objects.next();
- if (nextObject instanceof CorruptData) {
- System.err.println("returned CorruptData `" + nextObject + "'");
- break;
- }
-
- JavaObject aJavaObject = (JavaObject) nextObject;
- try {
- JavaClass theJavaClass = aJavaObject.getJavaClass();
- String theClassName = (theJavaClass).getName();
- if (theClassName.equals(SetupJavaObject_getDeclaredFields_getName.TestObjectClassName)){
-
- Iterator fields = theJavaClass.getDeclaredFields().iterator();
-
- while (fields.hasNext()) {
- Object nextField = fields.next();
-
- if (nextField instanceof CorruptData) {
- System.err.println("returned CorruptData `" + nextField + "'");
- break;
- }
-
- JavaField theField = (JavaField) nextField;
- String theFieldName = theField.getName();
- if (theFieldName.equals("JavaObject_getDeclaredFields_getName")){
- foundObject=true;
- }
-
- }
- }
-
- } catch (CorruptDataException e) {
- assertNotNull(e.getCorruptData());
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- assertTrue(foundObject);
- }
-}
+/*******************************************************************************
+ * 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.JavaClass;
+import javax.tools.diagnostics.runtime.java.JavaField;
+import javax.tools.diagnostics.runtime.java.JavaHeap;
+import javax.tools.diagnostics.runtime.java.JavaObject;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+
+import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
+import org.apache.kato.tck.scenario142.javaruntime.SetupJavaObject_getDeclaredFields_getName;
+
+
+
+public class TestJavaObject_getDeclaredFields_getName extends TCKJavaRuntimeTestcase {
+
+
+
+ /**
+ *
+ */
+public void testJavaObject_get()
+ {
+ boolean foundObject = false;
+
+ JavaRuntime runtime=getJavaRuntime();
+
+ Iterator heaps = runtime.getHeaps().iterator();
+
+ while (heaps.hasNext()) {
+ Object nextHeap = heaps.next();
+ if (nextHeap instanceof CorruptData) {
+ System.err.println("returned CorruptData `" + nextHeap + "'");
+ break;
+ }
+
+ JavaHeap aJavaHeap = (JavaHeap) nextHeap;
+ Iterator objects = aJavaHeap.getObjects().iterator();
+
+ while (objects.hasNext()) {
+ Object nextObject = objects.next();
+ if (nextObject instanceof CorruptData) {
+ System.err.println("returned CorruptData `" + nextObject + "'");
+ break;
+ }
+
+ JavaObject aJavaObject = (JavaObject) nextObject;
+ try {
+ JavaClass theJavaClass = aJavaObject.getJavaClass();
+ String theClassName = (theJavaClass).getName();
+ if (theClassName.equals(SetupJavaObject_getDeclaredFields_getName.TestObjectClassName)){
+
+ Iterator fields = theJavaClass.getDeclaredFields().iterator();
+
+ while (fields.hasNext()) {
+ Object nextField = fields.next();
+
+ if (nextField instanceof CorruptData) {
+ System.err.println("returned CorruptData `" + nextField + "'");
+ break;
+ }
+
+ JavaField theField = (JavaField) nextField;
+ String theFieldName = theField.getName();
+ if (theFieldName.equals("JavaObject_getDeclaredFields_getName")){
+ foundObject=true;
+ }
+
+ }
+ }
+
+ } catch (CorruptDataException e) {
+ assertNotNull(e.getCorruptData());
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ assertTrue(foundObject);
+ }
+}
Propchange: incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_getDeclaredFields_getName.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_getReferences.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_getReferences.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_getReferences.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_getReferences.java Mon Nov 23 15:53:48 2009
@@ -1,68 +1,68 @@
-/*******************************************************************************
- * 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.DataUnavailable;
-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.JavaReference;
-
-import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
-
-
-public class TestJavaObject_getReferences extends TCKJavaRuntimeTestcase {
-
- public void testMultiDimensionalArrayReferences() {
- try {
- JavaObject thisObject = getScenerioReference();
- JavaField multiDimArrayField = getJavaField(thisObject, "multiDimArray");
- Object multiDimArrayObject = multiDimArrayField.get(thisObject);
- if (multiDimArrayObject instanceof JavaObject) {
- JavaObject mdObject = (JavaObject)multiDimArrayObject;
- Iterator refs = mdObject.getReferences().iterator();
- while (refs.hasNext()) {
- Object next = refs.next();
- if (next instanceof JavaReference) {
- JavaReference ref = (JavaReference) next;
- try {
- Object target = ref.getTarget();
- if (target instanceof JavaObject) {
- JavaObject targetObject = (JavaObject) target;
- System.out.println(targetObject.getJavaClass().getName());
- }
- System.out.println(ref.getDescription());
- } catch (DataUnavailable e) {
- e.printStackTrace();
- }
- } else {
- fail ("Found reference which is NOT an instance of JavaReference.");
- }
- }
- } else {
- fail("Wrong object type for multiDimArray.");
- }
- } catch (CorruptDataException e) {
- assertNotNull(e.getCorruptData());
- //allowed by the API
- } catch (MemoryAccessException mae) {
- assertNotNull(mae.getPointer());
- mae.printStackTrace();
- }
- }
-
-}
+/*******************************************************************************
+ * 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.DataUnavailable;
+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.JavaReference;
+
+import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
+
+
+public class TestJavaObject_getReferences extends TCKJavaRuntimeTestcase {
+
+ public void testMultiDimensionalArrayReferences() {
+ try {
+ JavaObject thisObject = getScenerioReference();
+ JavaField multiDimArrayField = getJavaField(thisObject, "multiDimArray");
+ Object multiDimArrayObject = multiDimArrayField.get(thisObject);
+ if (multiDimArrayObject instanceof JavaObject) {
+ JavaObject mdObject = (JavaObject)multiDimArrayObject;
+ Iterator refs = mdObject.getReferences().iterator();
+ while (refs.hasNext()) {
+ Object next = refs.next();
+ if (next instanceof JavaReference) {
+ JavaReference ref = (JavaReference) next;
+ try {
+ Object target = ref.getTarget();
+ if (target instanceof JavaObject) {
+ JavaObject targetObject = (JavaObject) target;
+ System.out.println(targetObject.getJavaClass().getName());
+ }
+ System.out.println(ref.getDescription());
+ } catch (DataUnavailable e) {
+ e.printStackTrace();
+ }
+ } else {
+ fail ("Found reference which is NOT an instance of JavaReference.");
+ }
+ }
+ } else {
+ fail("Wrong object type for multiDimArray.");
+ }
+ } catch (CorruptDataException e) {
+ assertNotNull(e.getCorruptData());
+ //allowed by the API
+ } catch (MemoryAccessException mae) {
+ assertNotNull(mae.getPointer());
+ mae.printStackTrace();
+ }
+ }
+
+}
Propchange: incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_getReferences.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaReferences.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaReferences.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaReferences.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaReferences.java Mon Nov 23 15:53:48 2009
@@ -1,262 +1,262 @@
-/*******************************************************************************
- * 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.runtime.java.JavaClass;
-import javax.tools.diagnostics.runtime.java.JavaClassLoader;
-import javax.tools.diagnostics.runtime.java.JavaObject;
-import javax.tools.diagnostics.runtime.java.JavaReference;
-
-import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
-
-public class TestJavaReferences extends TCKJavaRuntimeTestcase {
-
-
- public void testReferences_getDescription() {
- JavaObject thisObj = getScenerioReference();
- Iterator references = thisObj.getReferences().iterator();
-
- while (references.hasNext()) {
- Object next = references.next();
- if (!(next instanceof JavaReference)) {
- continue;
- }
- JavaReference ref = (JavaReference)next;
- assertNotNull("Reference description is null", ref.getDescription());
- }
- }
-
- public void testReferences_getReachability() throws Exception {
- JavaObject thisObj = getScenerioReference();
- Iterator references = thisObj.getReferences().iterator();
-
- while (references.hasNext()) {
- Object next = references.next();
- if (!(next instanceof JavaReference)) {
- continue;
- }
- JavaReference ref = (JavaReference)next;
- Object target = ref.getTarget();
- if (!(target instanceof JavaObject)) {
- continue;
- }
- JavaObject targetObject = (JavaObject)target;
- if ("java/lang/ref/WeakReference".equals(targetObject.getJavaClass().getName())) {
- JavaReference referent = getReferent(targetObject);
- assertTrue("Reachability for weak referent different from \"Weak\"", JavaReference.REACHABILITY_WEAK == referent.getReachability());
-
-
- } else if ("java/lang/ref/SoftReference".equals(targetObject.getJavaClass().getName())) {
- JavaReference referent = getReferent(targetObject);
- assertTrue("Reachability for soft referent different from \"Soft\"", JavaReference.REACHABILITY_SOFT == referent.getReachability());
-
- } else if ("java/lang/ref/PhantomReference".equals(targetObject.getJavaClass().getName())) {
- JavaReference referent = getReferent(targetObject);
- assertTrue("Reachability for phantom referent different from \"Phantom\"", JavaReference.REACHABILITY_PHANTOM == referent.getReachability());
-
- } else if (targetObject.getJavaClass().getName().endsWith("StrongReferent")) {
- assertTrue("Reachability for strong field reference different from \"Strong\"", JavaReference.REACHABILITY_STRONG == ref.getReachability());
- }
- }
- }
-
- public void testReferences_isClassReference() throws Exception {
- JavaObject thisObj = getScenerioReference();
- Iterator references = thisObj.getReferences().iterator();
-
- while (references.hasNext()) {
- Object next = references.next();
- if (!(next instanceof JavaReference)) {
- continue;
- }
- JavaReference ref = (JavaReference)next;
- Object target = ref.getTarget();
- if (ref.isClassReference()) {
- assertTrue("Supposed class reference has a non-JavaClass target",target instanceof JavaClass);
- }
- }
-
- }
-
- public void testReferences_isObjectReference() throws Exception {
- JavaObject thisObj = getScenerioReference();
- Iterator references = thisObj.getReferences().iterator();
-
- while (references.hasNext()) {
- Object next = references.next();
- if (!(next instanceof JavaReference)) {
- continue;
- }
- JavaReference ref = (JavaReference)next;
- Object target = ref.getTarget();
- if (ref.isObjectReference()) {
- assertTrue("Supposed object reference has a non-JavaObject target",target instanceof JavaObject);
- }
- }
-
- }
-
- public void testReferences_getReferenceType() throws Exception {
- JavaObject thisObj = getScenerioReference();
- Iterator references = thisObj.getReferences().iterator();
-
- while (references.hasNext()) {
- Object next = references.next();
- if (!(next instanceof JavaReference)) {
- continue;
- }
- JavaReference ref = (JavaReference)next;
- int type = ref.getReferenceType();
- Object source = ref.getSource();
- Object target = ref.getTarget();
-
- switch (type) {
- case JavaReference.REFERENCE_FIELD:
- if (source instanceof JavaObject) {
- JavaObject sourceObject = (JavaObject)source;
- if (!(sourceObject.equals(thisObj))) {
- fail("Source object for a field reference not equal to this object.");
- }
-
- if (target instanceof JavaObject) {
- JavaObject targetObject = (JavaObject)target;
- String objectsClassName = targetObject.getJavaClass().getName();
- if (!(objectsClassName.endsWith("Reference") ||
- objectsClassName.endsWith("Referent") ||
- objectsClassName.endsWith("ArrayElement;") ||
- objectsClassName.endsWith("ClassLoader"))) {
- fail("Unexpected field reference of type: "+ objectsClassName);
- }
- if (objectsClassName.endsWith("ArrayElement;") && targetObject.isArray()) {
- //found the array field.
- Iterator refs = targetObject.getReferences().iterator();
- boolean arrayElementFound = false;
- while (refs.hasNext()) {
- Object next2 = refs.next();
- if (!(next2 instanceof JavaReference)) {
- continue;
- }
- JavaReference ref2 = (JavaReference)next2;
- int type2 = ref2.getReferenceType();
- Object target2 = ref2.getTarget();
-
- if (type2 == JavaReference.REFERENCE_ARRAY_ELEMENT) {
- if (target2 instanceof JavaObject) {
- JavaObject targetObject2 = (JavaObject)target2;
- String objectsClassName2 = targetObject2.getJavaClass().getName();
- if (objectsClassName2.endsWith("ArrayElement") && !targetObject2.isArray()) {
- arrayElementFound = true;
- }
- } else {
- fail("Target object of a REFERENCE_ARRAY_ELEMENT reference has the wrong type.");
- }
- }
- }
- assertTrue("Array element reference not found.", arrayElementFound);
- }
-
- } else {
- fail("Target object of a REFERENCE_ARRAY_ELEMENT reference has the wrong type.");
- }
-
- } else {
- fail("Source object of a field reference is not a valid JavaObject.");
- }
- break;
- case JavaReference.REFERENCE_CLASS:
- if (source instanceof JavaObject) {
- JavaObject sourceObject = (JavaObject)source;
- if (!(sourceObject.equals(thisObj))) {
- fail("Source object for a CLASS reference not equal to this object.");
- }
-
- if (!(target instanceof JavaClass)) {
- fail("Target object for a CLASS reference not a JavaClass object.");
- }
- JavaClass targetClass = (JavaClass)target;
- assertTrue("Target class for the CLASS reference of this object different from expected.", targetClass.getName().endsWith("TestJavaReferences"));
- Iterator refs = targetClass.getReferences().iterator();
- boolean classLoaderFound = false;
- while (refs.hasNext()) {
- Object next2 = refs.next();
- if (!(next2 instanceof JavaReference)) {
- continue;
- }
- JavaReference ref2 = (JavaReference)next2;
- int type2 = ref2.getReferenceType();
- Object target2 = ref2.getTarget();
-
- if (type2 == JavaReference.REFERENCE_CLASS_LOADER) {
- if (!(target2 instanceof JavaObject)) {
- fail("Target object for a CLASSLOADER reference does not represent a JavaObject.");
- }
- JavaObject targetObject2 = (JavaObject)target2;
- if (targetObject2.getClass().getName().endsWith("ClassLoader")) {
- fail("Target object for a CLASSLOADER reference does not represent a ClassLoader.");
- } else {
- classLoaderFound = true;
- }
- }
- }
- assertTrue("ClassLoader reference not found.", classLoaderFound);
-
- } else {
- fail("Source object of a CLASS reference is not a valid JavaObject.");
- }
- break;
- case JavaReference.REFERENCE_CLASS_LOADER:
- if (source instanceof JavaObject) {
- JavaObject sourceObject = (JavaObject)source;
- if (!(sourceObject.equals(thisObj))) {
- fail("Source object for a CLASSLOADER reference not equal to this object.");
- }
-
- if (!(target instanceof JavaClassLoader)) {
- fail("Target object for a CLASSLOADER reference not a JavaClass object.");
- }
- } else {
- fail("Source object of a CLASS reference is not a valid JavaObject.");
- }
- break;
-
- }
- }
-
- }
-
-
- private JavaReference getReferent (JavaObject obj) {
- Iterator references = obj.getReferences().iterator();
- JavaReference referent = null;
- while (references.hasNext() && referent == null) {
- Object next = references.next();
- if (!(next instanceof JavaReference)) {
- continue;
- }
- JavaReference ref = (JavaReference)next;
- String description = ref.getDescription();
- if (description.indexOf("referent") == -1) {
- continue;
- }
- referent = ref;
- }
- return referent;
-
- }
-
-
-}
+/*******************************************************************************
+ * 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.runtime.java.JavaClass;
+import javax.tools.diagnostics.runtime.java.JavaClassLoader;
+import javax.tools.diagnostics.runtime.java.JavaObject;
+import javax.tools.diagnostics.runtime.java.JavaReference;
+
+import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
+
+public class TestJavaReferences extends TCKJavaRuntimeTestcase {
+
+
+ public void testReferences_getDescription() {
+ JavaObject thisObj = getScenerioReference();
+ Iterator references = thisObj.getReferences().iterator();
+
+ while (references.hasNext()) {
+ Object next = references.next();
+ if (!(next instanceof JavaReference)) {
+ continue;
+ }
+ JavaReference ref = (JavaReference)next;
+ assertNotNull("Reference description is null", ref.getDescription());
+ }
+ }
+
+ public void testReferences_getReachability() throws Exception {
+ JavaObject thisObj = getScenerioReference();
+ Iterator references = thisObj.getReferences().iterator();
+
+ while (references.hasNext()) {
+ Object next = references.next();
+ if (!(next instanceof JavaReference)) {
+ continue;
+ }
+ JavaReference ref = (JavaReference)next;
+ Object target = ref.getTarget();
+ if (!(target instanceof JavaObject)) {
+ continue;
+ }
+ JavaObject targetObject = (JavaObject)target;
+ if ("java/lang/ref/WeakReference".equals(targetObject.getJavaClass().getName())) {
+ JavaReference referent = getReferent(targetObject);
+ assertTrue("Reachability for weak referent different from \"Weak\"", JavaReference.REACHABILITY_WEAK == referent.getReachability());
+
+
+ } else if ("java/lang/ref/SoftReference".equals(targetObject.getJavaClass().getName())) {
+ JavaReference referent = getReferent(targetObject);
+ assertTrue("Reachability for soft referent different from \"Soft\"", JavaReference.REACHABILITY_SOFT == referent.getReachability());
+
+ } else if ("java/lang/ref/PhantomReference".equals(targetObject.getJavaClass().getName())) {
+ JavaReference referent = getReferent(targetObject);
+ assertTrue("Reachability for phantom referent different from \"Phantom\"", JavaReference.REACHABILITY_PHANTOM == referent.getReachability());
+
+ } else if (targetObject.getJavaClass().getName().endsWith("StrongReferent")) {
+ assertTrue("Reachability for strong field reference different from \"Strong\"", JavaReference.REACHABILITY_STRONG == ref.getReachability());
+ }
+ }
+ }
+
+ public void testReferences_isClassReference() throws Exception {
+ JavaObject thisObj = getScenerioReference();
+ Iterator references = thisObj.getReferences().iterator();
+
+ while (references.hasNext()) {
+ Object next = references.next();
+ if (!(next instanceof JavaReference)) {
+ continue;
+ }
+ JavaReference ref = (JavaReference)next;
+ Object target = ref.getTarget();
+ if (ref.isClassReference()) {
+ assertTrue("Supposed class reference has a non-JavaClass target",target instanceof JavaClass);
+ }
+ }
+
+ }
+
+ public void testReferences_isObjectReference() throws Exception {
+ JavaObject thisObj = getScenerioReference();
+ Iterator references = thisObj.getReferences().iterator();
+
+ while (references.hasNext()) {
+ Object next = references.next();
+ if (!(next instanceof JavaReference)) {
+ continue;
+ }
+ JavaReference ref = (JavaReference)next;
+ Object target = ref.getTarget();
+ if (ref.isObjectReference()) {
+ assertTrue("Supposed object reference has a non-JavaObject target",target instanceof JavaObject);
+ }
+ }
+
+ }
+
+ public void testReferences_getReferenceType() throws Exception {
+ JavaObject thisObj = getScenerioReference();
+ Iterator references = thisObj.getReferences().iterator();
+
+ while (references.hasNext()) {
+ Object next = references.next();
+ if (!(next instanceof JavaReference)) {
+ continue;
+ }
+ JavaReference ref = (JavaReference)next;
+ int type = ref.getReferenceType();
+ Object source = ref.getSource();
+ Object target = ref.getTarget();
+
+ switch (type) {
+ case JavaReference.REFERENCE_FIELD:
+ if (source instanceof JavaObject) {
+ JavaObject sourceObject = (JavaObject)source;
+ if (!(sourceObject.equals(thisObj))) {
+ fail("Source object for a field reference not equal to this object.");
+ }
+
+ if (target instanceof JavaObject) {
+ JavaObject targetObject = (JavaObject)target;
+ String objectsClassName = targetObject.getJavaClass().getName();
+ if (!(objectsClassName.endsWith("Reference") ||
+ objectsClassName.endsWith("Referent") ||
+ objectsClassName.endsWith("ArrayElement;") ||
+ objectsClassName.endsWith("ClassLoader"))) {
+ fail("Unexpected field reference of type: "+ objectsClassName);
+ }
+ if (objectsClassName.endsWith("ArrayElement;") && targetObject.isArray()) {
+ //found the array field.
+ Iterator refs = targetObject.getReferences().iterator();
+ boolean arrayElementFound = false;
+ while (refs.hasNext()) {
+ Object next2 = refs.next();
+ if (!(next2 instanceof JavaReference)) {
+ continue;
+ }
+ JavaReference ref2 = (JavaReference)next2;
+ int type2 = ref2.getReferenceType();
+ Object target2 = ref2.getTarget();
+
+ if (type2 == JavaReference.REFERENCE_ARRAY_ELEMENT) {
+ if (target2 instanceof JavaObject) {
+ JavaObject targetObject2 = (JavaObject)target2;
+ String objectsClassName2 = targetObject2.getJavaClass().getName();
+ if (objectsClassName2.endsWith("ArrayElement") && !targetObject2.isArray()) {
+ arrayElementFound = true;
+ }
+ } else {
+ fail("Target object of a REFERENCE_ARRAY_ELEMENT reference has the wrong type.");
+ }
+ }
+ }
+ assertTrue("Array element reference not found.", arrayElementFound);
+ }
+
+ } else {
+ fail("Target object of a REFERENCE_ARRAY_ELEMENT reference has the wrong type.");
+ }
+
+ } else {
+ fail("Source object of a field reference is not a valid JavaObject.");
+ }
+ break;
+ case JavaReference.REFERENCE_CLASS:
+ if (source instanceof JavaObject) {
+ JavaObject sourceObject = (JavaObject)source;
+ if (!(sourceObject.equals(thisObj))) {
+ fail("Source object for a CLASS reference not equal to this object.");
+ }
+
+ if (!(target instanceof JavaClass)) {
+ fail("Target object for a CLASS reference not a JavaClass object.");
+ }
+ JavaClass targetClass = (JavaClass)target;
+ assertTrue("Target class for the CLASS reference of this object different from expected.", targetClass.getName().endsWith("TestJavaReferences"));
+ Iterator refs = targetClass.getReferences().iterator();
+ boolean classLoaderFound = false;
+ while (refs.hasNext()) {
+ Object next2 = refs.next();
+ if (!(next2 instanceof JavaReference)) {
+ continue;
+ }
+ JavaReference ref2 = (JavaReference)next2;
+ int type2 = ref2.getReferenceType();
+ Object target2 = ref2.getTarget();
+
+ if (type2 == JavaReference.REFERENCE_CLASS_LOADER) {
+ if (!(target2 instanceof JavaObject)) {
+ fail("Target object for a CLASSLOADER reference does not represent a JavaObject.");
+ }
+ JavaObject targetObject2 = (JavaObject)target2;
+ if (targetObject2.getClass().getName().endsWith("ClassLoader")) {
+ fail("Target object for a CLASSLOADER reference does not represent a ClassLoader.");
+ } else {
+ classLoaderFound = true;
+ }
+ }
+ }
+ assertTrue("ClassLoader reference not found.", classLoaderFound);
+
+ } else {
+ fail("Source object of a CLASS reference is not a valid JavaObject.");
+ }
+ break;
+ case JavaReference.REFERENCE_CLASS_LOADER:
+ if (source instanceof JavaObject) {
+ JavaObject sourceObject = (JavaObject)source;
+ if (!(sourceObject.equals(thisObj))) {
+ fail("Source object for a CLASSLOADER reference not equal to this object.");
+ }
+
+ if (!(target instanceof JavaClassLoader)) {
+ fail("Target object for a CLASSLOADER reference not a JavaClass object.");
+ }
+ } else {
+ fail("Source object of a CLASS reference is not a valid JavaObject.");
+ }
+ break;
+
+ }
+ }
+
+ }
+
+
+ private JavaReference getReferent (JavaObject obj) {
+ Iterator references = obj.getReferences().iterator();
+ JavaReference referent = null;
+ while (references.hasNext() && referent == null) {
+ Object next = references.next();
+ if (!(next instanceof JavaReference)) {
+ continue;
+ }
+ JavaReference ref = (JavaReference)next;
+ String description = ref.getDescription();
+ if (description.indexOf("referent") == -1) {
+ continue;
+ }
+ referent = ref;
+ }
+ return referent;
+
+ }
+
+
+}
Propchange: incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaReferences.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime.java Mon Nov 23 15:53:48 2009
@@ -1,82 +1,82 @@
-/*******************************************************************************
- * 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.DataUnavailable;
-import javax.tools.diagnostics.runtime.java.JavaRuntime;
-import javax.tools.diagnostics.runtime.java.JavaVMInitArgs;
-import javax.tools.diagnostics.runtime.java.JavaVMOption;
-
-import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
-import org.apache.kato.tck.scenario142.javaruntime.SetupJavaRuntime;
-
-
-/**
- *
- *
- */
-public class TestJavaRuntime extends TCKJavaRuntimeTestcase {
-
-
- public void testJavaJavaRuntime_getVersion() throws CorruptDataException, DataUnavailable
- {
-
- JavaRuntime runtime=getJavaRuntime();
- String version=runtime.getVersion();
- System.out.println("runtime.getVersion "+version);
- assertNotNull(version);
- }
-
- public void testJavaJavaRuntime_getVersionDetail() throws CorruptDataException, DataUnavailable
- {
-
- JavaRuntime runtime=getJavaRuntime();
- String version=runtime.getVersion();
-
-
- JavaVMInitArgs args=runtime.getJavaVMInitArgs();
- Iterator i=args.getOptions().iterator();
- while(i.hasNext()) {
- JavaVMOption option=(JavaVMOption) i.next();
- String data=option.getOptionString();
- if(data.startsWith(SetupJavaRuntime.DTCK_TEST_RUNTIME_VERSION)) {
- String received=data.substring(SetupJavaRuntime.DTCK_TEST_RUNTIME_VERSION.length());
- assertTrue(version.indexOf(received) != -1);
- return; // test passed
- }
-
- }
-
- fail("expected to see vm option for system property starting "+SetupJavaRuntime.DTCK_TEST_RUNTIME_VERSION);
- }
-
- public void testJavaRuntime_getFullVersion()
- {
- JavaRuntime runtime=(JavaRuntime) getJavaRuntime();
- String theFV=null;
- try {
- theFV=runtime.getFullVersion();
- } catch (CorruptDataException e) {
- fail();
- }
- assertNotNull(theFV);
- assertTrue(theFV.length() > 0);
- }
-
-
-}
-
+/*******************************************************************************
+ * 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.DataUnavailable;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+import javax.tools.diagnostics.runtime.java.JavaVMInitArgs;
+import javax.tools.diagnostics.runtime.java.JavaVMOption;
+
+import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
+import org.apache.kato.tck.scenario142.javaruntime.SetupJavaRuntime;
+
+
+/**
+ *
+ *
+ */
+public class TestJavaRuntime extends TCKJavaRuntimeTestcase {
+
+
+ public void testJavaJavaRuntime_getVersion() throws CorruptDataException, DataUnavailable
+ {
+
+ JavaRuntime runtime=getJavaRuntime();
+ String version=runtime.getVersion();
+ System.out.println("runtime.getVersion "+version);
+ assertNotNull(version);
+ }
+
+ public void testJavaJavaRuntime_getVersionDetail() throws CorruptDataException, DataUnavailable
+ {
+
+ JavaRuntime runtime=getJavaRuntime();
+ String version=runtime.getVersion();
+
+
+ JavaVMInitArgs args=runtime.getJavaVMInitArgs();
+ Iterator i=args.getOptions().iterator();
+ while(i.hasNext()) {
+ JavaVMOption option=(JavaVMOption) i.next();
+ String data=option.getOptionString();
+ if(data.startsWith(SetupJavaRuntime.DTCK_TEST_RUNTIME_VERSION)) {
+ String received=data.substring(SetupJavaRuntime.DTCK_TEST_RUNTIME_VERSION.length());
+ assertTrue(version.indexOf(received) != -1);
+ return; // test passed
+ }
+
+ }
+
+ fail("expected to see vm option for system property starting "+SetupJavaRuntime.DTCK_TEST_RUNTIME_VERSION);
+ }
+
+ public void testJavaRuntime_getFullVersion()
+ {
+ JavaRuntime runtime=(JavaRuntime) getJavaRuntime();
+ String theFV=null;
+ try {
+ theFV=runtime.getFullVersion();
+ } catch (CorruptDataException e) {
+ fail();
+ }
+ assertNotNull(theFV);
+ assertTrue(theFV.length() > 0);
+ }
+
+
+}
+
Propchange: incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntimeThreads.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntimeThreads.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntimeThreads.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntimeThreads.java Mon Nov 23 15:53:48 2009
@@ -1,164 +1,164 @@
-/*******************************************************************************
- * 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 java.util.LinkedList;
-import java.util.List;
-
-import javax.tools.diagnostics.image.CorruptDataException;
-import javax.tools.diagnostics.runtime.java.JavaLocation;
-import javax.tools.diagnostics.runtime.java.JavaMethod;
-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.SetupJavaRuntimeThreads;
-
-
-/**
- *
- *
- */
-public class TestJavaRuntimeThreads extends TCKJavaRuntimeTestcase {
-
- /**
- * Test has at least one thread
- *
- */
-
- public void testHasThreads() {
-
- JavaRuntime runtime=getJavaRuntime();
- Iterator threadIterator=runtime.getThreads().iterator();
- assertNotNull(threadIterator);
- assertTrue(threadIterator.hasNext());
-
-
- }
-
-
- /**
- * Test has configured threads
- * @throws CorruptDataException
- *
- */
-
- public void testHasExpectedThreads() throws CorruptDataException {
-
- List allThreads = getJavaRuntime().getThreads();
-
- assertNotNull(getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T1));
- assertNotNull(getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T2));
- assertNotNull(getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T3));
-
- }
-
- public void testExpectedThreadState() throws CorruptDataException {
-
- List allThreads = getJavaRuntime().getThreads();
-
- JavaThread t1=getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T1);
- int state=t1.getState();
- assertEquals(JavaThread.STATE_ALIVE | JavaThread.STATE_WAITING | JavaThread.STATE_SLEEPING,state);
-
- }
-
- public void testHasThreadStack() throws CorruptDataException {
-
- List allThreads = getJavaRuntime().getThreads();
-
- JavaThread t1=getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T1);
- Iterator i=t1.getStackFrames().iterator();
- assertTrue(i.hasNext());
-
-
- }
- public void testThreadStackFrameLocation() throws CorruptDataException {
-
- List allThreads = getJavaRuntime().getThreads();
-
- JavaThread t1=getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T1);
- Iterator i=t1.getStackFrames().iterator();
- JavaStackFrame frame=(JavaStackFrame) i.next();
- JavaLocation location=frame.getLocation();
- assertNotNull(location);
-
-
- }
- public void testThreadStackFrameLocationMethod() throws CorruptDataException {
-
- List allThreads = getJavaRuntime().getThreads();
-
- JavaThread t1=getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T1);
- Iterator i=t1.getStackFrames().iterator();
- JavaStackFrame frame=(JavaStackFrame) i.next();
- JavaLocation location=frame.getLocation();
- JavaMethod method=location.getMethod();
- assertNotNull(method);
-
-
- }
-public void testThreadStackFrameLocationMethodName() throws CorruptDataException {
-
- List allThreads = getJavaRuntime().getThreads();
-
- JavaThread t1=getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T1);
- Iterator i=t1.getStackFrames().iterator();
- JavaStackFrame frame=(JavaStackFrame) i.next();
- JavaLocation location=frame.getLocation();
- JavaMethod method=location.getMethod();
- String name=method.getName();
- assertEquals(name,"sleep");
-
-
-
- }
-
- private List getThreads() {
- JavaRuntime runtime=getJavaRuntime();
- Iterator threadIterator=runtime.getThreads().iterator();
-
- List allThreads=new LinkedList();
-
- while(threadIterator.hasNext()) {
- JavaThread thread=(JavaThread) threadIterator.next();
- allThreads.add(thread);
- }
- return allThreads;
- }
-
-
- public void testThreadGroupMembership() throws CorruptDataException {
-
- List allThreads = getJavaRuntime().getThreads();
- JavaThread t1=getThread(allThreads, SetupJavaRuntimeThreads.DTFJ_TCK_T1);
-
-
- }
- private JavaThread getThread(List allThreads, String threadname) throws CorruptDataException {
-
- Iterator i=allThreads.iterator();
- while(i.hasNext()) {
- JavaThread thread=(JavaThread) i.next();
- String name=thread.getName();
- if(name.equals(threadname)) return thread;
- }
- return null;
- }
-
-
-}
-
+/*******************************************************************************
+ * 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 java.util.LinkedList;
+import java.util.List;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.runtime.java.JavaLocation;
+import javax.tools.diagnostics.runtime.java.JavaMethod;
+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.SetupJavaRuntimeThreads;
+
+
+/**
+ *
+ *
+ */
+public class TestJavaRuntimeThreads extends TCKJavaRuntimeTestcase {
+
+ /**
+ * Test has at least one thread
+ *
+ */
+
+ public void testHasThreads() {
+
+ JavaRuntime runtime=getJavaRuntime();
+ Iterator threadIterator=runtime.getThreads().iterator();
+ assertNotNull(threadIterator);
+ assertTrue(threadIterator.hasNext());
+
+
+ }
+
+
+ /**
+ * Test has configured threads
+ * @throws CorruptDataException
+ *
+ */
+
+ public void testHasExpectedThreads() throws CorruptDataException {
+
+ List allThreads = getJavaRuntime().getThreads();
+
+ assertNotNull(getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T1));
+ assertNotNull(getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T2));
+ assertNotNull(getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T3));
+
+ }
+
+ public void testExpectedThreadState() throws CorruptDataException {
+
+ List allThreads = getJavaRuntime().getThreads();
+
+ JavaThread t1=getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T1);
+ int state=t1.getState();
+ assertEquals(JavaThread.STATE_ALIVE | JavaThread.STATE_WAITING | JavaThread.STATE_SLEEPING,state);
+
+ }
+
+ public void testHasThreadStack() throws CorruptDataException {
+
+ List allThreads = getJavaRuntime().getThreads();
+
+ JavaThread t1=getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T1);
+ Iterator i=t1.getStackFrames().iterator();
+ assertTrue(i.hasNext());
+
+
+ }
+ public void testThreadStackFrameLocation() throws CorruptDataException {
+
+ List allThreads = getJavaRuntime().getThreads();
+
+ JavaThread t1=getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T1);
+ Iterator i=t1.getStackFrames().iterator();
+ JavaStackFrame frame=(JavaStackFrame) i.next();
+ JavaLocation location=frame.getLocation();
+ assertNotNull(location);
+
+
+ }
+ public void testThreadStackFrameLocationMethod() throws CorruptDataException {
+
+ List allThreads = getJavaRuntime().getThreads();
+
+ JavaThread t1=getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T1);
+ Iterator i=t1.getStackFrames().iterator();
+ JavaStackFrame frame=(JavaStackFrame) i.next();
+ JavaLocation location=frame.getLocation();
+ JavaMethod method=location.getMethod();
+ assertNotNull(method);
+
+
+ }
+public void testThreadStackFrameLocationMethodName() throws CorruptDataException {
+
+ List allThreads = getJavaRuntime().getThreads();
+
+ JavaThread t1=getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T1);
+ Iterator i=t1.getStackFrames().iterator();
+ JavaStackFrame frame=(JavaStackFrame) i.next();
+ JavaLocation location=frame.getLocation();
+ JavaMethod method=location.getMethod();
+ String name=method.getName();
+ assertEquals(name,"sleep");
+
+
+
+ }
+
+ private List getThreads() {
+ JavaRuntime runtime=getJavaRuntime();
+ Iterator threadIterator=runtime.getThreads().iterator();
+
+ List allThreads=new LinkedList();
+
+ while(threadIterator.hasNext()) {
+ JavaThread thread=(JavaThread) threadIterator.next();
+ allThreads.add(thread);
+ }
+ return allThreads;
+ }
+
+
+ public void testThreadGroupMembership() throws CorruptDataException {
+
+ List allThreads = getJavaRuntime().getThreads();
+ JavaThread t1=getThread(allThreads, SetupJavaRuntimeThreads.DTFJ_TCK_T1);
+
+
+ }
+ private JavaThread getThread(List allThreads, String threadname) throws CorruptDataException {
+
+ Iterator i=allThreads.iterator();
+ while(i.hasNext()) {
+ JavaThread thread=(JavaThread) i.next();
+ String name=thread.getName();
+ if(name.equals(threadname)) return thread;
+ }
+ return null;
+ }
+
+
+}
+
Propchange: incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntimeThreads.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime_getCompiledMethods.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime_getCompiledMethods.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime_getCompiledMethods.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime_getCompiledMethods.java Mon Nov 23 15:53:48 2009
@@ -1,56 +1,56 @@
-/*******************************************************************************
- * 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.JavaMethod;
-import javax.tools.diagnostics.runtime.java.JavaRuntime;
-
-import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
-
-
-public class TestJavaRuntime_getCompiledMethods extends TCKJavaRuntimeTestcase {
- public void testHasCompiledMethods() {
- JavaRuntime runtime=getJavaRuntime();
- Iterator compiledMethods=runtime.getCompiledMethods().iterator();
- assertNotNull(compiledMethods);
- assertTrue(compiledMethods.hasNext());
- }
-
- public void testConfiguredCompiledMethods() {
- JavaRuntime runtime=getJavaRuntime();
- Iterator compiledMethods=runtime.getCompiledMethods().iterator();
- boolean found = false;
- while (compiledMethods.hasNext() && !found) {
- Object next = compiledMethods.next();
- if (!(next instanceof JavaMethod)) {
- continue;
- }
- JavaMethod method = (JavaMethod)next;
- try {
- String methodName = method.getName();
- // System.out.println("Current method is: "+ methodName);
- if ("jitMe".equals(methodName)) {
- return;
- }
- } catch (CorruptDataException cde) {
- assertNotNull(cde.getCorruptData());
- continue;
- }
- }
- fail("Compiled method not found");
- }
-}
+/*******************************************************************************
+ * 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.JavaMethod;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+
+import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
+
+
+public class TestJavaRuntime_getCompiledMethods extends TCKJavaRuntimeTestcase {
+ public void testHasCompiledMethods() {
+ JavaRuntime runtime=getJavaRuntime();
+ Iterator compiledMethods=runtime.getCompiledMethods().iterator();
+ assertNotNull(compiledMethods);
+ assertTrue(compiledMethods.hasNext());
+ }
+
+ public void testConfiguredCompiledMethods() {
+ JavaRuntime runtime=getJavaRuntime();
+ Iterator compiledMethods=runtime.getCompiledMethods().iterator();
+ boolean found = false;
+ while (compiledMethods.hasNext() && !found) {
+ Object next = compiledMethods.next();
+ if (!(next instanceof JavaMethod)) {
+ continue;
+ }
+ JavaMethod method = (JavaMethod)next;
+ try {
+ String methodName = method.getName();
+ // System.out.println("Current method is: "+ methodName);
+ if ("jitMe".equals(methodName)) {
+ return;
+ }
+ } catch (CorruptDataException cde) {
+ assertNotNull(cde.getCorruptData());
+ continue;
+ }
+ }
+ fail("Compiled method not found");
+ }
+}
Propchange: incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime_getCompiledMethods.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime_getHeapRoots.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime_getHeapRoots.java?rev=883384&r1=883383&r2=883384&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime_getHeapRoots.java (original)
+++ incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime_getHeapRoots.java Mon Nov 23 15:53:48 2009
@@ -1,345 +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);
- }
-
-}
+/*******************************************************************************
+ * 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);
+ }
+
+}
Propchange: incubator/kato/trunk/org.apache.kato/kato.tck.testsuite/src/main/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime_getHeapRoots.java
------------------------------------------------------------------------------
svn:eol-style = native