Initial import
[jpf-core.git] / src / tests / gov / nasa / jpf / test / mc / basic / TransitionLengthTest.java
1 /*
2  * Copyright (C) 2014, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
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
9  * 
10  *        http://www.apache.org/licenses/LICENSE-2.0. 
11  *
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.
17  */
18 package gov.nasa.jpf.test.mc.basic;
19
20 import gov.nasa.jpf.ListenerAdapter;
21 import gov.nasa.jpf.util.test.TestJPF;
22 import gov.nasa.jpf.vm.ChoiceGenerator;
23 import gov.nasa.jpf.vm.Instruction;
24 import gov.nasa.jpf.vm.ThreadInfo;
25 import gov.nasa.jpf.vm.VM;
26 import gov.nasa.jpf.vm.choice.BreakGenerator;
27 import org.junit.Test;
28
29 /**
30  * JPF regression test for breaking transitions when exceeding
31  * vm.max_transition_length. While the program would not terminate outside
32  * JPF, it will terminate when run under JPF because of state matching
33  * 
34  * the listener is purely informative - if the test fails it doesn't terminate.
35  * It should report two registrations within the loop, the second one matching
36  * the state that was stored after the first one. However, the number of 
37  * transition breaks might change with more sophisticated loop detection
38  */
39 public class TransitionLengthTest extends TestJPF {
40     
41   public static class Listener extends ListenerAdapter {
42     @Override
43     public void choiceGeneratorRegistered (VM vm, ChoiceGenerator<?> nextCG, ThreadInfo currentThread, Instruction executedInstruction) {
44       if (nextCG instanceof BreakGenerator){
45         System.out.println();
46         System.out.println("registered: " + nextCG);
47       }
48     }
49   }
50   
51   @Test
52   public void testTermination(){
53     if (verifyNoPropertyViolation("+vm.max_transition_length=500", 
54                                   "+listener=" + TransitionLengthTest.class.getName() + "$Listener")){
55       System.out.println("starting loop");
56       while (true){
57         // no program state change withing body - this should eventually run into state matching
58         System.out.print(".");
59       }
60       // we can never get here outside of JPF
61     }
62   }
63 }