Search in sources :

Example 6 with AgreeRenaming

use of com.rockwellcollins.atc.agree.analysis.AgreeRenaming in project AMASE by loonwerks.

the class GenMCSHandler method createVerification.

/**
 * Copied from AGREE VerifyHandler - allows for min cut set Analysis Type in
 * param analysisType
 *
 * @param resultName
 * @param compInst
 * @param lustreProgram
 * @param agreeProgram
 * @param analysisType
 * @return
 */
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 JKindResult(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);
    return result;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) JRealizabilityResult(jkind.api.results.JRealizabilityResult) AgreeRenaming(com.rockwellcollins.atc.agree.analysis.AgreeRenaming) Node(jkind.lustre.Node) ArrayList(java.util.ArrayList) JKindResult(jkind.api.results.JKindResult) AgreeAutomaterRegistry(com.rockwellcollins.atc.agree.analysis.extentions.AgreeAutomaterRegistry) AgreeLayout(com.rockwellcollins.atc.agree.analysis.AgreeLayout) ConsistencyResult(com.rockwellcollins.atc.agree.analysis.ConsistencyResult) AgreeAutomater(com.rockwellcollins.atc.agree.analysis.extentions.AgreeAutomater) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Example 7 with AgreeRenaming

use of com.rockwellcollins.atc.agree.analysis.AgreeRenaming in project AMASE by loonwerks.

the class SafetyAnalysisResultLabelProvider method getText.

@Override
public String getText(Object element) {
    if (element instanceof SafetyPropertyResult) {
        SafetyPropertyResult pr = (SafetyPropertyResult) element;
        switch(column) {
            case PROPERTY:
                if (AddPairwiseFaultDriverWitnesses.FAULT_DRIVER_PAIR_WITNESS_PATTERN.matcher(pr.getName()).find()) {
                    List<String> guarantees = new ArrayList<>();
                    AgreeRenaming renaming = (AgreeRenaming) pr.getRenaming();
                    final Pattern GUARANTEE_PATTERN = Pattern.compile(renaming.forceRename(GUARANTEE_BASENAME).replaceAll(".", "\\.") + "(\\d+)");
                    Matcher matcher = GUARANTEE_PATTERN.matcher(pr.getName());
                    while (matcher.find()) {
                        String varName = GUARANTEE_BASENAME + matcher.group(1);
                        String guaranteeName = renaming.rename(varName);
                        if (guaranteeName.length() > TRUNCATION_LENGTH) {
                            guaranteeName = guaranteeName.substring(0, TRUNCATION_LENGTH) + " ...";
                        }
                        guarantees.add("\"" + guaranteeName + "\"");
                    }
                    return String.join(" and ", guarantees) + " cannot fail together";
                }
            default:
        }
    }
    return super.getText(element);
}
Also used : Pattern(java.util.regex.Pattern) SafetyPropertyResult(edu.umn.cs.crisys.safety.analysis.results.SafetyPropertyResult) AgreeRenaming(com.rockwellcollins.atc.agree.analysis.AgreeRenaming) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList)

Example 8 with AgreeRenaming

use of com.rockwellcollins.atc.agree.analysis.AgreeRenaming in project AGREE by loonwerks.

the class VerifyHandler method createVerification.

