Search in sources :

Example 1 with FailException

use of com.cburch.logisim.data.FailException in project logisim-evolution by reds-heig.

the class TestPanel method getRowData.

public void getRowData(int firstRow, int numRows, ValueTable.Cell[][] rowData) {
    Model model = getModel();
    TestException[] results = model.getResults();
    int numPass = model.getPass();
    int numFail = model.getFail();
    TestVector vec = model.getVector();
    int columns = vec.columnName.length;
    String[] msg = new String[columns];
    Value[] altdata = new Value[columns];
    String passMsg = Strings.get("passStatus");
    String failMsg = Strings.get("failStatus");
    for (int i = firstRow; i < firstRow + numRows; i++) {
        int row = model.sortedIndex(i);
        Value[] data = vec.data.get(row);
        String rowmsg = null;
        String status = null;
        boolean failed = false;
        if (row < numPass + numFail) {
            TestException err = results[row];
            if (err != null && err instanceof FailException) {
                failed = true;
                for (FailException e = (FailException) err; e != null; e = e.getMore()) {
                    int col = e.getColumn();
                    msg[col] = StringUtil.format(Strings.get("expectedValueMessage"), e.getExpected().toDisplayString(getColumnValueRadix(col + 1)));
                    altdata[col] = e.getComputed();
                }
            } else if (err != null) {
                failed = true;
                rowmsg = err.getMessage();
            }
            status = failed ? failMsg : passMsg;
        }
        rowData[i - firstRow][0] = new ValueTable.Cell(status, rowmsg != null ? failColor : null, null, rowmsg);
        for (int col = 0; col < columns; col++) {
            rowData[i - firstRow][col + 1] = new ValueTable.Cell(altdata[col] != null ? altdata[col] : data[col], msg[col] != null ? failColor : null, null, msg[col]);
            msg[col] = null;
            altdata[col] = null;
        }
    }
}
Also used : TestException(com.cburch.logisim.data.TestException) TestVector(com.cburch.logisim.data.TestVector) ValueTable(com.cburch.logisim.gui.log.ValueTable) Value(com.cburch.logisim.data.Value) FailException(com.cburch.logisim.data.FailException)

Example 2 with FailException

use of com.cburch.logisim.data.FailException in project logisim-evolution by reds-heig.

the class TestThread method doTestVector.

// used only for automated testing via command line arguments
public static int doTestVector(Project proj, Circuit circuit, String vectorname) {
    System.out.println(StringUtil.format(Strings.get("testLoadingVector"), vectorname));
    TestVector vec;
    try {
        vec = new TestVector(vectorname);
    } catch (Exception e) {
        System.err.println(StringUtil.format(Strings.get("testLoadingFailed"), e.getMessage()));
        return -1;
    }
    TestThread tester;
    try {
        tester = new TestThread(proj, circuit, vec);
    } catch (TestException e) {
        System.err.println(StringUtil.format(Strings.get("testSetupFailed"), e.getMessage()));
        return -1;
    }
    System.out.println(StringUtil.format(Strings.get("testRunning"), Integer.toString(vec.data.size())));
    int numPass = 0, numFail = 0;
    for (int i = 0; i < vec.data.size(); i++) {
        try {
            System.out.print((i + 1) + " \r");
            tester.test(i);
            numPass++;
        } catch (FailException e) {
            System.out.println();
            System.err.println(StringUtil.format(Strings.get("testFailed"), Integer.toString(i + 1)));
            for (; e != null; e = e.getMore()) System.out.println("  " + e.getMessage());
            numFail++;
            continue;
        } catch (TestException e) {
            System.out.println();
            System.err.println(StringUtil.format(Strings.get("testFailed"), Integer.toString(i + 1) + " " + e.getMessage()));
            numFail++;
            continue;
        }
    }
    System.out.println();
    System.out.println(StringUtil.format(Strings.get("testResults"), Integer.toString(numPass), Integer.toString(numFail)));
    return 0;
}
Also used : TestVector(com.cburch.logisim.data.TestVector) TestException(com.cburch.logisim.data.TestException) FailException(com.cburch.logisim.data.FailException) TestException(com.cburch.logisim.data.TestException) FailException(com.cburch.logisim.data.FailException)

Example 3 with FailException

use of com.cburch.logisim.data.FailException in project logisim-evolution by reds-heig.

the class Circuit method doTestVector.

/**
 * Code taken from Cornell's version of Logisim:
 * http://www.cs.cornell.edu/courses/cs3410/2015sp/
 */
public void doTestVector(Project project, Instance[] pin, Value[] val) throws TestException {
    CircuitState state = project.getCircuitState();
    state.reset();
    for (int i = 0; i < pin.length; ++i) {
        if (Pin.FACTORY.isInputPin(pin[i])) {
            InstanceState pinState = state.getInstanceState(pin[i]);
            Pin.FACTORY.setValue(pinState, val[i]);
        }
    }
    Propagator prop = state.getPropagator();
    try {
        prop.propagate();
    } catch (Throwable thr) {
        thr.printStackTrace();
    }
    if (prop.isOscillating())
        throw new TestException("oscilation detected");
    FailException err = null;
    for (int i = 0; i < pin.length; i++) {
        InstanceState pinState = state.getInstanceState(pin[i]);
        if (Pin.FACTORY.isInputPin(pin[i]))
            continue;
        Value v = Pin.FACTORY.getValue(pinState);
        if (!val[i].compatible(v)) {
            if (err == null)
                err = new FailException(i, pinState.getAttributeValue(StdAttr.LABEL), val[i], v);
            else
                err.add(new FailException(i, pinState.getAttributeValue(StdAttr.LABEL), val[i], v));
        }
    }
    if (err != null) {
        throw err;
    }
}
Also used : InstanceState(com.cburch.logisim.instance.InstanceState) TestException(com.cburch.logisim.data.TestException) Value(com.cburch.logisim.data.Value) FailException(com.cburch.logisim.data.FailException)

Aggregations

FailException (com.cburch.logisim.data.FailException)3 TestException (com.cburch.logisim.data.TestException)3 TestVector (com.cburch.logisim.data.TestVector)2 Value (com.cburch.logisim.data.Value)2 ValueTable (com.cburch.logisim.gui.log.ValueTable)1 InstanceState (com.cburch.logisim.instance.InstanceState)1