incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spo...@apache.org
Subject svn commit: r888461 - in /incubator/kato/trunk/org.apache.kato/kato.tck/testcases/src/main/java/org/apache/kato/tck/tests/legacy: AllTests.java TestJavaHeapRoots.java
Date Tue, 08 Dec 2009 16:15:07 GMT
Author: spoole
Date: Tue Dec  8 16:15:07 2009
New Revision: 888461

URL: http://svn.apache.org/viewvc?rev=888461&view=rev
Log:
added new tests for javaHeap roots

Added:
    incubator/kato/trunk/org.apache.kato/kato.tck/testcases/src/main/java/org/apache/kato/tck/tests/legacy/TestJavaHeapRoots.java
Modified:
    incubator/kato/trunk/org.apache.kato/kato.tck/testcases/src/main/java/org/apache/kato/tck/tests/legacy/AllTests.java

Modified: incubator/kato/trunk/org.apache.kato/kato.tck/testcases/src/main/java/org/apache/kato/tck/tests/legacy/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/testcases/src/main/java/org/apache/kato/tck/tests/legacy/AllTests.java?rev=888461&r1=888460&r2=888461&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/testcases/src/main/java/org/apache/kato/tck/tests/legacy/AllTests.java
(original)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/testcases/src/main/java/org/apache/kato/tck/tests/legacy/AllTests.java
Tue Dec  8 16:15:07 2009
@@ -30,7 +30,7 @@
 		suite.addTestSuite(TestJavaRuntime.class);
 		suite.addTestSuite(TestJavaThread.class);
 		suite.addTestSuite(TestCompiledMethods.class);
-		
+		suite.addTestSuite(TestJavaHeapRoots.class);
 		//$JUnit-END$
 		return suite;
 	}

