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