Search in sources :

Example 1 with Context

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

the class VHDLTestBenchCreator method writeTestBench.

private void writeTestBench(CodePrinter out, String testName, ElementAttributes tc) throws IOException, TestingDataException, ParserException {
    out.print("--  A testbench for ").println(testName);
    out.println("LIBRARY ieee;");
    out.println("USE ieee.std_logic_1164.all;");
    out.println("USE ieee.numeric_std.all;");
    out.println();
    out.print("entity ").print(testName).println(" is");
    out.print("end ").print(testName).println(";");
    out.println();
    out.print("architecture behav of ").print(testName).println(" is").inc();
    out.println("component main").inc();
    VHDLCreator.writePorts(out, main);
    out.dec().println("end component;");
    out.println();
    for (HDLPort p : main.getInputs()) out.print("signal ").print(p.getName()).print(" : ").print(VHDLCreator.getType(p.getBits())).println(";");
    for (HDLPort p : main.getOutputs()) out.print("signal ").print(p.getName()).print(" : ").print(VHDLCreator.getType(p.getBits())).println(";");
    out.dec().println("begin").inc();
    out.println("main_0 : main port map (").inc();
    Separator comma = new Separator(out, ",\n");
    for (HDLPort p : main.getInputs()) {
        comma.check();
        out.print(p.getName() + " => " + p.getName());
    }
    for (HDLPort p : main.getOutputs()) {
        comma.check();
        out.print(p.getName() + " => " + p.getName());
    }
    out.println(" );").dec();
    out.println("process").inc();
    TestCaseDescription testdata = tc.get(TESTDATA);
    ArrayList<HDLPort> dataOrder = new ArrayList<>();
    out.println("type pattern_type is record").inc();
    for (String name : testdata.getNames()) {
        String saveName = renaming.checkName(name);
        boolean found = false;
        for (HDLPort p : main.getPorts()) {
            if (p.getName().equals(saveName)) {
                out.print(p.getName()).print(" : ").print(VHDLCreator.getType(p.getBits())).println(";");
                dataOrder.add(p);
                found = true;
                break;
            }
        }
        if (!found)
            throw new TestingDataException(Lang.get("err_testSignal_N_notFound", name));
    }
    out.dec().println("end record;");
    out.println("type pattern_array is array (natural range <>) of pattern_type;");
    out.println("constant patterns : pattern_array := (").inc();
    LineListener parent = new LineListenerVHDL(out, dataOrder);
    testdata.getLines().emitLines(parent, new Context());
    out.println(");").dec();
    String loopVar = "i";
    int lv = 0;
    while (loopVarExists(loopVar, main.getPorts())) loopVar = "i" + (lv++);
    out.dec().println("begin").inc();
    out.print("for ").print(loopVar).println(" in patterns'range loop").inc();
    for (HDLPort p : main.getInputs()) out.print(p.getName()).print(" <= patterns(").print(loopVar).print(").").print(p.getName()).println(";");
    out.println("wait for 10 ns;");
    for (HDLPort p : main.getOutputs()) {
        out.print("assert std_match(").print(p.getName()).print(", patterns(").print(loopVar).print(").").print(p.getName()).print(")");
        out.print(" OR (").print(p.getName()).print(" = ").print(getSimpleValue(p.getBits(), 'Z')).print(" AND patterns(").print(loopVar).print(").").print(p.getName()).print(" = ").print(getSimpleValue(p.getBits(), 'Z')).print(")").eol();
        out.inc().print("report \"wrong value for ").print(p.getName()).print(" ").print(loopVar).print("=\" & integer'image(").print(loopVar).println(") severity error;").dec();
    }
    out.dec().println("end loop;");
    out.println("wait;");
    out.dec().println("end process;");
    out.dec().println("end behav;");
}
Also used : Context(de.neemann.digital.testing.parser.Context) TestingDataException(de.neemann.digital.testing.TestingDataException) LineListener(de.neemann.digital.testing.parser.LineListener) ArrayList(java.util.ArrayList) HDLPort(de.neemann.digital.hdl.model2.HDLPort) TestCaseDescription(de.neemann.digital.testing.TestCaseDescription)

Example 2 with Context

use of de.neemann.digital.testing.parser.Context 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)

Aggregations

Context (de.neemann.digital.testing.parser.Context)2 ArrayList (java.util.ArrayList)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 Clock (de.neemann.digital.core.wiring.Clock)1 Value (de.neemann.digital.data.Value)1 ValueTable (de.neemann.digital.data.ValueTable)1 HDLPort (de.neemann.digital.hdl.model2.HDLPort)1 Lang (de.neemann.digital.lang.Lang)1 TestCaseDescription (de.neemann.digital.testing.TestCaseDescription)1 TestingDataException (de.neemann.digital.testing.TestingDataException)1 LineEmitter (de.neemann.digital.testing.parser.LineEmitter)1 LineListener (de.neemann.digital.testing.parser.LineListener)1 ParserException (de.neemann.digital.testing.parser.ParserException)1 HashSet (java.util.HashSet)1