use of edu.umn.cs.crisys.safety.analysis.transform.Fault in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method gatherFaults.
/**
* Method gathers fault statements within this agree node and begins processing.
* Creates FaultASTBuilder object, creates faults for each fault stmt, populates
* asym maps, separates asym/sym faults for separate processing, and returns
* processed faults.
*
* @param globalLustreNodes List of Nodes
* @param node This agree node
* @param isTop flag to determine if this is the top node of the
* program.
* @return list of faults associated with the fault stmts in this node.
*/
public List<Fault> gatherFaults(List<Node> globalLustreNodes, AgreeNode node, boolean isTop) {
List<SpecStatement> specs = SafetyUtil.collapseAnnexes(SafetyUtil.getSafetyAnnexes(node, isTop));
List<Fault> faults = new ArrayList<>();
// reset fault count for the new Agree Node
FaultASTBuilder.resetFaultCounter();
// Before looping through spec statements, separate out the asymmetric multiple
// faults on a single output with the sym/asym single faults on a single output.
// 1. Collect all fault statements and put into list.
// Do not collect any that are disabled.
// 2. Separate out multiple asym faults on one output and single faults on one
// output.
// 3. Perform necessary processing on each of these lists.
List<FaultStatement> allFaultStmts = new ArrayList<FaultStatement>();
for (SpecStatement s : specs) {
if (s instanceof FaultStatement) {
if (!isDisabled((FaultStatement) s)) {
allFaultStmts.add((FaultStatement) s);
}
}
}
List<FaultStatement> remainderFS = new ArrayList<FaultStatement>();
Map<String, List<FaultStatement>> multipleAsymFS = new HashMap<String, List<FaultStatement>>();
separateFaultStmts(allFaultStmts, remainderFS, multipleAsymFS);
// processes these stmts, creates faults, and creates associated comm nodes.
for (String output : multipleAsymFS.keySet()) {
if (multipleAsymFS.get(output).size() == 1) {
continue;
}
AsymFaultASTBuilder asymBuilder = new AsymFaultASTBuilder(globalLustreNodes, node);
List<Fault> safetyFaults = asymBuilder.processFaults(multipleAsymFS.get(output));
mapAsymCompOutputToCommNodeIn = asymBuilder.getMapAsymCompOutputToCommNodeIn();
mapCommNodeToInputs = asymBuilder.getMapCommNodeToInputs();
mapCommNodeOutputToConnections = asymBuilder.getMapCommNodeOutputToConnections();
mapSenderToReceiver = asymBuilder.getMapSenderToReceiver();
mapCompNameToCommNodes = asymBuilder.getMapCompNameToCommNodes();
// Create local mapAsymFaultToCompName
if (node.compInst instanceof ComponentInstance) {
ComponentInstance comp = node.compInst;
String name = comp.getName();
for (Fault safetyFault : safetyFaults) {
mapAsymFaultToCompName.put(safetyFault, name);
// Create mapping from fault to associated commNodes.
// Use mapping from fault to comp name, then map from comp name to
// comm nodes.
mapAsymFaultToCommNodes.put(safetyFault, mapCompNameToCommNodes.get(name));
}
}
faults.addAll(safetyFaults);
}
// Now process all the rest of the fault stmts.
for (SpecStatement s : remainderFS) {
if (s instanceof FaultStatement) {
FaultStatement fs = (FaultStatement) s;
FaultASTBuilder builder = new FaultASTBuilder(globalLustreNodes, node);
// Process fault determines if we have a
// symmetric or asymmetric fault and builds it accordingly.
Fault safetyFault = builder.processFault(fs);
// to main lustre node.
if (isAsymmetric(fs)) {
mapAsymCompOutputToCommNodeIn = builder.getMapAsymCompOutputToCommNodeIn();
mapCommNodeToInputs = builder.getMapCommNodeToInputs();
mapCommNodeOutputToConnections = builder.getMapCommNodeOutputToConnections();
mapSenderToReceiver = builder.getMapSenderToReceiver();
mapCompNameToCommNodes = builder.getMapCompNameToCommNodes();
// Create local mapAsymFaultToCompName
if (node.compInst instanceof ComponentInstance) {
ComponentInstance comp = node.compInst;
String name = comp.getName();
mapAsymFaultToCompName.put(safetyFault, name);
// Create mapping from fault to associated commNodes.
// Use mapping from fault to comp name, then map from comp name to
// comm nodes.
mapAsymFaultToCommNodes.put(safetyFault, mapCompNameToCommNodes.get(name));
}
}
faults.add(safetyFault);
}
}
return faults;
}
use of edu.umn.cs.crisys.safety.analysis.transform.Fault in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method visit.
// ////////////////////////////////////////////////////////////////
//
// AGREE NODE TRAVERSAL STARTS HERE.
//
// /////////////////////////////////////////////////////////////////
@Override
public AgreeNode visit(AgreeNode node) {
Map<String, List<Pair>> parentFaultyVarsExpr = faultyVarsExpr;
boolean isTop = (node == this.topNode);
// Gather non-hardware (dependent) faults
List<Fault> faults = gatherFaults(globalLustreNodes, node, isTop);
// Gather HW faults
List<HWFault> hwFaults = gatherHWFaults(globalLustreNodes, node, isTop);
// Rename var names in faults: fault_varName
faults = renameFaultEqs(faults);
if (faultMap.containsKey(node.compInst) || hwfaultMap.containsKey(node.compInst)) {
throw new SafetyException("Node: " + node.id + " has been visited twice.");
}
faultMap.put(node.compInst, faults);
hwfaultMap.put(node.compInst, hwFaults);
faultyVarsExpr = gatherFaultyOutputs(faults, node);
// this will traverse through the child nodes
node = super.visit(node);
AgreeNodeBuilder nb = new AgreeNodeBuilder(node);
// Change this nodes flag to reflect fault tree generation or not.
if (AddFaultsToAgree.getIsGenMCS()) {
nb.setFaultTreeFlag(true);
}
// If asymmetric, only add fault triggers to agree node.
for (Fault f : faults) {
if ((f.propType == null) || (f.propType.getPty() instanceof symmetric)) {
addFaultInputs(f, nb);
addFaultLocalEqsAndAsserts(f, nb);
} else {
addFaultInputs(f, nb);
}
}
addHWFaultInputs(hwFaults, nb);
addToMutualExclusionList();
addNominalVars(node, nb);
addFaultNodeEqs(faults, nb);
if (isTop) {
topNodeVisit(nb, node);
}
node = nb.build();
faultyVarsExpr = parentFaultyVarsExpr;
// for asymmetric faults.
if (!this.mapSenderToReceiver.isEmpty() && isTop) {
SafetyNodeBuilder sb = changeTopNodeAsymConnections(nb, node);
return sb.build();
} else {
return node;
}
}
use of edu.umn.cs.crisys.safety.analysis.transform.Fault in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method getSrcFaultExprList.
/**
* Method collect the list of expressions for the source faults in the
* propagations whose target fault is the current fault.
*
* @param f Fault in question (base fault)
* @param faultExprs List of all fault expressions.
*/
public void getSrcFaultExprList(BaseFault f, List<Expr> faultExprs) {
for (SafetyPropagation propagation : propagations) {
if (propagation.destFault.equals(f)) {
if (propagation.srcFault instanceof HWFault) {
// use the triggering event for HW fault in the src fault expr, so to get the
// effect
// from both hw dependent and hw independent faults
String interfaceVarId = addPathDelimiters(((HWFault) propagation.srcFault).path, this.createFaultNodeTriggerId(((HWFault) propagation.srcFault).id));
faultExprs.add(new IdExpr(interfaceVarId));
} else if (propagation.srcFault instanceof Fault) {
String base = addPathDelimiters(((Fault) propagation.srcFault).path, ((Fault) propagation.srcFault).id);
faultExprs.add(new IdExpr(this.createFaultIndependentActiveId(base)));
}
}
}
}
use of edu.umn.cs.crisys.safety.analysis.transform.Fault in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method addNominalVars.
/**
* Creates fault nominal input to the lustre node. Only add this if there is at
* least one symmetric fault defined for this node. If only asymmetric, then
* fault nominal does not exist in the agree node, only in comm nodes.
*
* @param node Agree node with these faults.
* @param nb NodeBuilder will have nominal vars added to locals.
*/
public void addNominalVars(AgreeNode node, AgreeNodeBuilder nb) {
List<String> inputIdList = new ArrayList<String>();
for (Map.Entry<String, List<Pair>> faultyVarsExprEntry : faultyVarsExpr.entrySet()) {
// get the specific output
String outputId = faultyVarsExprEntry.getKey();
List<Pair> faultPairs = faultyVarsExprEntry.getValue();
boolean onlyAsym = true;
Fault f = null;
// for list of fault pairs associated with the specific output
for (Pair p : faultPairs) {
if (!isAsymmetric(p.f)) {
onlyAsym = false;
}
f = p.f;
// if the current fault is not asymmetric, add the nominal output id to the node input list
if (!onlyAsym) {
AgreeVar out = findVar(node.outputs, (outputId));
if (out == null) {
new SafetyException("A fault defined for " + node.id + " has a connection" + " that is not a valid output for this component." + " Valid connections include {" + node.outputs + "}");
} else {
// we only add to the input list once for the nominal var for each output
if (!inputIdList.contains(outputId)) {
nb.addInput(new AgreeVar(createNominalId((outputId)), out.type, out.reference));
inputIdList.add(outputId);
}
}
}
}
}
}
Aggregations