Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fortran serialization codegen tests #198

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
511ae43
No dependency test created
ChristopherBignamini Apr 19, 2023
6d5034e
Missing dependency test added
ChristopherBignamini Apr 19, 2023
853c7bc
Added test for non existing granule input file
ChristopherBignamini Apr 20, 2023
d480745
Fix for source with no external dependencies
ChristopherBignamini Apr 27, 2023
173f2de
Serialization directives generation test created
ChristopherBignamini Apr 28, 2023
55d6591
Add small fixes
samkellerhals May 2, 2023
48ee72b
Serialization directives generation test created for diffusion granule
ChristopherBignamini May 3, 2023
43d4ce2
Useless import removed
ChristopherBignamini May 3, 2023
7e87416
Useless import removed
ChristopherBignamini May 3, 2023
9e60086
Merge branch 'fortran-serialisation' into fortran-serialization-codeg…
ChristopherBignamini May 3, 2023
6e9f16c
New interface adopted
ChristopherBignamini May 3, 2023
f3596a9
Codegen fixtures created
ChristopherBignamini May 4, 2023
6f106b5
Serialization directives reference file created
ChristopherBignamini May 4, 2023
1e71448
Fix tests
samkellerhals May 4, 2023
ba12eb5
Merge branch 'fortran-serialisation' into fortran-serialisation-cli-t…
ChristopherBignamini May 4, 2023
34fc8dc
Merge branch 'fortran-serialisation-cli-tests' of https://github.com/…
ChristopherBignamini May 4, 2023
adb2d4b
Merge branch 'fortran-serialisation-cli-tests' into fortran-serializa…
ChristopherBignamini May 5, 2023
645f312
Merge branch 'fortran-serialisation' into fortran-serialization-codeg…
ChristopherBignamini May 9, 2023
66952a0
Fix tests
samkellerhals May 9, 2023
e1859cb
Remove print statement
samkellerhals May 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions pyutils/src/icon4py/f2ser/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,12 @@ def _parse_derived_types(self, derived_types: dict) -> dict:
MissingDerivedTypeError: If the type definition for a derived type could not be found in any of the dependency files.
"""
derived_type_defs = {}
for dep in self.dependencies:
parsed = crack(dep)
for block in parsed["body"]:
if block["block"] == "type":
derived_type_defs[block["name"]] = block["vars"]
if self.dependencies:
for dep in self.dependencies:
parsed = crack(dep)
for block in parsed["body"]:
if block["block"] == "type":
derived_type_defs[block["name"]] = block["vars"]

for _, subroutine_vars in derived_types.items():
for _, intent_vars in subroutine_vars.items():
Expand Down
27 changes: 26 additions & 1 deletion pyutils/tests/f2ser/test_f2ser_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later

import pytest

from icon4py.f2ser.deserialise import ParsedGranuleDeserialiser
from icon4py.f2ser.parse import GranuleParser
from icon4py.liskov.codegen.serialisation.generate import SerialisationGenerator

from icon4py.liskov.codegen.types import GeneratedCode

def test_deserialiser_diffusion_codegen(diffusion_granule, diffusion_granule_deps):
parser = GranuleParser(diffusion_granule, diffusion_granule_deps)
Expand All @@ -24,3 +26,26 @@ def test_deserialiser_diffusion_codegen(diffusion_granule, diffusion_granule_dep
generator = SerialisationGenerator(interface)
generated = generator()
assert len(generated) == 3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add one test case for a fortran file which does have dependencies and where the dependencies include derived types so we can test they are being generated correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test_deserialiser_directives_diffusion_codegen test where I check if the serialization directives are correctly generated for the diffusion case, so the derived types serialization are included. I'm not sure this is what you expected, maybe I can create a smaller more specific test...

I have a question concerning the reference code fixtures: in the shorter case of the test_deserialiser_directives_no_deps_codegen test, where I check the generation of the serialization directives for a no-deps small source code, I create the GeneratedCode items and save them in a list, exactly as we do in the serialization code. In the diffusion case, instead, I saved the reference code in a file and then compare the file content to the generated code, after a conversion into a string of the GeneratedCode list (because creating the GeneratedCode instances is a bit complex giving the source code size). Should I unify the two approaches?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the small reference case it makes sense to define the generated code fixture like you did it. I agree that for more complex cases such as when defining the expected code for the diffusion granule, a better approach would be to define the expected code in an external file. Here a compromise would be to for example only check the first savepoint since otherwise the file would be quite large. I've modified the test to check for only the first savepoint, since anyhow that includes all the parts we want to test.

@pytest.fixture
def expected_no_deps_serialization_directives():
serialization_directives = [
GeneratedCode(startln=12,
source='\n!$ser init directory="." prefix="test"\n\n!$ser savepoint no_deps_init_in\n\n!$ser data a=a\n\n!$ser data b=b'),
GeneratedCode(startln=14,
source='\n!$ser savepoint no_deps_init_out\n\n!$ser data c=c\n\n!$ser data b=b'),
GeneratedCode(startln=20,
source='\n!$ser savepoint no_deps_run_in\n\n!$ser data a=a\n\n!$ser data b=b'),
GeneratedCode(startln=22,
source='\n!$ser savepoint no_deps_run_out\n\n!$ser data c=c\n\n!$ser data b=b')]
return serialization_directives

def test_deserialiser_no_deps_codegen(no_deps_source_file, diffusion_granule_deps,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you declared the no_deps_source_file fixture anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I forgot to push the conftest.py file

expected_no_deps_serialization_directives):
parser = GranuleParser(no_deps_source_file)
parsed = parser.parse()
deserialiser = ParsedGranuleDeserialiser(parsed, directory=".", prefix="test")
interface = deserialiser.deserialise()
generator = SerialisationGenerator(interface)
generated = generator()
assert(generated == expected_no_deps_serialization_directives())