Commit 79c0d286 authored by Johannes Eder's avatar Johannes Eder
Browse files

DSE SMT Test Cases

parent fb93785a
This source diff could not be displayed because it is too large. You can view the blob instead.
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2017 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.exploration.ui;
import static org.fortiss.af3.task.util.TaskArchitectureUtils.transformIntoTaskArchitecture;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.exploration.projectmodel.DSE;
import org.fortiss.af3.exploration.projectmodel.RuleSet;
import org.fortiss.af3.exploration.projectmodel.dseArtifacts.DSEPlatformArtifact;
import org.fortiss.af3.exploration.projectmodel.dseArtifacts.DSESuperSets;
import org.fortiss.af3.exploration.smt.model.SMTConstraint;
import org.fortiss.af3.exploration.smt.modeltransformation.rework.BasicDeploymentConstraint;
import org.fortiss.af3.exploration.smt.modeltransformation.rework.DeploymentRun2;
import org.fortiss.af3.exploration.smt.util.DeploymentSMTResult;
import org.fortiss.af3.exploration.smt.util.RouteUtils;
import org.fortiss.af3.exploration.util.DSEProjectModelElementFactory;
import org.fortiss.af3.platform.model.PlatformArchitecture;
import org.fortiss.af3.project.model.FileProject;
import org.fortiss.af3.project.utils.ProjectModelElementFactory;
import org.fortiss.af3.task.model.Signal;
import org.fortiss.af3.task.model.TaskArchitecture;
import org.fortiss.tooling.base.model.element.IConnection;
import org.junit.Test;
/**
*
* @author eder
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public class DseFeatureTest {
private class TestBundle {
ComponentArchitecture ca;
PlatformArchitecture pa;
}
/** Tests the DSE feature with different architectures. */
public List<TestBundle> createBundles() {
long before = System.currentTimeMillis();
LogArchTopologyGeneration logArchGeneration = new LogArchTopologyGeneration(10, 4);
List<ComponentArchitecture> generate = logArchGeneration.generate();
LogArchAnnotationGeneration annotationGeneration =
new LogArchAnnotationGeneration(generate);
List<ComponentArchitecture> generate2 = annotationGeneration.generate();
System.out.println();
System.out.println("Generated " + generate2.size() + " Component Architectures in " +
((System.currentTimeMillis() - before) / 1000) + "s");
long intermediate = System.currentTimeMillis();
TechArchTopologyGeneration techArchTopologyGeneration = new TechArchTopologyGeneration();
List<PlatformArchitecture> generate3 = techArchTopologyGeneration.generate();
System.out.println();
System.out.println("Generated " + generate3.size() + " Platform Architectures in " +
((System.currentTimeMillis() - intermediate) / 1000) + "s");
long intermediate2 = System.currentTimeMillis();
List<TestBundle> toTest = new ArrayList<>();
for(ComponentArchitecture ca : generate2) {
for(PlatformArchitecture pa : generate3) {
TestBundle bundle = new TestBundle();
bundle.ca = ca;
bundle.pa = pa;
toTest.add(bundle);
}
}
System.out.println();
System.out.println("Generated " + toTest.size() + " Test Cases in " +
((System.currentTimeMillis() - intermediate2) / 1000) + "s");
System.out.println("--\nTotal time: " + ((System.currentTimeMillis() - before) / 1000) +
"s");
return toTest;
}
@Test
public void test() {
long before = System.currentTimeMillis();
List<TestBundle> testBundles = createBundles();
int i = 0;
int max = testBundles.size();
String progress = "";
long lastProgressPercentage = 0;
try {
File file = new File("DSE_Test.csv");
FileOutputStream fileOutputStream = new FileOutputStream(file);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream);
outputStreamWriter.append("ComponentArchitecture, PlatformArchitecture, test \n");
// outputStreamWriter.append("ca, pa, 098 \n");
for(TestBundle bundle : testBundles) {
FileProject fileProject =
ProjectModelElementFactory.createFileProject("Dummy",
ProjectModelElementFactory.createProjectConfiguration());
DSE dse = DSEProjectModelElementFactory.createDSE();
fileProject.getRootElements().add(dse);
fileProject.getRootElements().add(bundle.ca);
fileProject.getRootElements().add(bundle.pa);
ComponentArchitecture ca = bundle.ca;
Component topComponent = ca.getTopComponent();
TaskArchitecture taskArchitecture = transformIntoTaskArchitecture(topComponent);
EList<Signal> signals = taskArchitecture.getSignals();
List<IConnection> connections = new ArrayList<>();
connections.addAll(signals);
DSEPlatformArtifact platformArchitecureArtifact =
DSEProjectModelElementFactory.createDsePlatformArtifact(bundle.pa);
dse.setDsePlatformArchitecture(platformArchitecureArtifact);
platformArchitecureArtifact.getVirtualLinks().addAll(
RouteUtils.extractRoutes(platformArchitecureArtifact));
DSESuperSets dseSuperSets =
DSEProjectModelElementFactory.createDseSuperSets(taskArchitecture,
platformArchitecureArtifact);
List<SMTConstraint> createBasicSignalConstraint =
BasicDeploymentConstraint.createBasicSignalConstraint(connections,
platformArchitecureArtifact, dseSuperSets);
RuleSet subSet = DSEProjectModelElementFactory.createRuleSet();
subSet.getExplorationTargets().addAll(createBasicSignalConstraint);
subSet.setImplicit(true);
subSet.setName("Basic Deployment Constraints");
subSet.setComment("Automatically added constraint.");
List<RuleSet> subsets = new ArrayList<>();
subsets.add(subSet);
DeploymentRun2 deploymentRun2 = new DeploymentRun2();
long solverStart = System.currentTimeMillis();
DeploymentSMTResult smtResult =
deploymentRun2.solveDeployment(subsets, 10000, null, dseSuperSets);
long solverDuration = System.currentTimeMillis() - solverStart;
// if(smtResult.isUNKNOWN()) {
// System.out.println("Platform:" + bundle.pa.getName());
// System.out.println("Components:" +
// bundle.ca.getTopComponent().getSubComponents().size());
// }
String string = GenerationProperties.INSTANCE.getPropertiesAsString(ca);
String arch =
bundle.ca.getTopComponent().getSubComponents().size() + " Components, " +
bundle.pa.getName() + ",";
outputStreamWriter.append(arch + string + "," + (solverDuration / 1000) + "\n");
// Assert.assertTrue(smtResult.isSAT());
double d = (i * 1.0) / (max * 1.0) * 100.0;
long progressPercentage = Math.round(d);
// System.out.println();
System.out.println("__");
System.out.print("Progress: " + progressPercentage + "% |");
for(long p = 0; p < progressPercentage; ++p) {
System.out.print("-");
}
for(long p = progressPercentage; p < 100; ++p) {
System.out.print(" ");
}
System.out.print("|");
System.out.println();
System.out.println("__");
i++;
}
outputStreamWriter.flush();
outputStreamWriter.close();
} catch(IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("--\nTotal time: " + ((System.currentTimeMillis() - before) / 1000) +
"s");
}
}
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2017 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.exploration.ui;
import java.util.HashMap;
import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.tooling.kernel.utils.EcoreUtils;
/**
*
* @author eder
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public class GenerationProperties {
/** Toplogies. */
public enum TOPOLOGY {
SINGLETON, PAIRS, STAR, LINE, COMPLETE;
}
/** Channel directions. */
public enum CHANNEL_DIRECTIONS {
UNI_DIR, BI_DIR;
}
public enum ASIL_DISTRIBUTION {
ASIL_A_ONLY, ASIL_D_ONLY, ASIL_MIX_AD
}
public enum RAM_DISTRIBUTION {
ONE, TEN, HUNDRED
}
public enum FLASH_DISTRIBUTION {
ONE, TEN, HUNDRED
}
public class AllGenerationProperties {
TOPOLOGY topology;
CHANNEL_DIRECTIONS channelDirections;
ASIL_DISTRIBUTION asildistribution;
RAM_DISTRIBUTION ramDistribution;
FLASH_DISTRIBUTION flashDistribution;
}
private static HashMap<ComponentArchitecture, AllGenerationProperties> propertiesMapping =
new HashMap<>();
public static GenerationProperties INSTANCE = new GenerationProperties();
public void setProperty(ComponentArchitecture ca, TOPOLOGY top) {
AllGenerationProperties agp = getProperties(ca);
agp.topology = top;
}
public void setProperty(ComponentArchitecture ca, CHANNEL_DIRECTIONS ch) {
AllGenerationProperties agp = getProperties(ca);
agp.channelDirections = ch;
}
public void setProperty(ComponentArchitecture ca, ASIL_DISTRIBUTION as) {
AllGenerationProperties agp = getProperties(ca);
agp.asildistribution = as;
}
public void setProperty(ComponentArchitecture ca, RAM_DISTRIBUTION as) {
AllGenerationProperties agp = getProperties(ca);
agp.ramDistribution = as;
}
public void setProperty(ComponentArchitecture ca, FLASH_DISTRIBUTION as) {
AllGenerationProperties agp = getProperties(ca);
agp.flashDistribution = as;
}
public AllGenerationProperties getPropertiesFor(ComponentArchitecture ca) {
return propertiesMapping.get(ca);
}
/**
* @param ca
* @return
*/
private AllGenerationProperties getProperties(ComponentArchitecture ca) {
AllGenerationProperties agp;
if(!propertiesMapping.containsKey(ca)) {
agp = new AllGenerationProperties();
propertiesMapping.put(ca, agp);
} else {
agp = propertiesMapping.get(ca);
}
return agp;
}
public String getPropertiesAsString(ComponentArchitecture ca) {
AllGenerationProperties agp = propertiesMapping.get(ca);
String resultString = "";
resultString += "Topology: " + agp.topology.name() + ", ";
resultString += "ChannelDir: " + agp.channelDirections.name() + ", ";
resultString += "ASIL_Dist: " + agp.asildistribution.name() + ",";
resultString += "RAM_Dist: " + agp.ramDistribution.name() + ",";
resultString += "Flash_Dist: " + agp.flashDistribution.name();
return resultString;
}
/**
*
*/
public ComponentArchitecture copy(ComponentArchitecture ca) {
AllGenerationProperties agp = propertiesMapping.get(ca);
ComponentArchitecture copy = EcoreUtils.copy(ca);
if(agp != null) {
AllGenerationProperties newagp = new AllGenerationProperties();
newagp.asildistribution = agp.asildistribution;
newagp.channelDirections = agp.channelDirections;
newagp.flashDistribution = agp.flashDistribution;
newagp.ramDistribution = agp.ramDistribution;
newagp.topology = agp.topology;
propertiesMapping.put(copy, newagp);
}
return copy;
}
}
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2017 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.exploration.ui;
import java.util.ArrayList;
import java.util.List;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.efficientdeployment.model.DSEModelFactory;
import org.fortiss.af3.efficientdeployment.model.Flash;
import org.fortiss.af3.efficientdeployment.model.RAM;
import org.fortiss.af3.exploration.ui.GenerationProperties.ASIL_DISTRIBUTION;
import org.fortiss.af3.exploration.ui.GenerationProperties.FLASH_DISTRIBUTION;
import org.fortiss.af3.exploration.ui.GenerationProperties.RAM_DISTRIBUTION;
import org.fortiss.af3.safety.model.ASIL;
import org.fortiss.af3.safety.model.SafetyStandard;
import org.fortiss.af3.safety.model.annotation.SafetyAnnotationFactory;
import org.fortiss.af3.safety.model.annotation.SafetyIntegrityLevel;
/**
*
* @author eder
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public class LogArchAnnotationGeneration {
private List<ComponentArchitecture> bluePrintArchitectures;
/** Constructor. */
public LogArchAnnotationGeneration(List<ComponentArchitecture> architectures) {
this.bluePrintArchitectures = architectures;
}
/** Generate. */
public List<ComponentArchitecture> generate() {
List<ComponentArchitecture> generateASILDist = generateASILDist(bluePrintArchitectures);
List<ComponentArchitecture> generateRAM = generateRAM(generateASILDist);
List<ComponentArchitecture> generateROM = generateFlash(generateRAM);
return generateROM;
}
/**
* @param ca
* @return
*/
private List<ComponentArchitecture> generateASILDist(
List<ComponentArchitecture> bluePrintArchitectures) {
List<ComponentArchitecture> results = new ArrayList<>();
for(ComponentArchitecture ca : bluePrintArchitectures) {
for(ASIL_DISTRIBUTION asil : ASIL_DISTRIBUTION.values()) {
if(ca.getTopComponent().getSubComponents().isEmpty()) {
continue;
}
ComponentArchitecture copy = GenerationProperties.INSTANCE.copy(ca);
Component topComponent;
GenerationProperties.INSTANCE.setProperty(copy, asil);
switch(asil) {
case ASIL_A_ONLY:
topComponent = copy.getTopComponent();
for(Component comp : topComponent.getSubComponents()) {
setSafetyLevel(comp, ASIL.ASILA);
}
break;
case ASIL_D_ONLY:
topComponent = copy.getTopComponent();
for(Component comp : topComponent.getSubComponents()) {
setSafetyLevel(comp, ASIL.ASILD);
}
break;
case ASIL_MIX_AD:
topComponent = copy.getTopComponent();
int half = topComponent.getSubComponents().size() / 2;
int counter = 0;
for(Component comp : topComponent.getSubComponents()) {
// half of the components will be ASIL A and half ASIL D
if(counter < half) {
setSafetyLevel(comp, ASIL.ASILA);
} else {
setSafetyLevel(comp, ASIL.ASILD);
}
counter++;
}
break;
default:
System.err.println("ASIL rule " + asil.name() + " not implemented.");
break;
}
results.add(copy);
}
}
return results;
}
/**
* @param ca
* @return
*/
private List<ComponentArchitecture> generateRAM(
List<ComponentArchitecture> bluePrintArchitectures) {
List<ComponentArchitecture> results = new ArrayList<>();
for(ComponentArchitecture ca : bluePrintArchitectures) {
for(RAM_DISTRIBUTION ram : RAM_DISTRIBUTION.values()) {
if(ca.getTopComponent().getSubComponents().isEmpty()) {
continue;
}
ComponentArchitecture copy = GenerationProperties.INSTANCE.copy(ca);
Component topComponent;
GenerationProperties.INSTANCE.setProperty(copy, ram);
switch(ram) {
case ONE:
topComponent = copy.getTopComponent();
for(Component comp : topComponent.getSubComponents()) {
setRAM(comp, 1);
}
break;
case TEN:
topComponent = copy.getTopComponent();
for(Component comp : topComponent.getSubComponents()) {
setRAM(comp, 10);
}
break;
case HUNDRED:
topComponent = copy.getTopComponent();
for(Component comp : topComponent.getSubComponents()) {
setRAM(comp, 100);
}
break;
default:
System.err.println("RAM rule " + ram.name() + " not implemented.");
break;
}
results.add(copy);
}
}
return results;
}
/**
* @param ca
* @return
*/
private List<ComponentArchitecture> generateFlash(
List<ComponentArchitecture> bluePrintArchitectures) {
List<ComponentArchitecture> results = new ArrayList<>();
for(ComponentArchitecture ca : bluePrintArchitectures) {
for(FLASH_DISTRIBUTION flash : FLASH_DISTRIBUTION.values()) {
if(ca.getTopComponent().getSubComponents().isEmpty()) {
continue;
}
ComponentArchitecture copy = GenerationProperties.INSTANCE.copy(ca);
Component topComponent;
GenerationProperties.INSTANCE.setProperty(copy, flash);
switch(flash) {
case ONE:
topComponent = copy.getTopComponent();
for(Component comp : topComponent.getSubComponents()) {
setFlash(comp, 1);
}
break;
case TEN:
topComponent = copy.getTopComponent();
for(Component comp : topComponent.getSubComponents()) {
setFlash(comp, 10);
}
break;
case HUNDRED:
topComponent = copy.getTopComponent();
for(Component comp : topComponent.getSubComponents()) {
setFlash(comp, 100);
}
break;
default:
System.err.println("Flash rule " + flash.name() + " not implemented.");
break;
}
results.add(copy);
}
}
return results;
}
/**
* @param comp
* @param i
*/
private void setFlash(Component comp, int i) {
Flash rom = DSEModelFactory.eINSTANCE.createFlash();
rom.setMemory(i);
comp.addSpecification(rom);
}