summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/concretize.py
blob: b3a77d076a16575bc2082d5227707674fae45a18 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
##############################################################################
# Copyright (c) 2013, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Written by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://scalability-llnl.github.io/spack
# Please also see the LICENSE file for our notice and the LGPL.
#
# This program 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) version 2.1 dated February 1999.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
# conditions of the GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
import unittest

import spack
from spack.spec import Spec, CompilerSpec
from spack.test.mock_packages_test import *

class ConcretizeTest(MockPackagesTest):

    def check_spec(self, abstract, concrete):
        if abstract.versions.concrete:
            self.assertEqual(abstract.versions, concrete.versions)

        if abstract.variants:
            for name in abstract.variants:
                avariant = abstract.variants[name]
                cvariant = concrete.variants[name]
                self.assertEqual(avariant.enabled, cvariant.enabled)

        for name in abstract.package.variants:
            self.assertTrue(name in concrete.variants)

        if abstract.compiler and abstract.compiler.concrete:
            self.assertEqual(abstract.compiler, concrete.compiler)

        if abstract.architecture and abstract.architecture.concrete:
            self.assertEqual(abstract.architecture, concrete.architecture)


    def check_concretize(self, abstract_spec):
        abstract = Spec(abstract_spec)
        concrete = abstract.concretized()

        self.assertFalse(abstract.concrete)
        self.assertTrue(concrete.concrete)
        self.check_spec(abstract, concrete)

        return concrete


    def test_concretize_no_deps(self):
        self.check_concretize('libelf')
        self.check_concretize('libelf@0.8.13')


    def test_concretize_dag(self):
        self.check_concretize('callpath')
        self.check_concretize('mpileaks')
        self.check_concretize('libelf')


    def test_concretize_variant(self):
        self.check_concretize('mpich+debug')
        self.check_concretize('mpich~debug')
        self.check_concretize('mpich')


    def test_concretize_with_virtual(self):
        self.check_concretize('mpileaks ^mpi')
        self.check_concretize('mpileaks ^mpi@:1.1')
        self.check_concretize('mpileaks ^mpi@2:')
        self.check_concretize('mpileaks ^mpi@2.1')
        self.check_concretize('mpileaks ^mpi@2.2')
        self.check_concretize('mpileaks ^mpi@2.2')
        self.check_concretize('mpileaks ^mpi@:1')
        self.check_concretize('mpileaks ^mpi@1.2:2')


    def test_concretize_with_restricted_virtual(self):
        self.check_concretize('mpileaks ^mpich2')

        concrete = self.check_concretize('mpileaks   ^mpich2@1.1')
        self.assertTrue(concrete['mpich2'].satisfies('mpich2@1.1'))

        concrete = self.check_concretize('mpileaks   ^mpich2@1.2')
        self.assertTrue(concrete['mpich2'].satisfies('mpich2@1.2'))

        concrete = self.check_concretize('mpileaks   ^mpich2@:1.5')
        self.assertTrue(concrete['mpich2'].satisfies('mpich2@:1.5'))

        concrete = self.check_concretize('mpileaks   ^mpich2@:1.3')
        self.assertTrue(concrete['mpich2'].satisfies('mpich2@:1.3'))

        concrete = self.check_concretize('mpileaks   ^mpich2@:1.2')
        self.assertTrue(concrete['mpich2'].satisfies('mpich2@:1.2'))

        concrete = self.check_concretize('mpileaks   ^mpich2@:1.1')
        self.assertTrue(concrete['mpich2'].satisfies('mpich2@:1.1'))

        concrete = self.check_concretize('mpileaks   ^mpich2@1.1:')
        self.assertTrue(concrete['mpich2'].satisfies('mpich2@1.1:'))

        concrete = self.check_concretize('mpileaks   ^mpich2@1.5:')
        self.assertTrue(concrete['mpich2'].satisfies('mpich2@1.5:'))

        concrete = self.check_concretize('mpileaks   ^mpich2@1.3.1:1.4')
        self.assertTrue(concrete['mpich2'].satisfies('mpich2@1.3.1:1.4'))


    def test_concretize_with_provides_when(self):
        """Make sure insufficient versions of MPI are not in providers list when
           we ask for some advanced version.
        """
        self.assertTrue(not any(spec.satisfies('mpich2@:1.0')
                                for spec in spack.db.providers_for('mpi@2.1')))

        self.assertTrue(not any(spec.satisfies('mpich2@:1.1')
                                for spec in spack.db.providers_for('mpi@2.2')))

        self.assertTrue(not any(spec.satisfies('mpich2@:1.1')
                                for spec in spack.db.providers_for('mpi@2.2')))

        self.assertTrue(not any(spec.satisfies('mpich@:1')
                                for spec in spack.db.providers_for('mpi@2')))

        self.assertTrue(not any(spec.satisfies('mpich@:1')
                                for spec in spack.db.providers_for('mpi@3')))

        self.assertTrue(not any(spec.satisfies('mpich2')
                                for spec in spack.db.providers_for('mpi@3')))


    def test_virtual_is_fully_expanded_for_callpath(self):
        # force dependence on fake "zmpi" by asking for MPI 10.0
        spec = Spec('callpath ^mpi@10.0')
        self.assertTrue('mpi' in spec.dependencies)
        self.assertFalse('fake' in spec)

        spec.concretize()

        self.assertTrue('zmpi' in spec.dependencies)
        self.assertTrue(all(not 'mpi' in d.dependencies for d in spec.traverse()))
        self.assertTrue('zmpi' in spec)
        self.assertTrue('mpi' in spec)

        self.assertTrue('fake' in spec.dependencies['zmpi'])


    def test_virtual_is_fully_expanded_for_mpileaks(self):
        spec = Spec('mpileaks ^mpi@10.0')
        self.assertTrue('mpi' in spec.dependencies)
        self.assertFalse('fake' in spec)

        spec.concretize()

        self.assertTrue('zmpi' in spec.dependencies)
        self.assertTrue('callpath' in spec.dependencies)
        self.assertTrue('zmpi' in spec.dependencies['callpath'].dependencies)
        self.assertTrue('fake' in spec.dependencies['callpath'].dependencies['zmpi'].dependencies)

        self.assertTrue(all(not 'mpi' in d.dependencies for d in spec.traverse()))
        self.assertTrue('zmpi' in spec)
        self.assertTrue('mpi' in spec)


    def test_my_dep_depends_on_provider_of_my_virtual_dep(self):
        spec = Spec('indirect_mpich')
        spec.normalize()
        spec.concretize()


    def test_compiler_inheritance(self):
        spec = Spec('mpileaks')
        spec.normalize()

        spec['dyninst'].compiler = CompilerSpec('clang')
        spec.concretize()

        # TODO: not exactly the syntax I would like.
        self.assertTrue(spec['libdwarf'].compiler.satisfies('clang'))
        self.assertTrue(spec['libelf'].compiler.satisfies('clang'))