Search in sources :

Example 1 with FaultStatement

use of edu.umn.cs.crisys.safety.safety.FaultStatement 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 FaultStatement

use of edu.umn.cs.crisys.safety.safety.FaultStatement 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)

Example 3 with FaultStatement

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

the class AddFaultsToNodeVisitor method gatherFaults.

/**
 * Method gathers fault statements within this agree node and begins processing.
 * Creates FaultASTBuilder object, creates faults for each fault stmt, populates
 * asym maps, separates asym/sym faults for separate processing, and returns
 * processed faults.
 *
 * @param globalLustreNodes List of Nodes
 * @param node              This agree node
 * @param isTop             flag to determine if this is the top node of the
 *                          program.
 * @return list of faults associated with the fault stmts in this node.
 */
public List<Fault> gatherFaults(List<Node> globalLustreNodes, AgreeNode node, boolean isTop) {
    List<SpecStatement> specs = SafetyUtil.collapseAnnexes(SafetyUtil.getSafetyAnnexes(node, isTop));
    List<Fault> faults = new ArrayList<>();
    // reset fault count for the new Agree Node
    FaultASTBuilder.resetFaultCounter();
    // Before looping through spec statements, separate out the asymmetric multiple
    // faults on a single output with the sym/asym single faults on a single output.
    // 1. Collect all fault statements and put into list.
    // Do not collect any that are disabled.
    // 2. Separate out multiple asym faults on one output and single faults on one
    // output.
    // 3. Perform necessary processing on each of these lists.
    List<FaultStatement> allFaultStmts = new ArrayList<FaultStatement>();
    for (SpecStatement s : specs) {
        if (s instanceof FaultStatement) {
            if (!isDisabled((FaultStatement) s)) {
                allFaultStmts.add((FaultStatement) s);
            }
        }
    }
    List<FaultStatement> remainderFS = new ArrayList<FaultStatement>();
    Map<String, List<FaultStatement>> multipleAsymFS = new HashMap<String, List<FaultStatement>>();
    separateFaultStmts(allFaultStmts, remainderFS, multipleAsymFS);
    // processes these stmts, creates faults, and creates associated comm nodes.
    for (String output : multipleAsymFS.keySet()) {
        if (multipleAsymFS.get(output).size() == 1) {
            continue;
        }
        AsymFaultASTBuilder asymBuilder = new AsymFaultASTBuilder(globalLustreNodes, node);
        List<Fault> safetyFaults = asymBuilder.processFaults(multipleAsymFS.get(output));
        mapAsymCompOutputToCommNodeIn = asymBuilder.getMapAsymCompOutputToCommNodeIn();
        mapCommNodeToInputs = asymBuilder.getMapCommNodeToInputs();
        mapCommNodeOutputToConnections = asymBuilder.getMapCommNodeOutputToConnections();
        mapSenderToReceiver = asymBuilder.getMapSenderToReceiver();
        mapCompNameToCommNodes = asymBuilder.getMapCompNameToCommNodes();
        // Create local mapAsymFaultToCompName
        if (node.compInst instanceof ComponentInstance) {
            ComponentInstance comp = node.compInst;
            String name = comp.getName();
            for (Fault safetyFault : safetyFaults) {
                mapAsymFaultToCompName.put(safetyFault, name);
                // Create mapping from fault to associated commNodes.
                // Use mapping from fault to comp name, then map from comp name to
                // comm nodes.
                mapAsymFaultToCommNodes.put(safetyFault, mapCompNameToCommNodes.get(name));
            }
        }
        faults.addAll(safetyFaults);
    }
    // Now process all the rest of the fault stmts.
    for (SpecStatement s : remainderFS) {
        if (s instanceof FaultStatement) {
            FaultStatement fs = (FaultStatement) s;
            FaultASTBuilder builder = new FaultASTBuilder(globalLustreNodes, node);
            // Process fault determines if we have a
            // symmetric or asymmetric fault and builds it accordingly.
            Fault safetyFault = builder.processFault(fs);
            // to main lustre node.
            if (isAsymmetric(fs)) {
                mapAsymCompOutputToCommNodeIn = builder.getMapAsymCompOutputToCommNodeIn();
                mapCommNodeToInputs = builder.getMapCommNodeToInputs();
                mapCommNodeOutputToConnections = builder.getMapCommNodeOutputToConnections();
                mapSenderToReceiver = builder.getMapSenderToReceiver();
                mapCompNameToCommNodes = builder.getMapCompNameToCommNodes();
                // Create local mapAsymFaultToCompName
                if (node.compInst instanceof ComponentInstance) {
                    ComponentInstance comp = node.compInst;
                    String name = comp.getName();
                    mapAsymFaultToCompName.put(safetyFault, name);
                    // Create mapping from fault to associated commNodes.
                    // Use mapping from fault to comp name, then map from comp name to
                    // comm nodes.
                    mapAsymFaultToCommNodes.put(safetyFault, mapCompNameToCommNodes.get(name));
                }
            }
            faults.add(safetyFault);
        }
    }
    return faults;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HWFaultASTBuilder(edu.umn.cs.crisys.safety.analysis.transform.HWFaultASTBuilder) FaultASTBuilder(edu.umn.cs.crisys.safety.analysis.transform.FaultASTBuilder) AsymFaultASTBuilder(edu.umn.cs.crisys.safety.analysis.transform.AsymFaultASTBuilder) SpecStatement(edu.umn.cs.crisys.safety.safety.SpecStatement) 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) FaultStatement(edu.umn.cs.crisys.safety.safety.FaultStatement) HWFaultStatement(edu.umn.cs.crisys.safety.safety.HWFaultStatement) AsymFaultASTBuilder(edu.umn.cs.crisys.safety.analysis.transform.AsymFaultASTBuilder) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList)

