Search in sources :

Example 71 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance in project osate-plugin by sireum.

the class HAMRUtil method checkModel.

public static List<Report> checkModel(SystemInstance root, HAMRPrompt prompt) {
    boolean targetSel4 = prompt.getOptionPlatform() == Platform.seL4 || prompt.getOptionPlatform() == Platform.seL4_Only || prompt.getOptionPlatform() == Platform.seL4_TB;
    boolean trustedBuild = prompt.getOptionPlatform() == Platform.seL4_Only || prompt.getOptionPlatform() == Platform.seL4_TB;
    boolean treatDevicesAsThreads = PreferenceValues.HAMR_DEVICES_AS_THREADS_OPT.getValue();
    List<Report> ret = new ArrayList<>();
    // List<ComponentInstance> allThreads = root.getAllComponentInstances().stream()
    // .filter(f -> isThread(f)).collect(Collectors.toList());
    // List<ComponentInstance> allDevices = root.getAllComponentInstances().stream()
    // .filter(f -> isDevice(f)).collect(Collectors.toList());
    List<ConnectionInstance> allConnections = root.getAllComponentInstances().stream().flatMap(f -> f.getConnectionInstances().stream()).collect(Collectors.toList());
    if (!trustedBuild) {
        List<ConnectionInstance> threadDeviceConnections = allConnections.stream().filter(conn -> {
            ComponentInstance src = conn.getSource().getComponentInstance();
            ComponentInstance dst = conn.getDestination().getComponentInstance();
            return treatDevicesAsThreads ? isThreadOrDevice(src) && isThreadOrDevice(dst) : isThread(src) && isThread(dst);
        }).collect(Collectors.toList());
        for (ConnectionInstance conn : threadDeviceConnections) {
            if (conn.getKind() != ConnectionKind.PORT_CONNECTION) {
                String msg = "HAMR integration does not currently support " + conn.getKind();
                if (targetSel4) {
                    msg += ". Use the '" + Platform.seL4_Only + "' or " + Platform.seL4_TB + "' option if only targeting CAmkES.";
                }
            // ret.add(inst.new ErrorReport(conn, msg));
            }
        }
    }
    return ret;
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) SystemInstance(org.osate.aadl2.instance.SystemInstance) List(java.util.List) ComponentCategory(org.osate.aadl2.ComponentCategory) ConnectionKind(org.osate.aadl2.instance.ConnectionKind) Platform(org.sireum.aadl.osate.hamr.handlers.HAMRPropertyProvider.Platform) NamedElement(org.osate.aadl2.NamedElement) PreferenceValues(org.sireum.aadl.osate.hamr.PreferenceValues) Collectors(java.util.stream.Collectors) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) ComponentInstance(org.osate.aadl2.instance.ComponentInstance)

Example 72 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance in project osate-plugin by sireum.

the class SireumTest method getSystemInstance.