Added: incubator/kato/trunk/org.apache.kato/kato.tck/testcases/src/main/java/org/apache/kato/tck/tests/legacy/TestJavaHeapRoots.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/testcases/src/main/java/org/apache/kato/tck/tests/legacy/TestJavaHeapRoots.java?rev=888461&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/testcases/src/main/java/org/apache/kato/tck/tests/legacy/TestJavaHeapRoots.java
(added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/testcases/src/main/java/org/apache/kato/tck/tests/legacy/TestJavaHeapRoots.java
Tue Dec  8 16:15:07 2009
@@ -0,0 +1,200 @@
+/*******************************************************************************
+ * 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.legacy;
+
+import java.util.List;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.ImagePointer;
+import javax.tools.diagnostics.image.ImageSection;
+import javax.tools.diagnostics.image.ImageThread;
+import javax.tools.diagnostics.runtime.java.JavaClass;
+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.harness.TCKJavaRuntimeTestcase;
+
+/**
+ * 
+ */
+public class TestJavaHeapRoots  extends TCKJavaRuntimeTestcase {
+
+	
+	public void testHeapRoots() {
+		JavaRuntime runtime=getJavaRuntime();
+		
+		List<JavaReference> references=runtime.getHeapRoots();
+		
+		if(references.isEmpty()) return; // no threads to test
+		
+		int counter=0;
+		
+		for(JavaReference ref:references) {
+			
+			
+			// name
+			
+			String name=ref.getDescription();
+			assertNotNull("Entry "+counter+":name  is null - DataUnavailable should have been thrown
instead",name);
+			
+			// reachability
+			
+			try {
+				int reachability=ref.getReachability();
+				
+				if(reachability!=JavaReference.REACHABILITY_UNKNOWN &&
+				   reachability!= JavaReference.REACHABILITY_STRONG &&
+				reachability!= JavaReference.REACHABILITY_SOFT   &&
+    			reachability!= JavaReference.REACHABILITY_WEAK    &&
+    			reachability!= JavaReference.REACHABILITY_PHANTOM ) {
+					fail("Entry "+counter+": reachability value "+reachability+" is invalid");
+				}
+
+				
+			} catch (CorruptDataException e) {
+				// allowed
+			}
+			
+			try {
+				
+				int refType=ref.getReferenceType();
+				if(   refType!=JavaReference.REFERENCE_UNKNOWN     &&
+					     
+				refType!=JavaReference.REFERENCE_CLASS &&
+					    
+				refType!=JavaReference.REFERENCE_FIELD  &&  
+					    
+				refType!=JavaReference.REFERENCE_ARRAY_ELEMENT    &&
+					    
+				refType!=JavaReference.REFERENCE_CLASS_LOADER     &&
+					    
+				refType!=JavaReference.REFERENCE_SIGNERS           &&
+					    
+				refType!=JavaReference.REFERENCE_PROTECTION_DOMAIN  &&
+					    
+				refType!=JavaReference.REFERENCE_INTERFACE          &&
+					    
+				refType!=JavaReference.REFERENCE_STATIC_FIELD       && 
+					    
+				refType!=JavaReference.REFERENCE_CONSTANT_POOL      &&
+					    
+				refType!=JavaReference.REFERENCE_SUPERCLASS     	 &&
+					    
+				refType!=JavaReference.REFERENCE_LOADED_CLASS      &&
+					    
+				refType!=JavaReference.REFERENCE_CLASS_OBJECT      &&
+				refType!=JavaReference.REFERENCE_ASSOCIATED_CLASS 
+	
+				) {
+					fail("Entry "+counter+": reference type value "+refType+" is invalid");
+				}
+				
+			} catch (CorruptDataException e) {
+				// allowed
+			}
+			
+			// root type
+			
+			try {
+				int rootType=ref.getRootType();
+				if(rootType!=JavaReference.HEAP_ROOT_CLASSLOADER &&
+						rootType!=JavaReference.HEAP_ROOT_UNKNOWN      &&
+						rootType!=JavaReference.HEAP_ROOT_JNI_GLOBAL    &&
+						rootType!=JavaReference.HEAP_ROOT_SYSTEM_CLASS  &&
+						rootType!=JavaReference.HEAP_ROOT_MONITOR      &&
+						rootType!=JavaReference.HEAP_ROOT_STACK_LOCAL   &&
+						rootType!=JavaReference.HEAP_ROOT_JNI_LOCAL     &&
+						rootType!=JavaReference.HEAP_ROOT_THREAD      &&
+						rootType!=JavaReference.HEAP_ROOT_OTHER        &&
+						rootType!=JavaReference.HEAP_ROOT_FINALIZABLE_OBJ  &&
+						rootType!=JavaReference.HEAP_ROOT_UNFINALIZED_OBJ  &&
+						rootType!=JavaReference.HEAP_ROOT_STRINGTABLE 
+				) {
+					fail("Entry "+counter+": root type value "+rootType+" is invalid");
+				}
+					
+			} catch (CorruptDataException e) {
+				// allowed
+			}
+			
+			// source type
+			
+			try {
+				
+				Object source=ref.getSource();
+				if(source!=null) {
+					assertTrue("Entry "+counter+": source class "+source.getClass()+" is invalid",source
instanceof JavaClass==false || 
+					   source instanceof JavaObject==false ||
+					   source instanceof JavaStackFrame==false  
+					);
+						
+				}
+				
+			} catch (DataUnavailable e) {
+				// allowed
+			} catch (CorruptDataException e) {
+				// allowed
+			}
+			
+			// target type
+			
+			try {
+				
+				Object target=ref.getTarget();
+				
+					assertNotNull("Entry "+counter+": target class is null",target);
+					assertTrue("Entry "+counter+": target class "+target.getClass()+" is invalid",target
instanceof JavaClass==false || 
+					   target instanceof JavaObject==false
+					);
+						
+				
+				
+			} catch (DataUnavailable e) {
+				// allowed
+			} catch (CorruptDataException e) {
+				// allowed
+			}
+			
+			// is class reference 
+			
+			try {
+				ref.isClassReference();
+			} catch (DataUnavailable e) {
+				// allowed
+			} catch (CorruptDataException e) {
+				// allowed
+			}
+			// is object reference
+			
+			try {
+				ref.isObjectReference();
+			} catch (DataUnavailable e) {
+				// allowed
+			} catch (CorruptDataException e) {
+				// allowed
+			}
+			
+		
+			counter++;
+		}
+		
+		
+		
+	}
+}



Mime
View raw message