Search in sources :

Example 1 with SafetyException

use of edu.umn.cs.crisys.safety.analysis.SafetyException in project AMASE by loonwerks.

the class AsymFaultASTBuilder method processFaults.

/**
 * Process all faults in the list of fault statements and return a list of
 * those faults. It is assumed that all faults in faultGroup are part of multiple
 * faults on a single output.
 *
 * @param faultGroup List of asymmetric FaultStatements.
 * @return List of processed faults.
 */
public List<Fault> processFaults(List<FaultStatement> faultGroup) {
    if (faultGroup.isEmpty()) {
        new SafetyException("Problem with multiple faults on the same output.");
    }
    List<Fault> faultList = new ArrayList<Fault>();
    List<ConnectionInstanceEnd> senderConnections = new ArrayList<>();
    DataPortImpl senderOutput = null;
    // 1. Create fault nodes using parent method
    for (FaultStatement fs : faultGroup) {
        faultList.add(super.createSenderFault(fs));
    }
    // 2. Gather connections and add to parent map - can use any fstmt to do this.
    senderOutput = super.findSenderOutput(faultGroup.get(0));
    senderConnections = super.populateMapSenderToReceiver(senderOutput);
    // 3. Create communication nodes
    createCommNodes(senderConnections, senderOutput, faultList);
    setPathForFaults(faultList, agreeNode);
    return faultList;
}
Also used : ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) DataPortImpl(org.osate.aadl2.impl.DataPortImpl) ArrayList(java.util.ArrayList) FaultStatement(edu.umn.cs.crisys.safety.safety.FaultStatement) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException)

Example 2 with SafetyException

use of edu.umn.cs.crisys.safety.analysis.SafetyException in project AMASE by loonwerks.

the class AddFaultsToNodeVisitor method faultToActual.

/**
 * Finds the lustre expr for output that fault is attached to. Ex: val_out ->
 * Sender__fault_3__node__val_out
 *
 * @param f  Fault in question
 * @param ex Expression of output
 * @return Lustre expression with id set correctly.
 */
private Expr faultToActual(Fault f, Expr ex) {
    // Match pair.ex -> key of faultOutputMap
    // If this expression is not in map, return exception message
    String outputName = f.faultOutputMap.get(ex);
    if (outputName == null) {
        new SafetyException("Cannot find fault output for fault " + f.id);
    }
    // Use outputName to get value from outputParamToActualMap
    AgreeVar actual = f.outputParamToActualMap.get(outputName);
    if (f.outputParamToActualMap.isEmpty()) {
        new SafetyException("Something went wrong with fault output parameter. Fault is: " + f.id + " and expr is: " + ex.toString());
    }
    // Create IdExpr out of actual string
    return new IdExpr(actual.id);
}
Also used : IdExpr(jkind.lustre.IdExpr) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 3 with SafetyException

use of edu.umn.cs.crisys.safety.analysis.SafetyException in project AMASE by loonwerks.

the class AddFaultsToNodeVisitor method constrainFaultActive.

/**
 * Method constrains hardware faults to be permanent.
 *
 * @param hwf      HardwareFault to be constrained.
 * @param nameBase Name of fault.
 * @param builder  AgreeNodeBuilder will have assertions added.
 */
public void constrainFaultActive(HWFault hwf, 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(hwf, 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 = hwf.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 " + hwf.id + ". Constraint must be 'permanent'.");
    }
    builder.addAssertion(new AgreeStatement("", assertIndependentExpr, hwf.hwFaultStatement));
    builder.addAssertion(new AgreeStatement("", assertDependentExpr, hwf.hwFaultStatement));
}
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)

Example 4 with SafetyException

use of edu.umn.cs.crisys.safety.analysis.SafetyException 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 5 with SafetyException

use of edu.umn.cs.crisys.safety.analysis.SafetyException in project AMASE by loonwerks.

the class AddFaultsToNodeVisitor method separateFaultStmts.

