2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package gov.nasa.jpf.vm.multiProcess;
21 import java.lang.annotation.Inherited;
22 import java.lang.annotation.Retention;
23 import java.lang.annotation.RetentionPolicy;
24 import java.util.List;
26 import gov.nasa.jpf.util.test.TestMultiProcessJPF;
27 import gov.nasa.jpf.vm.ClassInfo;
28 import gov.nasa.jpf.vm.ClassLoaderInfo;
30 import org.junit.Test;
33 * @author Nastaran Shafiei <nastaran.shafiei@gmail.com>
35 public class TypeSeparationTest extends TestMultiProcessJPF {
37 private static int counter = 0;
39 private static void incCounter() {
43 // To make sure that our multiProcess VM keeps the static attributes separated
44 // This also checks for type safe clone for the InvokeStatic instruction.
46 public void staticCounterTest() {
47 // Note that this code is executed 4 times. Since every time this is executed its
48 // state is restored, the value of counter should be always 1
49 if (mpVerifyNoPropertyViolation(2)) {
50 int id = getProcessId();
59 fail("invalid process number!");
62 assertEquals(counter,1);
66 @Retention(RetentionPolicy.RUNTIME)
68 public @interface A0 {
71 private native void keepAnnotationClass(Class annCls, int prcId);
74 public void annotationsTest () {
76 JPF_gov_nasa_jpf_vm_multiProcess_TypeSeparationTest.resetPrcIds();
79 if (mpVerifyNoPropertyViolation(2)) {
80 int prcId = getProcessId();
81 keepAnnotationClass(A0.class, prcId);
85 List<ClassInfo> annClassList = JPF_gov_nasa_jpf_vm_multiProcess_TypeSeparationTest.getAnnotationClasses();
86 assertEquals(annClassList.size(), 2);
87 assertTrue(annClassList.get(0)!=annClassList.get(1));
92 private native void keepClassLoader(ClassLoader thd, int prcId);
94 // to make sure that each process accesses the classes loaded by the right
95 // system class loader
97 public void systemClassLoaderTest() {
99 JPF_gov_nasa_jpf_vm_multiProcess_TypeSeparationTest.resetPrcIds();
102 if (mpVerifyNoPropertyViolation(2)) {
103 ClassLoader cl = Object.class.getClassLoader();
105 // in our implementation this goes through the class hierarchy of the
106 // current thread and it returns the class loader of the Thread class
107 ClassLoader sysLoader = ClassLoader.getSystemClassLoader();
108 assertEquals(cl, sysLoader);
110 int prcId = getProcessId();
111 keepClassLoader(cl, prcId);
115 List<ClassLoaderInfo> classLoaders = JPF_gov_nasa_jpf_vm_multiProcess_TypeSeparationTest.getClassLoaders();
116 assertEquals(classLoaders.size(), 2);
117 assertTrue(classLoaders.get(0)!=classLoaders.get(1));