summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/abi.py
blob: 757b8b6861d8dcb40136bfaa64a273ed3fa5f486 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
""" Test ABI compatibility helpers"""

import pytest

from spack.abi import ABI
from spack.spec import Spec


@pytest.mark.parametrize(
    "target,constraint,expected",
    [
        ("foo", "bar", True),
        ("platform=linux", "foo", True),
        ("foo", "arch=linux-fedora31-x86_64", True),
        ("arch=linux-fedora31-skylake", "arch=linux-fedora31-skylake", True),
        ("arch=linux-fedora31-skylake", "arch=linux-fedora31-x86_64", False),
        ("platform=linux os=fedora31", "arch=linux-fedora31-x86_64", True),
        ("platform=linux", "arch=linux-fedora31-x86_64", True),
        ("platform=linux os=fedora31", "platform=linux", True),
        ("platform=darwin", "arch=linux-fedora31-x86_64", False),
        ("os=fedora31", "platform=linux", True),
    ],
)
def test_architecture_compatibility(target, constraint, expected):
    assert ABI().architecture_compatible(Spec(target), Spec(constraint)) == expected


@pytest.mark.parametrize(
    "target,constraint,loose,expected",
    [
        ("foo", "bar", False, True),
        ("%gcc", "foo", False, True),
        ("foo", "%gcc", False, True),
        ("%gcc", "%gcc", False, True),
        ("%gcc", "%intel", False, False),
        ("%gcc", "%clang", False, False),
        ("%gcc@9.1", "%gcc@9.2", False, False),  # TODO should be true ?
        ("%gcc@9.2.1", "%gcc@9.2.2", False, False),  # TODO should be true ?
        ("%gcc@4.9", "%gcc@9.2", False, False),
        ("%clang@5", "%clang@6", False, False),
        ("%gcc@9.1", "%gcc@9.2", True, True),
        ("%gcc@9.2.1", "%gcc@9.2.2", True, True),
        ("%gcc@4.9", "%gcc@9.2", True, True),
        ("%clang@5", "%clang@6", True, True),
    ],
)
def test_compiler_compatibility(target, constraint, loose, expected):
    assert ABI().compiler_compatible(Spec(target), Spec(constraint), loose=loose) == expected


@pytest.mark.parametrize(
    "target,constraint,loose,expected",
    [
        ("foo", "bar", False, True),
        ("%gcc", "platform=linux", False, True),
        ("%gcc@9.2.1", "%gcc@8.3.1 platform=linux", False, False),
        ("%gcc@9.2.1", "%gcc@8.3.1 platform=linux", True, True),
        ("%gcc@9.2.1 arch=linux-fedora31-skylake", "%gcc@9.2.1 platform=linux", False, True),
    ],
)
def test_compatibility(target, constraint, loose, expected):
    assert ABI().compatible(Spec(target), Spec(constraint), loose=loose) == expected