Search in sources :

Example 6 with ValidProperty

use of jkind.results.ValidProperty in project AMASE by loonwerks.

the class IvcToSoteriaGenerator method extractPropertyResult.

private void extractPropertyResult(SoteriaComp comp, AgreeRenaming renaming, PropertyResult propertyResult) {
    // get original property name
    String origPropertyName = propertyResult.getName();
    String lustreName = renaming.getLustreNameFromAgreeVar(origPropertyName);
    String propertyName = updateElemName(comp.componentName + "_" + lustreName);
    // if it is a guarantee
    if (lustreName.startsWith("__GUARANTEE")) {
        // if it's a valid guarantee
        if (propertyResult.getStatus().equals(jkind.api.results.Status.VALID)) {
            // add property as an output to the soteria map
            comp.addOutput(propertyName);
            // add property violation as a top level fault to the model
            if (!isLowerLevel) {
                CompContractViolation contractViolation = new CompContractViolation(comp.componentName, propertyName);
                model.addTopLevelFault(contractViolation);
            }
            ValidProperty property = (ValidProperty) propertyResult.getProperty();
            SoteriaFormula formula = new SoteriaFormula(propertyName);
            // handle multiple ivc sets
            for (List<String> ivcSet : property.getIvcSets()) {
                SoteriaFormulaSubgroup formulaSubgroup = new SoteriaFormulaSubgroup(propertyName);
                extractIvcSets(comp, renaming, formulaSubgroup, ivcSet);
                if (!formulaSubgroup.elmeList.isEmpty()) {
                    formula.addFormulaSubgroup(formulaSubgroup);
                }
            }
            if (!formula.formulaBody.isEmpty()) {
                comp.addFormula(propertyName, formula);
            }
        } else if (propertyResult.getStatus().equals(jkind.api.results.Status.CANCELED)) {
            throw new SafetyException("One of the properties was canceled in the process of model checking." + " Rerun this analysis to proceed.");
        } else if (propertyResult.getStatus().equals(jkind.api.results.Status.INVALID)) {
            throw new SafetyException("One of the properties is invalid. The model must be valid using AGREE Verify All Layers.");
        }
    }
}
Also used : CompContractViolation(edu.umn.cs.crisys.safety.analysis.soteria.CompContractViolation) ValidProperty(jkind.results.ValidProperty) SoteriaFormulaSubgroup(edu.umn.cs.crisys.safety.analysis.soteria.SoteriaFormulaSubgroup) SoteriaFormula(edu.umn.cs.crisys.safety.analysis.soteria.SoteriaFormula) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException)

Example 7 with ValidProperty

use of jkind.results.ValidProperty in project AGREE by loonwerks.

the class AgreeMenuListener method writeIvcResult.

public static void writeIvcResult(AnalysisResult result, final MessageConsole console, final AgreeRenaming renaming) {
    try (MessageConsoleStream out = console.newMessageStream()) {
        ValidProperty vp = (ValidProperty) (((PropertyResult) result).getProperty());
        printHLine(out, 2);
        out.println("Set of Support for Guarantee: " + "{" + vp.getName() + "}");
        printHLine(out, 2);
        if (!vp.getIvc().isEmpty()) {
            printHLine(out, 2);
            out.println(String.format("%-25s%-25s", "Component name", "Property name"));
            printHLine(out, 2);
            for (String supportString : vp.getIvc()) {
                String componentName = "";
                String refStr = renaming.getSupportRefString(supportString);
                if (supportString.contains(".")) {
                    componentName = supportString.substring(0, supportString.indexOf('.'));
                } else {
                    componentName = "Top Level System";
                }
                out.println(String.format("%-25s%-25s", componentName, "{" + refStr + "}"));
            }
            printHLine(out, 2);
        } else {
            out.println("There are no support elements to display.");
        }
        out.println("");
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ValidProperty(jkind.results.ValidProperty) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) IOException(java.io.IOException) PropertyResult(jkind.api.results.PropertyResult)

Example 8 with ValidProperty

use of jkind.results.ValidProperty 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

ValidProperty (jkind.results.ValidProperty)8 PropertyResult (jkind.api.results.PropertyResult)6 HashSet (java.util.HashSet)3 JKindResult (jkind.api.results.JKindResult)3 SafetyException (edu.umn.cs.crisys.safety.analysis.SafetyException)2 InvalidProperty (jkind.results.InvalidProperty)2 GuaranteeStatement (com.rockwellcollins.atc.agree.agree.GuaranteeStatement)1 AgreeRenaming (com.rockwellcollins.atc.agree.analysis.AgreeRenaming)1 SimulationProgram (edu.uah.rsesc.aadlsimulator.agree.SimulationProgram)1 SimulationProperty (edu.uah.rsesc.aadlsimulator.agree.SimulationProperty)1 AddFaultDriverGuardAssertionVisitor (edu.umn.cs.crisys.safety.analysis.ast.visitors.AddFaultDriverGuardAssertionVisitor)1 AddFaultDriverVisitor (edu.umn.cs.crisys.safety.analysis.ast.visitors.AddFaultDriverVisitor)1 AddPairwiseFaultDriverWitnesses (edu.umn.cs.crisys.safety.analysis.ast.visitors.AddPairwiseFaultDriverWitnesses)1 FTAndNode (edu.umn.cs.crisys.safety.analysis.faultTree.FTAndNode)1 FTNonLeafNode (edu.umn.cs.crisys.safety.analysis.faultTree.FTNonLeafNode)1 FTOrNode (edu.umn.cs.crisys.safety.analysis.faultTree.FTOrNode)1 SafetyJKindResult (edu.umn.cs.crisys.safety.analysis.results.SafetyJKindResult)1 CompContractViolation (edu.umn.cs.crisys.safety.analysis.soteria.CompContractViolation)1 SoteriaFormula (edu.umn.cs.crisys.safety.analysis.soteria.SoteriaFormula)1 SoteriaFormulaSubgroup (edu.umn.cs.crisys.safety.analysis.soteria.SoteriaFormulaSubgroup)1