Search in sources :

Example 1 with ParserException

use of de.neemann.digital.testing.parser.ParserException in project Digital by hneemann.

the class VHDLTestBenchCreator method write.

/**
 * Writes the test benches
 *
 * @param file the original vhdl file
 * @return this for chained calls
 * @throws IOException  IOException
 * @throws HDLException HDLException
 */
public VHDLTestBenchCreator write(File file) throws IOException, HDLException {
    String filename = file.getName();
    int p = filename.indexOf('.');
    if (p > 0)
        filename = filename.substring(0, p);
    for (ElementAttributes tc : testCases) {
        String testName = tc.getCleanLabel();
        if (testName.length() > 0)
            testName = filename + "_" + testName + "_tb";
        else
            testName = filename + "_tb";
        File f = new File(file.getParentFile(), testName + ".vhdl");
        testFileWritten.add(f);
        try (CodePrinter out = new CodePrinter(f)) {
            try {
                writeTestBench(out, testName, tc);
            } catch (TestingDataException | ParserException | RuntimeException e) {
                throw new HDLException(Lang.get("err_vhdlErrorWritingTestBench"), e);
            }
        }
    }
    return this;
}
Also used : ParserException(de.neemann.digital.testing.parser.ParserException) TestingDataException(de.neemann.digital.testing.TestingDataException) CodePrinter(de.neemann.digital.hdl.printer.CodePrinter) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) HDLException(de.neemann.digital.hdl.model2.HDLException) File(java.io.File)

Example 2 with ParserException

use of de.neemann.digital.testing.parser.ParserException in project Digital by hneemann.

the class TestCaseDescription method check.

private void check() throws TestingDataException {
    if (lines == null) {
        try {
            Parser tdp = new Parser(dataString).parse();
            lines = tdp.getLines();
            names = tdp.getNames();
        } catch (ParserException | IOException e) {
            throw new TestingDataException(Lang.get("err_errorParsingTestdata"), e);
        }
    }
}
Also used : ParserException(de.neemann.digital.testing.parser.ParserException) IOException(java.io.IOException) Parser(de.neemann.digital.testing.parser.Parser)

Example 3 with ParserException

use of de.neemann.digital.testing.parser.ParserException in project Digital by hneemann.

the class TestDataTest method testSetDataNonParseable.

public void testSetDataNonParseable() throws Exception {
    TestCaseDescription td = new TestCaseDescription(DATA1);
    LineCollector cl = new LineCollector(td.getLines());
    assertEquals(4, cl.getLines().size());
    assertEquals(DATA1, td.getDataString());
    // try to set a non parsable string
    try {
        td.setDataString(DATA3);
        assertTrue(false);
    } catch (IOException | ParserException e) {
        assertTrue(true);
    }
    // TestData remains unchanged!
    assertEquals(DATA1, td.getDataString());
}
Also used : ParserException(de.neemann.digital.testing.parser.ParserException) IOException(java.io.IOException) LineCollector(de.neemann.digital.testing.parser.LineCollector)

Example 4 with ParserException

use of de.neemann.digital.testing.parser.ParserException 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 5 with ParserException

use of de.neemann.digital.testing.parser.ParserException in project Digital by hneemann.

the class SignExtend method calcValue.

@Override
public long calcValue(Context c, ArrayList<Expression> args) throws ParserException {
    int bits = (int) args.get(0).value(c);
    if (bits < 0 || bits > 63)
        throw new ParserException(Lang.get("err_invalidValue_N0_inFunction_N1", bits, "signExt"));
    long value = args.get(1).value(c);
    long mask = (1L << bits) - 1;
    long signBit = (1L << (bits - 1));
    if ((value & signBit) != 0) {
        return value & mask | (~mask);
    } else {
        return value & mask;
    }
}
Also used : ParserException(de.neemann.digital.testing.parser.ParserException)

Aggregations

ParserException (de.neemann.digital.testing.parser.ParserException)5 IOException (java.io.IOException)2 Model (de.neemann.digital.core.Model)1 NodeException (de.neemann.digital.core.NodeException)1 ObservableValue (de.neemann.digital.core.ObservableValue)1 Signal (de.neemann.digital.core.Signal)1 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)1 Clock (de.neemann.digital.core.wiring.Clock)1 Value (de.neemann.digital.data.Value)1 ValueTable (de.neemann.digital.data.ValueTable)1 HDLException (de.neemann.digital.hdl.model2.HDLException)1 CodePrinter (de.neemann.digital.hdl.printer.CodePrinter)1 Lang (de.neemann.digital.lang.Lang)1 TestingDataException (de.neemann.digital.testing.TestingDataException)1 Context (de.neemann.digital.testing.parser.Context)1 LineCollector (de.neemann.digital.testing.parser.LineCollector)1 LineEmitter (de.neemann.digital.testing.parser.LineEmitter)1 Parser (de.neemann.digital.testing.parser.Parser)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1