summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/config.py
blob: 8fffc094378c8aec2a97e9276fa580a68336d32f (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
195
##############################################################################
# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://github.com/llnl/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 Lesser General Public License (as
# published by the Free Software Foundation) version 2.1, 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 Lesser 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 os
import shutil
from tempfile import mkdtemp

import spack
import spack.config
from ordereddict_backport import OrderedDict
from spack.test.mock_packages_test import *

# Some sample compiler config data
a_comps =  {
    'gcc473': {
        'paths': {
            "cc" : "/gcc473",
            "cxx": "/g++473",
            "f77": None,
            "fc" : None 
            },
        'modules': None,
        'spec': 'gcc@4.7.3',
        'operating_system': {
            'name': 'CNL',
            'version': '10'
            }
        },
    'gcc450': {
        'paths': {
            "cc" : "/gcc450",
            "cxx": "/g++450",
            "f77": 'gfortran',
            "fc" : 'gfortran'
            },
        'modules': None,
        'spec': 'gcc@4.5.0',
        'operating_system': {
            'name': 'CNL',
            'version': '10'
            }
        },
    'clang33': {
        'paths': {
            "cc" : "<overwritten>",
            "cxx": "<overwritten>",
            "f77": '<overwritten>',
            "fc" : '<overwritten>' },
        'modules': None,
        'spec': 'clang@3.3',
        'operating_system': {
            'name': 'CNL',
            'version': '10'
            }
        }
}

b_comps = {
    'icc100': {
        'paths': {
            "cc" : "/icc100",
            "cxx": "/icp100",
            "f77": None,
            "fc" : None
            },
        'modules': None,
        'spec': 'icc@10.0',
        'operating_system': {
            'name': 'CNL',
            'version': '10'
            }
        },
    'icc111': {
        'paths': {
            "cc" : "/icc111",
            "cxx": "/icp111",
            "f77": 'ifort',
            "fc" : 'ifort'
            },
        'modules': None,
        'spec': 'icc@11.1',
        'operating_system': {
            'name': 'CNL',
            'version': '10'
            }
        },
    'clang33': {
        'paths': {
            "cc" : "<overwritten>",
            "cxx": "<overwritten>",
            "f77": '<overwritten>',
            "fc" : '<overwritten>' },
        'modules': None,
        'spec': 'clang@3.3',
        'operating_system': {
            'name': 'CNL',
            'version': '10'
            }
        }
}

# Some Sample repo data
repos_low = [ "/some/path" ]
repos_high = [ "/some/other/path" ]

class ConfigTest(MockPackagesTest):

    def setUp(self):
        super(ConfigTest, self).setUp()
        self.tmp_dir = mkdtemp('.tmp', 'spack-config-test-')
        spack.config.config_scopes = OrderedDict()
        spack.config.ConfigScope('test_low_priority', os.path.join(self.tmp_dir, 'low'))
        spack.config.ConfigScope('test_high_priority', os.path.join(self.tmp_dir, 'high'))

    def tearDown(self):
        super(ConfigTest, self).tearDown()
        shutil.rmtree(self.tmp_dir, True)


    def check_config(self, comps, *compiler_names):
        """Check that named compilers in comps match Spack's config."""
        config = spack.config.get_config('compilers')
        compiler_list = ['cc', 'cxx', 'f77', 'fc']
        param_list = ['modules', 'paths', 'spec', 'operating_system']
        for alias, compiler in config.items():
            if compiler['spec'] in compiler_names:
                for p in param_list:
                    expected = comps[alias][p]
                    actual = config[alias][p]
                    self.assertEqual(expected, actual)
                for c in compiler_list:
                    expected = comps[alias]['paths'][c]
                    actual = config[alias]['paths'][c]
                    self.assertEqual(expected, actual)

    def test_write_list_in_memory(self):
        spack.config.update_config('repos', repos_low, 'test_low_priority')
        spack.config.update_config('repos', repos_high, 'test_high_priority')
        config = spack.config.get_config('repos')
        self.assertEqual(config, repos_high+repos_low)

    def test_write_key_in_memory(self):
        # Write b_comps "on top of" a_comps.
        spack.config.update_config('compilers', a_comps, 'test_low_priority')
        spack.config.update_config('compilers', b_comps, 'test_high_priority')

        # Make sure the config looks how we expect.
        self.check_config(a_comps, 'gcc@4.7.3', 'gcc@4.5.0')
        self.check_config(b_comps, 'icc@10.0', 'icc@11.1', 'clang@3.3')


    def test_write_key_to_disk(self):
        # Write b_comps "on top of" a_comps.
        spack.config.update_config('compilers', a_comps, 'test_low_priority')
        spack.config.update_config('compilers', b_comps, 'test_high_priority')

        # Clear caches so we're forced to read from disk.
        spack.config.clear_config_caches()

        # Same check again, to ensure consistency.
        self.check_config(a_comps, 'gcc@4.7.3', 'gcc@4.5.0')
        self.check_config(b_comps, 'icc@10.0', 'icc@11.1', 'clang@3.3')

    def test_write_to_same_priority_file(self):
        # Write b_comps in the same file as a_comps.
        spack.config.update_config('compilers', a_comps, 'test_low_priority')
        spack.config.update_config('compilers', b_comps, 'test_low_priority')

        # Clear caches so we're forced to read from disk.
        spack.config.clear_config_caches()

        # Same check again, to ensure consistency.
        self.check_config(a_comps, 'gcc@4.7.3', 'gcc@4.5.0')
        self.check_config(b_comps, 'icc@10.0', 'icc@11.1', 'clang@3.3')