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;
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations