use of jkind.JKindException in project AGREE by loonwerks.
the class VerifyHandler method doAnalysis.
protected IStatus doAnalysis(final Element root, final IProgressMonitor monitor) {
Thread analysisThread = new Thread() {
@Override
public void run() {
activateTerminateHandler(monitor);
KindApi api = PreferencesUtil.getKindApi();
while (!queue.isEmpty() && !monitor.isCanceled()) {
JKindResult result = queue.peek();
NullProgressMonitor subMonitor = new NullProgressMonitor();
monitorRef.set(subMonitor);
TcgRenaming tcgRenaming = (TcgRenaming) linker.getRenaming(result);
Program ufcProgram = constructUfcProgram(linker.getProgram(result), tcgRenaming);
ufcProgram.getMainNode().properties.forEach(p -> result.addProperty(p));
writeIntermediateFiles(linker.getProgram(result), ufcProgram);
try {
System.out.println("Calling jkind...");
api.execute(ufcProgram, result, monitor);
System.out.println("executed API...");
TestSuite testSuite = TestSuiteUtils.testSuiteFromJKindResult(result, linker.getComponent(result).getQualifiedName(), result.getName(), result.getText(), tcgRenaming);
emitResult(testSuite);
// showSuiteView(testSuite, linker);
} catch (JKindException e) {
System.out.println(result.getText());
System.out.println("******** Error Occurred: HERE IS THE LUSTRE ********");
System.out.println(linker.getProgram(result));
break;
} finally {
deactivateTerminateHandler();
System.out.println("UFC generation complete");
}
queue.remove();
}
}
};
analysisThread.start();
return Status.OK_STATUS;
}
use of jkind.JKindException in project AMASE by loonwerks.
the class FaultsVerifyAllHandler method doAnalysis.
@Override
protected IStatus doAnalysis(final Element root, final IProgressMonitor globalMonitor) {
Thread analysisThread = new Thread() {
@Override
public void run() {
// Record the analysis start time and get model hashcode for
// saving to property analysis log, if necessary
String modelHash = "";
long startTime = 0;
if (Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_PROP_LOG)) {
try {
modelHash = AgreeFileUtil.getModelHashcode(root);
startTime = System.currentTimeMillis();
} catch (Exception e) {
System.out.println(e.getMessage());
return;
}
}
activateTerminateHandlers(globalMonitor);
KindApi api = PreferencesUtil.getKindApi();
KindApi consistApi = PreferencesUtil.getConsistencyApi();
JRealizabilityApi realApi = PreferencesUtil.getJRealizabilityApi();
// Due to the way the queue is constructed in traversal,
// reversing the queue will result in subcomponent instances
// being analyzed prior to their enclosing component instance.
// Reverse the queue using a stack.
{
Stack<JKindResult> stack = new Stack<>();
while (!queue.isEmpty()) {
stack.push(queue.remove());
}
while (!stack.empty()) {
queue.add(stack.pop());
}
}
while (!queue.isEmpty() && !globalMonitor.isCanceled()) {
JKindResult result = queue.peek();
NullProgressMonitor subMonitor = new NullProgressMonitor();
monitorRef.set(subMonitor);
Program program = doFaultPropagationInjection(result, linker.getProgram(result));
linker.setProgram(result, program);
if (api instanceof JKindApi) {
String resultName = result.getName();
String adviceFileName = rerunAdviceMap.get(resultName);
if (adviceFileName == null) {
adviceFileName = "agree_advice" + adviceCount++;
rerunAdviceMap.put(resultName, adviceFileName);
} else {
((JKindApi) api).setReadAdviceFile(adviceFileName);
}
((JKindApi) api).setWriteAdviceFile(adviceFileName);
}
try {
if (result instanceof ConsistencyResult) {
consistApi.execute(program, result, subMonitor);
} else if (result instanceof JRealizabilityResult) {
realApi.execute(program, (JRealizabilityResult) result, subMonitor);
} else {
api.execute(program, result, subMonitor);
}
} catch (JKindException e) {
System.out.println("******** JKindException Text ********");
e.printStackTrace(System.out);
String errStr = e.getMessage();
int l = Math.min(errStr.length(), 300);
System.out.println(e.getMessage().substring(0, l));
break;
}
// Print to property analysis log, if necessary
if (Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_PROP_LOG)) {
AgreeFileUtil.printLog(result, startTime, modelHash);
}
queue.remove();
}
while (!queue.isEmpty()) {
queue.remove().cancel();
}
AddFaultsToAgree.resetStaticVars();
deactivateTerminateHandlers();
enableRerunHandler(root);
}
};
analysisThread.start();
return Status.OK_STATUS;
}
use of jkind.JKindException in project AMASE by loonwerks.
the class GenMCSHandler method doAnalysis.
// The following method is copied and modified from AGREE VerifyHandler
private IStatus doAnalysis(final Element root, final IProgressMonitor globalMonitor, AnalysisResult result, AgreeResultsLinker linker) {
Thread analysisThread = new Thread() {
@Override
public void run() {
activateTerminateHandlers(globalMonitor);
KindApi api = PreferencesUtil.getKindApi();
KindApi consistApi = PreferencesUtil.getConsistencyApi();
JRealizabilityApi realApi = PreferencesUtil.getJRealizabilityApi();
while (!queue.isEmpty() && !globalMonitor.isCanceled()) {
JKindResult result = queue.peek();
NullProgressMonitor subMonitor = new NullProgressMonitor();
monitorRef.set(subMonitor);
Program program = linker.getProgram(result);
if (api instanceof JKindApi) {
result.getName();
}
try {
if (result instanceof ConsistencyResult) {
consistApi.execute(program, result, subMonitor);
} else if (result instanceof JRealizabilityResult) {
realApi.execute(program, (JRealizabilityResult) result, subMonitor);
} else {
api.execute(program, result, subMonitor);
}
} catch (JKindException e) {
new SafetyException("JKind exception: " + e.getMessage());
System.out.println("******** JKindException Text ********");
e.printStackTrace(System.out);
System.out.println("******** JKind Output ********");
System.out.println(result.getText());
System.out.println("******** Agree Lustre ********");
System.out.println(program);
break;
}
queue.remove();
}
while (!queue.isEmpty()) {
queue.remove().cancel();
}
// then print empty min cut set fault tree
if ((!AddFaultsToNodeVisitor.maxFaultHypothesis && !AddFaultsToNodeVisitor.probabilisticHypothesis) || (AddFaultsToNodeVisitor.maxFaultHypothesis && (AddFaultsToNodeVisitor.maxFaultCount == 0)) || (AddFaultsToNodeVisitor.probabilisticHypothesis && AddFaultsToNodeVisitor.faultCombinationsAboveThreshold.isEmpty())) {
PrintUtils printUtils = new PrintUtils();
printUtils.printEmptyTree();
try {
String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
File file = File.createTempFile("ResolvedFT_" + timeStamp + "_", ".ml");
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
bw.write(printUtils.toString());
bw.close();
org.eclipse.swt.program.Program.launch(file.toString());
} catch (IOException e) {
Dialog.showError("Unable to open file", e.getMessage());
e.printStackTrace();
}
} else {
// open progress bar
// shell.open();
IvcToFTGenerator ftGenerator = new IvcToFTGenerator();
FTResolveVisitor resolveVisitor = new FTResolveVisitor();
FaultTree faultTree = ftGenerator.generateFT(result, linker);
resolveVisitor.visit(faultTree);
LinkedHashMap<String, Set<List<String>>> mapForHFT = ftGenerator.getMapPropertyToMCSs();
try {
String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
File hierarchyFTFile = File.createTempFile("HierarchicalCausalFactors_" + timeStamp + "_", ".txt");
BufferedWriter bw = new BufferedWriter(new FileWriter(hierarchyFTFile));
PrintUtils printUtils = new PrintUtils();
bw.write(printUtils.printHierarchicalText(mapForHFT));
bw.close();
// display.dispose();
org.eclipse.swt.program.Program.launch(hierarchyFTFile.toString());
} catch (IOException e) {
// close progress bar
// display.dispose();
Dialog.showError("Unable to open file", e.getMessage());
e.printStackTrace();
}
try {
String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
File minCutSetFile = File.createTempFile("MinCutSet_" + timeStamp + "_", ".txt");
BufferedWriter bw = new BufferedWriter(new FileWriter(minCutSetFile));
bw.write(faultTree.printMinCutSetTxt());
bw.close();
// display.dispose();
org.eclipse.swt.program.Program.launch(minCutSetFile.toString());
} catch (IOException e) {
// close progress bar
// display.dispose();
Dialog.showError("Unable to open file", e.getMessage());
e.printStackTrace();
}
try {
String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
File minCutSetTallyFile = File.createTempFile("MinCutSetTally_" + timeStamp + "_", ".txt");
BufferedWriter bw = new BufferedWriter(new FileWriter(minCutSetTallyFile));
bw.write(faultTree.printMinCutSetTally());
bw.close();
// display.dispose();
org.eclipse.swt.program.Program.launch(minCutSetTallyFile.toString());
} catch (IOException e) {
// close progress bar
// display.dispose();
Dialog.showError("Unable to open file", e.getMessage());
e.printStackTrace();
}
}
AddFaultsToAgree.resetStaticVars();
deactivateTerminateHandlers();
enableRerunHandler(root);
}
};
analysisThread.start();
return Status.OK_STATUS;
}
use of jkind.JKindException in project AGREE by loonwerks.
the class VerifyHandler method doAnalysis.
protected IStatus doAnalysis(final Element root, final IProgressMonitor globalMonitor) {
Thread analysisThread = new Thread() {
@Override
public void run() {
// Record the analysis start time and get model hashcode for
// saving to property analysis log, if necessary
String modelHash = "";
long startTime = 0;
if (Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_PROP_LOG)) {
try {
modelHash = AgreeFileUtil.getModelHashcode(root);
startTime = System.currentTimeMillis();
} catch (Exception e) {
System.out.println(e.getMessage());
return;
}
}
try {
activateTerminateHandlers(globalMonitor);
KindApi api = PreferencesUtil.getKindApi();
KindApi consistApi = PreferencesUtil.getConsistencyApi();
JRealizabilityApi realApi = PreferencesUtil.getJRealizabilityApi();
while (!queue.isEmpty() && !globalMonitor.isCanceled()) {
JKindResult result = queue.peek();
NullProgressMonitor subMonitor = new NullProgressMonitor();
monitorRef.set(subMonitor);
Program program = linker.getProgram(result);
if (api instanceof JKindApi) {
String resultName = result.getName();
String adviceFileName = rerunAdviceMap.get(resultName);
if (adviceFileName == null) {
adviceFileName = "agree_advice" + adviceCount++;
rerunAdviceMap.put(resultName, adviceFileName);
} else {
((JKindApi) api).setReadAdviceFile(adviceFileName);
}
((JKindApi) api).setWriteAdviceFile(adviceFileName);
}
try {
if (result instanceof ConsistencyResult) {
consistApi.execute(program, result, subMonitor);
} else if (result instanceof JRealizabilityResult) {
realApi.execute(program, (JRealizabilityResult) result, subMonitor);
} else {
api.execute(program, result, subMonitor);
}
} catch (JKindException e) {
System.out.println("******** JKindException Text ********");
e.printStackTrace(System.out);
// System.out.println("******** JKind Output ********");
// System.out.println(result.getText());
// System.out.println("******** Agree Lustre ********");
// System.out.println(program);
String errStr = e.getMessage();
int l = Math.min(errStr.length(), 300);
System.out.println(e.getMessage().substring(0, l));
// >>>>>>> origin/develop
break;
}
// Print to property analysis log, if necessary
if (Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_PROP_LOG)) {
AgreeFileUtil.printLog(result, startTime, modelHash);
}
queue.remove();
}
while (!queue.isEmpty()) {
queue.remove().cancel();
}
} finally {
deactivateTerminateHandlers();
enableRerunHandler(root);
}
}
};
analysisThread.start();
return Status.OK_STATUS;
}
use of jkind.JKindException in project AGREE by loonwerks.
the class Simulation method executeFrame.
private SimulationFrameResults executeFrame(final List<Expr> assertions, final Set<SimulationProperty> disabledProperties) throws InterruptedException {
assert assertions != null;
// Build the final constrained lustre specification for the frame.
final ProgramBuilder programBuilder = new ProgramBuilder(program.getLustreProgram());
programBuilder.clearNodes();
final NodeBuilder nodeBuilder = new NodeBuilder(program.getLustreProgram().getMainNode());
// Add assignments for the sim assertions signal
// Actual assertions are not used because they can result in an inconsistent Lustre program which will prevent
// the set of support from being generated when using yices.
Expr prevSimAssertionExpr = new BoolExpr(true);
for (int assertionIndex = 0; assertionIndex < assertions.size(); assertionIndex++) {
final String simAssertionSignalId = CreateSimulationGuarantee.SIMULATION_ASSERTIONS_ID + assertionIndex;
final IdExpr simAssertionExpr = new IdExpr(simAssertionSignalId);
nodeBuilder.addLocal(new VarDecl(simAssertionSignalId, NamedType.BOOL));
nodeBuilder.addEquation(new Equation(simAssertionExpr, new BinaryExpr(prevSimAssertionExpr, BinaryOp.AND, assertions.get(assertionIndex))));
prevSimAssertionExpr = simAssertionExpr;
}
nodeBuilder.addEquation(new Equation(new IdExpr(CreateSimulationGuarantee.SIMULATION_ASSERTIONS_ID), prevSimAssertionExpr));
// Add assignments for property enablement variables
for (final SimulationProperty simProp : program.getSimulationProperties()) {
if (simProp.getEnablementVariableId() != null) {
nodeBuilder.addEquation(new Equation(new IdExpr(simProp.getEnablementVariableId()), new BoolExpr(disabledProperties.contains(simProp) ? false : true)));
}
}
// Build the lustre program for the frame
programBuilder.addNode(nodeBuilder.build());
final Program constrainedLustreProgram = programBuilder.build();
// Prepare to execute JKind
final KindApi api = PreferencesUtil.getKindApi();
// Enable IVC Reduction capability if using JKind
if (api instanceof JKindApi) {
final JKindApi jkindApi = (JKindApi) api;
jkindApi.setIvcReduction();
}
// Execute JKind
final JKindResult result = new JKindResult("Simulation");
// Lucas: This seems to be needed. If we do not add properties to the result explicitly,
// it looks like the result will grab the main property name with the main node prepended.
// This is causing an error when retrieving the property result in the
// if/then/else block structure below.
constrainedLustreProgram.getMainNode().properties.forEach(p -> result.addProperty(p));
System.out.println(constrainedLustreProgram.toString());
try {
final IProgressMonitor currentMonitor = new NullProgressMonitor();
api.execute(constrainedLustreProgram, result, currentMonitor);
// Create a model state from the results.
String simulationGuaranteeId = CreateSimulationGuarantee.SIMULATION_GUARANTEE_ID;
final PropertyResult propertyResult = result.getPropertyResult(simulationGuaranteeId);
final Property property = propertyResult.getProperty();
if (property == null) {
throw new AGREESimulatorException("Unexpected case. Unable to read property results", constrainedLustreProgram);
} else if (property instanceof InvalidProperty) {
final InvalidProperty invalidProperty = (InvalidProperty) property;
final Counterexample counterexample = invalidProperty.getCounterexample();
if (counterexample.getLength() != 1) {
throw new AGREESimulatorException("Unexpected case. Counterexample has " + counterexample.getLength() + " steps", constrainedLustreProgram);
}
SimulationState newState = SimulationState.WAITING_FOR_COMMANDS;
// and a counterexample will not have been generated. This should only occur when a disabled property, lemma, top-level guarantee, or a non-top-level assumption is false.
for (final SimulationProperty simulationProp : program.getSimulationProperties()) {
if (!disabledProperties.contains(simulationProp)) {
for (final String propLustreId : simulationProp.getLustreIds()) {
final Signal<BooleanValue> signal = counterexample.getBooleanSignal(propLustreId);
if (signal == null) {
throw new AGREESimulatorException("Unable to get signal for guarantee property: " + propLustreId, constrainedLustreProgram);
} else {
if (!signal.getValue(0).value) {
newState = SimulationState.WARNING_PROPERTY_NOT_SATISFIED;
break;
}
}
}
}
}
return new SimulationFrameResults(constrainedLustreProgram, counterexample, disabledProperties, newState);
} else if (property instanceof UnknownProperty) {
return new SimulationFrameResults(constrainedLustreProgram, assertions, disabledProperties, SimulationState.HALTED_UNABLE_TO_SATISFY_CONSTRAINTS);
} else if (property instanceof ValidProperty) {
return new SimulationFrameResults(constrainedLustreProgram, assertions, disabledProperties, ((ValidProperty) property).getIvc(), SimulationState.HALTED_UNABLE_TO_SATISFY_CONSTRAINTS);
} else {
throw new AGREESimulatorException("Unhandled case. Property is of type: " + property.getClass(), constrainedLustreProgram);
}
} catch (JKindException ex) {
if (ex.getCause() instanceof InterruptedException) {
throw (InterruptedException) ex.getCause();
}
throw new AGREESimulatorException(constrainedLustreProgram, ex, result.getText());
}
}
Aggregations