Skip to content

Commit

Permalink
#2716 improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
arporter committed Oct 7, 2024
1 parent f026e21 commit 6925697
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/psyclone/psyGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1379,13 +1379,13 @@ def get_kernel_schedule(self):
kernel code.
:rtype: tuple[:py:class:`psyclone.psyir.symbols.Symbol`,
list[:py:class:`psyclone.psyir.nodes.KernelSchedule`]]
:raises NotImplementedError: must be overridden in sub-class.
'''
from psyclone.psyir.frontend.fparser2 import Fparser2Reader
if self._kern_schedule is None:
astp = Fparser2Reader()
self._kern_schedule = [astp.generate_schedule(self.name, self.ast)]
# TODO: Validate kernel with metadata (issue #288).
return None, self._kern_schedule
raise NotImplementedError(
f"get_kernel_schedule() must be overridden in class "
f"{self.__class__}")

@property
def opencl_options(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@
# Authors: A. R. Porter and S. Siso, STFC Daresbury Lab
# Modified by R. W. Ford, STFC Daresbury Lab

''' Tests the KernelImportsToArguments Transformation for the GOcean
1.0 API.'''
''' Tests the KernelImportsToArguments Transformation for the GOcean API.'''

import os
import pytest
from psyclone.gocean1p0 import GOInvokeSchedule
from psyclone.parse.algorithm import parse
from psyclone.psyGen import PSyFactory, InvokeSchedule
from psyclone.psyir.symbols import DataSymbol, REAL_TYPE, INTEGER_TYPE, \
CHARACTER_TYPE, Symbol
from psyclone.tests.utilities import get_invoke
from psyclone.transformations import KernelImportsToArguments, \
TransformationError

Expand Down Expand Up @@ -106,6 +107,26 @@ def test_kernelimportstoargumentstrans_no_wildcard_import():
"container 'model_mod'" in str(err.value))


def test_kernelimportstoargumentstrans_no_polymorphic(monkeypatch):
'''
Check that the transformation rejects polymorphic kernels.
'''
trans = KernelImportsToArguments()
_, invoke = get_invoke("26.8_mixed_precision_args.f90", api="lfric", idx=0)
kernel = invoke.schedule.coded_kernels()[0]
invsched = kernel.ancestor(InvokeSchedule)
# Currently this transformation will only work for the GOcean API so
# monkeypatch the class of the parent InvokeSchedule.
monkeypatch.setattr(invsched, "__class__", GOInvokeSchedule)
with pytest.raises(TransformationError) as err:
trans.validate(kernel)
assert ("KernelImportsToArguments transformation does not support "
"polymorphic kernels but found the following implementations for "
"kernel 'mixed_code': ['mixed_code_32', 'mixed_code_64']"
in str(err.value))


@pytest.mark.xfail(reason="Transformation does not set modified property "
"of kernel - #663")
@pytest.mark.usefixtures("kernel_outputdir")
Expand Down
17 changes: 17 additions & 0 deletions src/psyclone/tests/psyGen_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,23 @@ def test_kern_children_validation():
"is a LeafNode and doesn't accept children.") in str(excinfo.value)


def test_codedkern_get_kernel_schedule(monkeypatch):
'''
Check that CodedKern.get_kernel_schedule() raises a NotImplementedError
(as it must be implemented by sub-classes).
'''
ast = fpapi.parse(FAKE_KERNEL_METADATA, ignore_comments=False)
metadata = LFRicKernMetadata(ast)
kern = LFRicKern()
kern.load_meta(metadata)
monkeypatch.setattr(kern, "__class__", CodedKern)
with pytest.raises(NotImplementedError) as err:
kern.get_kernel_schedule()
assert ("get_kernel_schedule() must be overridden in class "
in str(err.value))


def test_inlinedkern_children_validation():
'''Test that children added to InlinedKern are validated. An InlinedKern
must have one child that is a Schedule (which is created by its
Expand Down

0 comments on commit 6925697

Please sign in to comment.