use of de.neemann.digital.core.NodeException in project Digital by hneemann.
the class TestExecutor method create.
/**
* Creates the result by comparing the testing vector with the given model-
*
* @param model the model to check
* @return this for chained calls
* @throws TestingDataException DataException
* @throws NodeException NodeException
*/
public TestExecutor create(Model model) throws TestingDataException, NodeException {
allPassed = true;
HashSet<String> usedSignals = new HashSet<>();
inputs = new ArrayList<>();
outputs = new ArrayList<>();
for (Signal s : model.getInputs()) {
final int index = getIndexOf(s.getName());
if (index >= 0) {
inputs.add(new TestSignal(index, s.getValue()));
addTo(usedSignals, s.getName());
}
ObservableValue outValue = s.getBidirectionalReader();
if (outValue != null) {
final String outName = s.getName() + "_out";
final int inIndex = getIndexOf(outName);
if (inIndex >= 0) {
outputs.add(new TestSignal(inIndex, outValue));
addTo(usedSignals, outName);
}
}
}
for (Clock c : model.getClocks()) {
final int index = getIndexOf(c.getLabel());
if (index >= 0) {
inputs.add(new TestSignal(index, c.getClockOutput()));
addTo(usedSignals, c.getLabel());
}
}
for (Signal s : model.getOutputs()) {
final int index = getIndexOf(s.getName());
if (index >= 0) {
outputs.add(new TestSignal(index, s.getValue()));
addTo(usedSignals, s.getName());
}
}
for (String name : names) if (!usedSignals.contains(name))
throw new TestingDataException(Lang.get("err_testSignal_N_notFound", name));
if (inputs.size() == 0)
throw new TestingDataException(Lang.get("err_noTestInputSignalsDefined"));
if (outputs.size() == 0)
throw new TestingDataException(Lang.get("err_noTestOutputSignalsDefined"));
model.init();
try {
lines.emitLines(new LineListenerResolveDontCare(values -> checkRow(model, values), inputs), new Context());
} catch (ParserException e) {
throw new TestingDataException(Lang.get("err_errorParsingTestdata"), e);
} catch (RuntimeException e) {
if (allPassed) {
allPassed = false;
exception = e;
}
}
return this;
}
use of de.neemann.digital.core.NodeException in project Digital by hneemann.
the class ModelEntry method applyInputs.
/**
* Sets the Inputs of the element contained in this entry
*
* @throws PinException PinException
* @throws NodeException NodeException
*/
public void applyInputs() throws PinException, NodeException {
try {
HashMap<String, Pin> ins = pins.getInputs();
InverterConfig ic = visualElement.getElementAttributes().get(Keys.INVERTER_CONFIG);
ObservableValues values = ObservableValues.EMPTY_LIST;
ArrayList<ObservableValue> inputs = new ArrayList<>();
for (PinDescription inputName : inputNames) {
Pin pin = ins.get(inputName.getName());
if (pin == null)
throw new PinException(Lang.get("err_pin_N0_atElement_N1_notFound", inputName, visualElement), containingVisualElement);
ObservableValue value = pin.getValue();
if (value == null)
throw new PinException(Lang.get("err_noValueSetFor_N0_atElement_N1", inputName, visualElement), containingVisualElement);
inputs.add(ic.invert(inputName.getName(), value));
}
ArrayList<ObservableValue> bidirect = null;
for (Pin p : pins) {
if (p.getDirection() == Pin.Direction.both) {
if (bidirect == null)
bidirect = new ArrayList<>();
final ObservableValue readerValue = p.getReaderValue();
if (readerValue == null)
throw new PinException(Lang.get("err_noValueSetFor_N0_atElement_N1", p.getName(), visualElement), containingVisualElement);
bidirect.add(readerValue);
}
}
if (bidirect != null)
inputs.addAll(bidirect);
if (inputs.size() > 0) {
values = new ObservableValues(inputs);
element.setInputs(values);
}
ioState = new IOState(values, element.getOutputs(), element);
} catch (PinException | NodeException e) {
e.setOrigin(origin);
e.setVisualElement(containingVisualElement);
throw e;
}
}
use of de.neemann.digital.core.NodeException in project Digital by hneemann.
the class BitExtenderTest method testSignExtendError.
public void testSignExtendError() throws Exception {
try {
ObservableValue in = new ObservableValue("in", 4);
new BitExtender(new ElementAttributes().set(Keys.OUTPUT_BITS, 4)).setInputs(in.asList());
fail();
} catch (NodeException e) {
}
}
Aggregations