misc cleanups
[fleet.git] / src / com / sun / vlsi / chips / marina / test / MarinaTest.java
index 01fa1cb..01b394d 100644 (file)
@@ -3,26 +3,7 @@ package com.sun.vlsi.chips.marina.test;
 import java.util.ArrayList;
 import java.util.List;
 
-import com.sun.async.test.BitVector;
-import com.sun.async.test.ChainControl;
-import com.sun.async.test.ChainG;
-import com.sun.async.test.ChainTest;
-import com.sun.async.test.ChipModel;
-import com.sun.async.test.HP34401A;
-import com.sun.async.test.Infrastructure;
-import com.sun.async.test.JtagSubchainTesterModel;
-import com.sun.async.test.JtagTester;
-import com.sun.async.test.ManualPowerChannel;
-import com.sun.async.test.NanosimModel;
-import com.sun.async.test.NanosimLogicSettable;
-import com.sun.async.test.HsimModel;
-import com.sun.async.test.VerilogModel;
-import com.sun.async.test.Netscan4;
-import com.sun.async.test.PowerChannel;
-import com.sun.async.test.Pst3202Channel;
-import com.sun.async.test.SiliconChip;
-import com.sun.async.test.SimulationModel;
-import com.sun.async.test.VoltageReadable;
+import com.sun.electric.tool.simulation.test.*;
 import com.sun.vlsi.chips.marina.test.Marina.Ilc;
 import com.sun.vlsi.chips.marina.test.CmdArgs;
 import com.sun.vlsi.chips.marina.test.CmdArgs.Mode;
@@ -34,7 +15,8 @@ import edu.berkeley.fleet.api.Instruction.Set.SetDest;
 import edu.berkeley.fleet.api.Instruction.Set.SetSource;
 import edu.berkeley.fleet.marina.MarinaFleet;
 import edu.berkeley.fleet.marina.MarinaPath;