protected SystemInstance getSystemInstance(AadlSystem system) {
    try {
        ResourceSet rset = createResourceSet(system.projects);
        Resource sysImplResource = null;
        String candURI = "platform:/resource/" + system.systemFileContainer.get().proj.projectName + "/" + system.systemFileContainer.get().projectRelativePath;
        for (Resource rs : rset.getResources()) {
            if (rs.getURI().toString().equals(candURI)) {
                sysImplResource = rs;
                break;
            }
        }
        if (sysImplResource != null) {
            final AadlPackage pkg = (AadlPackage) (sysImplResource.getContents().isEmpty() ? null : sysImplResource.getContents().get(0));
            SystemImplementation sysImpl = (SystemImplementation) AadlProjectUtil.getResourceByName(system.systemImplementationName, pkg.getOwnedPublicSection().getOwnedClassifiers());
            return InstantiateModel.instantiate(sysImpl);
        } else {
            throw new RuntimeException("Couldn't find resource " + system.systemFileContainer.get().systemImplementationFile);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.exit(1);
    return null;
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) SystemImplementation(org.osate.aadl2.SystemImplementation) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException)

Example 73 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance in project osate-plugin by sireum.

the class SireumTest method execute.

public void execute(File modelDir, String sysFilename, String sysImplName) {
    try {
        File root = modelDir;
        List<File> aadlFiles = IOUtils.collectFiles(root, ".aadl", true);
        File sysImplFile = new File(root, sysFilename);
        assert sysImplFile.exists() : sysImplFile.getAbsolutePath() + "doesn't exist";
        AadlProject project = new AadlProject(root.getName(), root, aadlFiles);
        AadlSystem system = AadlSystem.makeAadlSystem(sysImplName, Optional.of(sysImplFile), Arrays.asList(project), null);
        SystemInstance instance = getSystemInstance(system);
        Aadl model = Util.getAir(instance, true, System.out);
        String ir = Util.serialize(model, SerializerType.JSON);
        if (writeResults) {
            File results = new File(root, sysImplName + "_results.json");
            IOUtils.writeFile(results, ir);
        }
        File expectedFile = new File(root, sysImplName + ".json");
        String expected = null;
        if (generateExpected) {
            IOUtils.writeFile(expectedFile, ir);
            expected = ir;
        } else {
            Assert.assertTrue("Expected results not found: " + expectedFile.getCanonicalPath(), expectedFile.exists());
            expected = IOUtils.readFile(expectedFile);
        }
        Assert.assertEquals(expected, ir);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.assertFalse(true);
    }
}
Also used : SystemInstance(org.osate.aadl2.instance.SystemInstance) Aadl(org.sireum.hamr.ir.Aadl) AadlProject(org.sireum.aadl.osate.util.AadlProjectUtil.AadlProject) AadlSystem(org.sireum.aadl.osate.util.AadlProjectUtil.AadlSystem) File(java.io.File) IOException(java.io.IOException)

Example 74 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance in project osate-plugin by sireum.

the class AirUpdater method regen.

void regen(AadlSystem system) {
    SystemInstance instance = getSystemInstance(system);
    assert instance != null : "System is null " + system.systemImplementationName;
    String air = Util.serialize(Util.getAir(instance, true), SerializerType.JSON);
    String instanceFilename = Util.toIFile(instance.eResource().getURI()).getName();
    String fname = instanceFilename.substring(0, instanceFilename.lastIndexOf(".")) + ".json";
    File slangDir = new File(system.projects.get(0).rootDirectory, File.separator + ".slang");
    slangDir.mkdir();
    assert slangDir.exists() && slangDir.isDirectory() : slangDir + " does not exist";
    File outFile = new File(slangDir, fname);
    IOUtils.writeFile(outFile, air);
}
Also used : SystemInstance(org.osate.aadl2.instance.SystemInstance) File(java.io.File)

Example 75 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance in project osate-plugin by sireum.

the class AbstractSireumHandler method getSystemInstance.

protected SystemInstance getSystemInstance(Element e) {
    if (e != null) {
        if (e instanceof SystemInstance) {
            return (SystemInstance) e;
        }
        if (e instanceof SystemImplementation) {
            try {
                SystemImplementation si = (SystemImplementation) e;
                writeToConsole("Generating System Instance ...");
                return InstantiateModel.buildInstanceModelFile(si);
            } catch (Exception ex) {
                Dialog.showError(getToolName(), "Could not instantiate model");
                ex.printStackTrace();
            }
        }
    }
    return null;
}
Also used : SystemInstance(org.osate.aadl2.instance.SystemInstance) SystemImplementation(org.osate.aadl2.SystemImplementation) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Aggregations

SystemInstance (org.osate.aadl2.instance.SystemInstance)100 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)52 InstanceObject (org.osate.aadl2.instance.InstanceObject)26 ComponentImplementation (org.osate.aadl2.ComponentImplementation)25 Element (org.osate.aadl2.Element)25 SystemOperationMode (org.osate.aadl2.instance.SystemOperationMode)22 ConnectionInstance (org.osate.aadl2.instance.ConnectionInstance)21 Classifier (org.osate.aadl2.Classifier)18 ForAllElement (org.osate.aadl2.modelsupport.modeltraversal.ForAllElement)18 ComponentCategory (org.osate.aadl2.ComponentCategory)17 NamedElement (org.osate.aadl2.NamedElement)16 List (java.util.List)14 Resource (org.eclipse.emf.ecore.resource.Resource)14 AadlPackage (org.osate.aadl2.AadlPackage)14 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)14 ArrayList (java.util.ArrayList)13 EList (org.eclipse.emf.common.util.EList)13 IOException (java.io.IOException)12 IStatus (org.eclipse.core.runtime.IStatus)12 Optional (java.util.Optional)10