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;
}
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);
}
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));
}
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;
}
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));
}
}
}
Aggregations