-import com.sun.async.test.*;
+
+import java.io.*;
 
 /**
  * Tests for Marina
@@ -43,6 +25,8 @@ public class MarinaTest {
     public static final MarinaFleet marinaFleet = new MarinaFleet();
     public static final Dock dock = marinaFleet.getOnlyInputDock();
 
+    public static float vdd = 1.0f;
+
     //--------------------------  constants -----------------------------------
     private static final String SCAN_CHAIN_XML = "marina.xml";
     private static final String NET_LIST = "marina.spi";
@@ -116,6 +100,8 @@ public class MarinaTest {
     private PowerChannel corePowerSupply, padsPowerSupply;
     private VoltageReadable coreVoltmeter, voltmeterForCurrent;
 
+
+
     private ChainTest ctD, ctR, ctC, ct;
     private ChainControl ccD, ccR, ccC, cc;
         
@@ -168,41 +154,17 @@ public class MarinaTest {
                 return;
         }
     }
-    private void setUpSuppliesAndMeters(Station station) {
-        // set up power supplies and meters
-        if (!sim()) {
-            prln("Testing station: "+station);
-            Infrastructure.gpibControllers = new int[] {0};
-            switch (cmdArgs.station) {
-                case ONE:
-                    corePowerSupply = new Pst3202Channel("ch1", "HPST3202", 1);
-                    padsPowerSupply = new Pst3202Channel("ch2", "HPST3202", 2);
-                    break;
-                case TWO:
-                    corePowerSupply = new Pst3202Channel("ch1", "HPST3202B", 1);
-                    padsPowerSupply = new Pst3202Channel("ch2", "HPST3202B", 2);
-                    break;
-                default:
-                    fatal(true, "Unrecognized station: "+cmdArgs.station);
-            }
-            corePowerSupply.setCurrent((float)1.7);
-            corePowerSupply.setVoltageWait((float)1.0);
-                  
-            padsPowerSupply.setCurrent((float)0.100);
-            padsPowerSupply.setVoltageWait((float)1.8);
-                  
-            coreVoltmeter = new HP34401A(station.coreVoltmeter);
-            voltmeterForCurrent = new HP34401A(station.currentVoltmenter);
-        }
-    }
-        
-    private MarinaTest(String[] args) {
+
+    private MarinaTest(String[] args) throws Exception {
         cmdArgs = new CmdArgs(args);
         reportTask(cmdArgs);
-        if (cmdArgs.mode==Mode.TEST_SILICON) doSilicon(); else doSim();
+        doSim();
     }
         
-    private void doSim() {
+    static PowerChannel vdd18;
+    static PowerChannel vdd10;
+
+    private void doSim() throws Exception {
         String netListName;
         switch (cmdArgs.mode) {
             case WHOLE_CHIP_SCHEMATIC_PARASITICS:
@@ -216,6 +178,12 @@ public class MarinaTest {
                 return;
         }
 
+        Infrastructure.gpibControllers = new int[]{1};
+        vdd18 = new Pst3202Channel("ch2", "tiPST3202", 2);
+        vdd10 = new Pst3202Channel("ch3", "tiPST3202", 3);
+        vdd10.setVoltageNoWait(vdd);
+        vdd18.setVoltageNoWait(1.8f);
+
         model = cmdArgs.useVerilog
             ? new VerilogModel()
             : cmdArgs.useHsim
@@ -241,21 +209,27 @@ public class MarinaTest {
         JtagTester tester =
             model instanceof SimulationModel
             ? ((SimulationModel)model).createJtagTester("TCK", "TMS", "TRSTb", "TDI", "TDO")
-            : new Netscan4("jtag3", 2);
-        if (tester instanceof Netscan4) {
-            ((Netscan4)tester).reset();
+            : new Netscan("jtag2"); // bad kessels counter
+            //: new Netscan4("jtag3", 4);    // good kessels counter
+        JtagLogicLevel mc0=null;
+        JtagLogicLevel mc1=null;
+        if (tester instanceof Netscan) {
+            ((Netscan)tester).reset();
             // master clear
             // not sure if "GPIO1" means "index 0" or not
-            JtagLogicLevel mc0 = new JtagLogicLevel(tester, 0);
-            JtagLogicLevel mc1 = new JtagLogicLevel(tester, 1);
+            mc0 = new JtagLogicLevel(tester, 0);
+            mc1 = new JtagLogicLevel(tester, 1);
             mc0.setLogicState(true);
             mc1.setLogicState(true);
         }
+        /*
         Logger.setLogInits(true);
         tester.setLogSets(true);
         tester.setLogOthers(true);
         tester.setAllLogging(true);
         tester.printInfo = true;
+        */
+        tester.printInfo = false;
 
         ChainControls ccs = new ChainControls();
         PowerChannel pc = new ManualPowerChannel("pc", false);
