allows to use measurement values as signals in a test case

This commit is contained in:
hneemann 2020-11-28 20:23:23 +01:00
parent 88ac232545
commit 6711cfe4da
11 changed files with 48 additions and 10 deletions

View File

@ -66,6 +66,7 @@ public class Model implements Iterable<Node>, SyncAccess {
private final ArrayList<Signal> signals; private final ArrayList<Signal> signals;
private final ArrayList<Signal> inputs; private final ArrayList<Signal> inputs;
private final ArrayList<Signal> outputs; private final ArrayList<Signal> outputs;
private final ArrayList<Signal> testOutputs;
private final ArrayList<Node> nodes; private final ArrayList<Node> nodes;
private ArrayList<Node> nodesToUpdateAct; private ArrayList<Node> nodesToUpdateAct;
@ -92,6 +93,7 @@ public class Model implements Iterable<Node>, SyncAccess {
this.buttonsToMap = new HashMap<>(); this.buttonsToMap = new HashMap<>();
this.signals = new ArrayList<>(); this.signals = new ArrayList<>();
this.outputs = new ArrayList<>(); this.outputs = new ArrayList<>();
this.testOutputs = new ArrayList<>();
this.inputs = new ArrayList<>(); this.inputs = new ArrayList<>();
this.nodes = new ArrayList<>(); this.nodes = new ArrayList<>();
this.nodesToUpdateAct = new ArrayList<>(); this.nodesToUpdateAct = new ArrayList<>();
@ -586,8 +588,13 @@ public class Model implements Iterable<Node>, SyncAccess {
* @param signal the signal * @param signal the signal
*/ */
public void addSignal(Signal signal) { public void addSignal(Signal signal) {
if (signal.isValid()) if (signal.isValid()) {
if (signals.contains(signal))
invalidSignal = signal;
signals.add(signal); signals.add(signal);
if (signal.isTestOutput())
testOutputs.add(signal);
}
} }
/** /**
@ -623,6 +630,7 @@ public class Model implements Iterable<Node>, SyncAccess {
invalidSignal = signal; invalidSignal = signal;
signals.add(signal); signals.add(signal);
outputs.add(signal); outputs.add(signal);
testOutputs.add(signal);
} else } else
invalidSignal = signal; invalidSignal = signal;
} }
@ -649,6 +657,13 @@ public class Model implements Iterable<Node>, SyncAccess {
return outputs; return outputs;
} }
/**
* @return the models outputs
*/
public ArrayList<Signal> getTestOutputs() {
return testOutputs;
}
/** /**
* @return all registered signals * @return all registered signals
*/ */

View File

@ -16,6 +16,7 @@ public final class Signal implements Comparable<Signal> {
private String pinNumber; private String pinNumber;
private ObservableValue bidirectionalReader; private ObservableValue bidirectionalReader;
private boolean showInGraph; private boolean showInGraph;
private boolean testOutput;
/** /**
* Creates a new Instance * Creates a new Instance
@ -60,6 +61,23 @@ public final class Signal implements Comparable<Signal> {
return showInGraph; return showInGraph;
} }
/**
* Makes this signal to a test output signal
*
* @return this for chained calls
*/
public Signal setTestOutput() {
testOutput = true;
return this;
}
/**
* @return true if this signal is a test output
*/
public boolean isTestOutput() {
return testOutput;
}
/** /**
* @return the name * @return the name
*/ */

View File

@ -86,7 +86,7 @@ abstract class FlipflopBit extends Node implements Element {
out = v != 0; out = v != 0;
q.setBool(out); q.setBool(out);
qn.setBool(!out); qn.setBool(!out);
})); }).setTestOutput());
} }
void setOut(boolean out) { void setOut(boolean out) {

View File

@ -120,7 +120,7 @@ public class FlipflopD extends Node implements Element, Countable {
value = v; value = v;
q.setValue(value); q.setValue(value);
qn.setValue(~value); qn.setValue(~value);
})); }).setTestOutput());
} }
/** /**

View File

@ -56,7 +56,7 @@ public class Probe implements Element {
@Override @Override
public void registerNodes(Model model) { public void registerNodes(Model model) {
model.addOutput(new Signal(label, value).setShowInGraph(showInGraph).setFormat(format)); model.addSignal(new Signal(label, value).setShowInGraph(showInGraph).setFormat(format).setTestOutput());
model.registerGlobalValue(label, value); model.registerGlobalValue(label, value);
} }

View File

@ -105,7 +105,7 @@ public class Counter extends Node implements Element, ProgramCounter {
boolean o = (counter == maxValue) && enable.getBool(); boolean o = (counter == maxValue) && enable.getBool();
out.setValue(counter); out.setValue(counter);
ovf.setBool(o); ovf.setBool(o);
})); }).setTestOutput());
} }
@Override @Override

View File

@ -146,7 +146,7 @@ public class CounterPreset extends Node implements Element, ProgramCounter {
boolean o = getOvfValue(counter, dir.getBool(), enable.getBool()); boolean o = getOvfValue(counter, dir.getBool(), enable.getBool());
out.setValue(counter); out.setValue(counter);
ovf.setBool(o); ovf.setBool(o);
})); }).setTestOutput());
} }
@Override @Override

View File

@ -90,7 +90,7 @@ public class Register extends Node implements Element, Countable, ProgramCounter
model.addSignal(new Signal(label, q, (v, z) -> { model.addSignal(new Signal(label, q, (v, z) -> {
value = v; value = v;
q.setValue(value); q.setValue(value);
})); }).setTestOutput());
} }
@Override @Override

View File

@ -119,7 +119,7 @@ public class TestExecutor {
} }
} }
for (Signal s : model.getOutputs()) { for (Signal s : model.getTestOutputs()) {
final int index = getIndexOf(s.getName()); final int index = getIndexOf(s.getName());
if (index >= 0) { if (index >= 0) {
outputs.add(new TestSignal(index, s.getValue())); outputs.add(new TestSignal(index, s.getValue()));

View File

@ -49,7 +49,7 @@ public class Context {
if (model != null) { if (model != null) {
// inputs are not supported because there are cases where values // inputs are not supported because there are cases where values
// are evaluated and model inputs are not set! // are evaluated and model inputs are not set!
for (Signal s : model.getOutputs()) for (Signal s : model.getTestOutputs())
if (s.getName().equals(name)) if (s.getName().equals(name))
return s.getValue().getValue(); return s.getValue().getValue();
} }

View File

@ -115,10 +115,15 @@ public class Parser {
expect(Tokenizer.Token.IDENT); expect(Tokenizer.Token.IDENT);
final String sName = tok.getIdent(); final String sName = tok.getIdent();
expect(Tokenizer.Token.EQUAL); expect(Tokenizer.Token.EQUAL);
int sign = 1;
if (tok.peek() == Tokenizer.Token.SUB) {
tok.consume();
sign = -1;
}
expect(Tokenizer.Token.NUMBER); expect(Tokenizer.Token.NUMBER);
long n = convToLong(tok.getIdent()); long n = convToLong(tok.getIdent());
expect(Tokenizer.Token.SEMICOLON); expect(Tokenizer.Token.SEMICOLON);
signalInitMap.put(sName, n); signalInitMap.put(sName, sign * n);
break; break;
case PROGRAM: case PROGRAM:
tok.consume(); tok.consume();