use of org.osate.aadl2.instance.SystemInstance in project osate2 by osate.
the class ProcessorCheck method perform.
@Override
public void perform(SystemInstance si) {
/**
* processor needs to define their schedule
*/
if (vxworks() || deos()) {
final List<ComponentInstance> badProcessors = si.getAllComponentInstances().stream().filter(comp -> comp.getCategory() == ComponentCategory.PROCESSOR).filter(cpu -> GetProperties.getModuleSchedule(cpu).size() == 0).collect(Collectors.toList());
for (ComponentInstance cpu : badProcessors) {
addError(new ErrorReport(cpu, "Processor must define the property ARINC653::Module_Schedule"));
}
}
/**
* For vxworks, we need to check that the Source_Name property is
* defined on each virtual processor.
*/
if (vxworks()) {
final List<ComponentInstance> virtualProcessorsWithoutSourceName = si.getAllComponentInstances(ComponentCategory.VIRTUAL_PROCESSOR).stream().filter(comp -> ((comp.getCategory() == ComponentCategory.VIRTUAL_PROCESSOR) && (GetProperties.getSourceName(comp) == null))).collect(Collectors.toList());
for (ComponentInstance vp : virtualProcessorsWithoutSourceName) {
addError(new ErrorReport(vp, "Virtual Processor must define the property Programming_Properties::Source_Name"));
}
}
/**
* For vxworks, we need to check that the Source_Name property is
* defined on each virtual processor.
*/
if (deos()) {
final List<ComponentInstance> virtualProcessorsWithoutExecutionTime = si.getAllComponentInstances(ComponentCategory.VIRTUAL_PROCESSOR).stream().filter(comp -> ((comp.getCategory() == ComponentCategory.VIRTUAL_PROCESSOR) && (GetProperties.getExecutionTimeInMS(comp) == 0))).collect(Collectors.toList());
for (ComponentInstance vp : virtualProcessorsWithoutExecutionTime) {
addError(new ErrorReport(vp, "Virtual processor must define the property Timing_Properties::Execution_Time"));
}
final List<ComponentInstance> virtualProcessorsWithoutPeriod = si.getAllComponentInstances(ComponentCategory.VIRTUAL_PROCESSOR).stream().filter(comp -> ((comp.getCategory() == ComponentCategory.VIRTUAL_PROCESSOR) && (PropertyUtils.getScaled(TimingProperties::getPeriod, comp, TimeUnits.MS).orElse(0.0) == 0))).collect(Collectors.toList());
for (ComponentInstance vp : virtualProcessorsWithoutPeriod) {
addError(new ErrorReport(vp, "Virtual processor must define the property Timing_Properties::Period"));
}
}
if (pok()) {
OsateDebug.osateDebug("pok case");
/**
* For each CPU, we check that every virtual processor contained in
* the cpu is correctly referenced in the schedule slots
*/
for (ComponentInstance cpu : si.getComponentInstances().stream().filter(comp -> comp.getCategory() == ComponentCategory.PROCESSOR).collect(Collectors.toList())) {
final List<ComponentInstance> unreferencedVirtualProcessors = cpu.getComponentInstances().stream().filter(comp -> ((comp.getCategory() == ComponentCategory.VIRTUAL_PROCESSOR) && (PokProperties.getSlotsAllocation(cpu).contains(comp) == false))).collect(Collectors.toList());
for (ComponentInstance vp : unreferencedVirtualProcessors) {
addError(new ErrorReport(vp, "Virtual processor must be declared in the containing processor's POK::Slots_Allocation property"));
}
int slotsAllocationSize = PokProperties.getSlotsAllocation(cpu).size();
int slotsSize = PokProperties.getTimeSlotInMs(cpu).size();
if (slotsAllocationSize != slotsSize) {
addError(new ErrorReport(cpu, "Property POK::Slots_Allocation has " + slotsAllocationSize + " elements, but property POK::Slots has " + slotsSize + "elements"));
}
}
// List<ComponentInstance> badProcessors = (List<ComponentInstance>)
// si.getAllComponentInstances().stream()
// .filter( comp -> comp.getCategory() ==
// ComponentCategory.PROCESSOR).filter( cpu ->
// GetProperties.getModuleSchedule(cpu).size() ==
// 0).collect(Collectors.toList());
//
// for (ComponentInstance cpu : badProcessors)
// {
// addError (new ErrorReport (cpu, "Need to define the processor
// schedule"));
// }
}
}
use of org.osate.aadl2.instance.SystemInstance in project osate2 by osate.
the class ThreadCheck method perform.
@Override
public void perform(SystemInstance si) {
final List<ComponentInstance> allThreads = si.getAllComponentInstances().stream().filter(comp -> (comp.getCategory() == ComponentCategory.THREAD)).collect(Collectors.toList());
/**
* Each thread needs to specify the dispatch protocol "periodic" or
* "sporadic"
*/
allThreads.stream().filter(comp -> {
EnumerationLiteral protocol = GetProperties.getDispatchProtocol(comp);
return protocol == null || !(protocol.toString().equalsIgnoreCase(AadlProject.PERIODIC_LITERAL) || protocol.toString().equalsIgnoreCase(AadlProject.SPORADIC_LITERAL));
}).forEach(thr -> addError(new ErrorReport(thr, "Thread needs a Thread_Properties::Dispatch_Protocol property of 'Periodic' or 'Sporadic'")));
/**
* Each thread needs to specify period
*/
final List<ComponentInstance> threadMissingPeriod = allThreads.stream().filter(comp -> (PropertyUtils.getScaled(TimingProperties::getPeriod, comp, TimeUnits.MS).orElse(0.0) == 0.0)).collect(Collectors.toList());
for (ComponentInstance thr : threadMissingPeriod) {
addError(new ErrorReport(thr, "Thread must define the property Timing_Properties::Period"));
}
final List<ComponentInstance> threadMissingDeadline = allThreads.stream().filter(comp -> (PropertyUtils.getScaled(TimingProperties::getDeadline, comp, TimeUnits.MS).orElse(0.0) == 0.0)).collect(Collectors.toList());
for (ComponentInstance thr : threadMissingDeadline) {
addError(new ErrorReport(thr, "Thread must define the property Timing_Properties::Deadline"));
}
for (ComponentInstance ci : allThreads) {
ComponentClassifier cc = ci.getComponentClassifier();
if (cc instanceof ThreadImplementation) {
ThreadImplementation ti = (ThreadImplementation) cc;
for (SubprogramCall sc : ti.getSubprogramCalls()) {
NamedElement cs = (NamedElement) sc.getCalledSubprogram();
if (GetProperties.getSourceName(cs) == null) {
addError(new ErrorReport(cs, "Subprogram must define the property Programming_Properties::Source_Name"));
}
if (GetProperties.getSourceText(cs).size() == 0) {
addError(new ErrorReport(cs, "Subprogram must define the property Programming_Properties::Source_Text"));
}
if (GetProperties.getSourceLanguage(cs).size() == 0) {
addError(new ErrorReport(cs, "Subprogram must define the property Programming_Properties::Source_Language"));
}
}
}
}
/**
* FIXME JD Each thread needs to specify execution time
*/
// List<ComponentInstance> threadMissingExecutionTime =
// (List<ComponentInstance>) si.getAllComponentInstances().stream().
// filter( comp -> (comp.getCategory() == ComponentCategory.THREAD) &&
// (GetProperties.get > 0.0));
// for (ComponentInstance thr : threadMissingPeriod)
// {
// addError (new ErrorReport (thr, "Thread needs to define a period"));
// }
}
use of org.osate.aadl2.instance.SystemInstance in project osate2 by osate.
the class ComponentCounterTest method exhaustiveTest.
@Test
public void exhaustiveTest() throws Exception {
AadlPackage pkg = testHelper.parseFile(path + "Exhaustive.aadl");
SystemImplementation impl = (SystemImplementation) pkg.getPublicSection().getOwnedClassifiers().get(1);
SystemInstance si = InstantiateModel.instantiate(impl);
ElementsCounts elementCounts = ComponentCounter.countComponents(si);
Assert.assertEquals(16, elementCounts.getTotalComponentCount());
Assert.assertEquals(1, elementCounts.getConnectionsCount());
Assert.assertEquals(1, elementCounts.getEndToEndFlowsCount());
Assert.assertEquals(14, elementCounts.getComponentCountMap().size());
Assert.assertEquals(2, elementCounts.getComponentCountMap().get(ComponentCategory.SYSTEM).intValue());
Assert.assertEquals(1, elementCounts.getComponentCountMap().get(ComponentCategory.ABSTRACT).intValue());
Assert.assertEquals(1, elementCounts.getComponentCountMap().get(ComponentCategory.BUS).intValue());
Assert.assertEquals(1, elementCounts.getComponentCountMap().get(ComponentCategory.DATA).intValue());
Assert.assertEquals(1, elementCounts.getComponentCountMap().get(ComponentCategory.DEVICE).intValue());
Assert.assertEquals(1, elementCounts.getComponentCountMap().get(ComponentCategory.MEMORY).intValue());
Assert.assertEquals(1, elementCounts.getComponentCountMap().get(ComponentCategory.PROCESS).intValue());
Assert.assertEquals(1, elementCounts.getComponentCountMap().get(ComponentCategory.PROCESSOR).intValue());
Assert.assertEquals(1, elementCounts.getComponentCountMap().get(ComponentCategory.SUBPROGRAM).intValue());
Assert.assertEquals(1, elementCounts.getComponentCountMap().get(ComponentCategory.SUBPROGRAM_GROUP).intValue());
Assert.assertEquals(1, elementCounts.getComponentCountMap().get(ComponentCategory.VIRTUAL_BUS).intValue());
Assert.assertEquals(1, elementCounts.getComponentCountMap().get(ComponentCategory.VIRTUAL_PROCESSOR).intValue());
Assert.assertEquals(2, elementCounts.getComponentCountMap().get(ComponentCategory.THREAD).intValue());
}
use of org.osate.aadl2.instance.SystemInstance in project osate2 by osate.
the class InstantiateModel method createSystemInstance.
/**
* create a system instance into the provided (empty) resource and save it
* @param ci
* @param aadlResource
* @return
* @throws RollbackException
* @throws InterruptedException
*/
public SystemInstance createSystemInstance(final ComponentImplementation ci, final Resource aadlResource) throws Exception {
SystemInstance result = createSystemInstanceInt(ci, aadlResource, true);
if (monitor.isCanceled()) {
throw new InterruptedException();
}
try {
// We're done: Save the model.
// We don't respond to a cancel at this point
monitor.subTask("Saving instance model");
aadlResource.save(null);
} catch (IOException e) {
InstancePlugin.log(new Status(IStatus.ERROR, InstancePlugin.getPluginId(), IStatus.OK, "Exception during instantiation", e));
setErrorMessage("Exception during instantiation, see error log");
return null;
}
return result;
}
use of org.osate.aadl2.instance.SystemInstance in project osate2 by osate.
the class InstantiateModel method interpretConnectionPatterns.
private boolean interpretConnectionPatterns(ConnectionInstance conni, boolean isOpposite, List<PropertyExpression> patterns, int offset, List<Integer> srcSizes, int srcOffset, List<Integer> dstSizes, int dstOffset, List<Long> srcIndices, List<Long> dstIndices) {
boolean result = true;
if (patterns != null ? offset >= patterns.size() : srcOffset == srcSizes.size() && dstOffset == dstSizes.size()) {
createNewConnection(conni, srcIndices, dstIndices);
return result;
}
String patternName = "One_to_One";
if (patterns == null) {
// default one-to-one pattern
if (!conni.isComplete()) {
// outgoing or incoming only
InstanceObject io = conni.getSource();
if (io instanceof FeatureInstance && io.getContainingComponentInstance() instanceof SystemInstance) {
if (srcSizes.isEmpty()) {
patternName = isOpposite ? "All_to_One" : "One_To_All";
}
} else {
if (dstSizes.isEmpty()) {
patternName = isOpposite ? "One_To_All" : "All_to_One";
}
}
}
} else {
NamedValue nv = (NamedValue) patterns.get(offset);
EnumerationLiteral pattern = (EnumerationLiteral) nv.getNamedValue();
patternName = pattern.getName();
}
if (!isOpposite && !patternName.equalsIgnoreCase("One_To_All") && (srcOffset >= srcSizes.size())) {
errManager.error(conni, "Too few indices for connection source for " + conni.getFullName());
return false;
}
if (!isOpposite && !patternName.equalsIgnoreCase("All_To_One") && (dstOffset >= dstSizes.size())) {
errManager.error(conni, "Too few indices for connection destination for " + conni.getFullName());
return false;
}
if (isOpposite && !patternName.equalsIgnoreCase("One_To_All") && (dstOffset >= dstSizes.size())) {
// verbose exception message
errManager.error(conni, "Too few indices for connection source for " + conni.getFullName());
return false;
}
if (isOpposite && !patternName.equalsIgnoreCase("All_To_One") && (srcOffset >= srcSizes.size())) {
errManager.error(conni, "Too few indices for connection destination for " + conni.getFullName());
return false;
}
if (patternName.equalsIgnoreCase("All_To_All")) {
for (long i = 1; i <= srcSizes.get(srcOffset); i++) {
srcIndices.add(i);
for (long j = 1; j <= dstSizes.get(dstOffset); j++) {
dstIndices.add(j);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
}
srcIndices.remove(srcOffset);
}
} else if ((!isOpposite && patternName.equalsIgnoreCase("One_To_All")) || (isOpposite && patternName.equalsIgnoreCase("All_To_One"))) {
for (long j = 1; j <= dstSizes.get(dstOffset); j++) {
dstIndices.add(j);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
}
} else if ((!isOpposite && patternName.equalsIgnoreCase("All_To_One")) || (isOpposite && patternName.equalsIgnoreCase("One_To_All"))) {
for (long i = 1; i <= srcSizes.get(srcOffset); i++) {
srcIndices.add(i);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset, srcIndices, dstIndices);
srcIndices.remove(srcOffset);
}
} else {
if (!srcSizes.get(srcOffset).equals(dstSizes.get(dstOffset))) {
// verbose exception message
errManager.error(conni, "Array size mismatch (" + patternName + ") on connection " + conni.getFullName() + " in " + conni.getContainingComponentInstance().getFullName() + ": " + srcSizes.get(srcOffset) + // ("+conni.getSource().getFullName()+")
" at source " + "and " + dstSizes.get(dstOffset) + // ("+conni.getSource().getFullName()+")."
" at destination.");
return false;
} else {
if (patternName.equalsIgnoreCase("One_To_One")) {
for (long i = 1; i <= srcSizes.get(srcOffset); i++) {
srcIndices.add(i);
dstIndices.add(i);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
srcIndices.remove(srcOffset);
dstIndices.remove(dstOffset);
}
} else if (patternName.equalsIgnoreCase("Next")) {
for (long i = 1; i <= srcSizes.get(srcOffset) - 1; i++) {
srcIndices.add(i);
dstIndices.add(i + 1);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
srcIndices.remove(srcOffset);
}
} else if (patternName.equalsIgnoreCase("Previous")) {
for (long i = 2; i <= srcSizes.get(srcOffset); i++) {
srcIndices.add(i);
dstIndices.add(i - 1);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
srcIndices.remove(srcOffset);
}
} else if (patternName.equalsIgnoreCase("Cyclic_Next")) {
for (long i = 1; i <= srcSizes.get(srcOffset); i++) {
srcIndices.add(i);
dstIndices.add(i == srcSizes.get(srcOffset) ? 1 : i + 1);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
srcIndices.remove(srcOffset);
}
} else if (patternName.equalsIgnoreCase("Cyclic_Previous")) {
for (long i = 1; i <= srcSizes.get(srcOffset); i++) {
srcIndices.add(i);
dstIndices.add(i == 1 ? srcSizes.get(srcOffset) : i - 1);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
srcIndices.remove(srcOffset);
}
} else if (patternName.equalsIgnoreCase("Next_Next")) {
for (long i = 1; i <= srcSizes.get(srcOffset) - 2; i++) {
srcIndices.add(i);
dstIndices.add(i + 2);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
srcIndices.remove(srcOffset);
}
} else if (patternName.equalsIgnoreCase("Previous_Previous")) {
for (long i = 3; i <= srcSizes.get(srcOffset); i++) {
srcIndices.add(i);
dstIndices.add(i - 2);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
srcIndices.remove(srcOffset);
}
} else if (patternName.equalsIgnoreCase("Cyclic_Next_Next")) {
for (long i = 1; i <= srcSizes.get(srcOffset); i++) {
srcIndices.add(i);
dstIndices.add(i == srcSizes.get(srcOffset) ? 2 : (i == srcSizes.get(srcOffset) - 1 ? 1 : i + 1));
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
srcIndices.remove(srcOffset);
}
} else if (patternName.equalsIgnoreCase("Cyclic_Previous_Previous")) {
for (long i = 1; i <= srcSizes.get(srcOffset); i++) {
srcIndices.add(i);
dstIndices.add(i == 2 ? srcSizes.get(srcOffset) : (i == 1 ? srcSizes.get(srcOffset) - 1 : i - 1));
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
srcIndices.remove(srcOffset);
}
} else if (patternName.equalsIgnoreCase("Even_To_Even")) {
for (long i = 2; i <= srcSizes.get(srcOffset); i = i + 2) {
srcIndices.add(i);
dstIndices.add(i);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
srcIndices.remove(srcOffset);
}
} else if (patternName.equalsIgnoreCase("Odd_To_Odd")) {
for (long i = 1; i <= srcSizes.get(srcOffset); i = i + 2) {
srcIndices.add(i);
dstIndices.add(i);
result &= interpretConnectionPatterns(conni, isOpposite, patterns, offset + 1, srcSizes, srcOffset + 1, dstSizes, dstOffset + 1, srcIndices, dstIndices);
dstIndices.remove(dstOffset);
srcIndices.remove(srcOffset);
}
}
}
}
return result;
}
Aggregations