Skip to content

WIP: Adds a test case to trigger the elt bug in the GIPSL code gen #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions gipsl.all.build.eltbug/.classpath
Original file line number Diff line number Diff line change
@@ -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-21"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src-gen"/>
<classpathentry kind="output" path="bin"/>
</classpath>
25 changes: 25 additions & 0 deletions gipsl.all.build.eltbug/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>gipsl.all.build.eltbug</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>
7 changes: 7 additions & 0 deletions gipsl.all.build.eltbug/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=21
17 changes: 17 additions & 0 deletions gipsl.all.build.eltbug/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Manifest-Version: 1.0
Automatic-Module-Name: gipsl.all.build.eltbug
Bundle-ManifestVersion: 2
Bundle-Name: gipsl.all.build.eltbug
Bundle-Vendor: My Company
Bundle-Version: 1.0.0.qualifier
Export-Package: gipsl.all.build.eltbug.connector
Bundle-SymbolicName: gipsl.all.build.eltbug; singleton:=true
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-21
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,
test.suite.utils
5 changes: 5 additions & 0 deletions gipsl.all.build.eltbug/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source.. = src/,\
src-gen/
bin.includes = META-INF/,\
.,\
plugin.xml
58 changes: 58 additions & 0 deletions gipsl.all.build.eltbug/src/gipsl/all/build/eltbug/Model.gipsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package "gipsl.all.build.eltbug"
import "platform:/resource/gipsl.all.build.model/model/Model.ecore"

config {
solver := GUROBI;
timeLimit := true [value := 10.0];
randomSeed := true [value := 0];
presolve := true;
debugOutput := false;
}

rule mapVnode {
root: Root {
-containers -> substrateContainer
-containers -> virtualContainer
}

substrateContainer: SubstrateContainer {
-substrateNodes -> snode
}

virtualContainer: VirtualContainer {
-virtualNodes -> vnode
}

snode: SubstrateResourceNode

vnode: VirtualResourceNode {
++ -host -> snode
}
}

pattern findRoot {
root : Root
}

//
// GIPSL starts here!
//

mapping n2n to mapVnode;

// Every node must be mapped exactly once
constraint with VirtualNode {
mappings.n2n->filter(element.nodes.vnode == context)->sum(element.value) == 1
}

// This function triggers the bug within the code generation
function dummy with Root {
mappings.n2n->sum(element.value)
*
patterns.findRoot->sum(1)
// ^this does also trigger the bug when access uses `rules.xy`
}

objective : min {
functions.dummy
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package gipsl.all.build.eltbug.connector;

import org.emoflon.gips.core.milp.SolverOutput;

import gipsl.all.build.eltbug.api.gips.EltbugGipsAPI;
import test.suite.gips.utils.AConnector;
import test.suite.gips.utils.GipsTestUtils;
import test.suite.gips.utils.GlobalTestConfig;

public class EltBugConnector extends AConnector {

public EltBugConnector(final String modelPath) {
api = new EltbugGipsAPI();
api.init(GipsTestUtils.pathToAbsUri(modelPath));
GlobalTestConfig.overrideSolver(api);
}

@Override
public SolverOutput run(final String outputPath) {
final SolverOutput output = solve();
((EltbugGipsAPI) api).getN2n().applyNonZeroMappings();
return output;
}

}
1 change: 1 addition & 0 deletions test.suite.gips/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Import-Package: gips.enumequals.connector,
gipsl.all.build.and.connector,
gipsl.all.build.booleanbrackets.connector,
gipsl.all.build.count.connector,
gipsl.all.build.eltbug.connector,
gipsl.all.build.equals.fxeqctrafo.connector,
gipsl.all.build.filter.connector,
gipsl.all.build.implication.connector,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package test.suite.gipsl.all.build;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.emoflon.gips.core.milp.SolverOutput;
import org.emoflon.gips.core.milp.SolverStatus;
import org.junit.jupiter.api.Test;

import gipsl.all.build.eltbug.connector.EltBugConnector;

public class GipslAllBuildEltBugTest extends AGipslAllBuildTest {

// Setup method

public void callableSetUp() {
gen.persistModel(MODEL_PATH);
con = new EltBugConnector(MODEL_PATH);
}

// Actual tests
// Positive tests

@Test
public void testMap2to1() {
gen.genSubstrateNode("s1", 10);
gen.genVirtualNode("v1", 1);
gen.genVirtualNode("v2", 1);
callableSetUp();

final SolverOutput ret = con.run(OUTPUT_PATH);

assertEquals(SolverStatus.OPTIMAL, ret.status());
assertEquals(2, ret.objectiveValue());
}

@Override
public Class<?> getConnectorClass() {
return EltBugConnector.class;
}

}