File: 030-cachebuild.exp

package info (click to toggle)
modules 5.6.1-1
  • 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,492; ansic: 474; python: 265; csh: 202; perl: 47; ruby: 44; lisp: 13
file content (261 lines) | stat: -rw-r--r-- 10,216 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
##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.30-cache/%M%
#   Revision:		%I%
#   First Edition:	2022/11/13
#   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
#		}C%
#
##############################################################################

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

# no modulepath defined
unsetenv_path_var MODULEPATH
set tserr "$error_msgs: $msg_nomodpath"
testouterr_cmd sh cachebuild ERR $tserr

# empty modulepath
setenv_path_var MODULEPATH {}
testouterr_cmd sh cachebuild OK {}

# create modulepaths for tests
set mp1 $env(HOME)/mp1
set mp2 $env(HOME)/mp2
set mp1cache $mp1/.modulecache
set mp2cache $mp2/.modulecache
set mp1modfile $mp1/foo
set mp2modfile $mp2/bar
set mpunk $env(HOME)/mpunk
set mpfile $mp1/qux
file mkdir $mp1
file mkdir $mp2

# 2 modulepath set, cache to build in first, empty second
setenv_path_var MODULEPATH $mp1:$mp2
create_dummy_modulefile $mp1modfile
set tserr [msg_create $mp1cache]\n\n[msg_create $mp2cache $warn_cache_nothingtorec]
set tscache "#%Module$cache_mcookie_version"
append tscache \n[list modulefile-content foo [file mtime $mp1modfile] #%Module #%Module\n]
testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache
file delete $mp1modfile

# cache file already exist in first, empty second modulepath
create_dummy_modulefile $mp1modfile
create_dummy_cachefile $mp1
set tserr [msg_create $mp1cache]\n\n[msg_create $mp2cache $warn_cache_nothingtorec]
set tscache "#%Module$cache_mcookie_version"
append tscache \n[list modulefile-content foo [file mtime $mp1modfile] #%Module #%Module\n]
testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache
file delete $mp1modfile
file delete $mp1cache

file delete $mp1
file delete $mp2
skip_if_quick_mode
file mkdir $mp1
file mkdir $mp2
close [open $mpfile w]

# silent mode
create_dummy_modulefile $mp1modfile
set tscache "#%Module$cache_mcookie_version"
append tscache \n[list modulefile-content foo [file mtime $mp1modfile] #%Module #%Module\n]
append tscache \n[list modulefile-invalid qux invalid {Magic cookie '#%Module' missing}]
testouterrfile_cmd sh {cachebuild -s} OK {} $mp1cache $tscache

# verbose mode
set tserr [msg_create $mp1cache]\n\n[msg_create $mp2cache $warn_cache_nothingtorec]
testouterrfile_cmd sh {cachebuild -v} OK $tserr $mp1cache $tscache
file delete $mp1modfile
file delete $mp1cache

# unexistent modulepath, then cache to build in next path
create_dummy_modulefile $mp2modfile
setenv_path_var MODULEPATH $mpunk:$mp2
set tserr [msg_create $mpunk/.modulecache "$error_msgs: '$mpunk' is not a directory"]\n\n[msg_create $mp2cache]
set tscache "#%Module$cache_mcookie_version"
append tscache \n[list modulefile-content bar [file mtime $mp2modfile] #%Module #%Module\n]
testouterrfile_cmd sh cachebuild ERR $tserr $mp2cache $tscache

# modulepath is a file, then cache to build in next path
setenv_path_var MODULEPATH $mpfile:$mp2
set tserr [msg_create $mpfile/.modulecache "$error_msgs: '$mpfile' is not a directory"]\n\n[msg_create $mp2cache]
testouterrfile_cmd sh cachebuild ERR $tserr $mp2cache $tscache
file delete $mp2modfile
file delete $mp2cache

# unexistent and file modulepaths passed as argument
setenv_path_var MODULEPATH $mp1:$mp2
set tserr [msg_create $mpunk/.modulecache "$error_msgs: '$mpunk' is not a directory"]\n\n[msg_create $mpfile/.modulecache "$error_msgs: '$mpfile' is not a directory"]
testouterr_cmd sh "cachebuild $mpunk $mpfile" ERR $tserr
file delete $mpfile

# empty string modulepath passed as argument
set tserr [msg_create /.modulecache "$error_msgs: '' is not a directory"]
testouterr_cmd sh "cachebuild " ERR $tserr


# 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 nowrite_perms ugo-w
set noread_perms ugo-r
set nosearch_perms ugo-x

# first modulepath not writable, no module content in it
setenv_path_var MODULEPATH $mp1:$mp2
change_file_perms $mp1 $nowrite_perms
create_dummy_modulefile $mp2modfile
set tserr [msg_create $mp1cache $warn_cache_build_nowritable]\n\n[msg_create $mp2cache]
set tscache "#%Module$cache_mcookie_version"
append tscache \n[list modulefile-content bar [file mtime $mp2modfile] #%Module #%Module\n]
testouterrfile_cmd sh cachebuild OK $tserr $mp2cache $tscache
set tscache [couldnotopen_nofile $mp1cache]
testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache
restore_file_perms $mp1
file delete $mp2modfile

# first modulepath not writable, module content in it
create_dummy_modulefile $mp1modfile
create_dummy_modulefile $mp2modfile
change_file_perms $mp1 $nowrite_perms
set tserr [msg_create $mp1cache $warn_cache_build_nowritable]\n\n[msg_create $mp2cache]
set tscache "#%Module$cache_mcookie_version"
append tscache \n[list modulefile-content bar [file mtime $mp2modfile] #%Module #%Module\n]
testouterrfile_cmd sh cachebuild OK $tserr $mp2cache $tscache
set tscache [couldnotopen_nofile $mp1cache]
testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache
restore_file_perms $mp1
file delete $mp1modfile
file delete $mp2modfile
file delete $mp2cache

# both modulepath not writable, module content in them
create_dummy_modulefile $mp1modfile
create_dummy_modulefile $mp2modfile
change_file_perms $mp1 $nowrite_perms
change_file_perms $mp2 $nowrite_perms
set tserr [msg_create $mp1cache $warn_cache_build_nowritable]\n\n[msg_create $mp2cache $warn_cache_build_nowritable]
set tscache [couldnotopen_nofile $mp2cache]
testouterrfile_cmd sh cachebuild OK $tserr $mp2cache $tscache
set tscache [couldnotopen_nofile $mp1cache]
testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache
restore_file_perms $mp1
restore_file_perms $mp2
file delete $mp1modfile
file delete $mp2modfile

# first modulepath not readable, second not searchable, module content in them
create_dummy_modulefile $mp1modfile
create_dummy_modulefile $mp2modfile
change_file_perms $mp1 $noread_perms
change_file_perms $mp2 $nosearch_perms
set tserr [msg_create $mp1cache $warn_cache_nothingtorec]\n\n[msg_create $mp2cache [err_couldnotopen_permdenied $mp2cache]]
set tscache [couldnotopen_permdenied $mp2cache]
testouterrfile_cmd sh cachebuild ERR $tserr $mp2cache $tscache
set tscache [couldnotopen_nofile $mp1cache]
testouterrfile_cmd sh cachebuild ERR $tserr $mp1cache $tscache
restore_file_perms $mp1
restore_file_perms $mp2
file delete $mp1modfile
file delete $mp2modfile

# modulepath writable, no module content in first path
create_dummy_modulefile $mp2modfile
set tserr [msg_create $mp1cache $warn_cache_nothingtorec]\n\n[msg_create $mp2cache]
set tscache [couldnotopen_nofile $mp1cache]
testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache
file delete $mp2modfile

# modulepath writable, pre-existing cache files: not readable in first, not writable in second
create_dummy_modulefile $mp1modfile
create_dummy_modulefile $mp2modfile
create_dummy_cachefile $mp1
create_dummy_cachefile $mp2
change_file_perms $mp1cache $noread_perms
change_file_perms $mp2cache $nowrite_perms
set tserr [msg_create $mp1cache]\n\n[msg_create $mp2cache [err_couldnotopen_permdenied $mp2cache]]
set tscache [couldnotopen_permdenied $mp1cache]
testouterrfile_cmd sh cachebuild ERR $tserr $mp1cache $tscache
set tscache "#%Module$cache_mcookie_version"
testouterrfile_cmd sh cachebuild ERR $tserr $mp2cache $tscache
file delete $mp1modfile
file delete $mp2modfile
file delete $mp1cache
file delete $mp2cache

# modulepath writable passed as argument, pre-existing cache files: not readable in first, not writable in second
setenv_path_var MODULEPATH $mpunk
create_dummy_modulefile $mp1modfile
create_dummy_modulefile $mp2modfile
create_dummy_cachefile $mp1
create_dummy_cachefile $mp2
change_file_perms $mp1cache $noread_perms
change_file_perms $mp2cache $nowrite_perms
set tserr [msg_create $mp1cache]\n\n[msg_create $mp2cache [err_couldnotopen_permdenied $mp2cache]]
set tscache [couldnotopen_permdenied $mp1cache]
testouterrfile_cmd sh "cachebuild $mp1 $mp2" ERR $tserr $mp1cache $tscache
set tscache "#%Module$cache_mcookie_version"
set tserr [msg_create $mp2cache [err_couldnotopen_permdenied $mp2cache]]\n\n[msg_create $mp1cache]
testouterrfile_cmd sh "cachebuild $mp2 $mp1" ERR $tserr $mp2cache $tscache
file delete $mp1modfile
file delete $mp2modfile
file delete $mp1cache
file delete $mp2cache
setenv_path_var MODULEPATH $mp1:$mp2

# check expected siteconfig file is installed
set is_stderr_tty [siteconfig_isStderrTty]
if {$is_stderr_tty} {
    # test a file creation failure by faking modulepath directory is writable
    setenv_var TESTSUITE_ENABLE_SITECONFIG_CACHEBUILD_CREATE 1
    create_dummy_modulefile $mp1modfile
    create_dummy_modulefile $mp2modfile
    change_file_perms $mp1 $nowrite_perms
    set tserr [msg_create $mp1cache [err_couldnotopen_permdenied $mp1cache]]\n\n[msg_create $mp2cache]
    set tscache "#%Module$cache_mcookie_version"
    append tscache \n[list modulefile-content bar [file mtime $mp2modfile] #%Module #%Module\n]
    testouterrfile_cmd sh cachebuild ERR $tserr $mp2cache $tscache
    set tscache [couldnotopen_nofile $mp1cache]
    testouterrfile_cmd sh cachebuild ERR $tserr $mp1cache $tscache
    restore_file_perms $mp1
    file delete $mp1modfile
    file delete $mp2modfile
    file delete $mp2cache
    unsetenv_var TESTSUITE_ENABLE_SITECONFIG_CACHEBUILD_CREATE
}

}


#
#  Cleanup
#

file delete $mp1
file delete $mp2

reset_test_env