Search in sources :

Example 26 with AgreeStatement

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

the class AddFaultsToNodeVisitor method addAsymFaultAssertions.

/**
 * Method adds assertions associated with the asym fault event. Adds triggers
 * for the communication node faults: __fault__trigger__Sender__fault_1 : bool;
 * Adds trigger expression linking fault of sender node to the comm node
 * behavior: output = if __fault__trigger__Sender__fault_1 then
 * Sender__fault_1__node__val_out else __fault__nominal__output
 *
 * @param nb NodeBuilder that will have these assertions added.
 */
private void addAsymFaultAssertions(AgreeNodeBuilder nb) {
    // List of idExpr holding dep ids and list for indep ids
    List<Expr> triggerList = new ArrayList<>();
    for (Fault fault : mapAsymFaultToCommNodes.keySet()) {
        for (String nodeName : mapAsymFaultToCommNodes.get(fault)) {
            // Create trigger statements for each of the faults comm nodes
            IdExpr trigger = new IdExpr(nodeName + "__fault__trigger__" + fault.id);
            triggerList.add(trigger);
        }
        // Create trigger expression that links fault of sender node to comm node
        // trigger.
        String compName = mapAsymFaultToCompName.get(fault);
        IdExpr trigger = new IdExpr(compName + "__fault__trigger__" + fault.id);
        Expr bigOrExpr = buildBigOrExpr(triggerList, 0);
        Expr notBigOrExpr = new UnaryExpr(UnaryOp.NOT, bigOrExpr);
        Expr ifThenElse = new IfThenElseExpr(trigger, bigOrExpr, notBigOrExpr);
        nb.addAssertion(new AgreeStatement("", ifThenElse, this.topNode.reference));
        triggerList.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) 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) UnaryExpr(jkind.lustre.UnaryExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr)

Example 27 with AgreeStatement

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

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

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

the class AddFaultsToNodeVisitor method changeAsymConnections.

/**
 * Method will remove the previous connections in the main lustre node from
 * sender to receivers and add in the new connections from sender to commNode
 * and from commNode to receiver. Ex: What used to be: Sender_out = reciever1.in
 * Sender_out = reciever2.in Sender_out = reciever3.in Is now: Sender_out =
 * asym0.in Sender_out = asym1.in Sender_out = asym2.in asym0.out = reciever1.in
 * asym1.out = reciever2.in asym2.out = reciever3.in
 *
 * @param nb NodeBuilder for the main lustre node.
 */
private void changeAsymConnections(AgreeNodeBuilder nb) {
    // Insert connections sender_output = commNode_input
    for (String output : mapAsymCompOutputToCommNodeIn.keySet()) {
        for (String nodeName : mapAsymCompOutputToCommNodeIn.get(output)) {
            Expr eq = new BinaryExpr(new IdExpr(output), BinaryOp.EQUAL, new IdExpr(nodeName));
            nb.addAssertion(new AgreeStatement("", eq, this.topNode.reference));
        }
    }
    // Insert connections commNode_output = receiver_input.
    for (String output : mapCommNodeOutputToConnections.keySet()) {
        String featureName = "";
        String componentName = "";
        // First access name of receiving component and its input
        if (mapCommNodeOutputToConnections.get(output).eContainer() instanceof SystemInstanceImpl) {
            FeatureInstanceImpl fi = (FeatureInstanceImpl) mapCommNodeOutputToConnections.get(output);
            componentName = "";
            featureName = fi.getName();
        } else if (mapCommNodeOutputToConnections.get(output) instanceof FeatureInstanceImpl) {
            FeatureInstanceImpl fi = (FeatureInstanceImpl) mapCommNodeOutputToConnections.get(output);
            featureName = fi.getName();
            if (fi.eContainer() instanceof ComponentInstanceImpl) {
                ComponentInstanceImpl ci = (ComponentInstanceImpl) fi.eContainer();
                componentName = ci.getName() + "__";
            } else {
                new SafetyException("Asymmetric fault must be connected to a component instance.");
            }
        } else {
            new SafetyException("Asymmetric fault must have an allowable connection.");
        }
        // Create lustre connection name, add to builder.
        IdExpr connectionName = new IdExpr(componentName + featureName);
        Expr eq = new BinaryExpr(new IdExpr(output), BinaryOp.EQUAL, connectionName);
        nb.addAssertion(new AgreeStatement("", eq, this.topNode.reference));
    }
}
Also used : ComponentInstanceImpl(org.osate.aadl2.instance.impl.ComponentInstanceImpl) 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) SystemInstanceImpl(org.osate.aadl2.instance.impl.SystemInstanceImpl) BinaryExpr(jkind.lustre.BinaryExpr) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException) FeatureInstanceImpl(org.osate.aadl2.instance.impl.FeatureInstanceImpl)

Example 30 with AgreeStatement

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

Aggregations

AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)56 IdExpr (jkind.lustre.IdExpr)50 Expr (jkind.lustre.Expr)49 BinaryExpr (jkind.lustre.BinaryExpr)47 NodeCallExpr (jkind.lustre.NodeCallExpr)45 BoolExpr (jkind.lustre.BoolExpr)44 UnaryExpr (jkind.lustre.UnaryExpr)40 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)39 IfThenElseExpr (jkind.lustre.IfThenElseExpr)28 ArrayList (java.util.ArrayList)25 IntExpr (jkind.lustre.IntExpr)23 RecordAccessExpr (jkind.lustre.RecordAccessExpr)19 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)15 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)13 RealExpr (jkind.lustre.RealExpr)13 VarDecl (jkind.lustre.VarDecl)13 AgreeNodeBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)12 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)11 Equation (jkind.lustre.Equation)11 TupleExpr (jkind.lustre.TupleExpr)11