mirror of
https://github.com/Echtzeitsysteme/gips-tests.git
synced 2024-05-20 12:00:56 +00:00
Adds a project and a test case to check correct eMoflon API termination
This commit is contained in:
parent
ecb69b9858
commit
e51a604c57
8
gips.gttermination/.classpath
Normal file
8
gips.gttermination/.classpath
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src-gen"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
25
gips.gttermination/.project
Normal file
25
gips.gttermination/.project
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>gips.gttermination</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.emoflon.gips.gipsl.ui.gipsNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
10
gips.gttermination/.settings/org.eclipse.jdt.core.prefs
Normal file
10
gips.gttermination/.settings/org.eclipse.jdt.core.prefs
Normal file
|
@ -0,0 +1,10 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
|
||||
org.eclipse.jdt.core.compiler.compliance=17
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=17
|
17
gips.gttermination/META-INF/MANIFEST.MF
Normal file
17
gips.gttermination/META-INF/MANIFEST.MF
Normal file
|
@ -0,0 +1,17 @@
|
|||
Manifest-Version: 1.0
|
||||
Automatic-Module-Name: gips.gttermination
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: gips.gttermination
|
||||
Bundle-Vendor: My Company
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Export-Package: gips.gttermination.connector
|
||||
Import-Package: test.suite.gips.utils
|
||||
Bundle-SymbolicName: gips.gttermination; singleton:=true
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-17
|
||||
Require-Bundle: org.emoflon.ibex.common,
|
||||
org.emoflon.ibex.gt,
|
||||
org.emoflon.gips.core,
|
||||
org.emoflon.ibex.gt.democles,
|
||||
org.emoflon.ibex.gt.hipe,
|
||||
gipsl.all.build.model
|
5
gips.gttermination/build.properties
Normal file
5
gips.gttermination/build.properties
Normal file
|
@ -0,0 +1,5 @@
|
|||
source.. = src/,\
|
||||
src-gen/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
plugin.xml
|
51
gips.gttermination/src/gips/gttermination/Model.gipsl
Normal file
51
gips.gttermination/src/gips/gttermination/Model.gipsl
Normal file
|
@ -0,0 +1,51 @@
|
|||
package "gips.gttermination"
|
||||
import "platform:/resource/gipsl.all.build.model/model/Model.ecore"
|
||||
|
||||
config {
|
||||
solver := GLPK [home:="fu", license:="bar"];
|
||||
launchConfig := true [main := "TODO"];
|
||||
timeLimit := true [value := 10.0];
|
||||
randomSeed := true [value := 73];
|
||||
presolve := true;
|
||||
debugOutput := true;
|
||||
}
|
||||
|
||||
rule mapVnode {
|
||||
root: Root {
|
||||
-containers -> substrateContainer
|
||||
-containers -> virtualContainer
|
||||
}
|
||||
|
||||
substrateContainer: SubstrateContainer {
|
||||
-substrateNodes -> snode
|
||||
}
|
||||
|
||||
virtualContainer: VirtualContainer {
|
||||
-virtualNodes -> vnode
|
||||
}
|
||||
|
||||
snode: SubstrateResourceNode
|
||||
|
||||
vnode: VirtualResourceNode {
|
||||
++ -host -> snode
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// GIPSL starts here!
|
||||
//
|
||||
|
||||
mapping n2n with mapVnode;
|
||||
|
||||
// AND
|
||||
constraint -> global {
|
||||
mappings.n2n->count() == 1
|
||||
}
|
||||
|
||||
objective nObj -> mapping::n2n {
|
||||
1
|
||||
}
|
||||
|
||||
global objective : max {
|
||||
nObj
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package gips.gttermination.connector;
|
||||
|
||||
import org.emoflon.gips.core.ilp.ILPSolverOutput;
|
||||
import org.emoflon.ibex.gt.api.GraphTransformationAPI;
|
||||
|
||||
import gips.gttermination.api.gips.GtterminationGipsAPI;
|
||||
import test.suite.gips.utils.AConnector;
|
||||
import test.suite.gips.utils.GipsTestUtils;
|
||||
import test.suite.gips.utils.GlobalTestConfig;
|
||||
|
||||
public class GtTerminationConnector extends AConnector {
|
||||
|
||||
public GtTerminationConnector(final String modelPath) {
|
||||
api = new GtterminationGipsAPI();
|
||||
api.init(GipsTestUtils.pathToAbsUri(modelPath));
|
||||
GlobalTestConfig.overrideSolver(api);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILPSolverOutput run(final String outputPath) {
|
||||
final ILPSolverOutput output = solve();
|
||||
((GtterminationGipsAPI) api).getN2n().applyNonZeroMappings();
|
||||
save(outputPath);
|
||||
return output;
|
||||
}
|
||||
|
||||
public GraphTransformationAPI getEmoflonApi() {
|
||||
return api.getEMoflonAPI();
|
||||
}
|
||||
|
||||
}
|
|
@ -20,6 +20,7 @@ Require-Bundle: junit-jupiter-api;bundle-version="5.9.0",
|
|||
gips.nullmodel;bundle-version="0.0.1",
|
||||
gips.scheduling.taskmodel;bundle-version="0.0.1"
|
||||
Import-Package: gips.generic.scheduling.connector,
|
||||
gips.gttermination.connector,
|
||||
gips.ilp.lpoutput.connector,
|
||||
gips.ilp.timeout.clsnotinmodel.connector,
|
||||
gips.ilp.timeout.connector,
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package test.suite.gips.gttermination;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.emoflon.gips.core.ilp.ILPSolverOutput;
|
||||
import org.emoflon.gips.core.ilp.ILPSolverStatus;
|
||||
import org.emoflon.ibex.common.operational.IMatch;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import gips.gttermination.connector.GtTerminationConnector;
|
||||
import model.Root;
|
||||
import test.suite.gipsl.all.build.AGipslAllBuildTest;
|
||||
|
||||
public class GipsGtTerminationTest extends AGipslAllBuildTest {
|
||||
|
||||
// Setup method/utilities
|
||||
|
||||
public void callableSetUp() {
|
||||
gen.persistModel(MODEL_PATH);
|
||||
con = new GtTerminationConnector(MODEL_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void terminateApi() {
|
||||
// Disable the automatic termination of the GIPS API of the super class
|
||||
}
|
||||
|
||||
// Actual tests
|
||||
|
||||
@Test
|
||||
public void testGtTermination() {
|
||||
gen.genSubstrateNode("s1", 2);
|
||||
gen.genVirtualNode("v1", 1);
|
||||
gen.genVirtualNode("v2", 1);
|
||||
callableSetUp();
|
||||
|
||||
final ILPSolverOutput ret = con.run(OUTPUT_PATH);
|
||||
assertEquals(ILPSolverStatus.OPTIMAL, ret.status());
|
||||
|
||||
// Get the interpreter and check number of matches before the termination
|
||||
// (must be 2)
|
||||
final var interpreter = ((GtTerminationConnector) con).getEmoflonApi().getInterpreter();
|
||||
final Iterator<Collection<IMatch>> it = interpreter.getMatches().values().iterator();
|
||||
assertTrue(it.hasNext());
|
||||
final var matches = it.next();
|
||||
assertEquals(2, matches.size());
|
||||
|
||||
// Terminate the GIPS API; this should also terminate the GT interpreter
|
||||
((GtTerminationConnector) con).terminate();
|
||||
|
||||
// Remove model elements such that all matches are invalid
|
||||
var res = ((GtTerminationConnector) con).getEmoflonApi().getModel().getResources().get(0);
|
||||
final Root root = (Root) res.getContents().get(0);
|
||||
root.getContainers().clear();
|
||||
|
||||
// Update matches
|
||||
interpreter.updateMatches();
|
||||
|
||||
// Now, **two** matches must still be present
|
||||
final Iterator<Collection<IMatch>> it2 = interpreter.getMatches().values().iterator();
|
||||
assertTrue(it2.hasNext());
|
||||
final var matches2 = it2.next();
|
||||
assertEquals(2, matches2.size(), "GT engine termination failed.");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue