Search in sources :

Example 31 with AgreeVar

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AMASE by loonwerks.

the class AddFaultsToNodeVisitor method changeTopNodeAsymConnections.

/**
 * Method changes top level connections to reflect communication nodes for
 * asymmetric faults. Finds old connections from sender to receiver and removes
 * them. Then adds new connections from sender to communication nodes and from
 * communication nodes to receivers.
 *
 * @param nb   NodeBuilder for this top node.
 * @param node The top node of the program.
 * @return SafetyNodeBuilder with connections changed.
 */
private SafetyNodeBuilder changeTopNodeAsymConnections(AgreeNodeBuilder nb, AgreeNode node) {
    SafetyNodeBuilder sb = new SafetyNodeBuilder(node);
    List<AgreeConnection> agreeConns = new ArrayList<AgreeConnection>();
    int i = 0;
    // Make sure we have AgreeAADLConnection and cast to access AgreeVar
    for (AgreeConnection ac : sb.getConnections()) {
        if (ac instanceof AgreeAADLConnection) {
            AgreeAADLConnection aac = (AgreeAADLConnection) ac;
            AgreeVar sourceName = aac.sourceVarName;
            AgreeVar destName = aac.destinationVarName;
            // cannot perform this removal of connections.
            if ((sourceName.compInst == null) || (destName.compInst == null)) {
                continue;
            }
            String senderName = sourceName.compInst.getName() + "." + sourceName.id;
            String receiverName = destName.compInst.getName() + "." + destName.id;
            // remove that element from agreeConns.
            for (String sendKey : mapSenderToReceiver.keySet()) {
                if (senderName.contentEquals(sendKey)) {
                    for (String receiveVal : mapSenderToReceiver.get(sendKey)) {
                        if (receiverName.equals(receiveVal)) {
                            agreeConns.add(ac);
                            break;
                        }
                    }
                }
            }
        }
        i++;
    }
    List<AgreeConnection> connList = sb.getConnections();
    for (AgreeConnection j : agreeConns) {
        connList.remove(j);
    }
    FaultASTBuilder.resetAsymMaps();
    return sb;
}
Also used : AgreeAADLConnection(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection) SafetyNodeBuilder(edu.umn.cs.crisys.safety.analysis.ast.SafetyNodeBuilder) AgreeConnection(com.rockwellcollins.atc.agree.analysis.ast.AgreeConnection) ArrayList(java.util.ArrayList) TransientConstraint(edu.umn.cs.crisys.safety.safety.TransientConstraint) PermanentConstraint(edu.umn.cs.crisys.safety.safety.PermanentConstraint) TemporalConstraint(edu.umn.cs.crisys.safety.safety.TemporalConstraint) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 32 with AgreeVar

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AMASE by loonwerks.

the class AddFaultsToNodeVisitor method addAsymNodeCalls.

/**
 * Method adds the asym communication node calls into main node in lustre.
 *
 * @param nb NodeBuilder has these node calls added.
 */
private void addAsymNodeCalls(AgreeNodeBuilder nb) {
    // For each key in map, get name of node and list of lustre inputs.
    List<Expr> tempIds = new ArrayList<>();
    for (String nodeName : mapCommNodeToInputs.keySet()) {
        for (AgreeVar av : mapCommNodeToInputs.get(nodeName)) {
            IdExpr id = new IdExpr(av.id);
            tempIds.add(id);
        }
        // Create node call expression
        NodeCallExpr nodeCall = new NodeCallExpr(nodeName, tempIds);
        nb.addAssertion(new AgreeStatement("", nodeCall, this.topNode.reference));
        tempIds.clear();
    }
}
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) NodeCallExpr(jkind.lustre.NodeCallExpr) ArrayList(java.util.ArrayList) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 33 with AgreeVar

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar in project AMASE by loonwerks.

the class AddFaultsToNodeVisitor method addTopLevelMaxFaultOccurrenceConstraint.

/**
 * Method adds count constraints to top level assertions.
 *
 * @param maxFaults No. of faults allowed in count.
 * @param topNode   This node (main)
 * @param builder   node builder will have constraints added.
 */
public void addTopLevelMaxFaultOccurrenceConstraint(int maxFaults, AgreeNode topNode, AgreeNodeBuilder builder) {
    // add a global fault count
    String id = "__fault__global_count";
    builder.addInput(new AgreeVar(id, NamedType.INT, topNode.reference));
    // assign it.
    List<Expr> sumExprs = new ArrayList<>();
    // getFaultCountExprList(topNode, new ArrayList<>(), sumExprs);
    getFaultCountExprList(topNode, sumExprs);
    Expr faultCountExpr = buildFaultCountExpr(sumExprs, 0);
    Expr equate = new BinaryExpr(new IdExpr(id), BinaryOp.EQUAL, faultCountExpr);
    builder.addAssertion(new AgreeStatement("", equate, topNode.reference));
    // add assertions that the mutually exclusive fault activations
    for (FaultPair curPair : mutualExclusiveFaults) {
        // assert that the pair cannot both be true
        // get fault triggers
        String ft1Trigger = this.getMainNodeFaultIndepStr(curPair.ft1);
        String ft2Trigger = this.getMainNodeFaultIndepStr(curPair.ft2);
        Expr ft1False = new UnaryExpr(UnaryOp.NOT, new IdExpr(ft1Trigger));
        Expr ft2False = new UnaryExpr(UnaryOp.NOT, new IdExpr(ft2Trigger));
        Expr ft1FalseOrft2False = new BinaryExpr(ft1False, BinaryOp.OR, ft2False);
        builder.addAssertion(new AgreeStatement("", ft1FalseOrft2False, topNode.reference));
    }
    // assert that the value is <= maxFaults
    Expr lessEqual = new BinaryExpr(new IdExpr(id), BinaryOp.LESSEQUAL, new IntExpr(maxFaults));
    builder.addAssertion(new AgreeStatement("", lessEqual, 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) IntExpr(jkind.lustre.IntExpr) UnaryExpr(jkind.lustre.UnaryExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 34 with AgreeVar

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar 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 35 with AgreeVar

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar 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)

Aggregations

AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)69 IdExpr (jkind.lustre.IdExpr)49 Expr (jkind.lustre.Expr)45 NodeCallExpr (jkind.lustre.NodeCallExpr)42 BinaryExpr (jkind.lustre.BinaryExpr)41 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)39 BoolExpr (jkind.lustre.BoolExpr)38 UnaryExpr (jkind.lustre.UnaryExpr)37 ArrayList (java.util.ArrayList)28 IfThenElseExpr (jkind.lustre.IfThenElseExpr)25 VarDecl (jkind.lustre.VarDecl)19 Equation (jkind.lustre.Equation)15 RealExpr (jkind.lustre.RealExpr)15 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)14 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)13 IntExpr (jkind.lustre.IntExpr)13 AgreeException (com.rockwellcollins.atc.agree.analysis.AgreeException)12 AgreeNodeBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)12 NodeBuilder (jkind.lustre.builders.NodeBuilder)11 SafetyException (edu.umn.cs.crisys.safety.analysis.SafetyException)9