Search in sources :

Example 6 with NodeException

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;
}
Also used : Clock(de.neemann.digital.core.wiring.Clock) LineEmitter(de.neemann.digital.testing.parser.LineEmitter) Signal(de.neemann.digital.core.Signal) ParserException(de.neemann.digital.testing.parser.ParserException) ObservableValue(de.neemann.digital.core.ObservableValue) Lang(de.neemann.digital.lang.Lang) ValueTable(de.neemann.digital.data.ValueTable) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Model(de.neemann.digital.core.Model) Value(de.neemann.digital.data.Value) Context(de.neemann.digital.testing.parser.Context) NodeException(de.neemann.digital.core.NodeException) Context(de.neemann.digital.testing.parser.Context) ParserException(de.neemann.digital.testing.parser.ParserException) ObservableValue(de.neemann.digital.core.ObservableValue) Clock(de.neemann.digital.core.wiring.Clock) Signal(de.neemann.digital.core.Signal) HashSet(java.util.HashSet)

Example 7 with NodeException

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;
    }
}
Also used : ObservableValues(de.neemann.digital.core.ObservableValues) PinDescription(de.neemann.digital.core.element.PinDescription) ObservableValue(de.neemann.digital.core.ObservableValue) ArrayList(java.util.ArrayList) NodeException(de.neemann.digital.core.NodeException)

Example 8 with NodeException

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) {
    }
}
Also used : ObservableValue(de.neemann.digital.core.ObservableValue) NodeException(de.neemann.digital.core.NodeException) ElementAttributes(de.neemann.digital.core.element.ElementAttributes)

Aggregations

NodeException (de.neemann.digital.core.NodeException)8 ObservableValue (de.neemann.digital.core.ObservableValue)5 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)2 Clock (de.neemann.digital.core.wiring.Clock)2 PinException (de.neemann.digital.draw.elements.PinException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Model (de.neemann.digital.core.Model)1 ObservableValues (de.neemann.digital.core.ObservableValues)1 Signal (de.neemann.digital.core.Signal)1 ElementTypeDescription (de.neemann.digital.core.element.ElementTypeDescription)1 PinDescription (de.neemann.digital.core.element.PinDescription)1 DataField (de.neemann.digital.core.memory.DataField)1 ROM (de.neemann.digital.core.memory.ROM)1 Value (de.neemann.digital.data.Value)1 ValueTable (de.neemann.digital.data.ValueTable)1 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)1 ElementNotFoundException (de.neemann.digital.draw.library.ElementNotFoundException)1 HGSEvalException (de.neemann.digital.hdl.hgs.HGSEvalException)1 HDLCircuit (de.neemann.digital.hdl.model2.HDLCircuit)1