comparison src/tests/gov/nasa/jpf/test/mc/basic/CGNotificationTest.java @ 0:61d41facf527

initial v8 import (history reset)
author Peter Mehlitz <Peter.C.Mehlitz@nasa.gov>
date Fri, 23 Jan 2015 10:14:01 -0800
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:61d41facf527
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
19 package gov.nasa.jpf.test.mc.basic;
20
21 import gov.nasa.jpf.ListenerAdapter;
22 import gov.nasa.jpf.jvm.bytecode.EXECUTENATIVE;
23 import gov.nasa.jpf.util.test.TestJPF;
24 import gov.nasa.jpf.vm.ChoiceGenerator;
25 import gov.nasa.jpf.vm.Instruction;
26 import gov.nasa.jpf.vm.SyncPolicy;
27 import gov.nasa.jpf.vm.VM;
28 import gov.nasa.jpf.vm.SystemState;
29 import gov.nasa.jpf.vm.ThreadInfo;
30 import gov.nasa.jpf.vm.Verify;
31 import gov.nasa.jpf.vm.choice.IntChoiceFromList;
32
33 import java.util.ArrayList;
34
35 import org.junit.Test;
36
37 /**
38 * regression test for CG notifications
39 */
40 public class CGNotificationTest extends TestJPF {
41
42 public static class Sequencer extends ListenerAdapter {
43
44 static ArrayList<String> sequence;
45
46 @Override
47 public void choiceGeneratorRegistered(VM vm, ChoiceGenerator<?> nextCG, ThreadInfo ti, Instruction executedInsn) {
48 System.out.println("# CG registered: " + nextCG);
49 sequence.add("registered " + nextCG.getId());
50
51 assert nextCG.hasMoreChoices();
52 }
53
54 @Override
55 public void choiceGeneratorSet(VM vm, ChoiceGenerator<?> newCG) {
56 System.out.println("# CG set: " + newCG);
57 sequence.add("set " + newCG.getId());
58
59 assert newCG.hasMoreChoices();
60 }
61
62 @Override
63 public void choiceGeneratorAdvanced(VM vm, ChoiceGenerator<?> currentCG) {
64 System.out.println("# CG advanced: " + currentCG);
65 sequence.add("advance " + currentCG.getId() + ' ' + currentCG.getNextChoice());
66 }
67
68 @Override
69 public void choiceGeneratorProcessed(VM vm, ChoiceGenerator<?> processedCG) {
70 System.out.println("# CG processed: " + processedCG);
71 sequence.add("processed " + processedCG.getId());
72
73 assert !processedCG.hasMoreChoices();
74 }
75
76 @Override
77 public void instructionExecuted(VM vm, ThreadInfo ti, Instruction nextInsn, Instruction lastInsn){
78 SystemState ss = vm.getSystemState();
79
80 if (lastInsn instanceof EXECUTENATIVE) { // break on native method exec
81 EXECUTENATIVE exec = (EXECUTENATIVE) lastInsn;
82
83 if (exec.getExecutedMethodName().equals("getInt")){// this insn did create a CG
84 if (!ti.isFirstStepInsn()){
85
86 ChoiceGenerator<Integer> cg = new IntChoiceFromList("listenerCG", 3,4);
87 ss.setNextChoiceGenerator(cg);
88 }
89 }
90 }
91
92 }
93 }
94
95 @Test
96 public void testCGNotificationSequence () {
97 if (!isJPFRun()){
98 Sequencer.sequence = new ArrayList<String>();
99 }
100
101 // make sure max insn preemption does not interfere
102 if (verifyNoPropertyViolation("+listener=.test.mc.basic.CGNotificationTest$Sequencer",
103 "+vm.max_transition_length=MAX")){
104 boolean b = Verify.getBoolean(); // first CG
105 int i = Verify.getInt(1,2); // this one gets a CG on top registered by the listener
106 /*
107 System.out.print("b=");
108 System.out.print(b);
109 System.out.print(",i=");
110 System.out.println(i);
111 */
112 }
113
114 if (!isJPFRun()){
115 String[] expected = {
116 "registered " + SyncPolicy.ROOT,
117 "set " + SyncPolicy.ROOT,
118 "advance " + SyncPolicy.ROOT + " ThreadInfo [name=main,id=0,state=RUNNING]",
119 "registered verifyGetBoolean",
120 "set verifyGetBoolean",
121 "advance verifyGetBoolean false",
122 "registered verifyGetInt(II)",
123 "registered listenerCG",
124 "set verifyGetInt(II)",
125 "set listenerCG",
126 "advance verifyGetInt(II) 1",
127 "advance listenerCG 3",
128 "advance listenerCG 4",
129 "processed listenerCG",
130 "advance verifyGetInt(II) 2",
131 "advance listenerCG 3",
132 "advance listenerCG 4",
133 "processed listenerCG",
134 "processed verifyGetInt(II)",
135 "advance verifyGetBoolean true",
136 "registered verifyGetInt(II)",
137 "registered listenerCG",
138 "set verifyGetInt(II)",
139 "set listenerCG",
140 "advance verifyGetInt(II) 1",
141 "advance listenerCG 3",
142 "advance listenerCG 4",
143 "processed listenerCG",
144 "advance verifyGetInt(II) 2",
145 "advance listenerCG 3",
146 "advance listenerCG 4",
147 "processed listenerCG",
148 "processed verifyGetInt(II)",
149 "processed verifyGetBoolean",
150 "processed " + SyncPolicy.ROOT
151 };
152
153 assert Sequencer.sequence.size() == expected.length;
154
155 int i=0;
156 for (String s : Sequencer.sequence){
157 assert expected[i].equals(s) : "\"" + expected[i] + "\" != \"" + s + "\"";
158 //System.out.println("\"" + s + "\",");
159 i++;
160 }
161 }
162 }
163 }