Debian Codegraph @

testsuite/modules.30-cache/030-cachebuild.exp

raw
1 ##############################################################################
2 # Modules Revision 3.0
3 # Providing a flexible user environment
4 #
5 # File: modules.30-cache/%M%
6 # Revision: %I%
7 # First Edition: 2022/11/13
8 # Last Mod.: %U%, %G%
9 #
10 # Authors: Xavier Delaruelle, [email protected]
11 #
12 # Description: Testuite testsequence
13 # Command: cachebuild
14 # Modulefiles:
15 # Sub-Command:
16 #
17 # Comment: %C{
18 # Test cachebuild sub-command
19 # }C%
20 #
21 ##############################################################################
22
23 # filesystem on Cygwin platform is responding in an unexpected way
24 # skip these tests on this platform for now
25 skip_if_os_in cygwin
26
27 # no modulepath defined
28 unsetenv_path_var MODULEPATH
29 set tserr "$error_msgs: $msg_nomodpath"
30 testouterr_cmd sh cachebuild ERR $tserr
31
32 # empty modulepath
33 setenv_path_var MODULEPATH {}
34 testouterr_cmd sh cachebuild OK {}
35
36 # create modulepaths for tests
37 set mp1 $env(HOME)/mp1
38 set mp2 $env(HOME)/mp2
39 set mp1cache $mp1/.modulecache
40 set mp2cache $mp2/.modulecache
41 set mp1modfile $mp1/foo
42 set mp2modfile $mp2/bar
43 set mpunk $env(HOME)/mpunk
44 set mpfile $mp1/qux
45 file mkdir $mp1
46 file mkdir $mp2
47
48 # 2 modulepath set, cache to build in first, empty second
49 setenv_path_var MODULEPATH $mp1:$mp2
50 create_dummy_modulefile $mp1modfile
51 set tserr [msg_create $mp1cache]\n\n[msg_create $mp2cache $warn_cache_nothingtorec]
52 set tscache "#%Module$cache_mcookie_version"
53 append tscache \n[list modulefile-content foo [file mtime $mp1modfile] #%Module #%Module\n]
54 testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache
55 file delete $mp1modfile
56
57 # cache file already exist in first, empty second modulepath
58 create_dummy_modulefile $mp1modfile
59 create_dummy_cachefile $mp1
60 set tserr [msg_create $mp1cache]\n\n[msg_create $mp2cache $warn_cache_nothingtorec]
61 set tscache "#%Module$cache_mcookie_version"
62 append tscache \n[list modulefile-content foo [file mtime $mp1modfile] #%Module #%Module\n]
63 testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache
64 file delete $mp1modfile
65 file delete $mp1cache
66
67 file delete $mp1
68 file delete $mp2
69 skip_if_quick_mode
70 file mkdir $mp1
71 file mkdir $mp2
72 close [open $mpfile w]
73
74 # silent mode
75 create_dummy_modulefile $mp1modfile
76 set tscache "#%Module$cache_mcookie_version"
77 append tscache \n[list modulefile-content foo [file mtime $mp1modfile] #%Module #%Module\n]
78 append tscache \n[list modulefile-invalid qux invalid {Magic cookie '#%Module' missing}]
79 testouterrfile_cmd sh {cachebuild -s} OK {} $mp1cache $tscache
80
81 # verbose mode
82 set tserr [msg_create $mp1cache]\n\n[msg_create $mp2cache $warn_cache_nothingtorec]
83 testouterrfile_cmd sh {cachebuild -v} OK $tserr $mp1cache $tscache
84 file delete $mp1modfile
85 file delete $mp1cache
86
87 # unexistent modulepath, then cache to build in next path
88 create_dummy_modulefile $mp2modfile
89 setenv_path_var MODULEPATH $mpunk:$mp2
90 set tserr [msg_create $mpunk/.modulecache "$error_msgs: '$mpunk' is not a directory"]\n\n[msg_create $mp2cache]
91 set tscache "#%Module$cache_mcookie_version"
92 append tscache \n[list modulefile-content bar [file mtime $mp2modfile] #%Module #%Module\n]
93 testouterrfile_cmd sh cachebuild ERR $tserr $mp2cache $tscache
94
95 # modulepath is a file, then cache to build in next path
96 setenv_path_var MODULEPATH $mpfile:$mp2
97 set tserr [msg_create $mpfile/.modulecache "$error_msgs: '$mpfile' is not a directory"]\n\n[msg_create $mp2cache]
98 testouterrfile_cmd sh cachebuild ERR $tserr $mp2cache $tscache
99 file delete $mp2modfile
100 file delete $mp2cache
101
102 # unexistent and file modulepaths passed as argument
103 setenv_path_var MODULEPATH $mp1:$mp2
104 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"]
105 testouterr_cmd sh "cachebuild $mpunk $mpfile" ERR $tserr
106 file delete $mpfile
107
108 # empty string modulepath passed as argument
109 set tserr [msg_create /.modulecache "$error_msgs: '' is not a directory"]
110 testouterr_cmd sh "cachebuild " ERR $tserr
111
112
113 # cannot test access if cannot change file permission
114 if {!$is_file_perms_editable} {
115 send_user "\tskipping access tests as file permissions cannot be changed\n"
116 # cannot test access if superuser privileges are in use
117 } elseif {$tcl_platform(user) eq "root"} {
118 send_user "\tskipping access tests as tests are run by superuser\n"
119 # cannot test access if restricted file permissions have no effect
120 } elseif {$is_locked_dir_file_readable && $is_locked_file_readable} {
121 send_user "\tskipping access tests as locked files or directories are still readable\n"
122 } else {
123
124 set nowrite_perms ugo-w
125 set noread_perms ugo-r
126 set nosearch_perms ugo-x
127
128 # first modulepath not writable, no module content in it
129 setenv_path_var MODULEPATH $mp1:$mp2
130 change_file_perms $mp1 $nowrite_perms
131 create_dummy_modulefile $mp2modfile
132 set tserr [msg_create $mp1cache $warn_cache_build_nowritable]\n\n[msg_create $mp2cache]
133 set tscache "#%Module$cache_mcookie_version"
134 append tscache \n[list modulefile-content bar [file mtime $mp2modfile] #%Module #%Module\n]
135 testouterrfile_cmd sh cachebuild OK $tserr $mp2cache $tscache
136 set tscache [couldnotopen_nofile $mp1cache]
137 testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache
138 restore_file_perms $mp1
139 file delete $mp2modfile
140
141 # first modulepath not writable, module content in it
142 create_dummy_modulefile $mp1modfile
143 create_dummy_modulefile $mp2modfile
144 change_file_perms $mp1 $nowrite_perms
145 set tserr [msg_create $mp1cache $warn_cache_build_nowritable]\n\n[msg_create $mp2cache]
146 set tscache "#%Module$cache_mcookie_version"
147 append tscache \n[list modulefile-content bar [file mtime $mp2modfile] #%Module #%Module\n]
148 testouterrfile_cmd sh cachebuild OK $tserr $mp2cache $tscache
149 set tscache [couldnotopen_nofile $mp1cache]
150 testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache
151 restore_file_perms $mp1
152 file delete $mp1modfile
153 file delete $mp2modfile
154 file delete $mp2cache
155
156 # both modulepath not writable, module content in them
157 create_dummy_modulefile $mp1modfile
158 create_dummy_modulefile $mp2modfile
159 change_file_perms $mp1 $nowrite_perms
160 change_file_perms $mp2 $nowrite_perms
161 set tserr [msg_create $mp1cache $warn_cache_build_nowritable]\n\n[msg_create $mp2cache $warn_cache_build_nowritable]
162 set tscache [couldnotopen_nofile $mp2cache]
163 testouterrfile_cmd sh cachebuild OK $tserr $mp2cache $tscache
164 set tscache [couldnotopen_nofile $mp1cache]
165 testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache
166 restore_file_perms $mp1
167 restore_file_perms $mp2
168 file delete $mp1modfile
169 file delete $mp2modfile
170
171 # first modulepath not readable, second not searchable, module content in them
172 create_dummy_modulefile $mp1modfile
173 create_dummy_modulefile $mp2modfile
174 change_file_perms $mp1 $noread_perms
175 change_file_perms $mp2 $nosearch_perms
176 set tserr [msg_create $mp1cache $warn_cache_nothingtorec]\n\n[msg_create $mp2cache [err_couldnotopen_permdenied $mp2cache]]
177 set tscache [couldnotopen_permdenied $mp2cache]
178 testouterrfile_cmd sh cachebuild ERR $tserr $mp2cache $tscache
179 set tscache [couldnotopen_nofile $mp1cache]
180 testouterrfile_cmd sh cachebuild ERR $tserr $mp1cache $tscache
181 restore_file_perms $mp1
182 restore_file_perms $mp2
183 file delete $mp1modfile
184 file delete $mp2modfile
185
186 # modulepath writable, no module content in first path
187 create_dummy_modulefile $mp2modfile
188 set tserr [msg_create $mp1cache $warn_cache_nothingtorec]\n\n[msg_create $mp2cache]
189 set tscache [couldnotopen_nofile $mp1cache]
190 testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache
191 file delete $mp2modfile
192
193 # modulepath writable, pre-existing cache files: not readable in first, not writable in second
194 create_dummy_modulefile $mp1modfile
195 create_dummy_modulefile $mp2modfile
196 create_dummy_cachefile $mp1
197 create_dummy_cachefile $mp2
198 change_file_perms $mp1cache $noread_perms
199 change_file_perms $mp2cache $nowrite_perms
200 set tserr [msg_create $mp1cache]\n\n[msg_create $mp2cache [err_couldnotopen_permdenied $mp2cache]]
201 set tscache [couldnotopen_permdenied $mp1cache]
202 testouterrfile_cmd sh cachebuild ERR $tserr $mp1cache $tscache
203 set tscache "#%Module$cache_mcookie_version"
204 testouterrfile_cmd sh cachebuild ERR $tserr $mp2cache $tscache
205 file delete $mp1modfile
206 file delete $mp2modfile
207 file delete $mp1cache
208 file delete $mp2cache
209
210 # modulepath writable passed as argument, pre-existing cache files: not readable in first, not writable in second
211 setenv_path_var MODULEPATH $mpunk
212 create_dummy_modulefile $mp1modfile
213 create_dummy_modulefile $mp2modfile
214 create_dummy_cachefile $mp1
215 create_dummy_cachefile $mp2
216 change_file_perms $mp1cache $noread_perms
217 change_file_perms $mp2cache $nowrite_perms
218 set tserr [msg_create $mp1cache]\n\n[msg_create $mp2cache [err_couldnotopen_permdenied $mp2cache]]
219 set tscache [couldnotopen_permdenied $mp1cache]
220 testouterrfile_cmd sh "cachebuild $mp1 $mp2" ERR $tserr $mp1cache $tscache
221 set tscache "#%Module$cache_mcookie_version"
222 set tserr [msg_create $mp2cache [err_couldnotopen_permdenied $mp2cache]]\n\n[msg_create $mp1cache]
223 testouterrfile_cmd sh "cachebuild $mp2 $mp1" ERR $tserr $mp2cache $tscache
224 file delete $mp1modfile
225 file delete $mp2modfile
226 file delete $mp1cache
227 file delete $mp2cache
228 setenv_path_var MODULEPATH $mp1:$mp2
229
230 # check expected siteconfig file is installed
231 set is_stderr_tty [siteconfig_isStderrTty]
232 if {$is_stderr_tty} {
233 # test a file creation failure by faking modulepath directory is writable
234 setenv_var TESTSUITE_ENABLE_SITECONFIG_CACHEBUILD_CREATE 1
235 create_dummy_modulefile $mp1modfile
236 create_dummy_modulefile $mp2modfile
237 change_file_perms $mp1 $nowrite_perms
238 set tserr [msg_create $mp1cache [err_couldnotopen_permdenied $mp1cache]]\n\n[msg_create $mp2cache]
239 set tscache "#%Module$cache_mcookie_version"
240 append tscache \n[list modulefile-content bar [file mtime $mp2modfile] #%Module #%Module\n]
241 testouterrfile_cmd sh cachebuild ERR $tserr $mp2cache $tscache
242 set tscache [couldnotopen_nofile $mp1cache]
243 testouterrfile_cmd sh cachebuild ERR $tserr $mp1cache $tscache
244 restore_file_perms $mp1
245 file delete $mp1modfile
246 file delete $mp2modfile
247 file delete $mp2cache
248 unsetenv_var TESTSUITE_ENABLE_SITECONFIG_CACHEBUILD_CREATE
249 }
250
251 }
252
253
254 #
255 # Cleanup
256 #
257
258 file delete $mp1
259 file delete $mp2
260
261 reset_test_env