Search in sources :

Example 6 with KindApi

use of jkind.api.KindApi 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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) JRealizabilityResult(jkind.api.results.JRealizabilityResult) Program(jkind.lustre.Program) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) JKindException(jkind.JKindException) Set(java.util.Set) FileWriter(java.io.FileWriter) IvcToFTGenerator(edu.umn.cs.crisys.safety.analysis.generators.IvcToFTGenerator) IOException(java.io.IOException) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException) FTResolveVisitor(edu.umn.cs.crisys.safety.analysis.ast.visitors.FTResolveVisitor) Date(java.util.Date) JKindResult(jkind.api.results.JKindResult) JKindApi(jkind.api.JKindApi) PrintUtils(edu.umn.cs.crisys.safety.analysis.ast.visitors.PrintUtils) BufferedWriter(java.io.BufferedWriter) JRealizabilityApi(jkind.api.JRealizabilityApi) ConsistencyResult(com.rockwellcollins.atc.agree.analysis.ConsistencyResult) FaultTree(edu.umn.cs.crisys.safety.analysis.faultTree.FaultTree) KindApi(jkind.api.KindApi) JKindApi(jkind.api.JKindApi) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File)

Example 7 with KindApi

use of jkind.api.KindApi 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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) JRealizabilityResult(jkind.api.results.JRealizabilityResult) Program(jkind.lustre.Program) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) JKindException(jkind.JKindException) PartInitException(org.eclipse.ui.PartInitException) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) JKindException(jkind.JKindException) JKindResult(jkind.api.results.JKindResult) JKindApi(jkind.api.JKindApi) JRealizabilityApi(jkind.api.JRealizabilityApi) ConsistencyResult(com.rockwellcollins.atc.agree.analysis.ConsistencyResult) KindApi(jkind.api.KindApi) JKindApi(jkind.api.JKindApi)

Example 8 with KindApi

use of jkind.api.KindApi in project AGREE by loonwerks.

the class AgreePreferencePage method checkAvailable.

private void checkAvailable() {
    try {
        String remoteUrl = remoteUrlFieldEditor.getStringValue();
        KindApi api = PreferencesUtil.getKindApi(selectedModelChecker, remoteUrl);
        String details = api.checkAvailable();
        MessageDialog.openInformation(getShell(), "Model checker available", details);
    } catch (Throwable t) {
        MessageDialog.openError(getShell(), "Error running model checker", "Error running model checker: " + t.getMessage());
    }
}
Also used : KindApi(jkind.api.KindApi)

Example 9 with KindApi

use of jkind.api.KindApi in project AGREE by loonwerks.

the class PreferencesUtil method getKindApi.

public static KindApi getKindApi() {
    IPreferenceStore prefs = getPreferenceStore();
    String modelChecker = prefs.getString(PreferenceConstants.PREF_MODEL_CHECKER);
    String remoteUrl = prefs.getString(PreferenceConstants.PREF_REMOTE_URL);
    KindApi api = getKindApi(modelChecker, remoteUrl);
    if (prefs.getBoolean(PreferenceConstants.PREF_DEBUG)) {
        api.setApiDebug();
    }
    return api;
}
Also used : KindApi(jkind.api.KindApi) JKindApi(jkind.api.JKindApi) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 10 with KindApi

use of jkind.api.KindApi 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());
    }
}
Also used : BoolExpr(jkind.lustre.BoolExpr) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) UnknownProperty(jkind.results.UnknownProperty) ValidProperty(jkind.results.ValidProperty) NodeBuilder(jkind.lustre.builders.NodeBuilder) Counterexample(jkind.results.Counterexample) PropertyResult(jkind.api.results.PropertyResult) JKindApi(jkind.api.JKindApi) Signal(jkind.results.Signal) VarDecl(jkind.lustre.VarDecl) SimulationProperty(edu.uah.rsesc.aadlsimulator.agree.SimulationProperty) KindApi(jkind.api.KindApi) JKindApi(jkind.api.JKindApi) SimulationProperty(edu.uah.rsesc.aadlsimulator.agree.SimulationProperty) ValidProperty(jkind.results.ValidProperty) Property(jkind.results.Property) UnknownProperty(jkind.results.UnknownProperty) InvalidProperty(jkind.results.InvalidProperty) InvalidProperty(jkind.results.InvalidProperty) Program(jkind.lustre.Program) SimulationProgram(edu.uah.rsesc.aadlsimulator.agree.SimulationProgram) JKindException(jkind.JKindException) IdExpr(jkind.lustre.IdExpr) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) BinaryExpr(jkind.lustre.BinaryExpr) Equation(jkind.lustre.Equation) JKindResult(jkind.api.results.JKindResult) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr)

Aggregations

KindApi (jkind.api.KindApi)10 JKindApi (jkind.api.JKindApi)8 JKindException (jkind.JKindException)5 JKindResult (jkind.api.results.JKindResult)5 Program (jkind.lustre.Program)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)4 ConsistencyResult (com.rockwellcollins.atc.agree.analysis.ConsistencyResult)3 AgreeProgram (com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram)3 JRealizabilityApi (jkind.api.JRealizabilityApi)3 JRealizabilityResult (jkind.api.results.JRealizabilityResult)3 AgreeException (com.rockwellcollins.atc.agree.analysis.AgreeException)2 SafetyException (edu.umn.cs.crisys.safety.analysis.SafetyException)2 PartInitException (org.eclipse.ui.PartInitException)2 TcgRenaming (com.rockwellcollins.atc.tcg.obligations.ufc.TcgRenaming)1 TestSuite (com.rockwellcollins.atc.tcg.suite.TestSuite)1 SimulationProgram (edu.uah.rsesc.aadlsimulator.agree.SimulationProgram)1 SimulationProperty (edu.uah.rsesc.aadlsimulator.agree.SimulationProperty)1 FTResolveVisitor (edu.umn.cs.crisys.safety.analysis.ast.visitors.FTResolveVisitor)1 PrintUtils (edu.umn.cs.crisys.safety.analysis.ast.visitors.PrintUtils)1