Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
af3
AF3
Commits
af0dac77
Commit
af0dac77
authored
Mar 22, 2018
by
Johannes Eder
Browse files
added deployment constraint check
parent
2c7dcd54
Changes
4
Hide whitespace changes
Inline
Side-by-side
org.fortiss.af3.exploration.smt/trunk/test-src/org/fortiss/af3/exploration/ui/featuretest/CreateJUnitTestFile.java
View file @
af0dac77
...
...
@@ -58,17 +58,33 @@ public class CreateJUnitTestFile {
"import java.util.Collection;\n"
+
"import java.util.Optional;\n"
+
"\n"
+
"import org.eclipse.emf.common.util.EList;\n"
+
"import org.fortiss.af3.component.model.Component;\n"
+
"import org.fortiss.af3.efficientdeployment.model.Flash;\n"
+
"import org.fortiss.af3.exploration.dsl_v2.model.booleanp.allocation.Allocation;\n"
+
"import org.fortiss.af3.exploration.dsl_v2.model.expression.SuperSet;\n"
+
"import org.fortiss.af3.exploration.model.ExplorationSpecification;\n"
+
"import org.fortiss.af3.exploration.model.ExplorationTarget;\n"
+
"import org.fortiss.af3.exploration.model.SuperSetMap;\n"
+
"import org.fortiss.af3.exploration.model.solutions.ExplorationSolution;\n"
+
"import org.fortiss.af3.exploration.model.solutions.SolutionState;\n"
+
"import org.fortiss.af3.exploration.projectmodel.DSE;\n"
+
"import org.fortiss.af3.exploration.smt.AF3ExplorationSMTActivator;\n"
+
"import org.fortiss.af3.exploration.projectmodel.RuleSet;\n"
+
"import org.fortiss.af3.exploration.smt.AF3ExplorationSMTActivator;\n"
+
"import org.fortiss.af3.exploration.smt.modeltransformation.rework.DeploymentRun2;\n"
+
"import org.fortiss.af3.exploration.ui.featuretest.GenerationProperties;\n"
+
"import org.fortiss.af3.exploration.util.ExplorationUtils;\n"
+
"import org.fortiss.af3.platform.model.allocation.ComponentToExecutionUnitAllocationEntry;\n"
+
"import org.fortiss.af3.project.model.FileProject;\n"
+
"import org.fortiss.af3.project.utils.ProjectUtils;\n"
+
"import org.fortiss.af3.task.model.Task;\n"
+
"import org.fortiss.af3.task.model.allocation.ComponentToTaskAllocationTable;\n"
+
"import org.fortiss.tooling.base.model.element.IModelElement;\n"
+
"import org.fortiss.tooling.base.utils.AnnotationUtils;\n"
+
"import org.fortiss.tooling.common.util.LambdaUtils;\n"
+
"import org.fortiss.tooling.kernel.model.INamedElement;\n"
+
"import org.fortiss.tooling.kernel.utils.EcoreUtils;\n"
+
"import org.junit.Assert;\n"
+
"import org.junit.Test;\n"
+
"\n"
+
"/**\n"
+
...
...
@@ -87,72 +103,112 @@ public class CreateJUnitTestFile {
" LambdaUtils.firstOfType(fileProject.getRootElements(), DSE.class);\n"
+
" DSE dse = firstOfType.get();\n"
+
"\n"
+
"
DeploymentRun2 run = new DeploymentRun2();\n"
+
"
Collection<ExplorationTarget<?>> targets =
\n"
+
"
convertRuleSetsToExplorationSpec(dse.getDseRunArtifacts().get(0).getR
uleSets
()
);\n"
+
"
ExplorationSpecification expSpec = createExplorationSpecification();\n"
+
"
expSpec.getTargets().addAll(targets);\n"
+
"
SuperSetMap superSets = ExplorationUtils.convertToMap(dse.getDseSuperSet());\n"
+
"
expSpec.setSearchSpace(superSets);\n"
+
"DeploymentRun2 run = new DeploymentRun2();\n"
+
"
EList<RuleSet> ruleSets = dse.getDseRunArtifacts().get(0).getRuleSets();
\n"
+
"
Collection<ExplorationTarget<?>> targets = convertRuleSetsToExplorationSpec(r
uleSets);\n"
+
" ExplorationSpecification expSpec = createExplorationSpecification();\n"
+
" expSpec.getTargets().addAll(targets);\n"
+
" SuperSetMap superSets = ExplorationUtils.convertToMap(dse.getDseSuperSet());\n"
+
" expSpec.setSearchSpace(superSets);\n"
+
"\n"
+
" ExplorationSolution expSolution = run.solveDeployment(expSpec, 10000, null);\n"
+
" expSolution.getUnsatConstraints().addAll(run.getFailedConstraints());\n"
+
" ExplorationSolution expSolution = run.solveDeployment(expSpec, 10000, null);\n"
+
" expSolution.getUnsatConstraints().addAll(run.getFailedConstraints());\n"
+
"\n"
+
" ComponentToTaskAllocationTable allocationTable = dse.getComponentToTaskAllocationTable();\n"
+
"\n"
+
" SuperSet<ComponentToExecutionUnitAllocationEntry> allocs =\n"
+
" expSolution.getSolutions().get(0)\n"
+
" .getSolutionModel(ComponentToExecutionUnitAllocationEntry.class);\n"
+
" // check in case of sat\n"
+
" if(expSolution.getSolutionState().getValue() != SolutionState.UNSAT_VALUE)\n"
+
" checkConstraints(ruleSets, allocationTable, allocs);\n"
+
" System.out.println();\n"
+
"}\n"
+
"\n"
+
"private void checkConstraints(EList<RuleSet> ruleSets,\n"
+
" ComponentToTaskAllocationTable allocationTable,\n"
+
" SuperSet<ComponentToExecutionUnitAllocationEntry> allocs) {\n"
+
" for(RuleSet rs : ruleSets) {\n"
+
" if(rs.getName().equals(GenerationProperties.ALLOCATION_RULE_SET_NAME)) {\n"
+
" for(ExplorationTarget<?> et : rs.getExplorationTargets()) {\n"
+
" Allocation a =\n"
+
" EcoreUtils.getFirstChildWithType(et.getExpression(), Allocation.class);\n"
+
" IModelElement left = a.getLeft().getSetReference().getEntries().get(0);\n"
+
" IModelElement right = a.getRight().getSetReference().getEntries().get(0);\n"
+
" boolean match = false;\n"
+
" for(ComponentToExecutionUnitAllocationEntry r : allocs.getEntries()) {\n"
+
" EList<Component> components = allocationTable.getComponents((Task)left);\n"
+
" boolean leftMatch = r.getSourceElements().containsAll(components);\n"
+
" boolean rightMatch = r.getTargetElement().equals(right);\n"
+
" match = leftMatch && rightMatch;\n"
+
" if(match) {\n"
+
" break;\n"
+
" }\n"
+
" }\n"
+
" Assert.assertEquals(((INamedElement)left).getName() + \" is not allocated to \" +\n"
+
" ((INamedElement)right).getName(), true, match);\n"
+
" }\n"
+
" } else if(rs.getName().equals(GenerationProperties.FLASH_RULE_SET_NAME)) {\n"
+
" for(ComponentToExecutionUnitAllocationEntry a : allocs.getEntries()) {\n"
+
" int flashSum = 0;\n"
+
" for(IModelElement s : a.getSourceElements()) {\n"
+
" Flash annotation = AnnotationUtils.getAnnotation(s, Flash.class);\n"
+
" flashSum += annotation.getMemory();\n"
+
" }\n"
+
" Flash ecuAnnotation =\n"
+
" AnnotationUtils.getAnnotation(a.getTargetElement(), Flash.class);\n"
+
" boolean actual = flashSum <= ecuAnnotation.getMemory();\n"
+
"\n"
+
" Assert.assertEquals(\n"
+
" \"Flash of ECU \" + ((INamedElement)a.getTargetElement()).getName() +\n"
+
" \" is exceeded.\", true, actual);\n"
+
" }\n"
+
" }\n"
+
" }\n"
+
"}\n"
+
"}"
;
return
fileText
;
}
/**
* Should be called after Test cases have been generated.
* @param testName2
* @return
*
* @param testName2
* @return
*/
public
String
getJUnitTestSuite
(
String
testName2
)
{
String
allTestCases
=
""
;
for
(
String
s
:
allTests
){
String
allTestCases
=
""
;
for
(
String
s
:
allTests
)
{
allTestCases
+=
s
+
".class,\n"
;
}
String
content
=
""
+
"/*-------------------------------------------------------------------------+\n"
+
"| Copyright 2011 fortiss GmbH |\n"
+
"| |\n"
+
"| Licensed under the Apache License, Version 2.0 (the \"License\"); |\n"
+
"| you may not use this file except in compliance with the License. |\n"
+
"| You may obtain a copy of the License at |\n"
+
"| |\n"
+
"| http://www.apache.org/licenses/LICENSE-2.0 |\n"
+
"| |\n"
+
"| Unless required by applicable law or agreed to in writing, software |\n"
+
"| distributed under the License is distributed on an \"AS IS\" BASIS, |\n"
+
"| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |\n"
+
"| See the License for the specific language governing permissions and |\n"
+
"| limitations under the License. |\n"
+
"+--------------------------------------------------------------------------*/\n"
+
"package junittestcases;\n"
+
"\n"
+
"import org.junit.runner.RunWith;\n"
+
"import org.junit.runners.Suite;\n"
+
"import org.junit.runners.Suite.SuiteClasses;\n"
+
"\n"
+
"/**\n"
+
" * This suite is an index to all tests defined in this plugin.\n"
+
" * \n"
+
" * @author eder\n"
+
" */\n"
+
"// @CodeFormatterOff\n"
+
"@RunWith(Suite.class)\n"
+
"@SuiteClasses({ \n"
+
allTestCases
+
"})\n"
+
"// @CodeFormatterOn\n"
+
"public class "
+
testName2
+
" {\n"
+
" // empty class: collection of test cases\n"
+
"}\n"
+
""
;
String
content
=
""
+
"/*-------------------------------------------------------------------------+\n"
+
"| Copyright 2011 fortiss GmbH |\n"
+
"| |\n"
+
"| Licensed under the Apache License, Version 2.0 (the \"License\"); |\n"
+
"| you may not use this file except in compliance with the License. |\n"
+
"| You may obtain a copy of the License at |\n"
+
"| |\n"
+
"| http://www.apache.org/licenses/LICENSE-2.0 |\n"
+
"| |\n"
+
"| Unless required by applicable law or agreed to in writing, software |\n"
+
"| distributed under the License is distributed on an \"AS IS\" BASIS, |\n"
+
"| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |\n"
+
"| See the License for the specific language governing permissions and |\n"
+
"| limitations under the License. |\n"
+
"+--------------------------------------------------------------------------*/\n"
+
"package junittestcases;\n"
+
"\n"
+
"import org.junit.runner.RunWith;\n"
+
"import org.junit.runners.Suite;\n"
+
"import org.junit.runners.Suite.SuiteClasses;\n"
+
"\n"
+
"/**\n"
+
" * This suite is an index to all tests defined in this plugin.\n"
+
" * \n"
+
" * @author eder\n"
+
" */\n"
+
"// @CodeFormatterOff\n"
+
"@RunWith(Suite.class)\n"
+
"@SuiteClasses({ \n"
+
allTestCases
+
"})\n"
+
"// @CodeFormatterOn\n"
+
"public class "
+
testName2
+
" {\n"
+
" // empty class: collection of test cases\n"
+
"}\n"
+
""
;
return
content
;
}
}
org.fortiss.af3.exploration.smt/trunk/test-src/org/fortiss/af3/exploration/ui/featuretest/GenerateTestBundles.java
View file @
af0dac77
...
...
@@ -220,7 +220,7 @@ public class GenerateTestBundles {
for
(
ALLOC_CONSTRAINT_DISTRIBUTION
acd
:
allocconstraintdistributions
)
{
RuleSet
ruleSet
=
DSEProjectModelElementFactory
.
createRuleSet
();
ruleSet
.
setImplicit
(
false
);
ruleSet
.
setName
(
"Allocation Constraints"
);
ruleSet
.
setName
(
GenerationProperties
.
ALLOCATION_RULE_SET_NAME
);
ruleSet
.
setComment
(
"Automatically generated allocation constraint."
);
TestBundle
clone
;
if
(
acd
.
ordinal
()
==
allocconstraintdistributions
.
length
-
1
)
{
...
...
@@ -281,7 +281,7 @@ public class GenerateTestBundles {
SMTConstraint
t
=
createDeploymentMemoryConstraint
(
Flash
.
class
,
bundle
);
incrementIDcounter1000andFixIDs
(
bundle
,
t
);
ruleSet
.
setImplicit
(
false
);
ruleSet
.
setName
(
"Flash Constraints"
);
ruleSet
.
setName
(
GenerationProperties
.
FLASH_RULE_SET_NAME
);
ruleSet
.
setComment
(
"Automatically generated flash constraint."
);
ruleSet
.
getExplorationTargets
().
add
(
t
);
bundle
.
ruleSets
.
add
(
ruleSet
);
...
...
org.fortiss.af3.exploration.smt/trunk/test-src/org/fortiss/af3/exploration/ui/featuretest/GenerationProperties.java
View file @
af0dac77
...
...
@@ -113,6 +113,10 @@ public class GenerationProperties {
ALLOC_CONSTRAINT_DISTRIBUTION
allocConstraintDistribution
;
}
public
static
final
String
ALLOCATION_RULE_SET_NAME
=
"Allocation Rule Set"
;
public
static
final
String
FLASH_RULE_SET_NAME
=
"Flash Rule Set"
;
public
static
final
String
RAM_RULE_SET_NAME
=
"RAM Rule Set"
;
private
static
HashMap
<
ComponentArchitecture
,
AllGenerationProperties
>
propertiesMapping
=
new
HashMap
<>();
private
static
HashMap
<
PlatformArchitecture
,
AllGenerationProperties
>
propertiesMapping_HW
=
...
...
org.fortiss.af3.exploration.smt/trunk/test-src/org/fortiss/af3/exploration/ui/featuretest/GenericTest.java
View file @
af0dac77
...
...
@@ -18,21 +18,35 @@ package org.fortiss.af3.exploration.ui.featuretest;
import
static
org
.
fortiss
.
af3
.
exploration
.
util
.
DesignSpaceExplorationModelElementFactory
.
createExplorationSpecification
;
import
static
org
.
fortiss
.
af3
.
exploration
.
util
.
ExplorationUtils
.
convertRuleSetsToExplorationSpec
;
import
java.io.File
;
import
java.util.Collection
;
import
java.util.Optional
;
import
org.eclipse.emf.common.util.EList
;
import
org.eclipse.emf.common.util.URI
;
import
org.fortiss.af3.component.model.Component
;
import
org.fortiss.af3.efficientdeployment.model.Flash
;
import
org.fortiss.af3.exploration.dsl_v2.model.booleanp.allocation.Allocation
;
import
org.fortiss.af3.exploration.dsl_v2.model.expression.SuperSet
;
import
org.fortiss.af3.exploration.model.ExplorationSpecification
;
import
org.fortiss.af3.exploration.model.ExplorationTarget
;
import
org.fortiss.af3.exploration.model.SuperSetMap
;
import
org.fortiss.af3.exploration.model.solutions.ExplorationSolution
;
import
org.fortiss.af3.exploration.model.solutions.SolutionState
;
import
org.fortiss.af3.exploration.projectmodel.DSE
;
import
org.fortiss.af3.exploration.projectmodel.RuleSet
;
import
org.fortiss.af3.exploration.smt.modeltransformation.rework.DeploymentRun2
;
import
org.fortiss.af3.exploration.util.ExplorationUtils
;
import
org.fortiss.af3.platform.model.allocation.ComponentToExecutionUnitAllocationEntry
;
import
org.fortiss.af3.project.model.FileProject
;
import
org.fortiss.af3.project.utils.ProjectUtils
;
import
org.fortiss.af3.task.model.Task
;
import
org.fortiss.af3.task.model.allocation.ComponentToTaskAllocationTable
;
import
org.fortiss.tooling.base.model.element.IModelElement
;
import
org.fortiss.tooling.base.utils.AnnotationUtils
;
import
org.fortiss.tooling.common.util.LambdaUtils
;
import
org.fortiss.tooling.kernel.model.INamedElement
;
import
org.fortiss.tooling.kernel.utils.EcoreUtils
;
import
org.junit.Assert
;
import
org.junit.Test
;
/**
...
...
@@ -47,7 +61,6 @@ public class GenericTest {
String
absolutePath
=
NewProjectTestUtils
.
GeneralProject
.
getAbsolutePath
()
+
"/"
+
"DSE_Test_Project_554.af3_23"
;
File
file
=
new
File
(
absolutePath
);
org
.
eclipse
.
emf
.
common
.
util
.
URI
uri
=
URI
.
createFileURI
(
absolutePath
);
FileProject
fileProject
=
ProjectUtils
.
loadProjectFromURI
(
uri
,
true
);
Optional
<
DSE
>
firstOfType
=
...
...
@@ -55,8 +68,8 @@ public class GenericTest {
DSE
dse
=
firstOfType
.
get
();
DeploymentRun2
run
=
new
DeploymentRun2
();
Collection
<
ExplorationTarget
<?>>
targets
=
convertRuleSetsToExplorationSpec
(
dse
.
getDseRunArtifacts
().
get
(
0
).
getR
uleSets
()
);
EList
<
RuleSet
>
ruleSets
=
dse
.
getDseRunArtifacts
().
get
(
0
).
getRuleSets
();
Collection
<
ExplorationTarget
<?>>
targets
=
convertRuleSetsToExplorationSpec
(
r
uleSets
);
ExplorationSpecification
expSpec
=
createExplorationSpecification
();
expSpec
.
getTargets
().
addAll
(
targets
);
SuperSetMap
superSets
=
ExplorationUtils
.
convertToMap
(
dse
.
getDseSuperSet
());
...
...
@@ -64,5 +77,57 @@ public class GenericTest {
ExplorationSolution
expSolution
=
run
.
solveDeployment
(
expSpec
,
10000
,
null
);
expSolution
.
getUnsatConstraints
().
addAll
(
run
.
getFailedConstraints
());
ComponentToTaskAllocationTable
allocationTable
=
dse
.
getComponentToTaskAllocationTable
();
SuperSet
<
ComponentToExecutionUnitAllocationEntry
>
allocs
=
expSolution
.
getSolutions
().
get
(
0
)
.
getSolutionModel
(
ComponentToExecutionUnitAllocationEntry
.
class
);
// check in case of sat
if
(
expSolution
.
getSolutionState
().
getValue
()
!=
SolutionState
.
UNSAT_VALUE
)
checkConstraints
(
ruleSets
,
allocationTable
,
allocs
);
System
.
out
.
println
();
}
private
void
checkConstraints
(
EList
<
RuleSet
>
ruleSets
,
ComponentToTaskAllocationTable
allocationTable
,
SuperSet
<
ComponentToExecutionUnitAllocationEntry
>
allocs
)
{
for
(
RuleSet
rs
:
ruleSets
)
{
if
(
rs
.
getName
().
equals
(
GenerationProperties
.
ALLOCATION_RULE_SET_NAME
))
{
for
(
ExplorationTarget
<?>
et
:
rs
.
getExplorationTargets
())
{
Allocation
a
=
EcoreUtils
.
getFirstChildWithType
(
et
.
getExpression
(),
Allocation
.
class
);
IModelElement
left
=
a
.
getLeft
().
getSetReference
().
getEntries
().
get
(
0
);
IModelElement
right
=
a
.
getRight
().
getSetReference
().
getEntries
().
get
(
0
);
boolean
match
=
false
;
for
(
ComponentToExecutionUnitAllocationEntry
r
:
allocs
.
getEntries
())
{
EList
<
Component
>
components
=
allocationTable
.
getComponents
((
Task
)
left
);
boolean
leftMatch
=
r
.
getSourceElements
().
containsAll
(
components
);
boolean
rightMatch
=
r
.
getTargetElement
().
equals
(
right
);
match
=
leftMatch
&&
rightMatch
;
if
(
match
)
{
break
;
}
}
Assert
.
assertEquals
(((
INamedElement
)
left
).
getName
()
+
" is not allocated to "
+
((
INamedElement
)
right
).
getName
(),
true
,
match
);
}
}
else
if
(
rs
.
getName
().
equals
(
GenerationProperties
.
FLASH_RULE_SET_NAME
))
{
for
(
ComponentToExecutionUnitAllocationEntry
a
:
allocs
.
getEntries
())
{
int
flashSum
=
0
;
for
(
IModelElement
s
:
a
.
getSourceElements
())
{
Flash
annotation
=
AnnotationUtils
.
getAnnotation
(
s
,
Flash
.
class
);
flashSum
+=
annotation
.
getMemory
();
}
Flash
ecuAnnotation
=
AnnotationUtils
.
getAnnotation
(
a
.
getTargetElement
(),
Flash
.
class
);
boolean
actual
=
flashSum
<=
ecuAnnotation
.
getMemory
();
Assert
.
assertEquals
(
"Flash of ECU "
+
((
INamedElement
)
a
.
getTargetElement
()).
getName
()
+
" is exceeded."
,
true
,
actual
);
}
}
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment