File: 031-cachebuild-full.exp

package info (click to toggle)
modules 5.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,036 kB
  • sloc: exp: 79,659; sh: 6,142; tcl: 5,900; makefile: 1,493; ansic: 474; python: 265; csh: 202; perl: 47; ruby: 44; lisp: 13
file content (273 lines) | stat: -rw-r--r-- 9,220 bytes parent folder | download
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.30-cache/%M%
#   Revision:		%I%
#   First Edition:	2022/11/20
#   Last Mod.:		%U%, %G%
#
#   Authors:		Xavier Delaruelle, xavier.delaruelle@cea.fr
#
#   Description:	Testuite testsequence
#   Command:		cachebuild
#   Modulefiles:
#   Sub-Command:
#
#   Comment:	%C{
#           Test cachebuild sub-command with fully recorded content
#		}C%
#
##############################################################################

# filesystem on Cygwin platform is responding in an unexpected way
# skip these tests on this platform for now
skip_if_os_in cygwin

skip_if_quick_mode

# ensure avail tests are made using in depth mode
setenv_var MODULES_AVAIL_INDEPTH 1

# create modulefile/modulerc complex setup
lassign [create_diverse_module_setup $mp1] dir_list file_list
array set file_arr $file_list

# expected cache file
set tscache "#%Module$cache_mcookie_version"
foreach f [lsort [array names file_arr]] {
    set entry {}
    switch -- $f {
        .git/ignmod - quux/SCCS/ignmod - {w s/1.0~} -\
        foo/1.0,v - quxc/1.0~ - .svn/ignmod - .sos/ignmod {}
        foo/1.0 {
            set entry [list modulefile-invalid $f invalid {Magic cookie '#%Module' missing}]
        }
        foo/3.0 - quux/nok/5.0 {
            set entry [list modulefile-invalid $f invalid {Modulefile requires at least Modules version 99}]
        }
        default {
            switch -- $f {
                foo/.modulerc {set header {}}
                foo/4.0 - quxc/.modulerc {set header {#%Module5.2}}
                quxb/.modulerc {set header {#%Module99}}
                default {set header {#%Module}}
            }

            if {[file tail $f] in {.modulerc .version}} {
                set entry [list modulerc-content $f $header $file_arr($f)]
            } else {
                set mtime [file mtime $mp1/$f]
                set entry [list modulefile-content $f $mtime $header $file_arr($f)]
            }
        }
    }
    if {[string length $entry]} {
        append tscache "\n$entry"
    }
}


setenv_path_var MODULEPATH $mp1

# make cache on built modulepath
set tserr [msg_create $mp1cache]
testouterrfile_cmd sh "cachebuild $mp1" OK $tserr $mp1cache $tscache

# build a second time, should get exact same cache file
testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache

# build when an empty cachefile pre-exist
file delete $mp1cache
create_dummy_cachefile $mp1
testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache


# .modulecache should be ignored from avail results
set tserr {}
foreach f [lsort [array names file_arr]] {
    switch -glob -- $f {
        .git/ignmod - quux/SCCS/ignmod - {w s/1.0~} -\
        foo/1.0,v - quxc/1.0~ - .svn/ignmod - .sos/ignmod {}
        */.modulerc - */.version - foo/1.0 - foo/3.0 - quux/nok/5.0 {}
        {* *}   {lappend tserr '$f'}
        default {lappend tserr $f}
    }
}
set tserr [join $tserr \n]
testouterr_cmd sh {avail -a -t -o } OK $tserr

# delete generated cache file
file delete $mp1cache


# test cache generation when mcookie_check is set to eval (should not change
# cache content)
setenv_path_var MODULEPATH $mp1
setenv_var MODULES_MCOOKIE_CHECK eval
set tserr [msg_create $mp1cache]
testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache
setenv_var MODULES_MCOOKIE_CHECK always
file delete $mp1cache

# test cache generation when mcookie_version_check is disabled (should not
# change cache content)
setenv_path_var MODULEPATH $mp1
setenv_var MODULES_MCOOKIE_VERSION_CHECK 0
set tserr [msg_create $mp1cache]
testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache
setenv_var MODULES_MCOOKIE_VERSION_CHECK 1
file delete $mp1cache


# generate simpler setup
lassign [create_simple_module_setup $mp2] other_dir_list other_file_list
array set other_file_arr $other_file_list


# cannot test access if cannot change file permission
if {!$is_file_perms_editable} {
    send_user "\tskipping access tests as file permissions cannot be changed\n"
# cannot test access if superuser privileges are in use
} elseif {$tcl_platform(user) eq "root"} {
    send_user "\tskipping access tests as tests are run by superuser\n"
# cannot test access if restricted file permissions have no effect
} elseif {$is_locked_dir_file_readable && $is_locked_file_readable} {
    send_user "\tskipping access tests as locked files or directories are still readable\n"
} else {

set noread_perms ugo-r

setenv_path_var MODULEPATH $mp2:$mp1

# one modulefile not readable
change_file_perms $mp2/bar/1.0 $noread_perms
set tserr [msg_create $mp2cache]\n[msg_create $mp1cache]
set tscache "#%Module$cache_mcookie_version"
foreach f [lsort [array names other_file_arr]] {
    switch -- $f {
        bar/1.0 {
            set entry [list limited-access-file $f]
        }
        default {
            if {[file tail $f] in {.modulerc .version}} {
                set entry [list modulerc-content $f {#%Module} $other_file_arr($f)]
            } else {
                set mtime [file mtime $mp2/$f]
                set entry [list modulefile-content $f $mtime {#%Module} $other_file_arr($f)]
            }
        }
    }
    append tscache "\n$entry"
}
testouterrfile_cmd sh cachebuild OK $tserr $mp2cache $tscache
restore_file_perms $mp2/bar/1.0

# one modulerc not readable
change_file_perms $mp2/foo/.modulerc $noread_perms
set tserr [msg_create $mp2cache]\n[msg_create $mp1cache]
set tscache "#%Module$cache_mcookie_version"
foreach f [lsort [array names other_file_arr]] {
    set entry {}
    switch -- $f {
        foo/.modulerc {
            set entry [list limited-access-file $f]
        }
        default {
            if {[file tail $f] in {.modulerc .version}} {
                set entry [list modulerc-content $f {#%Module} $other_file_arr($f)]
            } else {
                set mtime [file mtime $mp2/$f]
                set entry [list modulefile-content $f $mtime {#%Module} $other_file_arr($f)]
            }
        }
    }
    if {[string length $entry]} {
        append tscache "\n$entry"
    }
}
testouterrfile_cmd sh cachebuild OK $tserr $mp2cache $tscache
restore_file_perms $mp2/foo/.modulerc

# one directory not readable
change_file_perms $mp2/foo $noread_perms
set tserr [msg_create $mp2cache]\n[msg_create $mp1cache]
set tscache "#%Module$cache_mcookie_version"
foreach f [lsort [array names other_file_arr]] {
    set entry {}
    switch -- $f {
        foo/.modulerc - foo/1.0 {}
        default {
            if {[file tail $f] in {.modulerc .version}} {
                set entry [list modulerc-content $f {#%Module} $other_file_arr($f)]
            } else {
                set mtime [file mtime $mp2/$f]
                set entry [list modulefile-content $f $mtime {#%Module} $other_file_arr($f)]
            }
        }
    }
    if {[string length $entry]} {
        append tscache "\n$entry"
    }
}
set entry [list limited-access-directory foo]
append tscache "\n$entry"
testouterrfile_cmd sh cachebuild OK $tserr $mp2cache $tscache
restore_file_perms $mp2/foo

# access ok, but read fails
# check expected siteconfig file is installed
set is_stderr_tty [siteconfig_isStderrTty]
if {$is_stderr_tty} {

    # test a modulefile read failure during cache build by faking modulefile is readable
    setenv_var TESTSUITE_ENABLE_SITECONFIG_CACHEBUILD_READ1 1
    set tserr [msg_create $mp2cache]\n[msg_create $mp1cache]
    set tscache "#%Module$cache_mcookie_version"
    foreach f [lsort [array names other_file_arr]] {
        set entry {}
        switch -- $f {
            bar/1.0 {
                set entry [list modulefile-invalid $f accesserr "No such file or directory on '$mp2/bar/1.0'"]
            }
            default {
                if {[file tail $f] in {.modulerc .version}} {
                    set entry [list modulerc-content $f {#%Module} $other_file_arr($f)]
                } else {
                    set mtime [file mtime $mp2/$f]
                    set entry [list modulefile-content $f $mtime {#%Module} $other_file_arr($f)]
                }
            }
        }
        if {[string length $entry]} {
            append tscache "\n$entry"
        }
    }
    testouterrfile_cmd sh cachebuild OK $tserr $mp2cache $tscache
    unsetenv_var TESTSUITE_ENABLE_SITECONFIG_CACHEBUILD_READ1

    # test a modulerc read failure during cache build by faking modulerc is readable
    file delete $mp2cache
    setenv_var TESTSUITE_ENABLE_SITECONFIG_CACHEBUILD_READ2 1
    set tserr [msg_create $mp2cache "$error_msgs: No such file or directory on '$mp2/foo/.modulerc'"]\n\n[msg_create $mp1cache "$error_msgs: No such file or directory on '$mp1/foo/.modulerc'"]
    set tscache [couldnotopen_nofile $mp2cache]
    testouterrfile_cmd sh {cachebuild} ERR $tserr $mp2cache $tscache
    unsetenv_var TESTSUITE_ENABLE_SITECONFIG_CACHEBUILD_READ2
}

# delete generated cache files
file delete $mp1cache
file delete $mp2cache

}


#
#  Cleanup
#

# delete created files and dirs
delete_module_setup $mp1 [array names file_arr] $dir_list
delete_module_setup $mp2 [array names other_file_arr] $other_dir_list

reset_test_env