Search in sources :

Example 1 with SpecStatement

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

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

the class AddFaultsToNodeVisitor method gatherTopLevelFaultAnalysis.

/**
 * Method gets the analysis statement located in the top node system
 * implementation. Determines if max no. faults or prob.
 *
 * @param node Top agree node.
 * @return Analysis behavior stated in the annex.
 */
public AnalysisBehavior gatherTopLevelFaultAnalysis(AgreeNode node) {
    AnalysisBehavior ab = null;
    boolean found = false;
    List<SpecStatement> specs = SafetyUtil.collapseAnnexes(SafetyUtil.getSafetyAnnexes(node, true));
    for (SpecStatement s : specs) {
        if (s instanceof AnalysisStatement) {
            AnalysisStatement as = (AnalysisStatement) s;
            ab = as.getBehavior();
            if (ab instanceof FaultCountBehavior) {
                int maxFaults = Integer.valueOf(((FaultCountBehavior) ab).getMaxFaults());
                if (maxFaults < 0) {
                    throw new SafetyException("Maximum number of faults must be non-negative.");
                }
            } else if (ab instanceof ProbabilityBehavior) {
                double minProbability = Double.valueOf(((ProbabilityBehavior) ab).getProbabilty());
                if (minProbability > 1 || minProbability < 0) {
                    throw new SafetyException("Probability out of range [0, 1]");
                }
            }
            if (found) {
                throw new SafetyException("Multiple analysis specification statements found.  Only one can be processed");
            }
            found = true;
        }
    }
    if (!found && upperMostLevel) {
        throw new SafetyException("No analysis statement; unable to run safety analysis");
    }
    return ab;
}
Also used : AnalysisStatement(edu.umn.cs.crisys.safety.safety.AnalysisStatement) FaultCountBehavior(edu.umn.cs.crisys.safety.safety.FaultCountBehavior) AnalysisBehavior(edu.umn.cs.crisys.safety.safety.AnalysisBehavior) ProbabilityBehavior(edu.umn.cs.crisys.safety.safety.ProbabilityBehavior) SpecStatement(edu.umn.cs.crisys.safety.safety.SpecStatement) 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 SpecStatement

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

the class SafetyUtil method collapseAnnexes.

/**
 * Return a list of spec statements from a list of annexes
 * @param annexes Safety contracts
 * @return list of spec stmts
 */
public static List<SpecStatement> collapseAnnexes(List<SafetyContractSubclause> annexes) {
    List<SpecStatement> allSpecs = new ArrayList<>();
    for (SafetyContractSubclause safetyannex : annexes) {
        // and the safety annex's contract
        SafetyContract contract = (SafetyContract) safetyannex.getContract();
        // The specs from the contract is where we can access the fault definitions
        allSpecs.addAll(contract.getSpecs());
    }
    return allSpecs;
}
Also used : SafetyContractSubclause(edu.umn.cs.crisys.safety.safety.SafetyContractSubclause) ArrayList(java.util.ArrayList) SpecStatement(edu.umn.cs.crisys.safety.safety.SpecStatement) SafetyContract(edu.umn.cs.crisys.safety.safety.SafetyContract)

Example 4 with SpecStatement

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

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

the class FaultsVerifyAllHandler method isProbabilisticAnalysis.

private boolean isProbabilisticAnalysis() {
    List<Classifier> classifiers = getClassifiers();
    if (classifiers == null) {
        return false;
    }
    // TODO: Finish addressing this issue.
    for (Classifier cl : classifiers) {
        // Get impl of this level
        if (cl instanceof ComponentImplementationImpl) {
            List<AnnexSubclause> asList = cl.getOwnedAnnexSubclauses();
            for (AnnexSubclause as : asList) {
                if (as.getName().equalsIgnoreCase("safety")) {
                    if (as instanceof DefaultAnnexSubclauseImpl) {
                        DefaultAnnexSubclauseImpl defaultAnnex = (DefaultAnnexSubclauseImpl) as;
                        SafetyContractSubclauseImpl safetyAnnex = (SafetyContractSubclauseImpl) defaultAnnex.getParsedAnnexSubclause();
                        // Get analysis stmt
                        List<SpecStatement> specs = ((SafetyContract) safetyAnnex.getContract()).getSpecs();
                        for (SpecStatement spec : specs) {
                            if (spec instanceof AnalysisStatement) {
                                if (!(((AnalysisStatement) spec).getBehavior() instanceof ProbabilityBehavior)) {
                                    return false;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : SafetyContractSubclauseImpl(edu.umn.cs.crisys.safety.safety.impl.SafetyContractSubclauseImpl) AnalysisStatement(edu.umn.cs.crisys.safety.safety.AnalysisStatement) ComponentImplementationImpl(org.osate.aadl2.impl.ComponentImplementationImpl) DefaultAnnexSubclauseImpl(org.osate.aadl2.impl.DefaultAnnexSubclauseImpl) ProbabilityBehavior(edu.umn.cs.crisys.safety.safety.ProbabilityBehavior) SpecStatement(edu.umn.cs.crisys.safety.safety.SpecStatement) Classifier(org.osate.aadl2.Classifier) SafetyContract(edu.umn.cs.crisys.safety.safety.SafetyContract) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Aggregations

SpecStatement (edu.umn.cs.crisys.safety.safety.SpecStatement)10 ArrayList (java.util.ArrayList)5 SafetyException (edu.umn.cs.crisys.safety.analysis.SafetyException)3 BaseFault (edu.umn.cs.crisys.safety.analysis.transform.BaseFault)3 AnalysisStatement (edu.umn.cs.crisys.safety.safety.AnalysisStatement)3 HWFaultStatement (edu.umn.cs.crisys.safety.safety.HWFaultStatement)3 ProbabilityBehavior (edu.umn.cs.crisys.safety.safety.ProbabilityBehavior)3 SafetyContract (edu.umn.cs.crisys.safety.safety.SafetyContract)3 HWFault (edu.umn.cs.crisys.safety.analysis.transform.HWFault)2 HWFaultASTBuilder (edu.umn.cs.crisys.safety.analysis.transform.HWFaultASTBuilder)2 AnalysisBehavior (edu.umn.cs.crisys.safety.safety.AnalysisBehavior)2 FaultCountBehavior (edu.umn.cs.crisys.safety.safety.FaultCountBehavior)2 FaultStatement (edu.umn.cs.crisys.safety.safety.FaultStatement)2 SafetyContractSubclauseImpl (edu.umn.cs.crisys.safety.safety.impl.SafetyContractSubclauseImpl)2 AnnexSubclause (org.osate.aadl2.AnnexSubclause)2 Classifier (org.osate.aadl2.Classifier)2 NamedElement (org.osate.aadl2.NamedElement)2 DefaultAnnexSubclauseImpl (org.osate.aadl2.impl.DefaultAnnexSubclauseImpl)2 FaultActivationAssignment (edu.umn.cs.crisys.safety.analysis.ast.FaultActivationAssignment)1 SafetyPropagation (edu.umn.cs.crisys.safety.analysis.ast.SafetyPropagation)1