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;
21 import gov.nasa.jpf.util.test.TestJPF;
22 import gov.nasa.jpf.vm.BooleanChoiceGenerator;
23 import gov.nasa.jpf.vm.ChoiceGenerator;
24 import gov.nasa.jpf.vm.SystemState;
25 import gov.nasa.jpf.vm.choice.DoubleChoiceFromList;
26 import gov.nasa.jpf.vm.choice.IntChoiceFromSet;
28 import org.junit.Test;
32 * unit test driver for SystemState functions
34 public class SystemStateTest extends TestJPF {
36 static class MyJVM extends SingleProcessVM {
39 protected void notifyChoiceGeneratorSet (ChoiceGenerator<?>cg) {
40 System.out.println("notifyChoiceGeneratorSet: " + cg);
43 protected void notifyChoiceGeneratorAdvanced (ChoiceGenerator<?>cg) {
44 System.out.println("notifyChoiceGeneratorAdvanced: " + cg);
47 protected void notifyChoiceGeneratorProcessed (ChoiceGenerator<?>cg) {
48 System.out.println("notifyChoiceGeneratorProcessed: " + cg);
52 static class MySystemState extends SystemState {
57 public void testCascadedCGops() {
59 MyJVM vm = new MyJVM();
60 MySystemState ss = new MySystemState();
62 IntChoiceFromSet cg0 = new IntChoiceFromSet( "cg0", -100, -200); // not cascaded
63 BooleanChoiceGenerator cg1 = new BooleanChoiceGenerator("cg1"); // false,true
64 IntChoiceFromSet cg2 = new IntChoiceFromSet( "cg2", 1, 2);
65 DoubleChoiceFromList cg3 = new DoubleChoiceFromList( "cg3", 42.1, 42.2);
67 cg2.isCascaded = true;
68 cg1.isCascaded = true;
77 //--- test initial advance
78 System.out.println("--- testing advanceCurCg()");
81 assert cg0.getNextChoice() == -100;
82 assert cg1.getNextChoice() == false;
83 assert cg2.getNextChoice() == 1;
84 assert cg3.getNextChoice() == 42.1;
87 //--- test advanceCascadedParent
88 System.out.println("--- testing advanceCascadedParent()");
92 assert !cg2.hasMoreChoices();
93 assert !cg3.hasMoreChoices();
95 System.out.println(cg1);
96 System.out.println(cg2);
97 System.out.println(cg3);
99 ss.advanceCascadedParent(vm,cg3);
101 assert cg0.getNextChoice() == -100;
102 assert cg1.getNextChoice() == true;
103 assert cg2.getNextChoice() == 1;
104 assert cg3.getNextChoice() == 42.1;
108 public void testCascadedCGadvance() {
110 MyJVM vm = new MyJVM();
111 MySystemState ss = new MySystemState();
113 BooleanChoiceGenerator cg1 = new BooleanChoiceGenerator("cg1"); // false,true
114 IntChoiceFromSet cg2 = new IntChoiceFromSet( "cg2", 1, 2);
115 DoubleChoiceFromList cg3 = new DoubleChoiceFromList( "cg3", 42.1, 42.2);
117 cg2.isCascaded = true;
118 cg1.isCascaded = true;
125 while (ss.advanceCurCg(vm)){
126 System.out.println("--");