use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class XsymbolsTest method addToTableTest.
@Test
public void addToTableTest() {
Context context = new TestContext();
XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
assertNotNull(xcodeml);
XsymbolTable table = xcodeml.getGlobalSymbolsTable();
assertNotNull(table);
Xid id1 = xcodeml.createId(FortranType.INTEGER, XstorageClass.F_LOCAL, "id1");
table.add(id1);
assertTrue(table.contains("id1"));
}
use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class ConditionTest method dependsOnTest.
@Test
public void dependsOnTest() {
Context context = new TestContext();
XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_ASSIGN_STMT, context);
assertNotNull(xcodeml);
List<Xnode> nodes = xcodeml.matchAll(Xcode.F_IF_STATEMENT);
assertEquals(1, nodes.size());
Xnode ifStmt = nodes.get(0);
assertEquals(Xcode.F_IF_STATEMENT, ifStmt.opcode());
Xnode condition = ifStmt.matchDirectDescendant(Xcode.CONDITION);
assertNotNull(condition);
assertFalse(Condition.dependsOn(condition, Collections.emptySet()));
assertFalse(Condition.dependsOn(null, Collections.singleton("t")));
assertFalse(Condition.dependsOn(ifStmt, Collections.singleton("t")));
assertTrue(Condition.dependsOn(condition, Collections.singleton("t")));
assertFalse(Condition.dependsOn(condition, Collections.singleton("k")));
}
use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class LoopTest method mergeTest.
@Test
public void mergeTest() {
Context context = new TestContext();
XcodeML xcodeml = XmlHelper.getDummyXcodeProgram(context);
assertNotNull(xcodeml);
DimensionDefinition d1 = new DimensionDefinition("i", "1", "10");
Xnode inductionI = xcodeml.createVar(FortranType.INTEGER, "i", Xscope.LOCAL);
Xnode l1 = xcodeml.createDoStmt(inductionI, d1.generateIndexRange(xcodeml, true, false));
Xnode l2 = xcodeml.createDoStmt(inductionI, d1.generateIndexRange(xcodeml, true, false));
List<FfunctionDefinition> fctDefs = xcodeml.getAllFctDef();
assertFalse(fctDefs.isEmpty());
FfunctionDefinition f1 = fctDefs.get(0);
int doStmtCnt1 = f1.matchAll(Xcode.F_DO_STATEMENT).size();
f1.body().append(l1);
f1.body().append(l2);
int doStmtCnt2 = f1.matchAll(Xcode.F_DO_STATEMENT).size();
assertEquals(doStmtCnt1 + 2, doStmtCnt2);
try {
Loop.merge(l1, l2);
} catch (IllegalTransformationException e) {
fail();
}
int doStmtCnt3 = f1.matchAll(Xcode.F_DO_STATEMENT).size();
assertEquals(doStmtCnt1 + 1, doStmtCnt3);
}
use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class DimensionTest method boundDefinitionTest.
@Test
public void boundDefinitionTest() {
Context context = new TestContext();
XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
BoundDefinition lowerBound = new BoundDefinition("1", BoundDefinition.BoundType.LOWER);
BoundDefinition upperBound = new BoundDefinition("nend", BoundDefinition.BoundType.LOWER);
BoundDefinition step = new BoundDefinition("1", BoundDefinition.BoundType.STEP);
assertFalse(lowerBound.isVar());
assertTrue(upperBound.isVar());
assertFalse(step.isVar());
assertEquals(1, lowerBound.getIntValue());
assertEquals("nend", upperBound.getValue());
assertEquals(1, step.getIntValue());
Xnode lowerNode = lowerBound.generate(xcodeml);
assertNotNull(lowerNode);
assertNotNull(lowerNode.firstChild());
assertEquals(Xcode.F_INT_CONSTANT, lowerNode.firstChild().opcode());
assertEquals("1", lowerNode.firstChild().value());
Xnode upperNode = upperBound.generate(xcodeml);
assertNotNull(upperNode);
assertNotNull(upperNode.firstChild());
assertEquals(Xcode.VAR, upperNode.firstChild().opcode());
assertEquals("nend", upperNode.firstChild().value());
}
use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class XcodeProgTest method creationFailingTest.
@Test
public void creationFailingTest() throws IOException {
Context context = new TestContext();
XcodeProgram xc1 = XcodeProgram.createFromDocument(null, context);
assertNotNull(xc1);
assertTrue(xc1.hasErrors());
// Simulate STDIN
try (ByteArrayInputStream in = new ByteArrayInputStream("<dummy></dummy>".getBytes())) {
XcodeProgram xc2 = XcodeProgram.createFromStream(in, context);
assertNotNull(xc2);
assertTrue(xc2.hasErrors());
}
}
Aggregations