Search in sources :

Example 31 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 32 with AgreeStatement

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

the class AddFaultsToNodeVisitor method addFaultActivationAssertion.

/**
 * Method adds fault activations to lower levels. AgreeVar = fault_trigger
 *
 * @param agreeVarName  Name of agree var
 * @param f             Fault def
 * @param faultCompName Name of component with fault
 * @param nb            Node builder will have assertion added
 */
private void addFaultActivationAssertion(String agreeVarName, BaseFault f, String faultCompName, AgreeNodeBuilder nb) {
    IdExpr trigger = new IdExpr(faultCompName + "__fault__trigger__" + f.getID());
    Expr equate = new BinaryExpr(new IdExpr(agreeVarName), BinaryOp.EQUAL, trigger);
    nb.addAssertion(new AgreeStatement("", equate, topNode.reference));
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) 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) BinaryExpr(jkind.lustre.BinaryExpr)

Example 33 with AgreeStatement

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

the class AddFaultsToNodeVisitor method addAssumeHistStmts.

/**
 * Method is used to assert that the assume hist statements for each comm node
 * is true. This is added to main. Ex: assert
 * (asym_node_0__Sender__sender_out____ASSUME__HIST = __HIST(true));
 *
 * @param nb NodeBuilder that will have these assertions added.
 */
private void addAssumeHistStmts(AgreeNodeBuilder nb) {
    for (String commNodes : mapCommNodeToInputs.keySet()) {
        List<AgreeVar> inputs = mapCommNodeToInputs.get(commNodes);
        for (AgreeVar input : inputs) {
            if (input.id.contains("__ASSUME__HIST")) {
                NodeCallExpr nodeCall = new NodeCallExpr("__HIST", new BoolExpr(true));
                Expr eq = new BinaryExpr(new IdExpr(input.id), BinaryOp.EQUAL, nodeCall);
                nb.addAssertion(new AgreeStatement("", eq, topNode.reference));
                break;
            }
        }
    }
}
Also used : BoolExpr(jkind.lustre.BoolExpr) 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) BinaryExpr(jkind.lustre.BinaryExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 34 with AgreeStatement

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

the class AddFaultsToNodeVisitor method addTriggerExpr.

/**
 * Adds the nested lustre stmt that constrains agree node output based on which
 * fault trigger is active. Thus, the agree node output reflects the fault node
 * call linked to a specific trigger. Ex nested trigger expr: agree_node_output
 * = if fault__trigger_1 then fault__node_1__val_out else if fault__trigger_2
 * then fault__node_2__val_out ... else __fault__nominal__output)
 *
 * @param nb                   NodeBuilder that will have this assertion added
 *                             to it.
 * @param localFaultTriggerMap Map<Fault, Expr> from fault to trigger expr.
 * @param lhsWithStmtName      String of agree_node_output.
 */
private void addTriggerExpr(AgreeNodeBuilder nb, Map<Fault, Expr> localFaultTriggerMap, String lhsWithStmtName) {
    List<Pair> list = faultyVarsExpr.get(lhsWithStmtName);
    String nomId = createNominalId(lhsWithStmtName);
    Expr defaultExpr = new IdExpr(nomId);
    List<TriggerFaultOutPair> triggerList = new ArrayList<>();
    boolean isOnlyAsym = true;
    Expr outputExpr = null;
    // Go through pairs of the list and create with statements.
    for (Pair pair : list) {
        if (isAsymmetric(pair.f)) {
            continue;
        }
        isOnlyAsym = false;
        outputExpr = pair.ex;
        // base : replace the expression with nominal expression
        // repl : go from the fault to the actual
        // toAssign: createNestedUpdateExpr using base, repl
        // Expr base = replPathIdExpr(pair.ex, defaultExpr);
        // Expr repl = faultToActual(pair.f, pair.ex);
        // defaultExpr = SafetyUtil.createNestedUpdateExpr(base, repl);
        Expr faultNodeOut = faultToActual(pair.f, pair.ex);
        // Collect elements to build the nested if then else stmt described above.
        Expr ftTrigger = localFaultTriggerMap.get(pair.f);
        triggerList.add(new TriggerFaultOutPair(ftTrigger, faultNodeOut));
    }
    // anything in the sender node regarding fault nominal.
    if (!isOnlyAsym) {
        nb.addAssertion(new AgreeStatement("Adding new safety analysis BinaryExpr", new BinaryExpr(outputExpr, BinaryOp.EQUAL, createNestedIfThenElseExpr(triggerList, defaultExpr, 0)), null));
    }
}
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)

Example 35 with AgreeStatement

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

the class AddFaultsToNodeVisitor method constrainFaultActive.

/**
 * Constrains fault activity to permanent expression. If user attempts to create
 * transient, exception is thrown.
 *
 * @param f        Fault
 * @param nameBase Lustre name of fault
 * @param builder  The node builder that will have these assertions added.
 */
public void constrainFaultActive(Fault f, String nameBase, AgreeNodeBuilder builder) {
    IdExpr independentlyActiveExpr = new IdExpr(this.createFaultIndependentActiveId(nameBase));
    IdExpr dependentlyActiveExpr = new IdExpr(this.createFaultDependentActiveId(nameBase));
    IdExpr independentEventExpr = new IdExpr(this.createFaultEventId(nameBase));
    List<Expr> faultExprs = new ArrayList<>();
    // collect the list of source faults in the propagations
    // whose target fault is the current fault
    // the names of those source faults are created through
    // createFaultIndependentActiveId
    getSrcFaultExprList(f, faultExprs);
    // create a disjunction of the source faults as the triggering event
    // for the dependent fault
    Expr dependentEventExpr = buildFaultDisjunctionExpr(faultExprs, 0);
    Expr assertIndependentExpr;
    Expr assertDependentExpr;
    TemporalConstraint tc = f.duration.getTc();
    if (tc instanceof PermanentConstraint) {
        assertIndependentExpr = createPermanentExpr(independentlyActiveExpr, independentEventExpr);
        assertDependentExpr = createPermanentExpr(dependentlyActiveExpr, dependentEventExpr);
    } else if (tc instanceof TransientConstraint) {
        System.out.println("WARNING: ignoring duration on transient faults");
        assertIndependentExpr = createTransientExpr(independentlyActiveExpr, independentEventExpr);
        assertDependentExpr = createTransientExpr(dependentlyActiveExpr, dependentEventExpr);
    } else {
        throw new SafetyException("Unknown constraint type during translation of fault " + f.id + ". Constraint must be 'permanent'.");
    }
    builder.addAssertion(new AgreeStatement("", assertIndependentExpr, f.faultStatement));
    builder.addAssertion(new AgreeStatement("", assertDependentExpr, f.faultStatement));
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) 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) TransientConstraint(edu.umn.cs.crisys.safety.safety.TransientConstraint) PermanentConstraint(edu.umn.cs.crisys.safety.safety.PermanentConstraint) ArrayList(java.util.ArrayList) TemporalConstraint(edu.umn.cs.crisys.safety.safety.TemporalConstraint) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException)

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