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;
}
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);
}
}
}
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());
}
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;
}
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;
}
}
Aggregations