Ejemplo n.º 1
0
def test_no_stub_gen():
    ''' Check that the kernel-stub generator refuses to attempt to create
    a kernel stub if the meta-data contains mesh information. '''
    with pytest.raises(NotImplementedError) as excinfo:
        generate(os.path.join(BASE_PATH, "prolong_test_kernel_mod.f90"),
                 api="dynamo0.3")
    assert ('prolong_test_kernel_code is an inter-grid kernel and stub '
            'generation is not yet supported for inter-grid kernels'
            in str(excinfo.value))
Ejemplo n.º 2
0
def test_stub_generate_with_scalar_sums():
    '''check that the stub generator raises an exception when a kernel has
    a reduction (since these are not permitted for user-supplied kernels)'''
    with pytest.raises(ParseError) as err:
        _ = generate(os.path.join(BASE_PATH, "simple_with_reduction.f90"),
                     api=TEST_API)
    assert ("A user-supplied LFRic kernel must not write/update a scalar "
            "argument but kernel 'simple_with_reduction_type' has a scalar "
            "argument with 'gh_sum' access." in str(err.value))
Ejemplo n.º 3
0
def test_failures(monkeypatch, capsys):
    '''Tests various failures of the generate call.
    '''

    from psyclone.gen_kernel_stub import generate, run
    from psyclone.parse.algorithm import ParseError
    from psyclone.psyGen import GenerationError

    # Test error handling of command line options
    with pytest.raises(SystemExit) as err:
        # Use monkeypatch to spoof some command-line arguments
        monkeypatch.setattr(sys, "argv", ["genkernelstub",
                                          str("/does_not_exist")])
        run()
    result, _ = capsys.readouterr()
    assert "Error: file '/does_not_exist' not found" in str(result)

    # Test empty API (and file not found)
    with pytest.raises(IOError) as err:
        generate("/does_not_exist", api="")
    assert "file '/does_not_exist' not found" in str(err)

    # CHeck invalid API
    with pytest.raises(GenerationError) as err:
        generate("filename", api="invalid")
    assert "Unsupported API 'invalid' specified." in str(err)

    # Trapping Fortran errors:
    with pytest.raises(ParseError) as err:
        # Use this python file to trigger invalid Fortran
        generate(__file__, api="dynamo0.3")
    assert "Code appears to be invalid" in str(err)
Ejemplo n.º 4
0
def test_stub_generate_with_anyw2():
    '''check that the stub generate produces the expected output when we
    have any_w2 fields. In particular, check basis functions as these
    have specific sizes associated with the particular function space'''
    result = generate(os.path.join(BASE_PATH,
                                   "testkern_multi_anyw2_basis_mod.f90"),
                      api=TEST_API)
    expected_output = (
        "      REAL(KIND=r_def), intent(in), dimension(3,ndf_any_w2,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: basis_any_w2_qr_xyoz\n"
        "      REAL(KIND=r_def), intent(in), dimension(1,ndf_any_w2,"
        "np_xy_qr_xyoz,np_z_qr_xyoz) :: diff_basis_any_w2_qr_xyoz")
    assert expected_output in str(result)
Ejemplo n.º 5
0
def test_failures(monkeypatch, capsys):
    '''Tests various failures of the generate call.
    '''

    from psyclone.gen_kernel_stub import generate, run
    from psyclone.parse.algorithm import ParseError
    from psyclone.errors import GenerationError

    # Test error handling of command line options
    with pytest.raises(SystemExit) as err:
        # Use monkeypatch to spoof some command-line arguments
        monkeypatch.setattr(sys, "argv", ["genkernelstub",
                                          str("/does_not_exist")])
        run()
    result, _ = capsys.readouterr()
    assert ("Error: Kernel stub generator: File '/does_not_exist' "
            "not found" in str(result))

    # Test empty API (and file not found)
    with pytest.raises(IOError) as err:
        generate("/does_not_exist", api="")
    assert "File '/does_not_exist' not found" in str(err.value)

    # CHeck invalid API
    with pytest.raises(GenerationError) as err:
        generate("filename", api="invalid")
    assert ("Error: Kernel stub generator: Unsupported API 'invalid' "
            "specified." in str(err.value))

    # Trapping Fortran errors:
    with pytest.raises(ParseError) as err:
        # Use this python file to trigger invalid Fortran
        generate(__file__, api="dynamo0.3")
    assert ("Kernel stub generator: Code appears to be invalid "
            "Fortran" in str(err.value))

    # Check invalid iteration space in LFRic API
    kern_file = os.path.join(
        os.path.dirname(os.path.abspath(__file__)), "test_files",
        "dynamo0p3", "testkern_dofs_mod.f90")
    with pytest.raises(GenerationError) as excinfo:
        generate(kern_file, api="dynamo0.3")
    assert ("The LFRic API kernel stub generator supports kernels that "
            "operate on one of ['cells', 'cell_column'], but "
            "found 'dof' in kernel 'testkern_dofs_code'." in
            str(excinfo.value))
Ejemplo n.º 6
0
def test_stub_generate_with_scalars():
    ''' Check that the stub generate produces the expected output when
    the kernel has scalar arguments. '''
    result = generate(os.path.join(BASE_PATH,
                                   "testkern_three_scalars_mod.f90"),
                      api=TEST_API)

    expected = (
        "  MODULE testkern_three_scalars_mod\n"
        "    IMPLICIT NONE\n"
        "    CONTAINS\n"
        "    SUBROUTINE testkern_three_scalars_code(nlayers, rscalar_1, "
        "field_2_w1, field_3_w2, field_4_w2, field_5_w3, lscalar_6, "
        "iscalar_7, ndf_w1, undf_w1, map_w1, ndf_w2, undf_w2, map_w2, "
        "ndf_w3, undf_w3, map_w3)\n"
        "      USE constants_mod, ONLY: r_def, l_def, i_def\n"
        "      IMPLICIT NONE\n"
        "      INTEGER(KIND=i_def), intent(in) :: nlayers\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w1\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w1) :: map_w1\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w2\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w2) :: map_w2\n"
        "      INTEGER(KIND=i_def), intent(in) :: ndf_w3\n"
        "      INTEGER(KIND=i_def), intent(in), dimension(ndf_w3) :: map_w3\n"
        "      INTEGER(KIND=i_def), intent(in) :: undf_w1, undf_w2, undf_w3\n"
        "      REAL(KIND=r_def), intent(in) :: rscalar_1\n"
        "      INTEGER(KIND=i_def), intent(in) :: iscalar_7\n"
        "      LOGICAL(KIND=l_def), intent(in) :: lscalar_6\n"
        "      REAL(KIND=r_def), intent(inout), dimension(undf_w1) :: "
        "field_2_w1\n"
        "      REAL(KIND=r_def), intent(in), dimension(undf_w2) :: "
        "field_3_w2\n"
        "      REAL(KIND=r_def), intent(in), dimension(undf_w2) :: "
        "field_4_w2\n"
        "      REAL(KIND=r_def), intent(in), dimension(undf_w3) :: "
        "field_5_w3\n"
        "    END SUBROUTINE testkern_three_scalars_code\n"
        "  END MODULE testkern_three_scalars_mod")

    assert expected in str(result)
Ejemplo n.º 7
0
def test_stub_generate_with_scalars():
    ''' check that the stub generate produces the expected output when
    the kernel has scalar arguments '''
    result = generate(os.path.join(BASE_PATH, "simple_with_scalars.f90"),
                      api=TEST_API)
    assert SIMPLE_WITH_SCALARS in str(result)
Ejemplo n.º 8
0
def test_stub_generate_working_noapi():
    ''' check that the stub generate produces the expected output when
    we use the default api (which should be dynamo0.3)'''
    result = generate(os.path.join(BASE_PATH, "simple.f90"))
    assert SIMPLE in str(result)
Ejemplo n.º 9
0
def test_stub_generate_working():
    ''' Check that the stub generate produces the expected output '''
    result = generate(os.path.join(BASE_PATH, "simple.f90"), api=TEST_API)
    assert SIMPLE in str(result)