예제 #1
0
def test_basegen_start_parent_loop_omp_end_dbg(capsys):
    '''Check the debug option to the start_parent_loop method when we have
    an OpenMP end directive'''
    module = ModuleGen(name="testmodule")
    sub = SubroutineGen(module, name="testsubroutine")
    module.add(sub)
    dgen = DirectiveGen(sub, "omp", "end", "do", "")
    sub.add(dgen)
    loop = DoGen(sub, "it", "1", "10")
    sub.add(loop)
    call = CallGen(loop, "testcall")
    loop.add(call)
    call.start_parent_loop(debug=True)
    out, _ = capsys.readouterr()
    print out
    expected = ("Parent is a do loop so moving to the parent\n"
                "The type of the current node is now <class "
                "'fparser.block_statements.Do'>\n"
                "The type of parent is <class "
                "'fparser.block_statements.Subroutine'>\n"
                "Finding the loops position in its parent ...\n"
                "The loop's index is  1\n"
                "The type of the object at the index is <class "
                "'fparser.block_statements.Do'>\n"
                "If preceding node is a directive then move back one\n"
                "preceding node is a directive so find out what type ...\n")

    assert expected in out
예제 #2
0
def test_ompdirective_type():
    ''' Check that we can query the type of an OMP Directive '''
    from psyGen import Node
    parent = Node()
    dirgen = DirectiveGen(parent,
                          "omp", "begin", "do",
                          "schedule(static)")
    ompdir = dirgen.root
    assert ompdir.type == "do"
예제 #3
0
def test_ompdirective_wrong_posn():
    ''' Check that we raise an error if we request an OMP Directive with
    an invalid position '''
    from psyGen import Node
    parent = Node()
    with pytest.raises(RuntimeError) as err:
        _ = DirectiveGen(parent,
                         "omp", "start", "do",
                         "schedule(static)")
    assert "unrecognised position 'start'" in str(err)
예제 #4
0
def test_ompdirective_wrong():
    ''' Check that we raise an error if we request an OMP Directive of
    unrecognised type '''
    from psyGen import Node
    parent = Node()
    with pytest.raises(RuntimeError) as err:
        _ = DirectiveGen(parent,
                         "omp", "begin", "dosomething",
                         "schedule(static)")
    assert "unrecognised directive type" in str(err)
예제 #5
0
def test_directive_wrong_type():
    ''' Check that we raise an error if we request a Directive of
    unrecognised type '''
    from psyGen import Node
    parent = Node()
    with pytest.raises(RuntimeError) as err:
        _ = DirectiveGen(parent,
                         "some_dir_type", "begin", "do",
                         "schedule(static)")
    assert "unsupported directive language" in str(err)
예제 #6
0
def test_basegen_start_parent_loop_no_loop_dbg():
    '''Check the debug option to the start_parent_loop method when we have
    no loop'''
    module = ModuleGen(name="testmodule")
    sub = SubroutineGen(module, name="testsubroutine")
    module.add(sub)
    dgen = DirectiveGen(sub, "omp", "end", "do", "")
    sub.add(dgen)
    call = CallGen(sub, name="testcall", args=["a", "b"])
    sub.add(call)
    with pytest.raises(RuntimeError) as err:
        call.start_parent_loop(debug=True)
    assert "This node has no enclosing Do loop" in str(err)
예제 #7
0
def test_subroutine_var_intent_in_with_directive():
    ''' test that a variable declared as intent in is added before
    a directive in a subroutine'''
    module = ModuleGen(name="testmodule")
    subroutine = SubroutineGen(module, name="testsubroutine",
                               implicitnone=False)
    module.add(subroutine)
    subroutine.add(DirectiveGen(subroutine, "omp", "begin",
                                "parallel", ""))
    subroutine.add(DeclGen(subroutine, datatype="integer",
                           intent="in", entity_decls=["var1"]))
    idx_par = line_number(subroutine.root, "!$omp parallel")
    idx_var = line_number(subroutine.root,
                          "INTEGER, intent(in) :: var1")
    print str(module.root)
    assert idx_par - idx_var == 1, \
        "variable declaration must be before directive"