Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Alexander Diewald
AF3-new
Commits
fee1eb05
Commit
fee1eb05
authored
Sep 15, 2020
by
Simon Barner
Browse files
Merge branch '4048' into 'master'
4048 See merge request af3/af3!356
parents
99ee765f
330c39dc
Changes
6
Hide whitespace changes
Inline
Side-by-side
org.fortiss.af3.exploration/src/org/fortiss/af3/exploration/testgenerator/.ratings
View file @
fee1eb05
ArchitectureGraph.java 4f1539b6997b7a71d744ef750aa2f102097f211d GREEN
ExplorationTestCaseGenerator.java 5
83c4679996e0c8c277c23da4f5285dea849b650
GREEN
ExplorationTestCaseGenerator.java 5
e16627d68276a1e90912e1e85d65ef01e1303e6
GREEN
org.fortiss.af3.exploration/src/org/fortiss/af3/exploration/testgenerator/ExplorationTestCaseGenerator.java
View file @
fee1eb05
...
...
@@ -18,33 +18,41 @@ package org.fortiss.af3.exploration.testgenerator;
import
static
org
.
fortiss
.
af3
.
exploration
.
testgenerator
.
util
.
AnnotationGenerationUtils
.
expandArchitecturesByAnnotations
;
import
static
org
.
fortiss
.
af3
.
exploration
.
testgenerator
.
util
.
CompArchGeneratonUtil
.
generateLogicalArchitectures
;
import
static
org
.
fortiss
.
af3
.
exploration
.
testgenerator
.
util
.
DseUtils
.
expandByDseProblems
;
import
static
org
.
fortiss
.
af3
.
exploration
.
testgenerator
.
util
.
FileWriterUtil
.
write
;
import
static
org
.
fortiss
.
af3
.
exploration
.
testgenerator
.
util
.
GraphMetricUtils
.
getGraphMetrics
;
import
static
org
.
fortiss
.
af3
.
exploration
.
testgenerator
.
util
.
ProjectUtils
.
createAF3Projects
;
import
static
org
.
fortiss
.
af3
.
exploration
.
testgenerator
.
util
.
ProjectUtils
.
saveFileProjects
;
import
static
org
.
fortiss
.
af3
.
exploration
.
util
.
ExplorationUtils
.
isDumpTestgenGraphmetricsEnabled
;
import
static
org
.
fortiss
.
af3
.
project
.
utils
.
FileUtils
.
getDefaultGeneralProjectURI
;
import
static
org
.
fortiss
.
af3
.
project
.
utils
.
TestCaseProjectUtils
.
loadTestProject
;
import
static
org
.
fortiss
.
tooling
.
base
.
utils
.
AnnotationUtils
.
instantiateAnnotationsRecursive
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
EcoreUtils
.
copy
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
EcoreUtils
.
getFirstChildWithType
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
EcoreUtils
.
pickFirstInstanceOf
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
EcoreUtils
.
pickInstanceOf
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
LoggingUtils
.
error
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
LoggingUtils
.
info
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Future
;
import
org.fortiss.af3.component.model.Component
;
import
org.fortiss.af3.component.model.ComponentArchitecture
;
import
org.fortiss.af3.exploration.AF3ExplorationActivator
;
import
org.fortiss.af3.exploration.dseml.model.expression.SuperSet
;
import
org.fortiss.af3.exploration.model.IExplorationConstraint
;
import
org.fortiss.af3.exploration.model.IExplorationObjective
;
import
org.fortiss.af3.exploration.model.IExplorationTarget
;
import
org.fortiss.af3.exploration.model.project.DSE
;
import
org.fortiss.af3.exploration.model.project.ProcessStep
;
import
org.fortiss.af3.exploration.model.project.RuleSet
;
import
org.fortiss.af3.platform.model.PlatformArchitecture
;
import
org.fortiss.af3.project.model.FileProject
;
import
org.fortiss.af3.task.model.TaskArchitecture
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
/**
* Generator for DSE test case {@link FileProject}s. It creates deployment problems with generated
...
...
@@ -75,9 +83,6 @@ public class ExplorationTestCaseGenerator {
// Generate component Architectures
Collection
<
ComponentArchitecture
>
genCompArchs
=
generateLogicalArchitectures
(
compArchNum
,
minComponentNum
,
maxComponentNum
);
if
(
isDumpTestgenGraphmetricsEnabled
())
{
dumpGraphMetrics
(
genCompArchs
);
}
Collection
<
FileProject
>
fileProjects
=
createAF3Projects
(
genCompArchs
,
platformArchitectures
,
"DSE_Generated_TestCase"
);
...
...
@@ -86,43 +91,102 @@ public class ExplorationTestCaseGenerator {
fileProjects
=
expandByDseProblems
(
fileProjects
);
info
(
AF3ExplorationActivator
.
getDefault
(),
"Test cases are generated in the runtime
W
orkspace."
);
"Test cases are generated in the runtime
w
orkspace."
);
// Instantiate missing annotations.
fileProjects
.
forEach
(
fp
->
instantiateAnnotationsRecursive
(
fp
));
saveFileProjects
(
fileProjects
);
dumpDSEMetrics
(
fileProjects
);
}
/** Dumps the graph metrics of each generated {@link ComponentArchitecture}. */
private
static
void
dumpGraphMetrics
(
Collection
<
ComponentArchitecture
>
compArchs
)
throws
Exception
{
// Setup the parallel graph metric calculation by callables.
Set
<
Callable
<
Map
<
ComponentArchitecture
,
Map
<
String
,
Double
>>>>
graphMetricsCallables
=
new
HashSet
<
Callable
<
Map
<
ComponentArchitecture
,
Map
<
String
,
Double
>>>>();
compArchs
.
stream
().
forEach
(
componentArchitecture
->
graphMetricsCallables
.
add
(
new
Callable
<
Map
<
ComponentArchitecture
,
Map
<
String
,
Double
>>>()
{
@Override
public
Map
<
ComponentArchitecture
,
Map
<
String
,
Double
>>
call
()
throws
Exception
{
Map
<
ComponentArchitecture
,
Map
<
String
,
Double
>>
graphMetrics
=
new
HashMap
<
ComponentArchitecture
,
Map
<
String
,
Double
>>();
graphMetrics
.
put
(
componentArchitecture
,
getGraphMetrics
(
componentArchitecture
));
return
graphMetrics
;
/** Dumps information about the generated DSE test cases to a JSON file. */
@SuppressWarnings
(
"unchecked"
)
private
static
void
dumpDSEMetrics
(
Collection
<
FileProject
>
fileProjects
)
{
JSONObject
jsonObject
=
new
JSONObject
();
JSONArray
testCaseMetaData
=
new
JSONArray
();
try
{
jsonObject
.
put
(
"testcaseNumber"
,
fileProjects
.
size
());
jsonObject
.
put
(
"testcases"
,
testCaseMetaData
);
}
catch
(
JSONException
e
)
{
String
errorMsg
=
"Could not dump the meta data of the testcases."
;
error
(
AF3ExplorationActivator
.
getDefault
(),
errorMsg
,
e
);
}
for
(
FileProject
fp
:
fileProjects
)
{
try
{
JSONObject
projectMetaData
=
new
JSONObject
();
projectMetaData
.
put
(
"name"
,
fp
.
getName
());
DSE
dse
=
getFirstChildWithType
(
fp
,
DSE
.
class
);
ProcessStep
pStep
=
dse
.
getCurrentStep
();
SuperSet
<
Component
>
cSet
=
pStep
.
getSuperSetMap
().
get
(
Component
.
class
);
projectMetaData
.
put
(
"components"
,
cSet
.
getEntries
().
size
());
if
(
isDumpTestgenGraphmetricsEnabled
())
{
ComponentArchitecture
compArch
=
pickFirstInstanceOf
(
ComponentArchitecture
.
class
,
fp
.
getRootElements
());
JSONObject
compMetrics
=
new
JSONObject
(
getGraphMetrics
(
compArch
));
projectMetaData
.
put
(
"componentMetrics"
,
compMetrics
);
}
int
allConstraintsNumber
=
0
;
int
allObjectivesNumber
=
0
;
JSONArray
rsMetaDataArr
=
new
JSONArray
();
for
(
RuleSet
rS
:
pStep
.
getRuleSets
())
{
JSONObject
ruleSetMetaData
=
new
JSONObject
();
ruleSetMetaData
.
put
(
"name"
,
rS
.
getName
());
List
<
IExplorationTarget
<?>>
targets
=
rS
.
getExplorationTargets
();
@SuppressWarnings
(
"rawtypes"
)
List
<
IExplorationConstraint
>
constraints
=
pickInstanceOf
(
IExplorationConstraint
.
class
,
targets
);
@SuppressWarnings
(
"rawtypes"
)
List
<
IExplorationObjective
>
objectives
=
pickInstanceOf
(
IExplorationObjective
.
class
,
targets
);
if
(!
constraints
.
isEmpty
())
{
createExplorationTargetJSONArray
(
ruleSetMetaData
,
"constraints"
,
"constraintNames"
,
(
List
<?
extends
IExplorationTarget
<?>>)
constraints
);
allConstraintsNumber
+=
constraints
.
size
();
}
}));
// Execute the callables in parallel.
ExecutorService
graphMetricsExecutor
=
Executors
.
newFixedThreadPool
(
4
);
List
<
Future
<
Map
<
ComponentArchitecture
,
Map
<
String
,
Double
>>>>
futureGraphMetrics
=
graphMetricsExecutor
.
invokeAll
(
graphMetricsCallables
);
Map
<
ComponentArchitecture
,
Map
<
String
,
Double
>>
graphMetrics
=
new
HashMap
<
ComponentArchitecture
,
Map
<
String
,
Double
>>();
for
(
Future
<
Map
<
ComponentArchitecture
,
Map
<
String
,
Double
>>>
futureMetrics
:
futureGraphMetrics
)
{
graphMetrics
.
putAll
(
futureMetrics
.
get
());
if
(!
objectives
.
isEmpty
())
{
createExplorationTargetJSONArray
(
ruleSetMetaData
,
"objectives"
,
"objectiveNames"
,
(
List
<?
extends
IExplorationTarget
<?>>)
objectives
);
allObjectivesNumber
+=
objectives
.
size
();
}
rsMetaDataArr
.
put
(
ruleSetMetaData
);
}
projectMetaData
.
put
(
"constraints"
,
allConstraintsNumber
);
projectMetaData
.
put
(
"objectives"
,
allObjectivesNumber
);
projectMetaData
.
put
(
"ruleSets"
,
rsMetaDataArr
);
testCaseMetaData
.
put
(
projectMetaData
);
}
catch
(
JSONException
e
)
{
String
errorMsg
=
"Could not dump the meta data of the test case "
+
fp
.
getName
()
+
"."
;
error
(
AF3ExplorationActivator
.
getDefault
(),
errorMsg
,
e
);
}
}
graphMetricsExecutor
.
shutdown
();
write
(
"graph-metrics.csv"
,
graphMetrics
);
String
file
=
getDefaultGeneralProjectURI
().
appendSegment
(
"testcase-metadata.json"
)
.
toFileString
();
try
(
FileWriter
fw
=
new
FileWriter
(
file
))
{
fw
.
write
(
jsonObject
.
toString
(
2
));
}
catch
(
JSONException
|
IOException
e
)
{
String
errorMsg
=
"Could not write to the file "
+
file
+
"."
;
error
(
AF3ExplorationActivator
.
getDefault
(),
errorMsg
,
e
);
}
}
/** Creates a JSON-based description of the given {@link IExplorationTarget}s. */
private
static
void
createExplorationTargetJSONArray
(
JSONObject
ruleSetMetaData
,
String
sizeName
,
String
listName
,
List
<?
extends
IExplorationTarget
<?>>
targets
)
throws
JSONException
{
JSONArray
cNames
=
new
JSONArray
();
ruleSetMetaData
.
put
(
sizeName
,
targets
.
size
());
targets
.
forEach
(
c
->
cNames
.
put
(
c
.
getName
()));
ruleSetMetaData
.
put
(
listName
,
cNames
);
}
}
org.fortiss.af3.exploration/src/org/fortiss/af3/exploration/testgenerator/util/.ratings
View file @
fee1eb05
AnnotationGenerationUtils.java
599f568c7e7da8555399ae7ee4eb922cb490effd
GREEN
AnnotationGenerationUtils.java
0808cbc47239dfb8984690b51864ad5ea594bb01
GREEN
CompArchGeneratonUtil.java 0f1e3c048884fa4df6a35b6a110c46da58f59857 GREEN
DseUtils.java
beac7de04c0b5450f96799257ec57616b2ddc044
GREEN
DseUtils.java
1a9e73e2605271ad1e559e4ad38843171a60a48d
GREEN
FileWriterUtil.java 4a95559f571d41fa44e6236fc055ab5baac7c384 GREEN
GraphGenerationUtilities.java e637fd6a38339c60a6a7ac5af116db304266d345 GREEN
GraphMetricUtils.java 99a398d4ff9b15b3eeb35748e32aa34a9b197f07 GREEN
GraphUtils.java 4d59affe2bab3113f48d1a827ad0bc9599b3439e GREEN
ProjectUtils.java
5d4b2cbae16526bd99fedf38a10866d3b2eadde5
GREEN
ProjectUtils.java
0228e21e2875a9f7a472bb6ebacdf0574e9c7c10
GREEN
org.fortiss.af3.exploration/src/org/fortiss/af3/exploration/testgenerator/util/AnnotationGenerationUtils.java
View file @
fee1eb05
...
...
@@ -16,6 +16,7 @@
package
org.fortiss.af3.exploration.testgenerator.util
;
import
static
java
.
lang
.
Math
.
floor
;
import
static
java
.
lang
.
System
.
currentTimeMillis
;
import
static
java
.
math
.
BigDecimal
.
valueOf
;
import
static
org
.
fortiss
.
af3
.
safety
.
model
.
SafetyStandard
.
IEC61508
;
import
static
org
.
fortiss
.
tooling
.
base
.
utils
.
AnnotationUtils
.
getAnnotation
;
...
...
@@ -23,6 +24,7 @@ import static org.fortiss.tooling.base.utils.AnnotationUtils.setAnnotationValue;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
EcoreUtils
.
copy
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
EcoreUtils
.
getChildrenWithType
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
EcoreUtils
.
pickFirstInstanceOf
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
LoggingUtils
.
error
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
...
...
@@ -31,6 +33,7 @@ import java.util.List;
import
java.util.Random
;
import
org.fortiss.af3.component.model.ComponentArchitecture
;
import
org.fortiss.af3.exploration.AF3ExplorationActivator
;
import
org.fortiss.af3.platform.model.PlatformArchitecture
;
import
org.fortiss.af3.platform.model.annotation.FlashSize
;
import
org.fortiss.af3.platform.model.annotation.RamSize
;
...
...
@@ -43,6 +46,7 @@ import org.fortiss.af3.task.model.annotation.FlashRequirement;
import
org.fortiss.af3.task.model.timing.TaskStartEvent
;
import
org.fortiss.af3.timing.model.PeriodicConstraint
;
import
org.fortiss.af3.timing.model.TimingSpecification
;
import
org.fortiss.af3.timing.model.annotation.Wcet
;
import
org.fortiss.tooling.kernel.utils.EcoreUtils
;
/**
...
...
@@ -75,7 +79,7 @@ public class AnnotationGenerationUtils {
* PlatformArchitecture Annotations.
**********************************************************************************************/
private
final
static
Integer
[]
ANNOTATION
_AMOUNT
=
{
1
,
100
,
1000
};
private
final
static
Integer
[]
FLASH
_AMOUNT
=
{
1
0
,
100
,
1000
};
/** Sets the annotation values for the {@link PlatformArchitecture}s. */
private
static
Collection
<
FileProject
>
...
...
@@ -90,7 +94,7 @@ public class AnnotationGenerationUtils {
private
static
Collection
<
FileProject
>
defineRAM
(
Collection
<
FileProject
>
fileProjects
)
{
Collection
<
FileProject
>
expandedProjects
=
new
ArrayList
<>();
for
(
FileProject
origProject
:
fileProjects
)
{
for
(
int
amount
:
ANNOTATION
_AMOUNT
)
{
for
(
int
amount
:
FLASH
_AMOUNT
)
{
FileProject
project
=
copy
(
origProject
);
PlatformArchitecture
platArch
=
pickFirstInstanceOf
(
PlatformArchitecture
.
class
,
project
.
getRootElements
());
...
...
@@ -107,7 +111,7 @@ public class AnnotationGenerationUtils {
private
static
Collection
<
FileProject
>
defineFlash
(
Collection
<
FileProject
>
fileProjects
)
{
Collection
<
FileProject
>
expandedProjects
=
new
ArrayList
<>();
for
(
FileProject
origProject
:
fileProjects
)
{
for
(
int
amount
:
ANNOTATION
_AMOUNT
)
{
for
(
int
amount
:
FLASH
_AMOUNT
)
{
FileProject
project
=
copy
(
origProject
);
PlatformArchitecture
platArch
=
pickFirstInstanceOf
(
PlatformArchitecture
.
class
,
project
.
getRootElements
());
...
...
@@ -157,12 +161,18 @@ public class AnnotationGenerationUtils {
Collection
<
FileProject
>
expandedFileProjects
=
new
ArrayList
<>();
for
(
FileProject
filePrj
:
fileProjects
)
{
PlatformArchitecture
platArch
=
pickFirstInstanceOf
(
PlatformArchitecture
.
class
,
filePrj
.
getRootElements
());
List
<
FlashSize
>
flashAnnotations
=
getChildrenWithType
(
platArch
,
FlashSize
.
class
);
long
availFlash
=
flashAnnotations
.
stream
().
map
(
flash
->
flash
.
getValue
())
.
mapToLong
(
Long:
:
longValue
).
sum
();
for
(
double
memoryUsage
=
0.5
;
memoryUsage
<
1
;
memoryUsage
+=
0.25
)
{
FileProject
expandedFP
=
EcoreUtils
.
copy
(
filePrj
);
TaskArchitecture
taskArch
=
pickFirstInstanceOf
(
TaskArchitecture
.
class
,
expandedFP
.
getRootElements
());
defineTaskMemoryRequirements
(
taskArch
,
550
,
memoryUsage
);
defineWCETs
(
expandedFP
,
taskArch
);
defineTaskMemoryRequirements
(
taskArch
,
availFlash
,
memoryUsage
);
defineWCETs
(
taskArch
);
definePeriods
(
expandedFP
,
taskArch
);
expandedFileProjects
.
add
(
expandedFP
);
}
}
...
...
@@ -173,8 +183,8 @@ public class AnnotationGenerationUtils {
/**
* Defines the flash memory requirements of tasks based on an upper limit and random assignment.
*/
private
static
void
defineTaskMemoryRequirements
(
TaskArchitecture
taskArch
,
int
availableMemory
,
double
memoryUsageRatio
)
throws
Exception
{
private
static
void
defineTaskMemoryRequirements
(
TaskArchitecture
taskArch
,
long
availableMemory
,
double
memoryUsageRatio
)
throws
Exception
{
List
<
Task
>
tasks
=
taskArch
.
getTasks
();
int
childComponentNum
=
tasks
.
size
();
List
<
Long
>
memoryRequirements
=
...
...
@@ -186,6 +196,23 @@ public class AnnotationGenerationUtils {
}
}
/** Defines the WCETs of tasks. */
private
static
void
defineWCETs
(
TaskArchitecture
taskArch
)
{
Random
rand
=
new
Random
(
currentTimeMillis
());
// We use the sum of task WCETs to get an upper bound for single-core execution. Not
// considering allocation constraints, no multicore-based schedule should be worse
for
(
Task
task
:
taskArch
.
getTasks
())
{
BigDecimal
wcet
=
new
BigDecimal
(
rand
.
nextDouble
());
try
{
setAnnotationValue
(
task
,
Wcet
.
class
,
wcet
);
}
catch
(
Exception
e
)
{
error
(
AF3ExplorationActivator
.
getDefault
(),
"Could not set the WCET of the task "
+
task
.
getName
()
+
"."
);
}
}
}
/**
* Generates a set of memory requirements, one for each component.
*
...
...
@@ -197,7 +224,7 @@ public class AnnotationGenerationUtils {
* Ratio of the total amount of memory to use
* @return A set of integers, each representing a memory constraint for a component
*/
private
static
List
<
Long
>
generateMemoryRequirements
(
int
availableMemory
,
private
static
List
<
Long
>
generateMemoryRequirements
(
long
availableMemory
,
int
numberOfComponents
,
double
memoryUsageRatio
)
{
double
maxMemory
=
availableMemory
*
memoryUsageRatio
;
...
...
@@ -217,8 +244,8 @@ public class AnnotationGenerationUtils {
return
memoryRequirements
;
}
/** Defines the
WCET
s of tasks. */
private
static
void
define
WCET
s
(
FileProject
fp
,
TaskArchitecture
taskArch
)
{
/** Defines the
Period
s of tasks. */
private
static
void
define
Period
s
(
FileProject
fp
,
TaskArchitecture
taskArch
)
{
TimingSpecification
timingSpec
=
pickFirstInstanceOf
(
TimingSpecification
.
class
,
fp
.
getRootElements
());
...
...
org.fortiss.af3.exploration/src/org/fortiss/af3/exploration/testgenerator/util/DseUtils.java
View file @
fee1eb05
...
...
@@ -24,6 +24,8 @@ import static java.util.stream.Collectors.toList;
import
static
org
.
fortiss
.
af3
.
exploration
.
util
.
DSEProjectModelElementFactory
.
createDSE
;
import
static
org
.
fortiss
.
af3
.
exploration
.
util
.
DSEProjectModelElementFactory
.
createRuleSet
;
import
static
org
.
fortiss
.
af3
.
exploration
.
util
.
DSEProjectModelElementFactory
.
createTargetDefinitionStep
;
import
static
org
.
fortiss
.
af3
.
exploration
.
util
.
DSMLModelElementFactory
.
createAnd
;
import
static
org
.
fortiss
.
af3
.
exploration
.
util
.
DSMLModelElementFactory
.
createBooleanLiteral
;
import
static
org
.
fortiss
.
af3
.
exploration
.
util
.
ExplorationModelElementFactory
.
createExplorationConstraint
;
import
static
org
.
fortiss
.
af3
.
exploration
.
util
.
ExplorationModelElementFactory
.
createReliabilityDimension
;
import
static
org
.
fortiss
.
af3
.
exploration
.
util
.
ExplorationModelElementFactory
.
createResourceDimension
;
...
...
@@ -50,10 +52,10 @@ import java.util.Random;
import
org.eclipse.core.runtime.Assert
;
import
org.fortiss.af3.allocation.model.AllocationTableCollection
;
import
org.fortiss.af3.component.model.ComponentArchitecture
;
import
org.fortiss.af3.exploration.dseml.model.booleanp.IBooleanExpression
;
import
org.fortiss.af3.exploration.dseml.model.expression.IExpression
;
import
org.fortiss.af3.exploration.dseml.model.expression.SuperSet
;
import
org.fortiss.af3.exploration.model.IExplorationConstraint
;
import
org.fortiss.af3.exploration.model.IExplorationTarget
;
import
org.fortiss.af3.exploration.model.project.DSE
;
import
org.fortiss.af3.exploration.model.project.InitialInputDefinitionStep
;
import
org.fortiss.af3.exploration.model.project.ModelSnapshot
;
...
...
@@ -66,11 +68,12 @@ import org.fortiss.af3.platform.model.ExecutionUnit;
import
org.fortiss.af3.platform.model.PlatformArchitecture
;
import
org.fortiss.af3.platform.model.Route
;
import
org.fortiss.af3.platform.model.annotation.FlashSize
;
import
org.fortiss.af3.platform.model.annotation.RamSize
;
import
org.fortiss.af3.project.model.FileProject
;
import
org.fortiss.af3.task.model.Task
;
import
org.fortiss.af3.task.model.TaskArchitecture
;
import
org.fortiss.af3.task.model.allocation.TaskToExecutionUnitAllocationEntry
;
import
org.fortiss.af3.task.model.annotation.FlashRequirement
;
import
org.fortiss.af3.task.model.annotation.RamRequirement
;
import
org.fortiss.af3.timing.model.TimingSpecification
;
import
org.fortiss.tooling.kernel.model.IProjectRootElement
;
import
org.fortiss.tooling.kernel.utils.EcoreUtils
;
...
...
@@ -83,8 +86,8 @@ import org.fortiss.tooling.kernel.utils.EcoreUtils;
*/
public
class
DseUtils
{
/** Maximally allowed flash utilization per {@link ExecutionUnit}
.
*/
private
static
final
int
FLASH_MAX_UTIL
_PERCENT
=
1
0
0
;
/** Maximally allowed flash utilization per {@link ExecutionUnit}
(ratio)
*/
private
static
final
double
FLASH_MAX_UTIL
=
1
.
0
;
/** List of task percentages whose allocation is fixed. */
private
static
final
int
[]
ALLOC_PERCENTAGES
=
{
0
,
25
,
50
,
75
};
...
...
@@ -99,11 +102,10 @@ public class DseUtils {
expandByDseProblems
(
Collection
<
FileProject
>
fileProjects
)
{
fileProjects
.
forEach
(
fp
->
createAddDse
(
fp
));
// NOTE: The methods must group the produced constraints into RuleSets.
fileProjects
=
addFlashConstraints
(
fileProjects
);
fileProjects
=
expandByAllocationConstraints
(
fileProjects
);
fileProjects
=
createRuleSets
(
fileProjects
);
return
fileProjects
;
}
...
...
@@ -135,9 +137,8 @@ public class DseUtils {
ModelSnapshot
allocSnap
=
createAllocationTableCollectionSnapshot
(
firstOfType
(
copiedRootElements
,
AllocationTableCollection
.
class
).
get
());
ModelSnapshot
timeSnap
=
ModelSnapshotExtractUtils
.
createTimingSpecificationSnapshot
(
Optional
.
of
(
allocSnap
.
getSuperSet
(
TaskToExecutionUnitAllocationEntry
.
class
)),
taSnap
.
getSuperSet
(
Task
.
class
),
paSnap
.
getSuperSet
(
Route
.
class
),
Optional
.
empty
(),
firstOfType
(
copiedRootElements
,
TimingSpecification
.
class
).
get
());
Optional
.
empty
(),
taSnap
.
getSuperSet
(
Task
.
class
),
paSnap
.
getSuperSet
(
Route
.
class
),
Optional
.
empty
(),
firstOfType
(
copiedRootElements
,
TimingSpecification
.
class
).
get
());
inputDefStep
.
addSnapshot
(
caSnap
);
inputDefStep
.
addSnapshot
(
paSnap
);
...
...
@@ -174,22 +175,25 @@ public class DseUtils {
Collection
<
IExplorationConstraint
<
Boolean
>>
constraints
=
new
ArrayList
<>();
SuperSet
<
ExecutionUnit
>
execUnits
=
dse
.
getCurrentStep
().
getSuperSetMap
().
get
(
ExecutionUnit
.
class
);
for
(
ExecutionUnit
execUnit
:
execUnits
.
getEntries
())
{
IExpression
expr
=
createUtilizationPatternExpression
(
dse
,
FLASH_MAX_UTIL_PERCENT
,
execUnit
,
FlashRequirement
.
class
,
FlashSize
.
class
);
@SuppressWarnings
(
"unchecked"
)
IExplorationConstraint
<
Boolean
>
constr
=
createExplorationConstraint
(
Boolean
.
class
,
createResourceDimension
(),
newHashSet
(
IDeploymentSynthesis
.
class
),
expr
,
"Max Flash Util "
+
FLASH_MAX_UTIL_PERCENT
+
" of "
+
execUnit
.
getName
()
+
"."
,
false
);
constraints
.
add
(
constr
);
}
RuleSet
flashRuleSet
=
createRuleSet
(
"Flash constraints"
,
"Generated"
,
""
);
flashRuleSet
.
getExplorationTargets
().
addAll
(
constraints
);
tgtDefStep
.
getDefinedTargets
().
addAll
(
constraints
);
tgtDefStep
.
getDefinedRuleSets
().
add
(
flashRuleSet
);
IBooleanExpression
expression
=
createBooleanLiteral
(
true
);
for
(
ExecutionUnit
executionUnit
:
execUnits
.
getEntries
())
{
expression
=
createAnd
(
expression
,
createUtilizationPatternExpression
(
dse
,
FLASH_MAX_UTIL
,
executionUnit
,
RamRequirement
.
class
,
RamSize
.
class
));
}
@SuppressWarnings
(
"unchecked"
)
IExplorationConstraint
<
Boolean
>
constr
=
createExplorationConstraint
(
Boolean
.
class
,
createResourceDimension
(),
newHashSet
(
IDeploymentSynthesis
.
class
),
expression
,
"Max Flash Util "
+
FLASH_MAX_UTIL
*
100
+
" of all ExecutionUnits."
,
false
);
if
(!
constraints
.
isEmpty
())
{
RuleSet
flashRuleSet
=
createRuleSet
(
"Flash constraints"
,
"Generated"
,
""
);
flashRuleSet
.
getExplorationTargets
().
add
(
constr
);
tgtDefStep
.
getDefinedTargets
().
add
(
constr
);
tgtDefStep
.
getDefinedRuleSets
().
add
(
flashRuleSet
);
}
}
return
fileProjects
;
...
...
@@ -215,11 +219,14 @@ public class DseUtils {
Collection
<
IExplorationConstraint
<?>>
constraints
=
genAllocConstraints
(
dse
,
tgtDefStep
.
getSuperSetMap
().
get
(
Task
.
class
),
tgtDefStep
.
getSuperSetMap
().
get
(
ExecutionUnit
.
class
),
preAllocPercent
);
RuleSet
allocRuleSet
=
createRuleSet
(
"Alloc constraints"
,
"Generated"
,
""
);
allocRuleSet
.
getExplorationTargets
().
addAll
(
constraints
);
tgtDefStep
.
getDefinedTargets
().
addAll
(
constraints
);
tgtDefStep
.
getDefinedRuleSets
().
add
(
allocRuleSet
);
if
(!
constraints
.
isEmpty
())
{
RuleSet
allocRuleSet
=
createRuleSet
(
"Alloc constraints"
,
"Generated"
,
""
);
allocRuleSet
.
getExplorationTargets
().
addAll
(
constraints
);
tgtDefStep
.
getDefinedTargets
().
addAll
(
constraints
);
tgtDefStep
.
getDefinedRuleSets
().
add
(
allocRuleSet
);
}
}
}
...
...
@@ -243,7 +250,7 @@ public class DseUtils {
LinkedList
<
Task
>
tasks
=
new
LinkedList
<>(
taskSet
.
getEntries
());
shuffle
(
tasks
);
int
numTasksToAllocate
=
(
int
)
floor
(
allocPercent
*
tasks
.
size
()
/
100
d
);
int
numTasksToAllocate
=
(
int
)
floor
(
allocPercent
*
tasks
.
size
());
while
((
allocConstraints
.
size
()
<
numTasksToAllocate
)
&&
!
tasks
.
isEmpty
())
{
Task
task
=
tasks
.
poll
();
...
...
@@ -268,22 +275,4 @@ public class DseUtils {
return
allocConstraints
;
}
/**
* Collects all {@link IExplorationTarget}s of each {@link DSE} in the given
* {@link FileProject}s in a {@link RuleSet}s.
*/
private
static
Collection
<
FileProject
>
createRuleSets
(
Collection
<
FileProject
>
fileProjects
)
{
for
(
FileProject
fp
:
fileProjects
)
{
DSE
dse
=
pickFirstInstanceOf
(
DSE
.
class
,
fp
.
getRootElements
());
ProcessStep
pStep
=
dse
.
getCurrentStep
();
if
(
pStep
instanceof
TargetDefinitionStep
)
{
RuleSet
allTgtRuleSet
=
createRuleSet
(
"CLI All Defined Targets"
,
"No author"
,
"No comment"
);
((
TargetDefinitionStep
)
pStep
).
getDefinedRuleSets
().
add
(
allTgtRuleSet
);
}
}
return
fileProjects
;
}
}
org.fortiss.af3.exploration/src/org/fortiss/af3/exploration/testgenerator/util/ProjectUtils.java
View file @
fee1eb05
...
...
@@ -24,10 +24,12 @@ import static org.fortiss.af3.project.utils.ProjectModelElementFactory.createFil
import
static
org
.
fortiss
.
af3
.
project
.
utils
.
ProjectModelElementFactory
.
createProjectConfiguration
;
import
static
org
.
fortiss
.
af3
.
project
.
utils
.
ProjectUtils
.
ensureEclipseContainerProjectExists
;
import
static
org
.
fortiss
.
af3
.
project
.
utils
.
ProjectUtils
.
saveProject
;
import
static
org
.
fortiss
.
af3
.
task
.
util
.
TaskModelElementFactory
.
createTaskToExecutionUnitAllocationTable
;
import
static
org
.
fortiss
.
af3
.
timing
.
utils
.
TimingModelElementFactory
.
createEntityEvent
;
import
static
org
.
fortiss
.
af3
.
timing
.
utils
.
TimingModelElementFactory
.
createPeriodicConstraint
;
import
static
org
.
fortiss
.
af3
.
timing
.
utils
.
TimingModelElementFactory
.
createTimingSpecification
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
EcoreUtils
.
copy
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
EcoreUtils
.
getFirstChildWithType
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
UniqueIDUtils
.
generateAllIDs
;
import
java.io.IOException
;
...
...
@@ -39,6 +41,8 @@ import java.util.List;
import
org.eclipse.emf.common.util.URI
;
import
org.fortiss.af3.allocation.model.AllocationTableCollection
;
import
org.fortiss.af3.component.model.ComponentArchitecture
;
import
org.fortiss.af3.exploration.model.project.DSE
;
import
org.fortiss.af3.exploration.model.project.InitialInputDefinitionStep
;
import
org.fortiss.af3.platform.model.PlatformArchitecture
;
import
org.fortiss.af3.project.model.FileProject
;
import
org.fortiss.af3.task.model.Task
;
...
...
@@ -77,7 +81,12 @@ public class ProjectUtils {
AllocationTableCollection
allocTableColl
=
createAllocationTableCollection
(
"AllocationTable"
);
TaskArchitecture
taskArch
=
generateTaskArchitecture
(
fpCompArch
,
allocTableColl
);
// Create an empty Task --> HW allocation table to store WCETs
allocTableColl
.
getContainedElements
().
add
(
createTaskToExecutionUnitAllocationTable
(
"Task_ExU Allocs"
,
taskArch
,
fpPlatArch
));
TimingSpecification
timingSpec
=
generateTimingSpecification
(
taskArch
);
FileProject
fp
=
createAF3Project
(
fpCompArch
,
taskArch
,
timingSpec
,
allocTableColl
,
...
...
@@ -118,8 +127,7 @@ public class ProjectUtils {
pConstraint
.
setPeriod
(
BigDecimal
.
ONE
);
pConstraint
.
setJitter
(
BigDecimal
.
ZERO
);
TaskStartEvent
startEvent
=
(
TaskStartEvent
)
createEntityEvent
(
TaskStartEvent
.
class
,
task
);
TaskStartEvent
startEvent
=
createEntityEvent
(
TaskStartEvent
.
class
,
task
);
timingSpec
.
addEvent
(
startEvent
);
pConstraint
.
setEvent
(
startEvent
);
...
...
@@ -153,7 +161,23 @@ public class ProjectUtils {
for
(
FileProject
fp
:
fileProjects
)
{
generateAllIDs
(
fp
);
fp
.
setName
(
fp
.
getName
()
+
"_"
+
++
projectID
);
// Set readable name for file project, DSE node and initial import step
String
nameSuffix
=
"_"
+
++
projectID
;
fp
.
setName
(
fp
.
getName
()
+
nameSuffix
);
DSE
dse
=
getFirstChildWithType
(
fp
,
DSE
.
class
);