Commit 771b183f authored by Alexander Diewald's avatar Alexander Diewald

DSE-TCgen: Random Annotation Values for Platforms

In addition, the template PlatformArchitecture project is migrated to
the most recent version.

Issue-Ref: 4008
Issue-Url: https://af3-developer.fortiss.org/issues/4008Signed-off-by: Alexander Diewald's avatarAlexander Diewald <diewald@fortiss.org>
parent 0b6699a4
ArchitectureGraph.java 4f1539b6997b7a71d744ef750aa2f102097f211d YELLOW
ExplorationTestCaseGenerator.java 4465dd009dc67100d8e854b16c3088c3c368dfea RED
ExplorationTestCaseGenerator.java 6073ddd68470a1e6c6844b0df40f1443d81b0f0c YELLOW
......@@ -15,25 +15,19 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.exploration.testgenerator;
import static java.io.File.separator;
import static org.eclipse.emf.common.util.URI.createURI;
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.defineDSEProblems;
import static org.fortiss.af3.exploration.testgenerator.util.FileWriterUtil.write;
import static org.fortiss.af3.exploration.testgenerator.util.GraphUtil.getGraphMetrics;
import static org.fortiss.af3.exploration.testgenerator.util.ProjectUtil.createAF3Projects;
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.AF3Project.AF3_PRJ_SUFFIX;
import static org.fortiss.af3.project.utils.FileUtils.getDefaultGeneralProjectURI;
import static org.fortiss.af3.project.utils.ProjectUtils.ensureEclipseContainerProjectExists;
import static org.fortiss.af3.project.utils.ProjectUtils.saveProject;
import static org.fortiss.af3.project.utils.TestCaseProjectUtils.loadTestProject;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.copy;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.info;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
......@@ -45,7 +39,6 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.eclipse.emf.common.util.URI;
import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.exploration.AF3ExplorationActivator;
import org.fortiss.af3.platform.model.PlatformArchitecture;
......@@ -53,7 +46,9 @@ import org.fortiss.af3.project.model.FileProject;
import org.fortiss.af3.task.model.TaskArchitecture;
/**
* A JUnit test generating deployment problems.
* Generator for DSE test case {@link FileProject}s. It creates deployment problems with generated
* {@link ComponentArchitecture}s having a random structure and randomly assigned annotation values
* for generated {@link TaskArchitecture}s and {@link PlatformArchitecture}s.
*
* @author munaro
* @author diewald
......@@ -95,19 +90,6 @@ public class ExplorationTestCaseGenerator {
saveFileProjects(fileProjects);
}
/** Saves the given set of {@link FileProject}s to the AF3 workspace. */
// TODO(AD): Revisit this method after #3993 is merged. It should be combined with parts of the
// import method from the ProjectUtils
private static void saveFileProjects(Collection<FileProject> fileProjects) throws IOException {
ensureEclipseContainerProjectExists();
for(FileProject fp : fileProjects) {
URI prjURI = createURI(getDefaultGeneralProjectURI() + separator + fp.getName() + "." +
AF3_PRJ_SUFFIX);
saveProject(fp, prjURI);
}
}
/** Dumps the graph metrics of each generated {@link ComponentArchitecture}. */
private static void dumpGraphMetrics(Collection<ComponentArchitecture> compArchs)
throws Exception {
......
AnnotationGenerationUtils.java 902cf3ca212e472ff053848fa9df7244a838a827 YELLOW
AnnotationGenerationUtils.java 7fdab0a64ce72636bc59262b889b62eed54980ee YELLOW
CompArchGeneratonUtil.java 2796a78ae842d0cb0f8851ad607df5d8fb51e3f8 RED
ConstraintUtil.java 229f48efcae173018b06514d9c20fe2a89421063 RED
DseUtils.java c143d8d122a2aa7c547ef53d43e46ccc20ac1ee6 RED
......@@ -6,4 +6,5 @@ FileWriterUtil.java 4a95559f571d41fa44e6236fc055ab5baac7c384 YELLOW
GraphGenerationUtilities.java 3be2143bf23befd2c9103c621ce31accf65b7cc6 YELLOW
GraphMetricUtils.java ce15ba42b7bd36ad2ae46ebd084911e69c815a5f YELLOW
GraphUtil.java afaec2934ff3038bdcf9d10f7b75c71f0dd2e036 YELLOW
ProjectUtil.java cdd68b52cb6d9a7b7de8e49525886bec0b7d2720 YELLOW
ProjectUtil.java 169730c7438788f79faa4dd8d5a3017f5941c3d9 YELLOW
ProjectUtils.java fe0009a32f6aaa58fb3330e2b9e383e217afc0dd YELLOW
......@@ -16,7 +16,11 @@
package org.fortiss.af3.exploration.testgenerator.util;
import static java.lang.Math.floor;
import static org.fortiss.af3.safety.model.SafetyStandard.IEC61508;
import static org.fortiss.tooling.base.utils.AnnotationUtils.getAnnotation;
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 java.util.ArrayList;
......@@ -25,7 +29,12 @@ import java.util.List;
import java.util.Random;
import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.platform.model.PlatformArchitecture;
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.safety.model.SIL;
import org.fortiss.af3.safety.model.annotation.SafetyIntegrityLevel;
import org.fortiss.af3.task.model.Task;
import org.fortiss.af3.task.model.TaskArchitecture;
import org.fortiss.af3.task.model.annotation.FlashRequirement;
......@@ -50,15 +59,93 @@ public class AnnotationGenerationUtils {
*/
public static Collection<FileProject> expandArchitecturesByAnnotations(
Collection<FileProject> fileProjects) throws Exception {
Collection<FileProject> expandedFileProjects = new ArrayList<>(fileProjects);
// Add the expansion code for other
fileProjects = definePlatformArchitectureAnnotations(fileProjects);
fileProjects = expandTaskArchitecturesByAnnotations(fileProjects);
expandedFileProjects = expandTaskArchitecturesByAnnotations(expandedFileProjects);
return fileProjects;
}
return expandedFileProjects;
/***********************************************************************************************
* PlatformArchitecture Annotations.
**********************************************************************************************/
private final static Integer[] ANNOTATION_AMOUNT = {1, 100, 1000};
/** Sets the annotation values for the {@link PlatformArchitecture}s. */
private static Collection<FileProject>
definePlatformArchitectureAnnotations(Collection<FileProject> fileProjects) {
fileProjects = defineRAM(fileProjects);
fileProjects = defineFlash(fileProjects);
fileProjects = defineSIL(fileProjects);
return fileProjects;
}
/** Sets the values of {@link RamSize} annotations. */
private static Collection<FileProject> defineRAM(Collection<FileProject> fileProjects) {
Collection<FileProject> expandedProjects = new ArrayList<>();
for(FileProject origProject : fileProjects) {
for(int amount : ANNOTATION_AMOUNT) {
FileProject project = copy(origProject);
PlatformArchitecture platArch =
pickFirstInstanceOf(PlatformArchitecture.class, project.getRootElements());
List<RamSize> rams = getChildrenWithType(platArch, RamSize.class);
rams.forEach(ram -> ram.setBytes(amount));
expandedProjects.add(project);
}
}
return expandedProjects;
}
/** Sets the values of {@link FlashSize} annotations. */
private static Collection<FileProject> defineFlash(Collection<FileProject> fileProjects) {
Collection<FileProject> expandedProjects = new ArrayList<>();
for(FileProject origProject : fileProjects) {
for(int amount : ANNOTATION_AMOUNT) {
FileProject project = copy(origProject);
PlatformArchitecture platArch =
pickFirstInstanceOf(PlatformArchitecture.class, project.getRootElements());
List<FlashSize> falshs = getChildrenWithType(platArch, FlashSize.class);
falshs.forEach(flash -> flash.setBytes(amount));
expandedProjects.add(project);
}
}
return expandedProjects;
}
/** Sets the values of {@link SafetyIntegrityLevel} annotations. */
private static Collection<FileProject> defineSIL(Collection<FileProject> fileProjects) {
Random rand = new Random(System.currentTimeMillis());
Collection<FileProject> expandedProjects = new ArrayList<>();
for(FileProject origProject : fileProjects) {
FileProject project = copy(origProject);
PlatformArchitecture platArch =
pickFirstInstanceOf(PlatformArchitecture.class, project.getRootElements());
SafetyIntegrityLevel platSafety = getAnnotation(platArch, SafetyIntegrityLevel.class);
platSafety.setSafetyStandard(IEC61508);
for(SafetyIntegrityLevel sil : getChildrenWithType(platArch,
SafetyIntegrityLevel.class)) {
// Levels range from 0 to Max, then there is an "undefined" enum that is also the
// exclusive upper bound here.
int lvlIdx = rand.nextInt(SIL.VALUES.size());
sil.setSilValue(SIL.get(lvlIdx));
}
expandedProjects.add(project);
}
return expandedProjects;
}
/***********************************************************************************************
* TaskArchitecture Annotations.
**********************************************************************************************/
/** Adds annotations to the {@link TaskArchitecture}s of the given {@link FileProject}s */
private static Collection<FileProject> expandTaskArchitecturesByAnnotations(
Collection<FileProject> fileProjects) throws Exception {
......
......@@ -15,16 +15,24 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.exploration.testgenerator.util;
import static java.io.File.separator;
import static org.eclipse.emf.common.util.URI.createURI;
import static org.fortiss.af3.allocation.utils.AllocationModelElementFactory.createAllocationTableCollection;
import static org.fortiss.af3.project.AF3Project.AF3_PRJ_SUFFIX;
import static org.fortiss.af3.project.utils.FileUtils.getDefaultGeneralProjectURI;
import static org.fortiss.af3.project.utils.ProjectModelElementFactory.createFileProject;
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.tooling.kernel.utils.EcoreUtils.copy;
import static org.fortiss.tooling.kernel.utils.UniqueIDUtils.generateAllIDs;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
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.platform.model.PlatformArchitecture;
......@@ -40,10 +48,10 @@ import org.fortiss.af3.task.util.ComponentToTaskArchitectureTransformation;
* @author munaro
* @author diewald
*/
public class ProjectUtil {
public class ProjectUtils {
/** Hiding constructor. */
private ProjectUtil() {
private ProjectUtils() {
// Prevent instantiation.
}
......@@ -51,7 +59,6 @@ public class ProjectUtil {
public static List<FileProject> createAF3Projects(Collection<ComponentArchitecture> compArchs,
Collection<PlatformArchitecture> platArchs, String name) throws IllegalStateException {
List<FileProject> fileProjects = new ArrayList<>();
int projectCounter = 0;
for(PlatformArchitecture platArch : platArchs) {
for(ComponentArchitecture compArch : compArchs) {
......@@ -64,10 +71,9 @@ public class ProjectUtil {
createAllocationTableCollection("AllocationTable");
TaskArchitecture taskArch = generateTaskArchitecture(fpCompArch, allocTableColl);
FileProject fp = createAF3Project(fpCompArch, taskArch, allocTableColl, fpPlatArch,
name + "-" + projectCounter);
FileProject fp =
createAF3Project(fpCompArch, taskArch, allocTableColl, fpPlatArch, name);
fileProjects.add(fp);
projectCounter++;
}
}
......@@ -104,8 +110,21 @@ public class ProjectUtil {
fileProject.getRootElements().add(taskArch);
fileProject.getRootElements().add(platformArchitecture);
generateAllIDs(fileProject);
return fileProject;
}
/** Saves the given set of {@link FileProject}s to the AF3 workspace. */
public static void saveFileProjects(Collection<FileProject> fileProjects) throws IOException {
ensureEclipseContainerProjectExists();
int projectID = -1;
for(FileProject fp : fileProjects) {
generateAllIDs(fp);
fp.setName(fp.getName() + "_" + ++projectID);
URI prjURI = createURI(getDefaultGeneralProjectURI() + separator + fp.getName() + "." +
AF3_PRJ_SUFFIX);
saveProject(fp, prjURI);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment