Search in sources :

Example 6 with TestContext

use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.

the class AnalyzedPragmaTest method ctorTest.

@Test
public void ctorTest() {
    Context context = new TestContext();
    XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram(context);
    Xnode p1 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    p1.setValue("acc parallel");
    Xnode p2 = xcodeml.createNode(Xcode.F_PRAGMA_STATEMENT);
    p2.setValue("acc end parallel");
    AnalyzedPragma ap1 = new AnalyzedPragma(p1);
    assertFalse(ap1.isEndPragma());
    assertNotNull(ap1.getPragma());
    assertEquals("acc parallel", ap1.getPragma().value());
    ap1.setEndPragma();
    assertTrue(ap1.isEndPragma());
    AnalyzedPragma ap2 = new AnalyzedPragma();
    assertFalse(ap2.isEndPragma());
    assertNull(ap2.getPragma());
    ap2.setPragma(p2);
    ap2.setEndPragma();
    assertTrue(ap2.isEndPragma());
    assertNotNull(ap2.getPragma());
}
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 7 with TestContext

use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.

the class ConfigurationTest method readConfig.

void readConfig(Path cfgDirPath) {
    try {
        Configuration conf = new TestConfiguration();
        assertNotNull(conf);
        Context context = new TestContext();
        assertNotNull(context);
        conf = Configuration.load(cfgDirPath, null, null, null, null, Integer.valueOf(MAX_COLUMN), context, Collections.emptyList());
        assertNotNull(context.getGenerator());
        assertNotNull(conf.accelerator());
        assertEquals(MAX_COLUMN, context.getMaxColumns());
        assertFalse(conf.isForcePure());
        conf.setForcePure();
        assertTrue(conf.isForcePure());
        int[] majorMinor = conf.getMajorMinor("0.3");
        assertEquals(0, majorMinor[0]);
        assertEquals(3, majorMinor[1]);
        try {
            conf.checkVersion("0.2");
            fail();
        } catch (Exception ignored) {
        }
        try {
            conf.getMajorMinor("sdjhsajkd");
            fail();
        } catch (Exception ignored) {
        }
        try {
            conf.checkVersion(ClawVersion.VERSION);
        } catch (Exception ignored) {
            fail();
        }
        assertTrue(conf.accelerator() instanceof OpenAccConfiguration);
        assertTrue(context.getGenerator() instanceof OpenAcc);
        assertSame(Target.GPU, conf.getCurrentTarget());
        assertSame(CompilerDirective.OPENACC, conf.getCurrentDirective());
        assertEquals(Configuration.CPU_STRATEGY_FUSION, conf.getParameter(Configuration.CPU_STRATEGY));
        conf.overrideConfigurationParameter(Configuration.CPU_STRATEGY, Configuration.CPU_STRATEGY_SINGLE);
        assertEquals(Configuration.CPU_STRATEGY_SINGLE, conf.getParameter(Configuration.CPU_STRATEGY));
        assertNull(conf.getParameter(DUMMY_KEY));
        conf.overrideConfigurationParameter(DUMMY_KEY, DUMMY_VALUE);
        assertEquals(DUMMY_VALUE, conf.getParameter(DUMMY_KEY));
    } catch (Exception e) {
        fail();
    }
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) OpenAccConfiguration(claw.tatsu.directive.configuration.OpenAccConfiguration) TestConfiguration(helper.Utils.TestConfiguration) TestContext(helper.Utils.TestContext) TestConfiguration(helper.Utils.TestConfiguration) OpenAcc(claw.tatsu.directive.generator.OpenAcc) OpenAccConfiguration(claw.tatsu.directive.configuration.OpenAccConfiguration)

Example 8 with TestContext

use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.

the class FmoduleDefinitionTest method simpleModuleDefinitionTest.

@Test
public void simpleModuleDefinitionTest() {
    Context context = new TestContext();
    Xnode node = XmlHelper.createXnode(module1);
    FmoduleDefinition mod = new FmoduleDefinition(node);
    assertNotNull(mod);
    assertEquals("module", mod.getName());
    assertEquals(4, mod.lineNo());
    assertEquals("./src/module.f90", mod.filename());
    assertNull(mod.getSymbolTable());
    assertNull(mod.getDeclarationTable());
    XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_DECLARATIONS, context);
    assertNotNull(xcodeml);
    List<Xnode> nodes = xcodeml.matchAll(Xcode.F_MODULE_DEFINITION);
    assertFalse(nodes.isEmpty());
    FmoduleDefinition modDef = new FmoduleDefinition(nodes.get(0));
    assertEquals("mod1", modDef.getName());
    assertFalse(modDef.getFunctionDefinition(null).isPresent());
    assertFalse(modDef.getFunctionDefinition("").isPresent());
    assertTrue(modDef.getFunctionDefinition("sub1").isPresent());
    assertNotNull(modDef.cloneNode());
}
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 9 with TestContext

