Search in sources :

Example 6 with Fault

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;
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) RecordAccessExpr(jkind.lustre.RecordAccessExpr) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) IdExpr(jkind.lustre.IdExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) HWFault(edu.umn.cs.crisys.safety.analysis.transform.HWFault) BaseFault(edu.umn.cs.crisys.safety.analysis.transform.BaseFault) Fault(edu.umn.cs.crisys.safety.analysis.transform.Fault) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException) Map(java.util.Map) HashMap(java.util.HashMap) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 7 with Fault

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;
}
Also used : ArrayList(java.util.ArrayList) HWFault(edu.umn.cs.crisys.safety.analysis.transform.HWFault) BaseFault(edu.umn.cs.crisys.safety.analysis.transform.BaseFault) Fault(edu.umn.cs.crisys.safety.analysis.transform.Fault)

Example 8 with Fault

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);
    }
}
Also used : AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) IdExpr(jkind.lustre.IdExpr) HWFault(edu.umn.cs.crisys.safety.analysis.transform.HWFault) BaseFault(edu.umn.cs.crisys.safety.analysis.transform.BaseFault) Fault(edu.umn.cs.crisys.safety.analysis.transform.Fault) HWFault(edu.umn.cs.crisys.safety.analysis.transform.HWFault)

Example 9 with Fault

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));
    }
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) RecordAccessExpr(jkind.lustre.RecordAccessExpr) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) IdExpr(jkind.lustre.IdExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList) HWFault(edu.umn.cs.crisys.safety.analysis.transform.HWFault) BaseFault(edu.umn.cs.crisys.safety.analysis.transform.BaseFault) Fault(edu.umn.cs.crisys.safety.analysis.transform.Fault) IntExpr(jkind.lustre.IntExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 10 with Fault

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);
    }
}
Also used : AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) ArrayList(java.util.ArrayList) HWFault(edu.umn.cs.crisys.safety.analysis.transform.HWFault) BaseFault(edu.umn.cs.crisys.safety.analysis.transform.BaseFault) Fault(edu.umn.cs.crisys.safety.analysis.transform.Fault)

Aggregations

BaseFault (edu.umn.cs.crisys.safety.analysis.transform.BaseFault)14 Fault (edu.umn.cs.crisys.safety.analysis.transform.Fault)14 HWFault (edu.umn.cs.crisys.safety.analysis.transform.HWFault)14 ArrayList (java.util.ArrayList)10 IdExpr (jkind.lustre.IdExpr)6 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)4 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)4 HashMap (java.util.HashMap)4 List (java.util.List)4 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)4 BinaryExpr (jkind.lustre.BinaryExpr)4 BoolExpr (jkind.lustre.BoolExpr)4 Expr (jkind.lustre.Expr)4 IfThenElseExpr (jkind.lustre.IfThenElseExpr)4 IntExpr (jkind.lustre.IntExpr)4 NodeCallExpr (jkind.lustre.NodeCallExpr)4 RecordAccessExpr (jkind.lustre.RecordAccessExpr)4 UnaryExpr (jkind.lustre.UnaryExpr)4 EList (org.eclipse.emf.common.util.EList)4 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)3