use of edu.umn.cs.crisys.safety.analysis.transform.Fault in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method renameEqId.
/**
* Renames eq var id to match lustre name. Ex: eq some_var : bool;
* Sender_fault_1_some_var : bool;
*
* @param f Fault with safety eq var stmts.
* @param idMap Map<String, String> from user defined var to lustre name.
* @return Returns fault with var renamed.
*/
public Fault renameEqId(Fault f, Map<String, String> idMap) {
Fault newFault = new Fault(f);
newFault.safetyEqVars.clear();
newFault.safetyEqAsserts.clear();
newFault.faultOutputMap.clear();
newFault.faultInputMap.clear();
if (!f.triggers.isEmpty()) {
throw new SafetyException("User-defined triggers are currently unsupported.");
}
// update the variable declarations
for (AgreeVar eq : f.safetyEqVars) {
if (idMap.containsKey(eq.id)) {
eq = new AgreeVar(idMap.get(eq.id), eq.type, eq.reference);
}
newFault.safetyEqVars.add(eq);
}
ReplaceIdVisitor visitor = new ReplaceIdVisitor(idMap);
for (AgreeStatement s : f.safetyEqAsserts) {
newFault.safetyEqAsserts.add(visitor.visit(s));
}
for (Map.Entry<Expr, String> element : f.faultOutputMap.entrySet()) {
newFault.faultOutputMap.put(element.getKey().accept(visitor), element.getValue());
}
for (Map.Entry<String, Expr> element : f.faultInputMap.entrySet()) {
newFault.faultInputMap.put(element.getKey(), element.getValue().accept(visitor));
}
return newFault;
}
use of edu.umn.cs.crisys.safety.analysis.transform.Fault in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method renameFaultEqs.
/**
* Renames safety eq stmts to lustre names. Uses renameEqId as helper method.
*
* @param faults List of faults on this node that need eq stmts renamed.
* @return List of faults with eq stmts renamed.
*/
public List<Fault> renameFaultEqs(List<Fault> faults) {
List<Fault> newFaults = new ArrayList<>();
for (Fault f : faults) {
Map<String, String> idMap = constructEqIdMap(f, f.safetyEqVars);
newFaults.add(this.renameEqId(f, idMap));
}
return newFaults;
}
use of edu.umn.cs.crisys.safety.analysis.transform.Fault in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method getFaultCountExprList.
/**
* Get the list of faults that will contribute to the count.
*
* @param currentNode This agree node.
* @param sumExprs Expressions to be summed.
*/
public void getFaultCountExprList(AgreeNode currentNode, List<Expr> sumExprs) {
List<Fault> faults = this.faultMap.get(currentNode.compInst);
for (Fault f : faults) {
// only add independently active fault to sumExprs
String base = addPathDelimiters(f.path, f.id);
sumExprs.add(createSumExpr(new IdExpr(this.createFaultIndependentActiveId(base))));
}
for (HWFault hwf : this.hwfaultMap.get(currentNode.compInst)) {
String base = addPathDelimiters(hwf.path, hwf.id);
sumExprs.add(createSumExpr(new IdExpr(this.createFaultIndependentActiveId(base))));
}
for (AgreeNode n : currentNode.subNodes) {
// List<String> ext = new ArrayList<>(path);
// ext.add(n.id);
getFaultCountExprList(n, sumExprs);
}
}
use of edu.umn.cs.crisys.safety.analysis.transform.Fault in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method addAsymCountConstraints.
/**
* Method adds the local variable for the count of asymmetric faults.
* Constraints for this count are added in assertions. Ex:
* __fault__Sender__fault_1_count : int; (as local in main)
*
* assert (__fault__Sender__fault_1_count = ((if
* asym_node_0__fault__trigger__Sender__fault_1 then 1 else 0)
*
* assert (__fault__Sender__fault_1_count <= 3); (where 3 is total no. of
* connections)
*
* @param nb NodeBuilder that will have this information added.
*/
private void addAsymCountConstraints(AgreeNodeBuilder nb) {
// Make local map saving said count with its fault.
for (Fault f : mapAsymFaultToCommNodes.keySet()) {
String id = "__fault__" + f.id + "_count";
AgreeVar count = new AgreeVar(id, NamedType.INT, topNode.reference);
nb.addInput(count);
// Get nodes to build assert stmts
List<String> nodes = mapAsymFaultToCommNodes.get(f);
List<Expr> sumExprs = new ArrayList<>();
for (String n : nodes) {
sumExprs.add(createSumExpr(new IdExpr(n + "__fault__trigger__" + f.id)));
}
// Add the constraints associated with the count.
Expr faultCountExpr = buildFaultCountExpr(sumExprs, 0);
Expr equate = new BinaryExpr(new IdExpr(id), BinaryOp.EQUAL, faultCountExpr);
nb.addAssertion(new AgreeStatement("", equate, topNode.reference));
// Restrict to less than the total number of connections
Expr restrict = new BinaryExpr(new IdExpr(id), BinaryOp.LESSEQUAL, new IntExpr(nodes.size()));
nb.addAssertion(new AgreeStatement("", restrict, topNode.reference));
}
}
use of edu.umn.cs.crisys.safety.analysis.transform.Fault in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method getFaultProbExprList.
/**
* Get probabilities of all faults.
*
* @param currentNode Agree node we are visiting currently
* @param path path to this agree node
* @param probabilities prob list
*/
public void getFaultProbExprList(AgreeNode currentNode, List<String> path, List<FaultProbability> probabilities) {
List<Fault> faults = this.faultMap.get(currentNode.compInst);
for (Fault f : faults) {
String base = addPathDelimiters(path, f.id);
probabilities.add(new FaultProbability(this.createFaultIndependentActiveId(base), f.probability, f));
}
for (AgreeNode n : currentNode.subNodes) {
List<String> ext = new ArrayList<>(path);
ext.add(n.id);
getFaultProbExprList(n, ext, probabilities);
}
}
Aggregations