private AnalysisResult createVerification(String resultName, ComponentInstance compInst, Program lustreProgram, AgreeProgram agreeProgram, AnalysisType analysisType) {
    // ///////
    // Logger logger = Logger.getLogger("MyLog");
    // FileHandler fh;
    // try {
    // This block configure the logger with handler and formatter
    // fh = new FileHandler("/home/thomas/zzz.log");
    // logger.addHandler(fh);
    // SimpleFormatter formatter = new SimpleFormatter();
    // fh.setFormatter(formatter);
    // logger.info("Agree Program:");
    // AgreeASTPrettyprinter pp = new AgreeASTPrettyprinter();
    // pp.visit(agreeProgram);
    // logger.info(pp.toString());
    // } catch (SecurityException ex) {
    // ex.printStackTrace();
    // }
    // catch (IOException ex) {
    // ex.printStackTrace();
    // }
    // //////////////
    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:
            final Set<String> invertedProperties = renaming.getInvertedProperties();
            List<Boolean> invertedPropertyMask = mainNode.properties.stream().map(p -> invertedProperties.contains(p)).collect(Collectors.toList());
            result = new JKindResult(resultName, properties, invertedPropertyMask, 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;
}
Also used : AnnexUtil(org.osate.annexsupport.AnnexUtil) Element(org.osate.aadl2.Element) Program(jkind.lustre.Program) EphemeralImplementationUtil(com.rockwellcollins.atc.agree.analysis.EphemeralImplementationUtil) AnalysisResult(jkind.api.results.AnalysisResult) CompositeAnalysisResult(jkind.api.results.CompositeAnalysisResult) IStatus(org.eclipse.core.runtime.IStatus) AgreeAutomaterRegistry(com.rockwellcollins.atc.agree.analysis.extentions.AgreeAutomaterRegistry) Classifier(org.osate.aadl2.Classifier) PartInitException(org.eclipse.ui.PartInitException) Map(java.util.Map) ComponentType(org.osate.aadl2.ComponentType) RenamingVisitor(com.rockwellcollins.atc.agree.analysis.lustre.visitors.RenamingVisitor) IViewPart(org.eclipse.ui.IViewPart) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) PrintWriter(java.io.PrintWriter) SystemInstance(org.osate.aadl2.instance.SystemInstance) AgreeContractSubclause(com.rockwellcollins.atc.agree.agree.AgreeContractSubclause) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) AadlPackage(org.osate.aadl2.AadlPackage) PreferencesUtil(com.rockwellcollins.atc.agree.analysis.preferences.PreferencesUtil) Collectors(java.util.stream.Collectors) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) LustreAstBuilder(com.rockwellcollins.atc.agree.analysis.translation.LustreAstBuilder) IHandlerService(org.eclipse.ui.handlers.IHandlerService) Node(jkind.lustre.Node) List(java.util.List) AgreeUtils(com.rockwellcollins.atc.agree.analysis.AgreeUtils) JRealizabilityApi(jkind.api.JRealizabilityApi) Queue(java.util.Queue) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) AgreeAutomater(com.rockwellcollins.atc.agree.analysis.extentions.AgreeAutomater) ExtensionRegistry(com.rockwellcollins.atc.agree.analysis.extentions.ExtensionRegistry) Dialog(org.osate.ui.dialogs.Dialog) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) AgreePackage(com.rockwellcollins.atc.agree.agree.AgreePackage) ConsistencyResult(com.rockwellcollins.atc.agree.analysis.ConsistencyResult) AgreeSubclause(com.rockwellcollins.atc.agree.agree.AgreeSubclause) Activator(com.rockwellcollins.atc.agree.analysis.Activator) LustreContractAstBuilder(com.rockwellcollins.atc.agree.analysis.translation.LustreContractAstBuilder) ComponentImplementation(org.osate.aadl2.ComponentImplementation) AnalysisErrorReporterManager(org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager) HashMap(java.util.HashMap) AgreeLayout(com.rockwellcollins.atc.agree.analysis.AgreeLayout) AtomicReference(java.util.concurrent.atomic.AtomicReference) Message(org.osate.aadl2.modelsupport.errorreporting.QueuingAnalysisErrorReporter.Message) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Pair(org.eclipse.xtext.util.Pair) AgreeResultsLinker(com.rockwellcollins.atc.agree.analysis.views.AgreeResultsLinker) JKindResult(jkind.api.results.JKindResult) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) AgreeLogger(com.rockwellcollins.atc.agree.analysis.AgreeLogger) AgreeResultsView(com.rockwellcollins.atc.agree.analysis.views.AgreeResultsView) KindApi(jkind.api.KindApi) JRealizabilityResult(jkind.api.results.JRealizabilityResult) Shell(org.eclipse.swt.widgets.Shell) AadlUtil(org.osate.aadl2.modelsupport.util.AadlUtil) JKindException(jkind.JKindException) StringWriter(java.io.StringWriter) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) JKindApi(jkind.api.JKindApi) AgreeFileUtil(com.rockwellcollins.atc.agree.analysis.saving.AgreeFileUtil) QueuingAnalysisErrorReporter(org.osate.aadl2.modelsupport.errorreporting.QueuingAnalysisErrorReporter) PreferenceConstants(com.rockwellcollins.atc.agree.analysis.preferences.PreferenceConstants) AgreeRenaming(com.rockwellcollins.atc.agree.analysis.AgreeRenaming) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) AnnexSubclause(org.osate.aadl2.AnnexSubclause) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) AgreeASTBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeASTBuilder) ComponentImplementation(org.osate.aadl2.ComponentImplementation) JRealizabilityResult(jkind.api.results.JRealizabilityResult) AgreeRenaming(com.rockwellcollins.atc.agree.analysis.AgreeRenaming) Node(jkind.lustre.Node) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) ArrayList(java.util.ArrayList) JKindResult(jkind.api.results.JKindResult) AgreeAutomaterRegistry(com.rockwellcollins.atc.agree.analysis.extentions.AgreeAutomaterRegistry) AgreeLayout(com.rockwellcollins.atc.agree.analysis.AgreeLayout) ConsistencyResult(com.rockwellcollins.atc.agree.analysis.ConsistencyResult) AgreeAutomater(com.rockwellcollins.atc.agree.analysis.extentions.AgreeAutomater) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Example 9 with AgreeRenaming

use of com.rockwellcollins.atc.agree.analysis.AgreeRenaming in project AGREE by loonwerks.

the class AgreeMenuListener method addViewSupportConsole.

