02b7fcc494011574a133303fdfc9f1a8ef872004
[fleet.git] / src / com / sun / vlsi / chips / marina / test / MarinaUtils.java
1 package com.sun.vlsi.chips.marina.test;
2 import com.sun.async.test.BitVector;
3 import com.sun.async.test.Infrastructure;
4
5 import java.util.List;
6 import java.util.Random;
7 import java.util.ArrayList;
8
9 public class MarinaUtils {
10
11     /**
12      * StateWireState hides whether the state wire being high means FULL 
13      * or whether high means EMPTY
14      */
15     public static enum StateWireState {
16         FULL, EMPTY
17             };
18
19     public static int testnum;
20     
21     public static void fatal(boolean pred, String msg) {
22         if (pred) throw new FailureException(msg);
23     }
24
25     public static class FailureException extends RuntimeException {
26         public FailureException(String s) { super("test " + testnum + ": " + s); }
27     }
28
29     /**
30      *  Compare two lists of BitVectors
31      */
32     public static void compareItemsOrdered(List<BitVector> din, List<BitVector> dout) {
33         fatal(din.size()!=dout.size(),
34               "in count="+din.size()+" out count="+dout.size());
35         for (int i=0; i<din.size(); i++) {
36             BitVector dI = din.get(i);
37             BitVector dO = dout.get(i);
38             fatal(!dI.equals(dO),
39                   "item mismatch! in:"+dI.getState()+" out:"+dO.getState());
40         }
41     }
42
43     /**
44      *  Convert an edu.berkeley.fleet.api.BitVector to a com.sun.async.test.BitVector
45      */
46     public static BitVector berkToSun(edu.berkeley.fleet.api.BitVector berkBits) {
47         BitVector sunBits = new BitVector(berkBits.length(), "berkToSun()");
48         for(int i=0; i<sunBits.getNumBits(); i++) sunBits.set(i, berkBits.get(i));
49         return sunBits;
50     }
51
52     /**
53      *  Convert an a com.sun.async.test.BitVector to a edu.berkeley.fleet.api.BitVector
54      */
55     public static edu.berkeley.fleet.api.BitVector sunToBerk(BitVector sunBits) {
56         edu.berkeley.fleet.api.BitVector berkBits =
57             new edu.berkeley.fleet.api.BitVector(sunBits.getNumBits());
58         for(int i=0; i<sunBits.getNumBits(); i++) berkBits.set(i, sunBits.get(i));
59         return berkBits;
60     }
61
62
63     public static void expectLength(BitVector bv, int expected) {
64         if (bv.getNumBits()!=expected)
65             throw new RuntimeException("expected BitVector of length " + expected + ", but got " + bv.getNumBits() +" in " + bv);
66     }
67 }