Search in sources :

Example 21 with TestContext

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());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) TestContext(helper.Utils.TestContext) Test(org.junit.Test)

Example 22 with TestContext

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) {
    }
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) TestContext(helper.Utils.TestContext) XcodeML(claw.tatsu.xcodeml.xnode.common.XcodeML) Test(org.junit.Test)

Example 23 with TestContext

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));
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) TestContext(helper.Utils.TestContext) Test(org.junit.Test)

Example 24 with TestContext

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());
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) TestContext(helper.Utils.TestContext) XcodeProgram(claw.tatsu.xcodeml.xnode.common.XcodeProgram) Test(org.junit.Test)

Example 25 with TestContext

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());
    }
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) ByteArrayInputStream(java.io.ByteArrayInputStream) TestContext(helper.Utils.TestContext) Test(org.junit.Test)

Aggregations

TestContext (helper.Utils.TestContext)45 Context (claw.tatsu.common.Context)44 Test (org.junit.Test)43 XcodeProgram (claw.tatsu.xcodeml.xnode.common.XcodeProgram)22 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)20 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)9 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)4 DimensionDefinition (claw.tatsu.xcodeml.abstraction.DimensionDefinition)2 XcodeML (claw.tatsu.xcodeml.xnode.common.XcodeML)2 TestConfiguration (helper.Utils.TestConfiguration)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 AnalyzedPragma (claw.shenron.translator.AnalyzedPragma)1 OpenAccConfiguration (claw.tatsu.directive.configuration.OpenAccConfiguration)1 OpenAcc (claw.tatsu.directive.generator.OpenAcc)1 FunctionCall (claw.tatsu.xcodeml.abstraction.FunctionCall)1 HoistedNestedDoStatement (claw.tatsu.xcodeml.abstraction.HoistedNestedDoStatement)1 FfunctionType (claw.tatsu.xcodeml.xnode.fortran.FfunctionType)1 FmoduleDefinition (claw.tatsu.xcodeml.xnode.fortran.FmoduleDefinition)1 Before (org.junit.Before)1