@@ -281,6 +255,14 @@ public class MarinaTest {
         ccs.addChain(Marina.REPORT_CHAIN, ccR);
         ccs.addChain(Marina.CONTROL_CHAIN, ccC);
         */
+        /*
+        PowerChannel ch2 = new Pst3202Channel("ch2", "tiPST3202", 2);
+        PowerChannel ch3 = new Pst3202Channel("ch3", "tiPST3202", 3);
+        Infrastructure.gpibControllers = new int[]{1};
+        ch2.setVoltageNoWait(1f);
+        ch3.setVoltageNoWait(1.8f);
+        */
+
 
         cc = new ChainControl(SCAN_CHAIN_XML, tester, 1.8f, khz);
         cc.noTestSeverity = Infrastructure.SEVERITY_NOMESSAGE;
@@ -288,8 +270,11 @@ public class MarinaTest {
         ccs.addChain(Marina.DATA_CHAIN, cc);
         ccs.addChain(Marina.REPORT_CHAIN, cc);
         ccs.addChain(Marina.CONTROL_CHAIN, cc);
+        ccs.addChain(Marina.DUKE_CHAIN, cc);
 
         marina = new Marina(ccs, model, !cmdArgs.jtagShift, indenter);
+        marina.mc0=mc0;
+        marina.mc1=mc1;
 
         if (model instanceof NanosimModel) {
             NanosimLogicSettable mc = (NanosimLogicSettable)
@@ -313,7 +298,7 @@ public class MarinaTest {
         if (model instanceof SimulationModel)
             ((SimulationModel)model).setNodeState(Marina.MASTER_CLEAR, 0);
         else
-            prln("FIXME: need to deassert master clear");
+            marina.masterClear();
         model.waitNS(1000);
 
         if (cmdArgs.testNum!=0 && cmdArgs.testNum!=1) {
@@ -326,25 +311,6 @@ public class MarinaTest {
         if (model instanceof SimulationModel)
             ((SimulationModel)model).finish();
     }
-    private void doSilicon() {
-        model = new SiliconChip();
-        String ip = cmdArgs.station.ipAddr;
-        JtagTester tester = new Netscan4(ip, cmdArgs.station.jtagChannel);
-        tester.printInfo = false;
-        int khz = 1000;
-        ChainControl cc = new ChainControl("???", tester, 1.8f, khz);
-        cc.noTestSeverity = Infrastructure.SEVERITY_NOMESSAGE;
-        ChainControls ccs = new ChainControls();
-        ccs.addChain(Marina.DATA_CHAIN, cc);
-        ccs.addChain(Marina.REPORT_CHAIN, cc);
-        ccs.addChain(Marina.CONTROL_CHAIN, cc);
-        marina = new Marina(ccs, model, false, indenter);
-        PowerChannel pc = new ManualPowerChannel("pc", false);
-        ChainTest ct = new ChainTest(cc, pc);
-        ct.testAllChains("marina", Infrastructure.SEVERITY_WARNING);
-        doOneTest(cmdArgs.testNum);
-        setUpSuppliesAndMeters(cmdArgs.station);
-    }
 
     /** In the absence of looping, the longest path through Infinity is 4 column delays */
     private void waitUntilQuiescent() {
@@ -767,7 +733,43 @@ public class MarinaTest {
     private void walkOneOLC(Marina marina) {
         prln("Begin walkOneOLC");
         adjustIndent(2);
-        for (int i=0; i<6; i++) {
+        /*
+        //for (int i=-1; i<6; i++) {
+        marina.fillSouthProperStopper(new Instruction[] {
+
+                new Instruction.Head(dock),
+
+                //                new Instruction.Set(dock,Predicate.IgnoreFlagD, SetDest.OuterLoopCounter, 1),
+                FLAG_NOP,
+                FLAG_NOP,
+                FLAG_NOP,
+                TORPEDOABLE_RECV_DATA,
+                FLAG_NOP,
+                FLAG_NOP,
+                FLAG_NOP,
+
+
+                //new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter, SetSource.Decrement),
+                
+                new Instruction.Tail(dock),
+            });
+        marina.fillSouthProperStopper(new Instruction[] {
+                null,
+            },
+            true);
+        while(true) {
+            BitVector bits = null;
+            marina.shiftReport(true, false);
+            for(int i=0; i<4; i++) {
+                BitVector x = marina.cc.getOutBits(marina.REPORT_CHAIN+"."+marina.OLC_PATH_KESSEL+i);
+                //System.out.println("bits are: " + x);
+                bits = bits==null ? x : bits.cat(x);
+            }
+            System.out.println("dec="+bits.get(0));
+            if (bits.get(1)) throw new RuntimeException();
+        }
+        */
+        /*        for (int i=0; i<64; i++) {
 
             if (marina.kesselsCounter) {
                 System.out.println("master-clearing...");
@@ -776,16 +778,25 @@ public class MarinaTest {
                 marina.enableInstructionSend(true);
             }
 
+            expectTokensExactly(0);
+            marina.getOLC();
+
             int inOlc = i==-1 ? 0 : (1<<i);
+            inOlc = i;
             marina.instrIn.fill(new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter, inOlc));
+            marina.instrIn.fill(SEND_DATA_IF_D_SET);
+            marina.instrIn.fill(SEND_DATA_IF_D_NOT_SET);
+            marina.instrIn.fill(SEND_DATA);
 
             model.waitNS(128 * CYCLE_TIME_NS);
 
             expectOlc(inOlc);
             prln("walkOneOLC: "+inOlc+" checks out");
+            expectNorthFifoExactly(0);
         }
         adjustIndent(-2);
         prln("End walkOneOLC");
+        */
     }
     private void walkOneILC(Marina marina) {
         prln("Begin walkOneILC");
@@ -864,6 +875,7 @@ public class MarinaTest {
     }
     private void loadEveryValueOLC(Marina marina) {
         adjustIndent(2);
+        //while(true)
         for (int i=0; i<(1<<6); i++) {
 
             if (marina.kesselsCounter) {
@@ -931,9 +943,14 @@ public class MarinaTest {
                             CLEAR_FLAG.add(Predicate.FlagA),
                             CLEAR_FLAG.add(Predicate.FlagB));
 
+    private static final Instruction FLAG_NOP_IF_FLAG_A =
+        new Instruction.Set(dock, Predicate.FlagA,
+                            CLEAR_FLAG.add(Predicate.FlagA),
+                            CLEAR_FLAG.add(Predicate.FlagB));
+
     private static final Instruction NOP =
         new Instruction.Move(dock,
-                             Predicate.IgnoreFlagD,   /* predicate   */
+                             Predicate.IgnoreFlagD, /* predicate   */
                              false,                 /* torpedoable */
                              null,                  /* path        */
                              false,                 /* tokenIn     */
@@ -970,6 +987,19 @@ public class MarinaTest {
                              false                  /* tokenOut    */
                              );
 
+    private static final Instruction SEND_DATA_IF_A_SET_AND_D_NOT_SET =
+        new Instruction.Move(dock,
+                             Predicate.FlagA,       /* predicate   */
+                             false,                 /* torpedoable */
+                             null_path,             /* path        */
+                             false,                 /* tokenIn     */
+                             false,                 /* dataIn      */
+                             false,                 /* latchData   */
+                             false,                 /* latchPath   */
+                             true,                  /* dataOut     */
+                             false                  /* tokenOut    */
+                             );
+
     private static final Instruction SEND_DATA_IF_D_SET =
         new Instruction.Move(dock,
                              Predicate.FlagD,       /* predicate   */
@@ -983,6 +1013,32 @@ public class MarinaTest {
                              false                  /* tokenOut    */
                              );
 
+    private static final Instruction SEND_TOKEN_IF_D_SET =
+        new Instruction.Move(dock,
+                             Predicate.FlagD,       /* predicate   */
+                             false,                 /* torpedoable */
+                             null_path,             /* path        */
+                             false,                 /* tokenIn     */
+                             false,                 /* dataIn      */
+                             false,                 /* latchData   */
+                             false,                 /* latchPath   */
+                             false,                 /* dataOut     */
+                             true                   /* tokenOut    */
+                             );
+
+    private static final Instruction SEND_TOKEN_IF_D_NOT_SET =
+        new Instruction.Move(dock,
+                             Predicate.Default,     /* predicate   */
+                             false,                 /* torpedoable */
+                             null_path,             /* path        */
+                             false,                 /* tokenIn     */
+                             false,                 /* dataIn      */
+                             false,                 /* latchData   */
+                             false,                 /* latchPath   */
+                             false,                 /* dataOut     */
+                             true                   /* tokenOut    */
+                             );
+
     private static final Instruction TORPEDOABLE_RECV_DATA =
         new Instruction.Move(dock,
                              Predicate.IgnoreFlagD, /* predicate   */
@@ -1994,16 +2050,22 @@ public class MarinaTest {
 
     private void testDFlagWhenTorpedoLyingInWait(Marina marina) {
         marina.fillSouthProperStopper(new Instruction[] {
+                setOlc(1),
                 RECV_DATA,
                 TORPEDOABLE_RECV_DATA,
-                marina.kesselsCounter ? null : FLAG_NOP,
-                SEND_DATA_IF_D_SET,
+                FLAG_NOP,
+                FLAG_NOP,
+                FLAG_NOP,
+                SEND_TOKEN_IF_D_SET,
             });
-        marina.instrIn.fillTorpedo();
-        model.waitNS(64 * CYCLE_TIME_NS);
+
+        expectTokensExactly(0);
+
+        // changing the order of these lines should work, but it does not
         marina.fillNorthProperStopper();
-        model.waitNS(64 * CYCLE_TIME_NS);
-        expectNorthFifoExactly(1);
+        marina.instrIn.fillTorpedo();
+
+        expectTokensExactly(1);
     }
 
     private void testSetOlcFollowedByDPredicated(Marina marina) {
@@ -2087,6 +2149,7 @@ public class MarinaTest {
             int expected = decr_amount>=olc ? 0 : 1;
             dataItems = marina.data.drainMany(2);
             fatal(dataItems.size()!=expected, "Expected "+expected+" item to emerge but got: "+dataItems.size()+" data items");
+            expectOlc(Math.max(0,olc-decr_amount));
 
             if (marina.kesselsCounter) {
                 // master clear on each iteration; otherwise we'd need to "run down" the olc
@@ -2245,17 +2308,54 @@ public class MarinaTest {
 
 
 
-    private void doOneTest(int testNum) {
+    private void doOneTest(int testNum) throws Exception {
+        try {
+            doOneTest_(testNum);
+        } catch (MarinaUtils.FailureException fe) {
+            System.out.println("******************************************************************************");
+            System.out.println("******************************************************************************");
+            System.out.println("******************************************************************************");
+            System.out.println("******************************************************************************");
+            fe.printStackTrace();
+        }
+    }
+
+    private void doOneTest_(int testNum) throws Exception {
         prln("");
         prln("============================================================");
         prln("MarinaTest: performing test: "+testNum);
 
+        if (testNum==999) {
+            //vdd = 0.5f;
+            vdd = 1.0f;
+            int[] tests = new int[] { 1002, 1003, 1005, 3002, 3004, 3005, 3006, 3008, 3009, 3025, 3026, 3029 };
+            try {
+                PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream("test.out")));
+                while(vdd <= 1.3f) {
+                    vdd10.setVoltageWait(vdd);
+                    System.out.println("vdd10 = " + vdd10.readVoltage());
+                    Thread.sleep(1000);
+                    for(int i=0; i<tests.length; i++) {
+                        try {
+                            doOneTest_(tests[i]);
+                            pw.println(vdd + " " + i + " " + "1");
+                        } catch (MarinaUtils.FailureException fe) {
+                            pw.println(vdd + " " + i + " " + "0");
+                        }
+                        pw.flush();
+                    }
+                    vdd -= 0.01f;
+                }
+            } catch (Exception e) { throw new RuntimeException(e); }
+        }
+
         if (testNum!=0) {
             marina.masterClear();
             marina.enableInstructionSend(true);
         }
-        
-        try {
+
+        MarinaUtils.testnum = testNum;
+
             switch (testNum) {
                 case 0: {
 
@@ -2294,8 +2394,8 @@ public class MarinaTest {
                     doOneTest(3027);    // passes extracted parasitics
                     doOneTest(3028);    // passes extracted parasitics
                     doOneTest(3029);    // passes extracted parasitics
-                    doOneTest(3030);    // passes extracted parasitics
-                    doOneTest(3031);    // passes extracted parasitics
+                    //doOneTest(3030);    // passes extracted parasitics (questionable)
+                    //doOneTest(3031);    // passes extracted parasitics should not pass!
                     
                     // these tests take a while and usually pass
                     doOneTest(1002);
@@ -2372,6 +2472,68 @@ public class MarinaTest {
                 case 3031: testOverfillTokens(marina); break;
 
                 case 3040: loadEveryValueOLC(marina); break;
+                case 8888: {
+
+                    //int wait = 1000;
+                    int wait = 200;
+                    //int toks = 1;
+
+                    PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream("out.dat")));
+                    for(double myvdd = 1.0; myvdd<2.0; myvdd += 0.05) {
+                        vdd = (float)myvdd;
+                        vdd18.setVoltageWait((float)Math.max(1.8,vdd));
+                        vdd10.setVoltageWait(vdd);
+                        Thread.sleep(1000);
+
+                    for(int toks = 0; toks < 13; toks++) {
+                            int MAX_ITER = 10;
+                            double total = 0;
+                            for(int iter = 0; iter < MAX_ITER; iter++) {
+
+                                marina.masterClear();
+                                marina.data.sink();
+                                marina.stopAndResetCounters();
+                                
+                                marina.enableInstructionSend(true);
+                                marina.fillSouthProperStopper(setOlc(1));
+                                marina.fillSouthProperStopper(new Instruction.Head(dock));
+                                for(int i=0; i<toks; i++)
+                                    marina.fillSouthProperStopper(/*SEND_DATA*/NOP);
+                                marina.fillSouthProperStopper(new Instruction[] {
+                                        new Instruction.Tail(dock),
+                                    }, false, true);
+                                marina.startCounters();
+                                
+                                marina.instrIn.run();
+                                try { Thread.sleep(wait); } catch (Exception e) { }
+                                //marina.instrIn.stop();
+                                
+                                marina.stopAndResetCounters();
+                                int countNorth = marina.getNorthCount();
+                                int count      = marina.getSouthCount();
+                                System.out.println();
+                                System.out.println();
+                                if (count > (2<<29))
+                                    System.out.println("warning: count was greater than 2^29...");
+                                double gst = ((((double)count*2)) / (1000000. * wait /* * toks*/));
+                                System.out.println("south counter is: " + count + ", which is " + gst + "Ginst/sec with toks="+toks + " @vdd="+vdd);
+                                total += gst;
+
+                                System.out.println();
+                                System.out.println();
+                                /*
+                                  System.out.println("counters are " + count + " and " + countNorth + "; ratio is "+
+                                  (((double)countNorth)/((double)(count*2))) + " " +
+                                  (((double)countNorth)/((double)(count*2+1))) + " " +
+                                  "");
+                                */
+                            }
+                            pw.println(vdd + " " + toks + " " + (((double)total) / MAX_ITER));
+                            pw.flush();
+                        }
+                    }
+                    break;
+                }
                 case 9999:
                     loadEveryValueOLC(marina);
                     countOlc(marina);
@@ -2385,13 +2547,6 @@ public class MarinaTest {
             prln("Test Result: Passed");
             printTestTime();
             //Infrastructure.exit(0);
-        } catch (MarinaUtils.FailureException fe) {
-            System.out.println("******************************************************************************");
-            System.out.println("******************************************************************************");
-            System.out.println("******************************************************************************");
-            System.out.println("******************************************************************************");
-            fe.printStackTrace();
-        }
     }
 
 
@@ -2402,7 +2557,7 @@ public class MarinaTest {
      * 2: test detected failure
      * 1: test crashed
      */ 
-    public static void main(String[] args) {
+    public static void main(String[] args) throws Exception {
         startTime = System.currentTimeMillis();
         new MarinaTest(args);
     }