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.util.event;
21 import gov.nasa.jpf.util.event.EventTree;
22 import gov.nasa.jpf.util.event.Event;
23 import gov.nasa.jpf.util.test.TestJPF;
24 import org.junit.Test;
27 * regression test for EventTree
29 public class EventTreeTest extends TestJPF {
31 protected boolean checkGeneratedPaths (EventTree m, String[] expected){
32 System.out.println("event tree: ");
36 for (Event ee : m.visibleEndEvents()){
37 String trace = ee.getPathString(null);
38 System.out.print("checking path: \"" + trace + '"');
40 if (!m.checkPath(ee, expected)){
41 System.out.println(" UNEXPECTED");
44 System.out.println(" OK");
50 if (nMatches != expected.length){
51 System.out.println("UNCOVERED PATH: ");
52 for (int i=0; i<expected.length; i++){
53 if (expected[i] != null){
54 System.err.println(expected[i]);
64 //--------------------------------------------------------------------
66 static class SimpleTree extends EventTree {
68 public Event createRoot() {
84 public void testSimpleTree(){
85 SimpleTree m = new SimpleTree();
92 if (!checkGeneratedPaths(m, expected)){
93 fail("failed to match traces");
97 //--------------------------------------------------------------------
98 public static class CombinationTree extends EventTree {
100 public Event createRoot() {
101 return anyCombination(
111 public void testCombinationTree(){
112 CombinationTree t = new CombinationTree();
115 String[] expected = {
134 if (!checkGeneratedPaths(t, expected)){
135 fail("failed to match traces");
139 static class SimpleCombinationTree extends EventTree {
141 public Event createRoot() {
142 return anyCombination(
150 public void testSimpleCombinationTree(){
151 SimpleCombinationTree t = new SimpleCombinationTree();
152 System.out.println("--- tree:");
154 System.out.println("--- paths:");
158 //--------------------------------------------------------------------
160 static class EmbeddedCombinationTree extends EventTree {
162 public Event createRoot() {
173 public void testEmbeddedCombinationTree(){
174 EventTree t = new EmbeddedCombinationTree();
175 System.out.println("--- tree:");
177 System.out.println("--- paths:");
182 //--------------------------------------------------------------------
183 static class DT extends EventTree {
185 public Event createRoot() {
204 public void testMaxDepth(){
209 int maxDepth = t.getMaxDepth();
210 System.out.println("max depth: " + maxDepth);
212 assertTrue( maxDepth == 5);
215 //--------------------------------------------------------------------
216 static class PermutationTree extends EventTree {
218 public Event createRoot(){
219 return anyPermutation(
228 public void testPermutationTree(){
229 PermutationTree t = new PermutationTree();
232 String[] expected = {
241 if (!checkGeneratedPaths(t, expected)){
242 fail("failed to match traces");
246 //--------------------------------------------------------------------
247 static class AddPathTree extends EventTree {
249 public Event createRoot(){
259 public void testAddPath () {
260 AddPathTree t = new AddPathTree();
266 String[] expected = { "abc", "ab3" };
268 if (!checkGeneratedPaths(t, expected)){
269 fail("failed to match traces");
273 //-------------------------------------------------------------------
274 static class MT1 extends EventTree {
276 public Event createRoot(){
285 static class MT2 extends EventTree {
287 public Event createRoot(){
296 static class MT3 extends EventTree {
298 public Event createRoot(){
308 public void testMerge (){
311 //MT3 t3 = new MT3();
313 EventTree t = t1.interleave( t2);
316 String[] expected = {
339 if (!checkGeneratedPaths(t, expected)){
340 fail("failed to match traces");
344 //-------------------------------------------------------------------
345 static class SMT1 extends EventTree {
347 public Event createRoot(){
355 static class SMT2 extends EventTree {
357 public Event createRoot(){
366 public void testSimpleMerge (){
367 SMT1 t1 = new SMT1();
368 SMT2 t2 = new SMT2();
369 //MT3 t3 = new MT3();
371 EventTree t = t1.interleave( t2);
372 System.out.println("--- merged tree:");
374 System.out.println("--- merged paths:");
379 //-------------------------------------------------------------------
380 static class RT1 extends EventTree {
382 public Event createRoot(){
390 static class RT2 extends EventTree {
392 public Event createRoot(){
402 public void testRemove (){
406 EventTree t = t1.interleave( t2);
407 System.out.println("merged tree: ");
411 t = new EventTree( t.removeSource(t2));
412 System.out.println("reduced tree: ");
416 String[] expected = { "ab" };
417 if (!checkGeneratedPaths(t, expected)){
418 fail("failed to match traces");