private IAction addViewSupportConsole(String text, IMenuManager manager, AnalysisResult result) {
    return new Action(text) {

        @Override
        public void run() {
            Map<String, EObject> tempRefMap = linker.getReferenceMap(result.getParent());
            if (tempRefMap == null) {
                tempRefMap = linker.getReferenceMap(result);
            }
            final Map<String, EObject> refMap = tempRefMap;
            final MessageConsole console = findConsole("Support");
            Renaming tempRenaming = linker.getRenaming(result);
            while (tempRenaming == null) {
                AnalysisResult parent = result.getParent();
                if (parent == null) {
                    throw new AgreeException("Problem finding renaming");
                }
                tempRenaming = linker.getRenaming(parent);
            }
            final Renaming renaming = tempRenaming;
            showConsole(console);
            console.clearConsole();
            if (patternListener != null) {
                console.removePatternMatchListener(patternListener);
            }
            patternListener = new AgreePatternListener(refMap);
            console.addPatternMatchListener(patternListener);
            new Thread(() -> {
                if (renaming instanceof AgreeRenaming) {
                    writeIvcResult(result, console, (AgreeRenaming) renaming);
                }
            }).start();
        }
    };
}
Also used : IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) MessageConsole(org.eclipse.ui.console.MessageConsole) AgreeRenaming(com.rockwellcollins.atc.agree.analysis.AgreeRenaming) EObject(org.eclipse.emf.ecore.EObject) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) AnalysisResult(jkind.api.results.AnalysisResult) AgreeRenaming(com.rockwellcollins.atc.agree.analysis.AgreeRenaming) Renaming(jkind.api.results.Renaming)

Example 10 with AgreeRenaming

use of com.rockwellcollins.atc.agree.analysis.AgreeRenaming in project AGREE by loonwerks.

the class AgreeMenuListener method addViewTraceabilityConsole.

private IAction addViewTraceabilityConsole(String text, IMenuManager manager, AnalysisResult result) {
    return new Action(text) {

        @Override
        public void run() {
            Map<String, EObject> tempRefMap = linker.getReferenceMap(result.getParent());
            if (tempRefMap == null) {
                tempRefMap = linker.getReferenceMap(result);
            }
            final Map<String, EObject> refMap = tempRefMap;
            final MessageConsole console = findConsole("Traceability");
            final Renaming renaming = linker.getRenaming(result);
            showConsole(console);
            console.clearConsole();
            console.addPatternMatchListener(new AgreePatternListener(refMap));
            new Thread(() -> {
                try {
                    MessageConsoleStream out = console.newMessageStream();
                    printHLine(out, 2);
                    out.println("Traceability for Valid Contract Guarantees");
                    printHLine(out, 2);
                    out.println("");
                    List<PropertyResult> allProperties = new ArrayList<PropertyResult>(((JKindResult) result).getPropertyResults());
                    if (!allProperties.isEmpty()) {
                        for (PropertyResult prop : allProperties) {
                            if (prop.getStatus().equals(jkind.api.results.Status.VALID)) {
                                if (renaming instanceof AgreeRenaming) {
                                    writeIvcResult(prop, console, (AgreeRenaming) renaming);
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }).start();
        }
    };
}
Also used : IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) MessageConsole(org.eclipse.ui.console.MessageConsole) AgreeRenaming(com.rockwellcollins.atc.agree.analysis.AgreeRenaming) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) PropertyResult(jkind.api.results.PropertyResult) PartInitException(org.eclipse.ui.PartInitException) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) AgreeRenaming(com.rockwellcollins.atc.agree.analysis.AgreeRenaming) Renaming(jkind.api.results.Renaming) JKindResult(jkind.api.results.JKindResult) EObject(org.eclipse.emf.ecore.EObject) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

AgreeRenaming (com.rockwellcollins.atc.agree.analysis.AgreeRenaming)12 AgreeException (com.rockwellcollins.atc.agree.analysis.AgreeException)8 ArrayList (java.util.ArrayList)8 JKindResult (jkind.api.results.JKindResult)8 ComponentImplementation (org.osate.aadl2.ComponentImplementation)7 AgreeLayout (com.rockwellcollins.atc.agree.analysis.AgreeLayout)6 Node (jkind.lustre.Node)5 ConsistencyResult (com.rockwellcollins.atc.agree.analysis.ConsistencyResult)4 AgreeAutomater (com.rockwellcollins.atc.agree.analysis.extentions.AgreeAutomater)4 AgreeAutomaterRegistry (com.rockwellcollins.atc.agree.analysis.extentions.AgreeAutomaterRegistry)4 AnalysisResult (jkind.api.results.AnalysisResult)4 JRealizabilityResult (jkind.api.results.JRealizabilityResult)4 Renaming (jkind.api.results.Renaming)4 EObject (org.eclipse.emf.ecore.EObject)4 Action (org.eclipse.jface.action.Action)4 IAction (org.eclipse.jface.action.IAction)4 List (java.util.List)3 PropertyResult (jkind.api.results.PropertyResult)3 Program (jkind.lustre.Program)3 InvalidProperty (jkind.results.InvalidProperty)3