use of de.neemann.digital.testing.TestCaseDescription in project Digital by hneemann.
the class TestExamples method check.
/**
* Loads the model and initializes and test it if test cases are present
*
* @param dig the model file
*/
public static void check(File dig) throws Exception {
boolean shouldFail = dig.getName().endsWith("Error.dig");
ToBreakRunner br;
try {
br = new ToBreakRunner(dig);
} catch (Exception e) {
if (shouldFail) {
return;
} else
throw e;
}
try {
boolean isLib = dig.getPath().replace('\\', '/').contains("/lib/");
assertTrue("wrong locked mode", isLib == br.getCircuit().getAttributes().get(Keys.LOCKED_MODE));
try {
for (VisualElement el : br.getCircuit().getElements()) if (el.equalsDescription(TestCaseElement.TESTCASEDESCRIPTION)) {
String label = el.getElementAttributes().getCleanLabel();
TestCaseDescription td = el.getElementAttributes().get(TestCaseElement.TESTDATA);
Model model = new ModelCreator(br.getCircuit(), br.getLibrary()).createModel(false);
try {
TestExecutor tr = new TestExecutor(td).create(model);
if (label.contains("Failing"))
assertFalse(dig.getName() + ":" + label, tr.allPassed());
else
assertTrue(dig.getName() + ":" + label, tr.allPassed());
testCasesInFiles++;
} finally {
model.close();
}
}
} catch (Exception e) {
if (shouldFail) {
return;
} else
throw e;
}
assertFalse("File should fail but doesn't!", shouldFail);
} finally {
br.close();
}
}
use of de.neemann.digital.testing.TestCaseDescription 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;");
}
use of de.neemann.digital.testing.TestCaseDescription in project Digital by hneemann.
the class JarComponentManagerTest method testJarAvailable.
public void testJarAvailable() throws PinException, NodeException, IOException, ElementNotFoundException, TestingDataException {
ToBreakRunner br = new ToBreakRunner("dig/jarLib/jarLibTest.dig") {
@Override
public void initLibrary(ElementLibrary library) {
library.addExternalJarComponents(new File(Resources.getRoot(), "dig/jarLib/pluginExample-1.0-SNAPSHOT.jar"));
assertNull(library.checkForException());
}
};
for (VisualElement ve : br.getCircuit().getElements()) {
if (ve.equalsDescription(TestCaseElement.TESTCASEDESCRIPTION)) {
TestCaseDescription td = ve.getElementAttributes().get(TestCaseElement.TESTDATA);
TestExecutor tr = new TestExecutor(td).create(br.getModel());
assertTrue(tr.allPassed());
}
}
}
Aggregations