From eda5090f600f1c0277f35b8c28ea51cbe12b5d46 Mon Sep 17 00:00:00 2001 From: Hannes Vogt Date: Thu, 3 Dec 2026 18:19:26 +0100 Subject: [PATCH] test[next]: apply exclusion-matrix xfails as strict markers and drop stale entries --- .../ADRs/next/0015-Test_Exclusion_Matrices.md | 2 +- pyproject.toml | 1 + tests/next_tests/definitions.py | 62 ++++++++++--------- .../integration_tests/cases_utils.py | 6 +- .../ffront_tests/test_concat_where.py | 12 +++- .../ffront_tests/test_decorator.py | 7 ++- .../feature_tests/ffront_tests/test_domain.py | 6 +- .../test_with_toy_connectivity.py | 1 - tests/next_tests/unit_tests/conftest.py | 7 +-- 9 files changed, 54 insertions(+), 50 deletions(-) diff --git a/docs/development/ADRs/next/0015-Test_Exclusion_Matrices.md b/docs/development/ADRs/next/0015-Test_Exclusion_Matrices.md index 4eb29dba59..ba8dfad0d0 100644 --- a/docs/development/ADRs/next/0015-Test_Exclusion_Matrices.md +++ b/docs/development/ADRs/next/0015-Test_Exclusion_Matrices.md @@ -13,7 +13,7 @@ In the context of Field View testing, lacking support for specific ITIR features is being developed, we decided to use `pytest` fixtures to exclude unsupported tests. > [!NOTE] -> The processor list and the exclusion-matrix example below reflect the state when this ADR was written: `GTFN_CPU_IMPERATIVE` and `GTFN_CPU_WITH_TEMPORARIES` no longer exist. The current processors and their exclusion lists are in `tests/next_tests/definitions.py`. The mechanism described here is unchanged. +> The processor list and the exclusion-matrix example below reflect the state when this ADR was written: `GTFN_CPU_IMPERATIVE` and `GTFN_CPU_WITH_TEMPORARIES` no longer exist. The current processors and their exclusion lists are in `tests/next_tests/definitions.py`. The mechanism described here is unchanged, except that `XFAIL` entries are applied as strict `xfail` markers, so a test that passes on a backend listed as unsupported fails as an unexpected pass. ## Context diff --git a/pyproject.toml b/pyproject.toml index a9daac3da0..7321f46ec4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -284,6 +284,7 @@ markers = [ 'uses_max_over: tests that use the max_over builtin', 'uses_mesh_with_skip_values: tests that use a mesh with skip values', 'uses_concat_where: tests that use the concat_where builtin', + 'uses_concat_where_mixed_local_dims: tests that use concat_where on branches with different local dimensions', 'embedded_concat_where_infinite_domain: tests with concat_where resulting in an infinite domain', 'embedded_concat_where_non_contiguous_domain: tests with concat_where on non-contiguous domains', 'uses_program_metrics: tests that require backend support for program metrics', diff --git a/tests/next_tests/definitions.py b/tests/next_tests/definitions.py index 734c4677ff..a6464f66b7 100644 --- a/tests/next_tests/definitions.py +++ b/tests/next_tests/definitions.py @@ -51,7 +51,6 @@ class ProgramBackendId(_PythonObjectIdMixin, str, enum.Enum): ROUNDTRIP = "gt4py.next.program_processors.runners.roundtrip.default" ROUNDTRIP_NO_TRANSFORMS = "gt4py.next.program_processors.runners.roundtrip.no_transforms" GTIR_EMBEDDED = "gt4py.next.program_processors.runners.roundtrip.gtir" - ROUNDTRIP_WITH_TEMPORARIES = "gt4py.next.program_processors.runners.roundtrip.with_temporaries" DOUBLE_ROUNDTRIP = "gt4py.next.program_processors.runners.double_roundtrip.backend" @@ -185,6 +184,7 @@ class ProgramFormatterId(_PythonObjectIdMixin, str, enum.Enum): USES_PROGRAM_METRICS = "uses_program_metrics" USES_SCALAR_IN_DOMAIN_AND_FO = "uses_scalar_in_domain_and_fo" USES_CONCAT_WHERE = "uses_concat_where" +USES_CONCAT_WHERE_MIXED_LOCAL_DIMS = "uses_concat_where_mixed_local_dims" EMBEDDED_CONCAT_WHERE_INFINITE_DOMAIN = "embedded_concat_where_infinite_domain" EMBEDDED_CONCAT_WHERE_NON_CONTIGUOUS_DOMAIN = "embedded_concat_where_non_contiguous_domain" USES_PROGRAM_WITH_SLICED_OUT_ARGUMENTS = "uses_program_with_sliced_out_arguments" @@ -223,9 +223,7 @@ class ProgramFormatterId(_PythonObjectIdMixin, str, enum.Enum): COMMON_SKIP_TEST_LIST = [ (USES_APPLIED_SHIFTS, XFAIL, UNSUPPORTED_MESSAGE), (USES_NEGATIVE_MODULO, XFAIL, UNSUPPORTED_MESSAGE), - (USES_REDUCTION_WITH_ONLY_SPARSE_FIELDS, XFAIL, REDUCTION_WITH_ONLY_SPARSE_FIELDS_MESSAGE), (USES_SPARSE_FIELDS_AS_OUTPUT, XFAIL, UNSUPPORTED_MESSAGE), - (USES_TUPLES_ARGS_WITH_DIFFERENT_BUT_PROMOTABLE_DIMS, XFAIL, UNSUPPORTED_MESSAGE), ] # Markers to skip because of missing features in the domain inference DOMAIN_INFERENCE_SKIP_LIST = [ @@ -239,6 +237,7 @@ class ProgramFormatterId(_PythonObjectIdMixin, str, enum.Enum): (USES_COMPOSITE_SHIFTS, XFAIL, UNSUPPORTED_MESSAGE), (USES_LIFT, XFAIL, UNSUPPORTED_MESSAGE), (USES_REDUCE_WITH_LAMBDA, XFAIL, UNSUPPORTED_MESSAGE), + (USES_REDUCTION_WITH_ONLY_SPARSE_FIELDS, XFAIL, REDUCTION_WITH_ONLY_SPARSE_FIELDS_MESSAGE), (USES_SPARSE_FIELDS, XFAIL, UNSUPPORTED_MESSAGE), (USES_TUPLE_ITERATOR, XFAIL, UNSUPPORTED_MESSAGE), ( @@ -255,11 +254,6 @@ class ProgramFormatterId(_PythonObjectIdMixin, str, enum.Enum): ) EMBEDDED_SKIP_LIST = [ (CHECKS_SPECIFIC_ERROR, XFAIL, UNSUPPORTED_MESSAGE), - ( - USES_SCAN_WITHOUT_FIELD_ARGS, - XFAIL, - UNSUPPORTED_MESSAGE, - ), # we can't extract the field type from scan args (EMBEDDED_CONCAT_WHERE_INFINITE_DOMAIN, XFAIL, UNSUPPORTED_MESSAGE), (EMBEDDED_CONCAT_WHERE_NON_CONTIGUOUS_DOMAIN, XFAIL, UNSUPPORTED_MESSAGE), ( @@ -268,7 +262,11 @@ class ProgramFormatterId(_PythonObjectIdMixin, str, enum.Enum): OFFSET_TAG_DIFFERING_FROM_LOCAL_DIM_MESSAGE, ), ] -JAX_EMBEDDED_SKIP_LIST = EMBEDDED_SKIP_LIST + [ +#: a scan without field arguments has no buffer to take the array type from, so it allocates with NumPy +NON_NUMPY_EMBEDDED_SKIP_LIST = EMBEDDED_SKIP_LIST + [ + (USES_SCAN_WITHOUT_FIELD_ARGS, XFAIL, UNSUPPORTED_MESSAGE), +] +JAX_EMBEDDED_SKIP_LIST = NON_NUMPY_EMBEDDED_SKIP_LIST + [ (USES_PROGRAM_WITH_SLICED_OUT_ARGUMENTS, XFAIL, UNSUPPORTED_MESSAGE), ] #: under a tracing compiler, scalar arguments are traced unless they are in `static_params` @@ -278,19 +276,19 @@ class ProgramFormatterId(_PythonObjectIdMixin, str, enum.Enum): (USES_SCAN_CARRY_IN_CONTROL_FLOW, XFAIL, UNSUPPORTED_MESSAGE), ] JAX_JIT_SKIP_LIST = JAX_EMBEDDED_SKIP_LIST + TRACED_SCALARS_SKIP_LIST -TORCH_COMPILE_SKIP_LIST = EMBEDDED_SKIP_LIST + TRACED_SCALARS_SKIP_LIST +TORCH_COMPILE_SKIP_LIST = NON_NUMPY_EMBEDDED_SKIP_LIST + TRACED_SCALARS_SKIP_LIST # TODO(havogt): inductor builds CPU code with `$CXX`, which is `hipcc` on the ROCm CI and fails TORCH_COMPILE_CPU_MESSAGE = "'torch.compile' on CPU is skipped for now." -ARRAY_API_STRICT_EMBEDDED_SKIP_LIST = EMBEDDED_SKIP_LIST + [ +ARRAY_API_STRICT_EMBEDDED_SKIP_LIST = NON_NUMPY_EMBEDDED_SKIP_LIST + [ (USES_MATH_OUTSIDE_ARRAY_API, XFAIL, "Not in the Array API standard."), ] ROUNDTRIP_SKIP_LIST = DOMAIN_INFERENCE_SKIP_LIST + [ (USES_PROGRAM_METRICS, XFAIL, UNSUPPORTED_MESSAGE), (USES_SPARSE_FIELDS_AS_OUTPUT, XFAIL, UNSUPPORTED_MESSAGE), - (USES_TUPLES_ARGS_WITH_DIFFERENT_BUT_PROMOTABLE_DIMS, XFAIL, UNSUPPORTED_MESSAGE), - (USES_CONCAT_WHERE, XFAIL, UNSUPPORTED_MESSAGE), + (USES_CONCAT_WHERE_MIXED_LOCAL_DIMS, XFAIL, UNSUPPORTED_MESSAGE), ] GTIR_EMBEDDED_SKIP_LIST = ROUNDTRIP_SKIP_LIST + [ + (USES_CONCAT_WHERE, XFAIL, UNSUPPORTED_MESSAGE), # NOTE: not in `ROUNDTRIP_SKIP_LIST`: the roundtrip backend passes this, only the # lower-level `iterator/embedded.py` execution keys on the local dimension's name. ( @@ -321,32 +319,38 @@ class ProgramFormatterId(_PythonObjectIdMixin, str, enum.Enum): #: (, ) BACKEND_SKIP_TEST_MATRIX = { EmbeddedIds.NUMPY_EXECUTION: EMBEDDED_SKIP_LIST, - EmbeddedIds.CUPY_EXECUTION: EMBEDDED_SKIP_LIST, + EmbeddedIds.CUPY_EXECUTION: NON_NUMPY_EMBEDDED_SKIP_LIST, EmbeddedIds.JAX_NUMPY_EXECUTION: JAX_EMBEDDED_SKIP_LIST, EmbeddedIds.ARRAY_API_STRICT_EXECUTION: ARRAY_API_STRICT_EMBEDDED_SKIP_LIST, - EmbeddedIds.TORCH_EXECUTION: EMBEDDED_SKIP_LIST, - EmbeddedIds.TORCH_CUDA_EXECUTION: EMBEDDED_SKIP_LIST, + EmbeddedIds.TORCH_EXECUTION: NON_NUMPY_EMBEDDED_SKIP_LIST, + EmbeddedIds.TORCH_CUDA_EXECUTION: NON_NUMPY_EMBEDDED_SKIP_LIST, OptionalProgramBackendId.DACE_CPU: DACE_SKIP_TEST_LIST, OptionalProgramBackendId.DACE_GPU: DACE_SKIP_TEST_LIST, OptionalProgramBackendId.DACE_CPU_NO_OPT: DACE_SKIP_TEST_LIST, OptionalProgramBackendId.JAX_JIT: JAX_JIT_SKIP_LIST, OptionalProgramBackendId.TORCH_COMPILE: [(ALL, SKIP, TORCH_COMPILE_CPU_MESSAGE)], OptionalProgramBackendId.TORCH_COMPILE_CUDA: TORCH_COMPILE_SKIP_LIST, - ProgramBackendId.GTFN_CPU: GTFN_SKIP_TEST_LIST - + [(USES_SCAN_NESTED, XFAIL, UNSUPPORTED_MESSAGE)], - ProgramBackendId.GTFN_GPU: GTFN_SKIP_TEST_LIST - + [(USES_SCAN_NESTED, XFAIL, UNSUPPORTED_MESSAGE)], - ProgramFormatterId.GTFN_CPP_FORMATTER: DOMAIN_INFERENCE_SKIP_LIST - + [ - (USES_REDUCTION_WITH_ONLY_SPARSE_FIELDS, XFAIL, REDUCTION_WITH_ONLY_SPARSE_FIELDS_MESSAGE), - ], + ProgramBackendId.GTFN_CPU: GTFN_SKIP_TEST_LIST, + ProgramBackendId.GTFN_GPU: GTFN_SKIP_TEST_LIST, + ProgramFormatterId.GTFN_CPP_FORMATTER: DOMAIN_INFERENCE_SKIP_LIST, ProgramFormatterId.LISP_FORMATTER: DOMAIN_INFERENCE_SKIP_LIST, ProgramBackendId.ROUNDTRIP: ROUNDTRIP_SKIP_LIST, ProgramBackendId.DOUBLE_ROUNDTRIP: ROUNDTRIP_SKIP_LIST, - ProgramBackendId.ROUNDTRIP_WITH_TEMPORARIES: ROUNDTRIP_SKIP_LIST - + [ - (ALL, XFAIL, UNSUPPORTED_MESSAGE), - (USES_STRIDED_NEIGHBOR_OFFSET, XFAIL, UNSUPPORTED_MESSAGE), - ], ProgramBackendId.GTIR_EMBEDDED: GTIR_EMBEDDED_SKIP_LIST, } + + +def apply_backend_exclusions(request: pytest.FixtureRequest, backend_id: object) -> None: + """Apply the first entry of `BACKEND_SKIP_TEST_MATRIX` matching the test's markers. + + `XFAIL` entries are applied as markers, not raised, so that the test still runs and a + passing test is reported as an unexpected pass (failure under `xfail_strict`). + """ + for marker, skip_mark, msg in BACKEND_SKIP_TEST_MATRIX.get(backend_id, []): + if marker == ALL or request.node.get_closest_marker(marker): + reason = msg.format(marker=marker, backend=backend_id) + if skip_mark is XFAIL: + request.applymarker(pytest.mark.xfail(reason=reason, strict=True)) + else: + skip_mark(reason) + return diff --git a/tests/next_tests/integration_tests/cases_utils.py b/tests/next_tests/integration_tests/cases_utils.py index afdbc99619..f9bf184d18 100644 --- a/tests/next_tests/integration_tests/cases_utils.py +++ b/tests/next_tests/integration_tests/cases_utils.py @@ -155,11 +155,7 @@ def exec_alloc_descriptor(request): backend_id = request.param backend = backend_id.load() - for marker, skip_mark, msg in next_tests.definitions.BACKEND_SKIP_TEST_MATRIX.get( - backend_id, [] - ): - if marker == next_tests.definitions.ALL or request.node.get_closest_marker(marker): - skip_mark(msg.format(marker=marker, backend=backend_id)) + next_tests.definitions.apply_backend_exclusions(request, backend_id) backup_backend = decorator.DEFAULT_BACKEND decorator.DEFAULT_BACKEND = no_backend diff --git a/tests/next_tests/integration_tests/feature_tests/ffront_tests/test_concat_where.py b/tests/next_tests/integration_tests/feature_tests/ffront_tests/test_concat_where.py index 3c7273123d..c6f4af216d 100644 --- a/tests/next_tests/integration_tests/feature_tests/ffront_tests/test_concat_where.py +++ b/tests/next_tests/integration_tests/feature_tests/ffront_tests/test_concat_where.py @@ -29,10 +29,13 @@ mesh_descriptor, ) -pytestmark = pytest.mark.uses_concat_where +_DYNAMIC_DOMAINS = pytest.param(False, marks=pytest.mark.uses_concat_where, id="dynamic_domains") +_STATIC_DOMAINS = pytest.param(True, marks=pytest.mark.uses_concat_where, id="static_domains") +# With static domains the empty branch is pruned before lowering: no `concat_where` reaches the backend. +_STATIC_DOMAINS_PRUNED = pytest.param(True, id="static_domains") -@pytest.fixture(params=[False, True], ids=["dynamic_domains", "static_domains"]) +@pytest.fixture(params=[_DYNAMIC_DOMAINS, _STATIC_DOMAINS]) def static_domains(request) -> bool: """Fixture to select compilation with dynamic or statically known domain bounds.""" return request.param @@ -208,6 +211,7 @@ def testee(interior: cases.IJKField, boundary: cases.IJField) -> cases.IJKField: ) +@pytest.mark.parametrize("static_domains", [_DYNAMIC_DOMAINS, _STATIC_DOMAINS_PRUNED]) def test_boundary_single_layer_2d_bc_on_empty_branch(cartesian_case, static_domains: bool): @gtx.field_operator(static_domains=static_domains) def testee(interior: cases.IJKField, boundary: cases.IJField) -> cases.IJKField: @@ -495,6 +499,7 @@ def testee( @pytest.mark.uses_unstructured_shift +@pytest.mark.uses_concat_where_mixed_local_dims def test_with_local_and_nonlocal_field(unstructured_case, static_domains: bool): @gtx.field_operator(static_domains=static_domains) def testee(a: cases.EField, b: cases.VField) -> cases.VField: @@ -552,6 +557,7 @@ def testee( @pytest.mark.uses_tuple_returns @pytest.mark.uses_unstructured_shift @pytest.mark.embedded_concat_where_infinite_domain +@pytest.mark.uses_concat_where_mixed_local_dims def test_with_local_field_and_scalar(unstructured_case, static_domains: bool): @gtx.field_operator(static_domains=static_domains) def testee(a: cases.EField) -> tuple[cases.VField, cases.VField]: @@ -585,6 +591,7 @@ def testee(a: cases.EField) -> tuple[cases.VField, cases.VField]: @pytest.mark.uses_tuple_returns @pytest.mark.uses_unstructured_shift @pytest.mark.embedded_concat_where_infinite_domain +@pytest.mark.uses_concat_where_mixed_local_dims def test_with_tuples_of_local_and_nonlocal_leaves(unstructured_case, static_domains: bool): @gtx.field_operator(static_domains=static_domains) def testee( @@ -662,6 +669,7 @@ def ref(interior0, boundary0, interior1, boundary1): cases.verify_with_default_data(cartesian_case, testee, ref) +@pytest.mark.parametrize("static_domains", [_DYNAMIC_DOMAINS, _STATIC_DOMAINS_PRUNED]) def test_concat_where_field_broadcast_on_empty_branch(cartesian_case, static_domains: bool): """ A field branch with fewer dimensions than the expression is implicitly broadcast. diff --git a/tests/next_tests/integration_tests/feature_tests/ffront_tests/test_decorator.py b/tests/next_tests/integration_tests/feature_tests/ffront_tests/test_decorator.py index 7974161504..3ab917a1c2 100644 --- a/tests/next_tests/integration_tests/feature_tests/ffront_tests/test_decorator.py +++ b/tests/next_tests/integration_tests/feature_tests/ffront_tests/test_decorator.py @@ -40,11 +40,12 @@ def testee(a: cases.IField, out: cases.IField): [ (metrics.DISABLED, ()), (metrics.MINIMAL, ("total",)), - (metrics.PERFORMANCE, ("total", "compute")), - (metrics.ALL, ("compute", "total")), + pytest.param( + metrics.PERFORMANCE, ("total", "compute"), marks=pytest.mark.uses_program_metrics + ), + pytest.param(metrics.ALL, ("compute", "total"), marks=pytest.mark.uses_program_metrics), ], ) -@pytest.mark.uses_program_metrics def test_collect_metrics(cartesian_case, metrics_level, expected_names): if cases.runs_embedded(cartesian_case): pytest.skip("Precompiled program with embedded execution is not possible.") diff --git a/tests/next_tests/integration_tests/feature_tests/ffront_tests/test_domain.py b/tests/next_tests/integration_tests/feature_tests/ffront_tests/test_domain.py index 3021bdc04f..756e7d83f5 100644 --- a/tests/next_tests/integration_tests/feature_tests/ffront_tests/test_domain.py +++ b/tests/next_tests/integration_tests/feature_tests/ffront_tests/test_domain.py @@ -45,16 +45,16 @@ def testee(size: gtx.IndexType, out: gtx.Field[[IDim], gtx.IndexType]): def test_single_value_field(cartesian_case): @gtx.field_operator def testee_fo(a: cases.IKField) -> cases.IKField: - return a + return a + 1 @gtx.program def testee_prog(a: cases.IKField): testee_fo(a, out=a[1:2, 3:4]) a = cases.allocate(cartesian_case, testee_prog, "a")() - ref = a[1, 3] + ref = a.asnumpy()[1:2, 3:4] + 1 - cases.verify(cartesian_case, testee_prog, a, inout=a[1, 3], ref=ref) + cases.verify(cartesian_case, testee_prog, a, inout=a[1:2, 3:4], ref=ref) @pytest.mark.uses_scalar_in_domain diff --git a/tests/next_tests/integration_tests/multi_feature_tests/iterator_tests/test_with_toy_connectivity.py b/tests/next_tests/integration_tests/multi_feature_tests/iterator_tests/test_with_toy_connectivity.py index ad2337237d..58f53b27ed 100644 --- a/tests/next_tests/integration_tests/multi_feature_tests/iterator_tests/test_with_toy_connectivity.py +++ b/tests/next_tests/integration_tests/multi_feature_tests/iterator_tests/test_with_toy_connectivity.py @@ -229,7 +229,6 @@ def slice_sparse_stencil(sparse): return list_get(1, deref(sparse)) -@pytest.mark.uses_sparse_fields def test_slice_sparse(program_processor): program_processor, validate = program_processor inp = gtx.as_field([Vertex, V2VDim], v2v_arr) diff --git a/tests/next_tests/unit_tests/conftest.py b/tests/next_tests/unit_tests/conftest.py index 1afb82397c..9f568e7090 100644 --- a/tests/next_tests/unit_tests/conftest.py +++ b/tests/next_tests/unit_tests/conftest.py @@ -42,11 +42,7 @@ def _program_processor(request) -> tuple[ProgramProcessor, bool]: processor = processor_id.load() - for marker, skip_mark, msg in next_tests.definitions.BACKEND_SKIP_TEST_MATRIX.get( - processor_id, [] - ): - if marker == next_tests.definitions.ALL or request.node.get_closest_marker(marker): - skip_mark(msg.format(marker=marker, backend=processor_id)) + next_tests.definitions.apply_backend_exclusions(request, processor_id) return processor, is_backend @@ -56,7 +52,6 @@ def _program_processor(request) -> tuple[ProgramProcessor, bool]: params=[ (None, True), (next_tests.definitions.ProgramBackendId.ROUNDTRIP, True), - (next_tests.definitions.ProgramBackendId.ROUNDTRIP_WITH_TEMPORARIES, True), (next_tests.definitions.ProgramBackendId.GTIR_EMBEDDED, True), (next_tests.definitions.ProgramBackendId.DOUBLE_ROUNDTRIP, True), (next_tests.definitions.ProgramBackendId.GTFN_CPU, True),