Fixed null pointer exception and added test cases
diff --git a/plugins/org.eclipse.app4mc.amalthea.converters.200/src/org/eclipse/app4mc/amalthea/converters200/impl/SchedulerConverter.java b/plugins/org.eclipse.app4mc.amalthea.converters.200/src/org/eclipse/app4mc/amalthea/converters200/impl/SchedulerConverter.java index 86c7eff..9edab98 100644 --- a/plugins/org.eclipse.app4mc.amalthea.converters.200/src/org/eclipse/app4mc/amalthea/converters200/impl/SchedulerConverter.java +++ b/plugins/org.eclipse.app4mc.amalthea.converters.200/src/org/eclipse/app4mc/amalthea/converters200/impl/SchedulerConverter.java
@@ -229,7 +229,7 @@ // add new multiple child elements "schedulingParameters" String priorityValue = elem.getAttributeValue(PRIORITY); - if (! priorityValue.equals("0")) { + if (priorityValue != null && (! priorityValue.equals("0"))) { addIntegerSchedulingParameter(parent, PRIORITY, priorityValue); }
diff --git a/plugins/org.eclipse.app4mc.amalthea.converters.200/src/org/eclipse/app4mc/amalthea/converters200/utils/SchedulerCache.java b/plugins/org.eclipse.app4mc.amalthea.converters.200/src/org/eclipse/app4mc/amalthea/converters200/utils/SchedulerCache.java index c7e903c..a6764da 100644 --- a/plugins/org.eclipse.app4mc.amalthea.converters.200/src/org/eclipse/app4mc/amalthea/converters200/utils/SchedulerCache.java +++ b/plugins/org.eclipse.app4mc.amalthea.converters.200/src/org/eclipse/app4mc/amalthea/converters200/utils/SchedulerCache.java
@@ -168,7 +168,8 @@ Element.class, am, xsi); for (Element elem : parameterElements) { - if (! elem.getAttributeValue("priority").equals("0")) { + String priorityValue = elem.getAttributeValue("priority"); + if (priorityValue != null && (! priorityValue.equals("0"))) { standardParameterCache.add("priority"); } if (elem.getChild("minBudget") != null) {
diff --git a/tests/org.eclipse.app4mc.amalthea.converters.200.tests/TestModels/input/schedulers/hierarchical/hierarchicalExample.amxmi b/tests/org.eclipse.app4mc.amalthea.converters.200.tests/TestModels/input/schedulers/hierarchical/hierarchicalExample.amxmi new file mode 100644 index 0000000..9bd13a2 --- /dev/null +++ b/tests/org.eclipse.app4mc.amalthea.converters.200.tests/TestModels/input/schedulers/hierarchical/hierarchicalExample.amxmi
@@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="UTF-8"?> +<am:Amalthea xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:am="http://app4mc.eclipse.org/amalthea/1.2.0"> + <swModel> + <tasks xmi:id="TaskA1?type=Task" name="TaskA1" multipleTaskActivationLimit="0"/> + <tasks xmi:id="TaskB1?type=Task" name="TaskB1" multipleTaskActivationLimit="0"/> + <tasks xmi:id="TaskC1?type=Task" name="TaskC1" multipleTaskActivationLimit="0"/> + <tasks xmi:id="TaskD1?type=Task" name="TaskD1" multipleTaskActivationLimit="0"/> + <tasks xmi:id="TaskA2?type=Task" name="TaskA2" multipleTaskActivationLimit="0"/> + <tasks xmi:id="TaskB2?type=Task" name="TaskB2" multipleTaskActivationLimit="0"/> + <tasks xmi:id="TaskC2?type=Task" name="TaskC2" multipleTaskActivationLimit="0"/> + <tasks xmi:id="TaskD2?type=Task" name="TaskD2" multipleTaskActivationLimit="0"/> + </swModel> + <hwModel> + <definitions xsi:type="am:ProcessingUnitDefinition" xmi:id="Core_Definition?type=ProcessingUnitDefinition" name="Core_Definition" puType="CPU"/> + <structures xmi:id="System?type=HwStructure" name="System" structureType="System"> + <structures xmi:id="ECU?type=HwStructure" name="ECU" structureType="ECU"> + <modules xsi:type="am:ProcessingUnit" xmi:id="CoreA?type=ProcessingUnit" name="CoreA" frequencyDomain="Main_Freq_Domain?type=FrequencyDomain" definition="Core_Definition?type=ProcessingUnitDefinition"/> + <modules xsi:type="am:ProcessingUnit" xmi:id="CoreB?type=ProcessingUnit" name="CoreB" frequencyDomain="Main_Freq_Domain?type=FrequencyDomain" definition="Core_Definition?type=ProcessingUnitDefinition"/> + </structures> + </structures> + <domains xsi:type="am:FrequencyDomain" xmi:id="Main_Freq_Domain?type=FrequencyDomain" name="Main_Freq_Domain" clockGating="false"> + <defaultValue value="200.0" unit="MHz"/> + </domains> + </hwModel> + <osModel> + <operatingSystems name=""> + <taskSchedulers xmi:id="Priority+Based+Round+Robin?type=TaskScheduler" name="Priority Based Round Robin"> + <schedulingAlgorithm xsi:type="am:PriorityBasedRoundRobin"/> + </taskSchedulers> + <taskSchedulers xmi:id="OSEKA?type=TaskScheduler" name="OSEKA"> + <schedulingAlgorithm xsi:type="am:OSEK"/> + <parentAssociation parent="Priority+Based+Round+Robin?type=TaskScheduler"> + <schedulingParameters priority="20"/> + </parentAssociation> + </taskSchedulers> + <taskSchedulers xmi:id="OSEKB?type=TaskScheduler" name="OSEKB"> + <schedulingAlgorithm xsi:type="am:OSEK"/> + <parentAssociation parent="Priority+Based+Round+Robin?type=TaskScheduler"> + <schedulingParameters priority="15"/> + </parentAssociation> + </taskSchedulers> + <taskSchedulers xmi:id="OSEKC?type=TaskScheduler" name="OSEKC"> + <schedulingAlgorithm xsi:type="am:OSEK"/> + <parentAssociation parent="Priority+Based+Round+Robin?type=TaskScheduler"> + <schedulingParameters priority="5"/> + </parentAssociation> + </taskSchedulers> + <taskSchedulers xmi:id="OSEKD?type=TaskScheduler" name="OSEKD"> + <schedulingAlgorithm xsi:type="am:OSEK"/> + <parentAssociation parent="Priority+Based+Round+Robin?type=TaskScheduler"> + <schedulingParameters priority="10"/> + </parentAssociation> + </taskSchedulers> + </operatingSystems> + </osModel> + <mappingModel> + <schedulerAllocation scheduler="Priority+Based+Round+Robin?type=TaskScheduler" responsibility="CoreA?type=ProcessingUnit CoreB?type=ProcessingUnit" executingPU="CoreA?type=ProcessingUnit"/> + <schedulerAllocation scheduler="OSEKA?type=TaskScheduler" responsibility="CoreA?type=ProcessingUnit" executingPU="CoreA?type=ProcessingUnit"/> + <schedulerAllocation scheduler="OSEKB?type=TaskScheduler" responsibility="CoreA?type=ProcessingUnit" executingPU="CoreA?type=ProcessingUnit"/> + <schedulerAllocation scheduler="OSEKC?type=TaskScheduler" responsibility="CoreB?type=ProcessingUnit" executingPU="CoreB?type=ProcessingUnit"/> + <schedulerAllocation scheduler="OSEKD?type=TaskScheduler" responsibility="CoreB?type=ProcessingUnit" executingPU="CoreB?type=ProcessingUnit"/> + <taskAllocation task="TaskA1?type=Task" scheduler="OSEKA?type=TaskScheduler"> + <schedulingParameters priority="5"/> + </taskAllocation> + <taskAllocation task="TaskA2?type=Task" scheduler="OSEKA?type=TaskScheduler"> + <schedulingParameters priority="15"/> + </taskAllocation> + <taskAllocation task="TaskB1?type=Task" scheduler="OSEKB?type=TaskScheduler"> + <schedulingParameters priority="10"/> + </taskAllocation> + <taskAllocation task="TaskB2?type=Task" scheduler="OSEKB?type=TaskScheduler"> + <schedulingParameters priority="50"/> + </taskAllocation> + <taskAllocation task="TaskC1?type=Task" scheduler="OSEKC?type=TaskScheduler"> + <schedulingParameters priority="40"/> + </taskAllocation> + <taskAllocation task="TaskC2?type=Task" scheduler="OSEKC?type=TaskScheduler"> + <schedulingParameters priority="20"/> + </taskAllocation> + <taskAllocation task="TaskD1?type=Task" scheduler="OSEKD?type=TaskScheduler"> + <schedulingParameters priority="25"/> + </taskAllocation> + <taskAllocation task="TaskD2?type=Task" scheduler="OSEKD?type=TaskScheduler"> + <schedulingParameters priority="55"/> + </taskAllocation> + </mappingModel> +</am:Amalthea>
diff --git a/tests/org.eclipse.app4mc.amalthea.converters.200.tests/TestModels/input/schedulers/partitioned_fpp/partitioned_fpp.amxmi b/tests/org.eclipse.app4mc.amalthea.converters.200.tests/TestModels/input/schedulers/partitioned_fpp/partitioned_fpp.amxmi new file mode 100644 index 0000000..227c4db --- /dev/null +++ b/tests/org.eclipse.app4mc.amalthea.converters.200.tests/TestModels/input/schedulers/partitioned_fpp/partitioned_fpp.amxmi
@@ -0,0 +1,95 @@ +<?xml version="1.0" encoding="UTF-8"?> +<am:Amalthea xmlns:am="http://app4mc.eclipse.org/amalthea/1.2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmi:version="2.0"> + <swModel> + <tasks xmi:id="TaskA1?type=Task" name="TaskA1" multipleTaskActivationLimit="0" /> + <tasks xmi:id="TaskB1?type=Task" name="TaskB1" multipleTaskActivationLimit="0" /> + <tasks xmi:id="TaskC1?type=Task" name="TaskC1" multipleTaskActivationLimit="0" /> + <tasks xmi:id="TaskD1?type=Task" name="TaskD1" multipleTaskActivationLimit="0" /> + <tasks xmi:id="TaskA2?type=Task" name="TaskA2" multipleTaskActivationLimit="0" /> + <tasks xmi:id="TaskB2?type=Task" name="TaskB2" multipleTaskActivationLimit="0" /> + <tasks xmi:id="TaskC2?type=Task" name="TaskC2" multipleTaskActivationLimit="0" /> + <tasks xmi:id="TaskD2?type=Task" name="TaskD2" multipleTaskActivationLimit="0" /> + </swModel> + <hwModel> + <definitions xsi:type="am:ProcessingUnitDefinition" xmi:id="Core_Definition?type=ProcessingUnitDefinition" name="Core_Definition" puType="CPU" /> + <structures xmi:id="System?type=HwStructure" name="System" structureType="System"> + <structures xmi:id="ECU?type=HwStructure" name="ECU" structureType="ECU"> + <modules xsi:type="am:ProcessingUnit" xmi:id="CoreA?type=ProcessingUnit" name="CoreA" frequencyDomain="Main_Freq_Domain?type=FrequencyDomain" definition="Core_Definition?type=ProcessingUnitDefinition" /> + <modules xsi:type="am:ProcessingUnit" xmi:id="CoreB?type=ProcessingUnit" name="CoreB" frequencyDomain="Main_Freq_Domain?type=FrequencyDomain" definition="Core_Definition?type=ProcessingUnitDefinition" /> + </structures> + </structures> + <domains xsi:type="am:FrequencyDomain" xmi:id="Main_Freq_Domain?type=FrequencyDomain" name="Main_Freq_Domain" clockGating="false"> + <defaultValue value="200.0" unit="MHz" /> + </domains> + </hwModel> + <osModel> + <operatingSystems name=""> + <taskSchedulers xmi:id="Partitioned_FPP?type=TaskScheduler" name="Partitioned_FPP"> + <schedulingAlgorithm xsi:type="am:UserSpecificSchedulingAlgorithm" /> + </taskSchedulers> + <taskSchedulers xmi:id="GroupA?type=TaskScheduler" name="GroupA"> + <schedulingAlgorithm xsi:type="am:Grouping" /> + <parentAssociation parent="Partitioned_FPP?type=TaskScheduler"> + <schedulingParameters> + <maxBudget value="1" unit="ms" /> + <replenishment value="10" unit="ms" /> + </schedulingParameters> + </parentAssociation> + </taskSchedulers> + <taskSchedulers xmi:id="GroupB?type=TaskScheduler" name="GroupB"> + <schedulingAlgorithm xsi:type="am:Grouping" /> + <parentAssociation parent="Partitioned_FPP?type=TaskScheduler"> + <schedulingParameters> + <maxBudget value="2" unit="ms" /> + <replenishment value="15" unit="ms" /> + </schedulingParameters> + </parentAssociation> + </taskSchedulers> + <taskSchedulers xmi:id="GroupC?type=TaskScheduler" name="GroupC"> + <schedulingAlgorithm xsi:type="am:Grouping" /> + <parentAssociation parent="Partitioned_FPP?type=TaskScheduler"> + <schedulingParameters> + <maxBudget value="5" unit="ms" /> + <replenishment value="20" unit="ms" /> + </schedulingParameters> + </parentAssociation> + </taskSchedulers> + <taskSchedulers xmi:id="GroupD?type=TaskScheduler" name="GroupD"> + <schedulingAlgorithm xsi:type="am:Grouping" /> + <parentAssociation parent="Partitioned_FPP?type=TaskScheduler"> + <schedulingParameters> + <maxBudget value="2" unit="ms" /> + <replenishment value="5" unit="ms" /> + </schedulingParameters> + </parentAssociation> + </taskSchedulers> + </operatingSystems> + </osModel> + <mappingModel> + <schedulerAllocation scheduler="Partitioned_FPP?type=TaskScheduler" responsibility="CoreA?type=ProcessingUnit CoreB?type=ProcessingUnit" executingPU="CoreA?type=ProcessingUnit" /> + <taskAllocation task="TaskA1?type=Task" scheduler="GroupA?type=TaskScheduler" affinity="CoreA?type=ProcessingUnit"> + <schedulingParameters priority="50" /> + </taskAllocation> + <taskAllocation task="TaskA2?type=Task" scheduler="GroupA?type=TaskScheduler" affinity="CoreA?type=ProcessingUnit CoreB?type=ProcessingUnit"> + <schedulingParameters priority="30" /> + </taskAllocation> + <taskAllocation task="TaskB1?type=Task" scheduler="GroupB?type=TaskScheduler" affinity="CoreB?type=ProcessingUnit"> + <schedulingParameters priority="55" /> + </taskAllocation> + <taskAllocation task="TaskB2?type=Task" scheduler="GroupB?type=TaskScheduler" affinity="CoreB?type=ProcessingUnit"> + <schedulingParameters priority="60" /> + </taskAllocation> + <taskAllocation task="TaskC1?type=Task" scheduler="GroupC?type=TaskScheduler" affinity="CoreA?type=ProcessingUnit"> + <schedulingParameters priority="75" /> + </taskAllocation> + <taskAllocation task="TaskC2?type=Task" scheduler="GroupC?type=TaskScheduler" affinity="CoreA?type=ProcessingUnit"> + <schedulingParameters priority="20" /> + </taskAllocation> + <taskAllocation task="TaskD1?type=Task" scheduler="GroupD?type=TaskScheduler" affinity="CoreA?type=ProcessingUnit CoreB?type=ProcessingUnit"> + <schedulingParameters priority="100" /> + </taskAllocation> + <taskAllocation task="TaskD2?type=Task" scheduler="GroupD?type=TaskScheduler" affinity="CoreB?type=ProcessingUnit CoreA?type=ProcessingUnit"> + <schedulingParameters priority="10" /> + </taskAllocation> + </mappingModel> +</am:Amalthea>
diff --git a/tests/org.eclipse.app4mc.amalthea.converters.200.tests/src/org/eclipse/app4mc/amalthea/converters200/tests/SchedulerConverterTest.java b/tests/org.eclipse.app4mc.amalthea.converters.200.tests/src/org/eclipse/app4mc/amalthea/converters200/tests/SchedulerConverterTest.java index caf1a74..217a223 100644 --- a/tests/org.eclipse.app4mc.amalthea.converters.200.tests/src/org/eclipse/app4mc/amalthea/converters200/tests/SchedulerConverterTest.java +++ b/tests/org.eclipse.app4mc.amalthea.converters.200.tests/src/org/eclipse/app4mc/amalthea/converters200/tests/SchedulerConverterTest.java
@@ -36,7 +36,9 @@ public static Collection<Object[]> getTestData() { return Arrays.asList(new Object[][] { - { new String[] {"/schedulers/model1.amxmi", "/schedulers/model2.amxmi", "/schedulers/model3.amxmi"}, true } + { new String[] {"/schedulers/model1.amxmi", "/schedulers/model2.amxmi", "/schedulers/model3.amxmi"}, true }, + { new String[] {"/schedulers/hierarchical/hierarchicalExample.amxmi"}, true }, + { new String[] {"/schedulers/partitioned_fpp/partitioned_fpp.amxmi"}, true } }); }