use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class FfunctionDefinitionTest method basicFunctionDefinitionTest.
@Test
public void basicFunctionDefinitionTest() {
Context context = new TestContext();
context.init(CompilerDirective.OPENACC, Target.GPU, null, 80);
FfunctionDefinition fctDef = XmlHelper.createXfunctionDefinitionFromString(basicFDef);
assertNotNull(fctDef);
assertEquals("force_dummy", fctDef.getName());
assertEquals("force_dummy", fctDef.name().value());
assertEquals("F7ff951406df0", fctDef.getType());
assertEquals(0, fctDef.getSymbolTable().size());
assertEquals(0, fctDef.getDeclarationTable().count());
assertNull(fctDef.getParams());
assertNotNull(fctDef.body());
assertEquals(1, fctDef.lineNo());
assertEquals("original_code.f90", fctDef.filename());
assertNull(fctDef.findContainingXmod(context));
FfunctionDefinition clone = fctDef.cloneNode();
assertNotNull(clone);
assertEquals("force_dummy", fctDef.getName());
assertEquals("force_dummy", fctDef.name().value());
}
use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class LoopTest method mergeFailTest.
@Test
public void mergeFailTest() {
Context context = new TestContext();
XcodeML xcodeml = XmlHelper.getDummyXcodeProgram(context);
assertNotNull(xcodeml);
Xnode n1 = xcodeml.createNode(Xcode.F_IF_STATEMENT);
Xnode n2 = xcodeml.createNode(Xcode.F_IF_STATEMENT);
try {
Loop.merge(n1, null);
fail();
} catch (IllegalTransformationException ignored) {
}
try {
Loop.merge(null, n2);
fail();
} catch (IllegalTransformationException ignored) {
}
try {
Loop.merge(n1, n2);
fail();
} catch (IllegalTransformationException ignored) {
}
}
use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class XmodTest method getSuffixTest.
@Test
public void getSuffixTest() {
Context context = new TestContext();
context.init(CompilerDirective.OPENACC, Target.GPU, null, 80);
// .[directive].[target].claw
assertEquals(".openacc.gpu.claw.xmod", Xmod.getSuffix(context));
context.init(CompilerDirective.OPENMP, Target.CPU, null, 80);
assertEquals(".openmp.cpu.claw.xmod", Xmod.getSuffix(context));
context.init(CompilerDirective.NONE, Target.CPU, null, 80);
assertEquals(".none.cpu.claw.xmod", Xmod.getSuffix(context));
context.init(CompilerDirective.OPENMP, Target.MIC, null, 80);
assertEquals(".openmp.mic.claw.xmod", Xmod.getSuffix(context));
context.init(CompilerDirective.NONE, Target.FPGA, null, 80);
assertEquals(".none.fpga.claw.xmod", Xmod.getSuffix(context));
context.init(CompilerDirective.OPENACC, null, null, 80);
assertEquals(".openacc.none.claw.xmod", Xmod.getSuffix(context));
context.init(null, null, null, 80);
assertEquals(".none.none.claw.xmod", Xmod.getSuffix(context));
context.init(CompilerDirective.NONE, Target.GPU, null, 80);
assertEquals(".none.gpu.claw.xmod", Xmod.getSuffix(context));
}
use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class DimensionTest method dimensionDefinitionTest.
@Test
public void dimensionDefinitionTest() {
Context context = new TestContext();
XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
DimensionDefinition dimDef = new DimensionDefinition("nproma", "1", "nend");
DimensionDefinition dimDef2 = new DimensionDefinition("nproma", "nstart", "nend");
assertEquals("nproma(nstart:nend)", dimDef2.toString());
assertNotNull(dimDef.getLowerBound());
assertNotNull(dimDef.getUpperBound());
assertNotNull(dimDef.getIterationLowerBound());
assertNotNull(dimDef.getIterationUpperBound());
assertNotNull(dimDef.getIterationStep());
assertFalse(dimDef.getLowerBound().isVar());
assertEquals(1, dimDef.getLowerBound().getIntValue());
assertFalse(dimDef.getIterationLowerBound().isVar());
assertEquals(1, dimDef.getIterationLowerBound().getIntValue());
assertTrue(dimDef.getUpperBound().isVar());
assertEquals("nend", dimDef.getUpperBound().getValue());
assertTrue(dimDef.getIterationUpperBound().isVar());
assertEquals("nend", dimDef.getIterationUpperBound().getValue());
assertFalse(dimDef.getIterationStep().isVar());
assertEquals(1, dimDef.getIterationStep().getIntValue());
assertEquals("nproma", dimDef.getIdentifier());
assertEquals(InsertionPosition.BEFORE, dimDef.getInsertionPosition());
dimDef.setInsertionPosition(InsertionPosition.AFTER);
assertEquals(InsertionPosition.AFTER, dimDef.getInsertionPosition());
assertEquals("nproma(1:nend)", dimDef.toString());
Xnode indexRange = dimDef.generateIndexRange(xcodeml, false, false);
assertNotNull(indexRange);
assertEquals(Xcode.INDEX_RANGE, indexRange.opcode());
assertEquals(2, indexRange.children().size());
assertEquals(Xcode.LOWER_BOUND, indexRange.firstChild().opcode());
assertEquals(Xcode.UPPER_BOUND, indexRange.lastChild().opcode());
Xnode indexRangeStep = dimDef.generateIndexRange(xcodeml, true, false);
assertNotNull(indexRangeStep);
assertEquals(Xcode.INDEX_RANGE, indexRangeStep.opcode());
assertEquals(3, indexRangeStep.children().size());
assertEquals(Xcode.LOWER_BOUND, indexRangeStep.firstChild().opcode());
assertEquals(Xcode.UPPER_BOUND, indexRangeStep.child(1).opcode());
assertEquals(Xcode.STEP, indexRangeStep.lastChild().opcode());
Xnode arrayIndex = dimDef.generateArrayIndex(xcodeml);
assertNotNull(arrayIndex);
assertEquals(Xcode.ARRAY_INDEX, arrayIndex.opcode());
assertEquals(Xcode.VAR, arrayIndex.firstChild().opcode());
assertEquals(dimDef.getIdentifier(), arrayIndex.firstChild().value());
Xnode allocateNode = dimDef.generateAllocateNode(xcodeml);
assertEquals(Xcode.ARRAY_INDEX, allocateNode.opcode());
assertEquals(Xcode.VAR, allocateNode.firstChild().opcode());
assertEquals(dimDef.getUpperBound().getValue(), allocateNode.firstChild().value());
}
use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.
the class XcodeProgTest method createUnvalidXcodeProgram.
@Test
public void createUnvalidXcodeProgram() throws IOException {
Context context = new TestContext();
final String d1 = "<XcodeProgram source=\"original_code.f90\"\n" + "language=\"Fortran\"\n" + "time=\"2015-11-25 14:47:59\"\n" + "compiler-info=\"XcodeML/Fortran-FrontEnd\"\n" + "version=\"1.5\"></XcodeProgram>";
final String d2 = "<XcodeProgram source=\"original_code.f90\"\n" + "language=\"C\"\n" + "time=\"2015-11-25 14:47:59\"\n" + "compiler-info=\"XcodeML/Fortran-FrontEnd\"\n" + "version=\"1.0\"></XcodeProgram>";
// Simulate STDIN
try (ByteArrayInputStream in = new ByteArrayInputStream(d1.getBytes())) {
// Version not valid
XcodeProgram xc1 = XcodeProgram.createFromStream(in, context);
assertNotNull(xc1);
assertTrue(xc1.hasErrors());
}
try (ByteArrayInputStream in = new ByteArrayInputStream(d2.getBytes())) {
// Language not valid
XcodeProgram xc2 = XcodeProgram.createFromStream(in, context);
assertNotNull(xc2);
assertTrue(xc2.hasErrors());
}
}
Aggregations