use of com.cburch.logisim.data.TestException 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;
}
}
}
use of com.cburch.logisim.data.TestException 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;
}
use of com.cburch.logisim.data.TestException in project logisim-evolution by reds-heig.
the class TestThread method matchPins.
void matchPins() throws TestException {
int n = vector.columnName.length;
pin = new Instance[n];
CircuitState state = new CircuitState(this.project, this.circuit);
for (int i = 0; i < n; i++) {
String columnName = vector.columnName[i];
for (Component comp : circuit.getNonWires()) {
if (!(comp.getFactory() instanceof Pin))
continue;
Instance inst = Instance.getInstanceFor(comp);
InstanceState pinState = state.getInstanceState(comp);
String label = pinState.getAttributeValue(StdAttr.LABEL);
if (label == null || !label.equals(columnName))
continue;
if (Pin.FACTORY.getWidth(inst).getWidth() != vector.columnWidth[i].getWidth())
throw new TestException("test vector column '" + columnName + "' has width " + vector.columnWidth[i] + ", but pin has width " + Pin.FACTORY.getWidth(inst));
pin[i] = inst;
break;
}
if (pin[i] == null)
throw new TestException("test vector column '" + columnName + "' has no matching pin");
}
}
use of com.cburch.logisim.data.TestException 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;
}
}
Aggregations