Example 4 with FaultStatement

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

the class SafetyValidator method getFaultNamesFromSpecs.

/**
 * Collects fault names from the safety spec statements.
 * @param specs Safety SpecStatements
 * @return List<String> of all fault names defined in these specs.
 */
private List<String> getFaultNamesFromSpecs(List<SpecStatement> specs) {
    List<String> faultNames = new ArrayList<String>();
    for (SpecStatement sp : specs) {
        if (sp instanceof FaultStatement) {
            FaultStatement fs = (FaultStatement) sp;
            faultNames.add(fs.getName());
        } else if (sp instanceof HWFaultStatement) {
            HWFaultStatement hwfs = (HWFaultStatement) sp;
            faultNames.add(hwfs.getName());
            if (!definedHWFaultsInProgram.contains(hwfs.getName())) {
                definedHWFaultsInProgram.add(hwfs.getName());
            }
        }
    }
    return faultNames;
}
Also used : HWFaultStatement(edu.umn.cs.crisys.safety.safety.HWFaultStatement) ArrayList(java.util.ArrayList) SpecStatement(edu.umn.cs.crisys.safety.safety.SpecStatement) FaultStatement(edu.umn.cs.crisys.safety.safety.FaultStatement) HWFaultStatement(edu.umn.cs.crisys.safety.safety.HWFaultStatement)

Example 5 with FaultStatement

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

the class SafetyValidator method checkOutput.

/**
 * Check return params of fault node against params listed
 * in outputs.
 * @param outputs
 */
@Check(CheckType.FAST)
public void checkOutput(OutputStatement outputs) {
    List<String> faultsOut = outputs.getFault_out();
    EObject container = outputs.eContainer();
    List<Arg> retValues = new ArrayList<Arg>();
    List<String> returnNames = new ArrayList<String>();
    if (container instanceof FaultStatement) {
        retValues = getNodeReturnArgs((FaultStatement) container);
        if (retValues == null) {
            error(outputs, "Fault node definition is not valid for these outputs.");
        }
        for (Arg arg : retValues) {
            returnNames.add(arg.getFullName());
        }
        // Check sizes
        if (retValues.size() == (faultsOut.size())) {
            // Check names
            for (String outputName : faultsOut) {
                if (!returnNames.contains(outputName)) {
                    error(outputs, "The output name: " + outputName + " is not an return value in the node definition. " + "All possible output names are: " + returnNames.toString());
                }
            }
        } else {
            error(outputs, "The number of outputs must match the number of return values in the node definition." + "No. of outputs must be " + returnNames.size() + ".");
        }
    } else {
        error(outputs, "Fault outputs must be in a fault statement.");
    }
    if (!checkOutputTypes(faultsOut, outputs.getNom_conn(), retValues)) {
        error(outputs, "The output types do not match the node return parameter types.");
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Arg(com.rockwellcollins.atc.agree.agree.Arg) ArrayList(java.util.ArrayList) FaultStatement(edu.umn.cs.crisys.safety.safety.FaultStatement) HWFaultStatement(edu.umn.cs.crisys.safety.safety.HWFaultStatement) Check(org.eclipse.xtext.validation.Check)

Aggregations

FaultStatement (edu.umn.cs.crisys.safety.safety.FaultStatement)8 HWFaultStatement (edu.umn.cs.crisys.safety.safety.HWFaultStatement)6 ArrayList (java.util.ArrayList)6 Arg (com.rockwellcollins.atc.agree.agree.Arg)2 SafetyException (edu.umn.cs.crisys.safety.analysis.SafetyException)2 EqValue (edu.umn.cs.crisys.safety.safety.EqValue)2 FaultSubcomponent (edu.umn.cs.crisys.safety.safety.FaultSubcomponent)2 IntervalEq (edu.umn.cs.crisys.safety.safety.IntervalEq)2 PermanentConstraint (edu.umn.cs.crisys.safety.safety.PermanentConstraint)2 PropagationTypeStatement (edu.umn.cs.crisys.safety.safety.PropagationTypeStatement)2 SpecStatement (edu.umn.cs.crisys.safety.safety.SpecStatement)2 TransientConstraint (edu.umn.cs.crisys.safety.safety.TransientConstraint)2 edu.umn.cs.crisys.safety.safety.asymmetric (edu.umn.cs.crisys.safety.safety.asymmetric)2 EObject (org.eclipse.emf.ecore.EObject)2 Check (org.eclipse.xtext.validation.Check)2 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)1 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)1 Expr (com.rockwellcollins.atc.agree.agree.Expr)1 InputStatement (com.rockwellcollins.atc.agree.agree.InputStatement)1 IntLitExpr (com.rockwellcollins.atc.agree.agree.IntLitExpr)1