use of com.rockwellcollins.atc.agree.analysis.AgreeException in project AGREE by loonwerks.
the class AgreePatternTranslator method translatePatternProperty.
private Expr translatePatternProperty(AgreeSporadicPattern pattern, AgreeNodeBuilder builder, EObject varReference) {
if (!((RealExpr) pattern.jitter).value.equals(BigDecimal.ZERO)) {
throw new AgreeException("We currently do not handle non-zero jitter values correctly for sporadic patterns");
}
AgreeVar timeofEvent = getTimeOf(pattern.event.id, builder, null);
Expr propExpr = expr("(true -> (not ((pre laste) = -1.0) => event => time - (pre laste) >= period))", to("laste", timeofEvent), to("event", pattern.event), to("time", timeExpr), to("period", pattern.period));
return propExpr;
}
use of com.rockwellcollins.atc.agree.analysis.AgreeException in project AGREE by loonwerks.
the class MATLABFunctionHandler method runJob.
@Override
protected IStatus runJob(Element root, IProgressMonitor monitor) {
Classifier classifier = getOutermostClassifier(root);
if (!(classifier instanceof ComponentType)) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Must select an AADL Component Type");
}
ComponentType ct = (ComponentType) classifier;
ComponentImplementation ci = null;
EphemeralImplementationUtil implUtil = new EphemeralImplementationUtil(monitor);
try {
SystemInstance si = implUtil.generateEphemeralCompInstanceFromType(ct);
ComponentType sysType = AgreeUtils.getInstanceType(si);
EList<AnnexSubclause> annexSubClauses = AnnexUtil.getAllAnnexSubclauses(sysType, AgreePackage.eINSTANCE.getAgreeContractSubclause());
if (annexSubClauses.size() == 0) {
throw new AgreeException("There is not an AGREE annex in the '" + sysType.getName() + "' system type.");
}
// Get Agree program
AgreeProgram agreeProgram = new AgreeASTBuilder().getAgreeProgram(si, false);
if (agreeProgram.containsRealTimePatterns) {
throw new AgreeException("'" + sysType.getName() + "' system type contains AGREE Real Time Patterns." + " Export of AGREE Real Time Patterns NOT Supported - they are considered scheduling properties" + " of components and can be decomposed further.");
}
// Translate Agree Node to Lustre Node with pre-statement flatten, helper nodes inlined,
// and variable declarations sorted so they are declared before use
Node lustreNode = AgreeNodeToLustreContract.translate(agreeProgram.topNode, agreeProgram);
// Translate Lustre Node to MATLAB Function AST
MATLABPrimaryFunction matlabFunction = LustreToMATLABTranslator.translate(lustreNode, agreeProgram);
ModelInfo info = getModelInfo(ct);
if (info == null) {
// return;
return Status.CANCEL_STATUS;
}
String dirStr = info.outputDirPath;
if (dirStr == null || dirStr.isEmpty()) {
// return;
return Status.CANCEL_STATUS;
}
boolean exportContractsPressed = info.exportPressed;
boolean genImplPressed = info.generatePressed;
boolean genVerificationPressed = info.updatePressed;
boolean verifySubsysPressed = info.verifyPressed;
String matlabFuncScriptName = matlabFunction.name + ".m";
if (genImplPressed) {
// Write MATLAB script to generate subsystem in the selected
// output folder
String subsysName = "";
if (info.subsystemName.equals("")) {
subsysName = sysType.getName();
} else {
subsysName = info.subsystemName;
}
MdlScriptCreator implMdlScript = new MdlScriptCreator(dirStr, info.implMdlPath, info.verifyMdlName, subsysName, matlabFunction.ports, matlabFuncScriptName, true, info.verifyPressed);
String implMdlScriptName = "generate_" + subsysName + ".m";
// generate the script to create the impl model file into the path specified for the model
File implMdlFile = new File(info.implMdlPath);
String implMdlDir = implMdlFile.getParent();
if (implMdlDir != null) {
Path implMdlScriptPath = Paths.get(implMdlDir, implMdlScriptName);
writeToFile(implMdlScriptPath, implMdlScript.toString());
}
}
if (exportContractsPressed || genVerificationPressed || verifySubsysPressed) {
Path matlabFuncScriptPath = Paths.get(dirStr, matlabFuncScriptName);
// Write MATLAB function code into the specified file in the
// selected output folder
writeToFile(matlabFuncScriptPath, matlabFunction.toString());
if (genVerificationPressed || verifySubsysPressed) {
// Create Simulink Model Update script into the output
// folder
MdlScriptCreator verifMdlScript = new MdlScriptCreator(dirStr, info.implMdlPath, info.verifyMdlName, info.subsystemName, matlabFunction.ports, matlabFuncScriptName, false, info.verifyPressed);
String verifMdlScriptName = matlabFunction.name + "_Observer.m";
Path verifMdlScriptPath = Paths.get(dirStr, verifMdlScriptName);
writeToFile(verifMdlScriptPath, verifMdlScript.toString());
}
}
// return;
return Status.OK_STATUS;
} catch (Throwable e) {
String messages = getNestedMessages(e);
e.printStackTrace();
Dialog.showError("AGREE Error", e.toString());
// return;
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, messages, e);
} finally {
if (ci != null) {
ci.eResource().getContents().remove(ci);
}
implUtil.cleanup();
}
}
use of com.rockwellcollins.atc.agree.analysis.AgreeException in project AMASE by loonwerks.
the class GenMCSHandler method runJob.
@Override
protected IStatus runJob(Element root, IProgressMonitor monitor) {
EphemeralImplementationUtil implUtil = new EphemeralImplementationUtil(monitor);
// this flag is set by the rerun handler to prevent clearing the advice map
if (!calledFromRerun) {
rerunAdviceMap.clear();
}
calledFromRerun = false;
disableRerunHandler();
handlerService = getWindow().getService(IHandlerService.class);
try {
// Make sure the user selected a component implementation
ComponentImplementation ci = getComponentImplementation(root, implUtil);
SystemInstance si = getSysInstance(ci, implUtil);
AnalysisResult result;
CompositeAnalysisResult wrapper = new CompositeAnalysisResult("");
// SystemType sysType = si.getSystemImplementation().getType();
ComponentType sysType = AgreeUtils.getInstanceType(si);
EList<AnnexSubclause> annexSubClauses = AnnexUtil.getAllAnnexSubclauses(sysType, AgreePackage.eINSTANCE.getAgreeContractSubclause());
if (annexSubClauses.size() == 0) {
throw new AgreeException("There is not an AGREE annex in the '" + sysType.getName() + "' system type.");
}
if (isRecursive()) {
if (AgreeUtils.usingKind2()) {
throw new AgreeException("Kind2 only supports monolithic verification");
}
result = buildAnalysisResult(((NamedElement) root).getName(), si);
wrapper.addChild(result);
result = wrapper;
} else if (isRealizability()) {
AgreeProgram agreeProgram = new AgreeASTBuilder().getAgreeProgram(si, false);
Program program = LustreAstBuilder.getRealizabilityLustreProgram(agreeProgram);
wrapper.addChild(createVerification("Realizability Check", si, program, agreeProgram, AnalysisType.Realizability));
result = wrapper;
} else {
wrapVerificationResult(si, wrapper);
result = wrapper;
}
showView(result, linker);
return doAnalysis(root, monitor, result, linker);
} catch (Throwable e) {
String messages = getNestedMessages(e);
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, messages, e);
} finally {
implUtil.cleanup();
}
}
use of com.rockwellcollins.atc.agree.analysis.AgreeException in project AMASE by loonwerks.
the class SafetyLinkerFactory method createVerification.
protected AnalysisResult createVerification(String resultName, ComponentInstance compInst, Program lustreProgram, AgreeProgram agreeProgram) {
// Renaming: organizes things between jkind and agree results?
AgreeRenaming agreeRenaming = new AgreeRenaming();
AgreeLayout layout = new AgreeLayout();
RenamingVisitor.addRenamings(lustreProgram, agreeRenaming, compInst, layout);
SafetyRenaming renaming = new SafetyRenaming(agreeRenaming, agreeRenaming.getRefMap());
Node mainNode = lustreProgram.getMainNode();
if (mainNode == null) {
throw new AgreeException("Could not find main lustre node after translation");
}
List<String> properties = new ArrayList<>();
JKindResult result;
result = new JKindResult(resultName, properties, renaming);
queue.add(result);
// Set the program, component, contract, layout, log, and renaming
ComponentImplementation compImpl = AgreeUtils.getInstanceImplementation(compInst);
linker.setAgreeProgram(result, agreeProgram);
linker.setProgram(result, lustreProgram);
linker.setComponent(result, compImpl);
linker.setContract(result, getContract(compImpl));
linker.setLayout(result, layout);
linker.setReferenceMap(result, renaming.getRefMap());
linker.setLog(result, AgreeLogger.getLog());
linker.setRenaming(result, renaming);
return result;
}
use of com.rockwellcollins.atc.agree.analysis.AgreeException in project AMASE by loonwerks.
the class FaultsVerifyAllHandler method createVerification.
private AnalysisResult createVerification(String resultName, ComponentInstance compInst, Program lustreProgram, AgreeProgram agreeProgram, AnalysisType analysisType) {
AgreeAutomaterRegistry aAReg = (AgreeAutomaterRegistry) ExtensionRegistry.getRegistry(ExtensionRegistry.AGREE_AUTOMATER_EXT_ID);
List<AgreeAutomater> automaters = aAReg.getAgreeAutomaters();
AgreeRenaming renaming = new AgreeRenaming();
AgreeLayout layout = new AgreeLayout();
Node mainNode = null;
for (Node node : lustreProgram.nodes) {
if (node.id.equals(lustreProgram.main)) {
mainNode = node;
break;
}
}
if (mainNode == null) {
throw new AgreeException("Could not find main lustre node after translation");
}
List<String> properties = new ArrayList<>();
RenamingVisitor.addRenamings(lustreProgram, renaming, compInst, layout);
addProperties(renaming, properties, mainNode, agreeProgram);
for (AgreeAutomater aa : automaters) {
renaming = aa.rename(renaming);
layout = aa.transformLayout(layout);
}
JKindResult result;
switch(analysisType) {
case Consistency:
result = new ConsistencyResult(resultName, mainNode.properties, Collections.singletonList(true), renaming);
break;
case Realizability:
result = new JRealizabilityResult(resultName, renaming);
break;
case AssumeGuarantee:
result = new SafetyJKindResult(resultName, properties, renaming);
break;
default:
throw new AgreeException("Unhandled Analysis Type");
}
queue.add(result);
ComponentImplementation compImpl = AgreeUtils.getInstanceImplementation(compInst);
linker.setProgram(result, lustreProgram);
linker.setComponent(result, compImpl);
linker.setContract(result, getContract(compImpl));
linker.setLayout(result, layout);
linker.setReferenceMap(result, renaming.getRefMap());
linker.setLog(result, AgreeLogger.getLog());
linker.setRenaming(result, renaming);
// System.out.println(program);
return result;
}
Aggregations