/**
 * This method uses a list of fault statements and divides them into multiple
 * asym faults on a single output and everything else.
 *
 * @param allFS          List<FaultStatement> All fault statements in this agree
 *                       node
 * @param remainderFS    List<FaultStatement> List to add all single asym faults
 *                       on single output AND sym faults.
 * @param multipleAsymFS List<FaultStatement> List to add all multiple asym
 *                       faults on single output.
 */
private void separateFaultStmts(List<FaultStatement> allFS, List<FaultStatement> remainderFS, Map<String, List<FaultStatement>> asymMap) {
    // Else append to multipleAsymFS list.
    for (FaultStatement fs : allFS) {
        int count = fs.getFaultDefinitions().size();
        for (FaultSubcomponent fc : fs.getFaultDefinitions()) {
            count--;
            if (fc instanceof PropagationTypeStatement) {
                if (((PropagationTypeStatement) fc).getPty() instanceof asymmetric) {
                    // Asym fault needs to be processed further and added to map.
                    String outputName = getOutputNameFromFaultStatement(fs);
                    if (outputName.isEmpty()) {
                        new SafetyException("Error processing asymmetric fault: the output name is undefined for fault statement:" + fs.getName());
                    } else {
                        List<FaultStatement> tempAsymFaults = new ArrayList<FaultStatement>();
                        tempAsymFaults.add(fs);
                        if (asymMap.containsKey(outputName)) {
                            asymMap.get(outputName).addAll(tempAsymFaults);
                        } else {
                            asymMap.put(outputName, tempAsymFaults);
                        }
                        break;
                    }
                } else {
                    // symmetric faults added to remainderFS list
                    remainderFS.add(fs);
                    break;
                }
            }
            // all definitions, then we have no prop type stmt. It is sym.
            if (count == 0) {
                remainderFS.add(fs);
            }
        }
    }
    // Add multiples to multiple list.
    for (String key : asymMap.keySet()) {
        if (asymMap.get(key).size() == 1) {
            remainderFS.addAll(asymMap.get(key));
        }
    }
}
Also used : FaultSubcomponent(edu.umn.cs.crisys.safety.safety.FaultSubcomponent) ArrayList(java.util.ArrayList) FaultStatement(edu.umn.cs.crisys.safety.safety.FaultStatement) HWFaultStatement(edu.umn.cs.crisys.safety.safety.HWFaultStatement) PropagationTypeStatement(edu.umn.cs.crisys.safety.safety.PropagationTypeStatement) edu.umn.cs.crisys.safety.safety.asymmetric(edu.umn.cs.crisys.safety.safety.asymmetric) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException) TransientConstraint(edu.umn.cs.crisys.safety.safety.TransientConstraint) PermanentConstraint(edu.umn.cs.crisys.safety.safety.PermanentConstraint) TemporalConstraint(edu.umn.cs.crisys.safety.safety.TemporalConstraint)

Aggregations

SafetyException (edu.umn.cs.crisys.safety.analysis.SafetyException)34 ArrayList (java.util.ArrayList)14 IdExpr (jkind.lustre.IdExpr)12 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)9 BinaryExpr (jkind.lustre.BinaryExpr)9 BoolExpr (jkind.lustre.BoolExpr)9 Expr (jkind.lustre.Expr)9 NodeCallExpr (jkind.lustre.NodeCallExpr)9 RecordAccessExpr (jkind.lustre.RecordAccessExpr)9 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)7 IfThenElseExpr (jkind.lustre.IfThenElseExpr)7 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)6 IntExpr (jkind.lustre.IntExpr)6 UnaryExpr (jkind.lustre.UnaryExpr)6 BaseFault (edu.umn.cs.crisys.safety.analysis.transform.BaseFault)5 PermanentConstraint (edu.umn.cs.crisys.safety.safety.PermanentConstraint)5 TemporalConstraint (edu.umn.cs.crisys.safety.safety.TemporalConstraint)5 TransientConstraint (edu.umn.cs.crisys.safety.safety.TransientConstraint)5 FTAndNode (edu.umn.cs.crisys.safety.analysis.faultTree.FTAndNode)3 FTNode (edu.umn.cs.crisys.safety.analysis.faultTree.FTNode)3