-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test[next]: check for DaCe dependency in test execution (#1336)
Expanding the pytest fixture for unit tests with markers to exclude tests based on feature support in the selected backend. In addition, a check is added to the DaCe backend so that tests are skipped if dace module is not installed. This is required for Spack build of icon4py, which uses the base installation of gt4py, where dace module is optional.
- Loading branch information
Showing
29 changed files
with
346 additions
and
403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
--- | ||
tags: [] | ||
--- | ||
|
||
# Test-Exclusion Matrices | ||
|
||
- **Status**: valid | ||
- **Authors**: Edoardo Paone (@edopao), Enrique G. Paredes (@egparedes) | ||
- **Created**: 2023-09-21 | ||
- **Updated**: 2023-09-21 | ||
|
||
In the context of Field View testing, lacking support for specific ITIR features while a certain backend | ||
is being developed, we decided to use `pytest` fixtures to exclude unsupported tests. | ||
|
||
## Context | ||
|
||
It should be possible to run Field View tests on different backends. However, specific tests could be unsupported | ||
on a certain backend, or the backend implementation could be only partially ready. | ||
Therefore, we need a mechanism to specify the features required by each test and selectively enable | ||
the supported backends, while keeping the test code clean. | ||
|
||
## Decision | ||
|
||
It was decided to apply fixtures and markers from `pytest` module. The fixture is the same used to execute the test | ||
on different backends (`fieldview_backend` and `program_processor`), but it is extended with a check on the available feature markers. | ||
If a test is annotated with a feature marker, the fixture will check if this feature is supported on the selected backend. | ||
If no marker is specified, the test is supposed to run on all backends. | ||
|
||
In the example below, `test_offset_field` requires the backend to support dynamic offsets in the translation from ITIR: | ||
|
||
```python | ||
@pytest.mark.uses_dynamic_offsets | ||
def test_offset_field(cartesian_case): | ||
``` | ||
|
||
In order to selectively enable the backends, the dictionary `next_tests.exclusion_matrices.BACKEND_SKIP_TEST_MATRIX` | ||
lists for each backend the features that are not supported. | ||
The fixture will check if the annotated feature is present in the exclusion-matrix for the selected backend. | ||
If so, the exclusion matrix will also specify the action `pytest` should take (e.g. `SKIP` or `XFAIL`). | ||
|
||
The test-exclusion matrix is a dictionary, where `key` is the backend name and each entry is a tuple with the following fields: | ||
|
||
`(<marker[str]>, <skip_definition[SKIP,XFAIL]>, <skip_message(format keys: 'marker', 'backend')>)` | ||
|
||
The backend string, used both as dictionary key and as string formatter in the skip message, is retrieved | ||
by calling `tests.next_tests.get_processor_id()`, which returns the so-called processor name. | ||
The following backend processors are defined: | ||
|
||
```python | ||
DACE = "dace_iterator.run_dace_iterator" | ||
GTFN_CPU = "otf_compile_executor.run_gtfn" | ||
GTFN_CPU_IMPERATIVE = "otf_compile_executor.run_gtfn_imperative" | ||
GTFN_CPU_WITH_TEMPORARIES = "otf_compile_executor.run_gtfn_with_temporaries" | ||
``` | ||
|
||
Following the previous example, the GTFN backend with temporaries does not support yet dynamic offsets in ITIR: | ||
|
||
```python | ||
BACKEND_SKIP_TEST_MATRIX = { | ||
GTFN_CPU_WITH_TEMPORARIES: [ | ||
("uses_dynamic_offsets", pytest.XFAIL, "'{marker}' tests not supported by '{backend}' backend"), | ||
] | ||
} | ||
``` | ||
|
||
## Consequences | ||
|
||
Positive outcomes of this decision: | ||
|
||
- The solution provides a central place to specify test exclusion. | ||
- The test code remains clean from if-statements for backend exclusion. | ||
- The exclusion matrix gives an overview of the feature-readiness of different backends. | ||
|
||
Negative outcomes: | ||
|
||
- There is not (yet) any code-style check to enforce this solution, so code reviews should be aware of the ADR. | ||
|
||
## References <!-- optional --> | ||
|
||
- [pytest - Using markers to pass data to fixtures](https://docs.pytest.org/en/6.2.x/fixture.html#using-markers-to-pass-data-to-fixtures) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# GT4Py - GridTools Framework | ||
# | ||
# Copyright (c) 2014-2023, ETH Zurich | ||
# All rights reserved. | ||
# | ||
# This file is part of the GT4Py project and the GridTools framework. | ||
# GT4Py is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU General Public License as published by the | ||
# Free Software Foundation, either version 3 of the License, or any later | ||
# version. See the LICENSE.txt file at the top-level directory of this | ||
# distribution for a copy of the license or check <https://www.gnu.org/licenses/>. | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
import pytest | ||
|
||
|
||
""" | ||
Contains definition of test-exclusion matrices, see ADR 15. | ||
""" | ||
|
||
# Skip definitions | ||
XFAIL = pytest.xfail | ||
SKIP = pytest.skip | ||
|
||
# Skip messages (available format keys: 'marker', 'backend') | ||
UNSUPPORTED_MESSAGE = "'{marker}' tests not supported by '{backend}' backend" | ||
BINDINGS_UNSUPPORTED_MESSAGE = "'{marker}' not supported by '{backend}' bindings" | ||
|
||
# Processor ids as returned by next_tests.get_processor_id() | ||
DACE = "dace_iterator.run_dace_iterator" | ||
GTFN_CPU = "otf_compile_executor.run_gtfn" | ||
GTFN_CPU_IMPERATIVE = "otf_compile_executor.run_gtfn_imperative" | ||
GTFN_CPU_WITH_TEMPORARIES = "otf_compile_executor.run_gtfn_with_temporaries" | ||
|
||
# Test markers | ||
REQUIRES_ATLAS = "requires_atlas" | ||
USES_APPLIED_SHIFTS = "uses_applied_shifts" | ||
USES_CAN_DEREF = "uses_can_deref" | ||
USES_CONSTANT_FIELDS = "uses_constant_fields" | ||
USES_DYNAMIC_OFFSETS = "uses_dynamic_offsets" | ||
USES_IF_STMTS = "uses_if_stmts" | ||
USES_INDEX_FIELDS = "uses_index_fields" | ||
USES_LIFT_EXPRESSIONS = "uses_lift_expressions" | ||
USES_NEGATIVE_MODULO = "uses_negative_modulo" | ||
USES_ORIGIN = "uses_origin" | ||
USES_REDUCTION_OVER_LIFT_EXPRESSIONS = "uses_reduction_over_lift_expressions" | ||
USES_SCAN_IN_FIELD_OPERATOR = "uses_scan_in_field_operator" | ||
USES_SPARSE_FIELDS = "uses_sparse_fields" | ||
USES_STRIDED_NEIGHBOR_OFFSET = "uses_strided_neighbor_offset" | ||
USES_TUPLE_ARGS = "uses_tuple_args" | ||
USES_TUPLE_RETURNS = "uses_tuple_returns" | ||
USES_ZERO_DIMENSIONAL_FIELDS = "uses_zero_dimensional_fields" | ||
|
||
# Common list of feature markers to skip | ||
GTFN_SKIP_TEST_LIST = [ | ||
(REQUIRES_ATLAS, XFAIL, BINDINGS_UNSUPPORTED_MESSAGE), | ||
(USES_APPLIED_SHIFTS, XFAIL, UNSUPPORTED_MESSAGE), | ||
(USES_IF_STMTS, XFAIL, UNSUPPORTED_MESSAGE), | ||
(USES_NEGATIVE_MODULO, XFAIL, UNSUPPORTED_MESSAGE), | ||
(USES_SCAN_IN_FIELD_OPERATOR, XFAIL, UNSUPPORTED_MESSAGE), | ||
(USES_STRIDED_NEIGHBOR_OFFSET, XFAIL, BINDINGS_UNSUPPORTED_MESSAGE), | ||
] | ||
|
||
""" | ||
Skip matrix, contains for each backend processor a list of tuples with following fields: | ||
(<test_marker>, <skip_definition, <skip_message>) | ||
""" | ||
BACKEND_SKIP_TEST_MATRIX = { | ||
DACE: GTFN_SKIP_TEST_LIST | ||
+ [ | ||
(USES_CAN_DEREF, XFAIL, UNSUPPORTED_MESSAGE), | ||
(USES_CONSTANT_FIELDS, XFAIL, UNSUPPORTED_MESSAGE), | ||
(USES_DYNAMIC_OFFSETS, XFAIL, UNSUPPORTED_MESSAGE), | ||
(USES_INDEX_FIELDS, XFAIL, UNSUPPORTED_MESSAGE), | ||
(USES_LIFT_EXPRESSIONS, XFAIL, UNSUPPORTED_MESSAGE), | ||
(USES_ORIGIN, XFAIL, UNSUPPORTED_MESSAGE), | ||
(USES_REDUCTION_OVER_LIFT_EXPRESSIONS, XFAIL, UNSUPPORTED_MESSAGE), | ||
(USES_SPARSE_FIELDS, XFAIL, UNSUPPORTED_MESSAGE), | ||
(USES_TUPLE_ARGS, XFAIL, UNSUPPORTED_MESSAGE), | ||
(USES_TUPLE_RETURNS, XFAIL, UNSUPPORTED_MESSAGE), | ||
(USES_ZERO_DIMENSIONAL_FIELDS, XFAIL, UNSUPPORTED_MESSAGE), | ||
], | ||
GTFN_CPU: GTFN_SKIP_TEST_LIST, | ||
GTFN_CPU_IMPERATIVE: GTFN_SKIP_TEST_LIST, | ||
GTFN_CPU_WITH_TEMPORARIES: GTFN_SKIP_TEST_LIST | ||
+ [ | ||
(USES_DYNAMIC_OFFSETS, XFAIL, UNSUPPORTED_MESSAGE), | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.