Skip to content

Commit

Permalink
Re-enable temporarily disabled test
Browse files Browse the repository at this point in the history
  • Loading branch information
lhstrh committed Jan 19, 2023
1 parent 68ddd53 commit 3ad413b
Showing 1 changed file with 90 additions and 86 deletions.
176 changes: 90 additions & 86 deletions org.lflang.tests/src/org/lflang/tests/compiler/LetInferenceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,33 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***************/

import static org.lflang.ASTUtils.toDefinition;

import javax.inject.Inject;

import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.extensions.InjectionExtension;
import org.eclipse.xtext.testing.util.ParseHelper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

//import org.lflang.ASTUtils;
//import org.lflang.DefaultErrorReporter;
//import org.lflang.FileConfig;
//import org.lflang.TimeUnit;
//import org.lflang.TimeValue;
//import org.lflang.ast.AfterDelayTransformation;
//import org.lflang.generator.ReactionInstance;
//import org.lflang.generator.ReactorInstance;
//import org.lflang.generator.c.CDelayBodyGenerator;
//import org.lflang.generator.c.CGenerator;
//import org.lflang.generator.c.CTypes;
//import org.lflang.lf.Instantiation;
//import org.lflang.lf.LfFactory;
import org.lflang.ASTUtils;
import org.lflang.DefaultErrorReporter;
import org.lflang.TimeUnit;
import org.lflang.TimeValue;
import org.lflang.ast.AfterDelayTransformation;
import org.lflang.generator.ReactionInstance;
import org.lflang.generator.ReactorInstance;
import org.lflang.generator.c.CDelayBodyGenerator;
import org.lflang.generator.c.CTypes;
import org.lflang.lf.Instantiation;
import org.lflang.lf.LfFactory;

import org.lflang.lf.Model;
import org.lflang.lf.Reactor;
import org.lflang.tests.LFInjectorProvider;

@ExtendWith(InjectionExtension.class)
Expand All @@ -66,78 +71,77 @@ class LetInferenceTest {
ParseHelper<Model> parser;


// @Test
// public void testLet() throws Exception {
// Model model = parser.parse(String.join(
// System.getProperty("line.separator"),
// "target C;",
// "main reactor {",
// " ramp = new Ramp();",
// " print = new Print();",
// " print2 = new Print();",
// " ramp.y -> print.x after 20 msec;",
// " ramp.y -> print2.x after 30 msec;",
// "}",
// "reactor Ramp {",
// " logical action a(60 msec):int;",
// " logical action b(100 msec):int;",
// " input x:int;",
// " output y:int;",
// " output z:int;",
// " reaction(startup) -> y, z, a, b{=",
// " =}",
// "}",
// "reactor Print {",
// " input x:int;",
// " output z:int;",
// " reaction(x) -> z {=",
// " =}",
// "}"
// ));
//
// Assertions.assertNotNull(model);
// final var ctypes = new CTypes(new DefaultErrorReporter());
// final var resource = model.eResource();
// final var transformation = new AfterDelayTransformation(new CDelayBodyGenerator(ctypes), ctypes, resource);
// transformation.applyTransformation(ASTUtils.getAllReactors(resource));
//
// Assertions.assertTrue(model.eResource().getErrors().isEmpty(),
// "Encountered unexpected error while parsing: " +
// model.eResource().getErrors());
//
// Instantiation mainDef = null;
//
// TreeIterator<EObject> it = model.eResource().getAllContents();
// while (it.hasNext()) {
// EObject obj = it.next();
// if (!(obj instanceof Reactor)) {
// continue;
// }
// Reactor reactor = (Reactor) obj;
// if (reactor.isMain()) {
// mainDef = LfFactory.eINSTANCE.createInstantiation();
// mainDef.setName(reactor.getName());
// mainDef.setReactorClass(reactor);
// }
// }
//
// ReactorInstance mainInstance = new ReactorInstance(toDefinition(mainDef.getReactorClass()), new DefaultErrorReporter());
//
// for (ReactorInstance reactorInstance : mainInstance.children) {
// if (reactorInstance.isGeneratedDelay()) {
// for (ReactionInstance reactionInstance : reactorInstance.reactions) {
// Assertions.assertEquals(reactionInstance.assignLogicalExecutionTime(), TimeValue.ZERO);
// }
// } else if (reactorInstance.getName().contains("ramp")) {
// for (ReactionInstance reactionInstance : reactorInstance.reactions) {
// Assertions.assertEquals(new TimeValue(20L, TimeUnit.MILLI), reactionInstance.assignLogicalExecutionTime());
// }
// } else if (reactorInstance.getName().contains("print")) {
// for (ReactionInstance reactionInstance : reactorInstance.reactions) {
// Assertions.assertEquals(TimeValue.ZERO, reactionInstance.assignLogicalExecutionTime());
// }
// }
// }
// }
@Test
public void testLet() throws Exception {
Model model = parser.parse(String.join(
System.getProperty("line.separator"),
"target C;",
"main reactor {",
" ramp = new Ramp();",
" print = new Print();",
" print2 = new Print();",
" ramp.y -> print.x after 20 msec;",
" ramp.y -> print2.x after 30 msec;",
"}",
"reactor Ramp {",
" logical action a(60 msec):int;",
" logical action b(100 msec):int;",
" input x:int;",
" output y:int;",
" output z:int;",
" reaction(startup) -> y, z, a, b{=",
" =}",
"}",
"reactor Print {",
" input x:int;",
" output z:int;",
" reaction(x) -> z {=",
" =}",
"}"
));

Assertions.assertNotNull(model);
final var ctypes = new CTypes(new DefaultErrorReporter());
final var resource = model.eResource();
final var transformation = new AfterDelayTransformation(new CDelayBodyGenerator(ctypes), ctypes, resource);
transformation.applyTransformation(ASTUtils.getAllReactors(resource));

Assertions.assertTrue(model.eResource().getErrors().isEmpty(),
"Encountered unexpected error while parsing: " +
model.eResource().getErrors());

Instantiation mainDef = null;

TreeIterator<EObject> it = model.eResource().getAllContents();
while (it.hasNext()) {
EObject obj = it.next();
if (!(obj instanceof Reactor)) {
continue;
}
Reactor reactor = (Reactor) obj;
if (reactor.isMain()) {
mainDef = LfFactory.eINSTANCE.createInstantiation();
mainDef.setName(reactor.getName());
mainDef.setReactorClass(reactor);
}
}

ReactorInstance mainInstance = new ReactorInstance(toDefinition(mainDef.getReactorClass()), new DefaultErrorReporter());

for (ReactorInstance reactorInstance : mainInstance.children) {
if (reactorInstance.isGeneratedDelay()) {
for (ReactionInstance reactionInstance : reactorInstance.reactions) {
Assertions.assertEquals(reactionInstance.assignLogicalExecutionTime(), TimeValue.ZERO);
}
} else if (reactorInstance.getName().contains("ramp")) {
for (ReactionInstance reactionInstance : reactorInstance.reactions) {
Assertions.assertEquals(new TimeValue(20L, TimeUnit.MILLI), reactionInstance.assignLogicalExecutionTime());
}
} else if (reactorInstance.getName().contains("print")) {
for (ReactionInstance reactionInstance : reactorInstance.reactions) {
Assertions.assertEquals(TimeValue.ZERO, reactionInstance.assignLogicalExecutionTime());
}
}
}
}
}

0 comments on commit 3ad413b

Please sign in to comment.