use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.

the class ClawPragmaTest method setUp.

@Before
public void setUp() {
    cfg = new TestConfiguration();
    context = new TestContext();
}
Also used : TestContext(helper.Utils.TestContext) TestConfiguration(helper.Utils.TestConfiguration) Before(org.junit.Before)

Example 10 with TestContext

use of helper.Utils.TestContext in project claw-compiler by C2SM-RCM.

the class XnodeUtilTest method gatherArgumentsTest.

@Test
public void gatherArgumentsTest() {
    Context context = new TestContext();
    String arg1 = "nz";
    String arg2 = "q(:,1:60)";
    String arg3 = "ty%y(:,:)";
    String arg4 = "z(:)";
    String arg5 = "nproma";
    assertTrue(Files.exists(TestConstant.TEST_ARGUMENTS));
    XcodeProgram xcodeml = XcodeProgram.createFromFile(TestConstant.TEST_ARGUMENTS, context);
    assertNotNull(xcodeml);
    List<Xnode> functionCalls = xcodeml.matchAll(Xcode.FUNCTION_CALL);
    assertEquals(1, functionCalls.size());
    FunctionCall fctCall = new FunctionCall(functionCalls.get(0));
    assertSame(fctCall.opcode(), Xcode.FUNCTION_CALL);
    FfunctionType fctType = xcodeml.getTypeTable().getFunctionType(fctCall);
    List<String> allArguments = fctCall.gatherArguments(xcodeml, fctType, xcodeml, Intent.ANY, false, false);
    assertEquals(5, allArguments.size());
    assertEquals(arg1, allArguments.get(0));
    assertEquals(arg2, allArguments.get(1));
    assertEquals(arg3, allArguments.get(2));
    assertEquals(arg4, allArguments.get(3));
    assertEquals(arg5, allArguments.get(4));
    List<String> inArguments = fctCall.gatherArguments(xcodeml, fctType, xcodeml, Intent.IN, false, false);
    assertEquals(5, inArguments.size());
    assertEquals(arg1, inArguments.get(0));
    assertEquals(arg2, inArguments.get(1));
    assertEquals(arg3, inArguments.get(2));
    assertEquals(arg4, inArguments.get(3));
    assertEquals(arg5, inArguments.get(4));
    List<String> outArguments = fctCall.gatherArguments(xcodeml, fctType, xcodeml, Intent.OUT, false, false);
    assertEquals(3, outArguments.size());
    assertEquals(arg2, outArguments.get(0));
    assertEquals(arg3, outArguments.get(1));
    assertEquals(arg4, outArguments.get(2));
    List<String> inArrayArguments = fctCall.gatherArguments(xcodeml, fctType, xcodeml, Intent.IN, true, false);
    assertEquals(3, inArrayArguments.size());
    assertEquals(arg2, inArrayArguments.get(0));
    assertEquals(arg3, inArrayArguments.get(1));
    assertEquals(arg4, inArrayArguments.get(2));
    List<String> outArrayArguments = fctCall.gatherArguments(xcodeml, fctType, xcodeml, Intent.OUT, true, false);
    assertEquals(3, outArrayArguments.size());
    assertEquals(arg2, outArrayArguments.get(0));
    assertEquals(arg3, outArrayArguments.get(1));
    assertEquals(arg4, outArrayArguments.get(2));
    List<String> inOutArrayArguments = fctCall.gatherArguments(xcodeml, fctType, xcodeml, Intent.INOUT, true, false);
    assertEquals(3, inOutArrayArguments.size());
    assertEquals(arg2, inOutArrayArguments.get(0));
    assertEquals(arg3, inOutArrayArguments.get(1));
    assertEquals(arg4, inOutArrayArguments.get(2));
// TODO add test with optional arguments
}
Also used : Context(claw.tatsu.common.Context) TestContext(helper.Utils.TestContext) FfunctionType(claw.tatsu.xcodeml.xnode.fortran.FfunctionType) TestContext(helper.Utils.TestContext) FunctionCall(claw.tatsu.xcodeml.abstraction.FunctionCall) 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