| 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: 2026/08/19 |
| 8 |
# Last Mod.: %U%, %G% |
| 9 |
# |
| 10 |
# Authors: Xavier Delaruelle, [email protected] |
| 11 |
# |
| 12 |
# Description: Testuite testsequence |
| 13 |
# Command: cachebuild, avail, load |
| 14 |
# Modulefiles: |
| 15 |
# Sub-Command: |
| 16 |
# |
| 17 |
# Comment: %C{ |
| 18 |
# Check modulepath elements matching modulepath-ignore patterns |
| 19 |
# are excluded from built cache file |
| 20 |
# }C% |
| 21 |
# |
| 22 |
############################################################################## |
| 23 |
|
| 24 |
# filesystem on Cygwin platform is responding in an unexpected way |
| 25 |
# skip these tests on this platform for now |
| 26 |
skip_if_os_in cygwin |
| 27 |
|
| 28 |
# ensure avail tests are made using in depth mode |
| 29 |
setenv_var MODULES_AVAIL_INDEPTH 1 |
| 30 |
|
| 31 |
# ensure avail tests have implicit default enabled |
| 32 |
setenv_var MODULES_IMPLICIT_DEFAULT 1 |
| 33 |
|
| 34 |
# ensure auto symbolic versions are set for these tests |
| 35 |
setenv_var MODULES_ADVANCED_VERSION_SPEC 1 |
| 36 |
|
| 37 |
# create modulepath for tests |
| 38 |
set mp1 $env(HOME)/mpigncache1 |
| 39 |
set mp1cache $mp1/.modulecache |
| 40 |
set mfcontent "#%Module\nmodule-whatis \[module-info name\]" |
| 41 |
|
| 42 |
file mkdir $mp1/foo $mp1/bar $mp1/helper |
| 43 |
set mp1rc_content "#%Module\nmodulepath-ignore *.tcl helper/" |
| 44 |
set fid [open $mp1/.modulerc w] |
| 45 |
puts -nonewline $fid $mp1rc_content |
| 46 |
close $fid |
| 47 |
set barrc_content "#%Module\nmodulepath-ignore 2*" |
| 48 |
set fid [open $mp1/bar/.modulerc w] |
| 49 |
puts -nonewline $fid $barrc_content |
| 50 |
close $fid |
| 51 |
foreach f [list foo/1.0 bar/1.0 bar/2.0] { |
| 52 |
set fid [open $mp1/$f w] |
| 53 |
puts -nonewline $fid $mfcontent |
| 54 |
close $fid |
| 55 |
} |
| 56 |
set fid [open $mp1/foo/lib.tcl w] |
| 57 |
puts -nonewline $fid "proc helperproc {} {}" |
| 58 |
close $fid |
| 59 |
set fid [open $mp1/helper/util w] |
| 60 |
puts -nonewline $fid "not a modulefile" |
| 61 |
close $fid |
| 62 |
|
| 63 |
setenv_path_var MODULEPATH $mp1 |
| 64 |
|
| 65 |
# ignored elements are excluded from built cache file |
| 66 |
set tserr [msg_create $mp1cache] |
| 67 |
set tscache "#%Module$cache_mcookie_version" |
| 68 |
append tscache \n[list modulerc-content .modulerc #%Module $mp1rc_content] |
| 69 |
append tscache \n[list modulerc-content bar/.modulerc #%Module\ |
| 70 |
$barrc_content] |
| 71 |
append tscache \n[list modulefile-content bar/1.0 [file mtime $mp1/bar/1.0]\ |
| 72 |
#%Module $mfcontent] |
| 73 |
append tscache \n[list modulefile-content foo/1.0 [file mtime $mp1/foo/1.0]\ |
| 74 |
#%Module $mfcontent] |
| 75 |
testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache |
| 76 |
|
| 77 |
# same search result whether cache file is used or not |
| 78 |
set tserr "bar/1.0 |
| 79 |
foo/1.0" |
| 80 |
testouterr_cmd sh {avail -a -t -o } OK $tserr |
| 81 |
setenv_var MODULES_IGNORE_CACHE 1 |
| 82 |
testouterr_cmd sh {avail -a -t -o } OK $tserr |
| 83 |
unsetenv_var MODULES_IGNORE_CACHE |
| 84 |
|
| 85 |
# same not found error whether cache file is used or not |
| 86 |
testouterr_cmd sh {load bar/2.0} ERR $err_path'bar/2.0' |
| 87 |
setenv_var MODULES_IGNORE_CACHE 1 |
| 88 |
testouterr_cmd sh {load bar/2.0} ERR $err_path'bar/2.0' |
| 89 |
unsetenv_var MODULES_IGNORE_CACHE |
| 90 |
|
| 91 |
# ignored elements are excluded from cache file at build time: disabling |
| 92 |
# modulepath_ignore option does not get them back when cache file is used, |
| 93 |
# cache file also needs to be ignored to fetch them from disk |
| 94 |
set tserr "bar/1.0 |
| 95 |
foo/1.0" |
| 96 |
testouterr_cmd sh {--no-modulepath-ignore avail -a -t -o } OK $tserr |
| 97 |
set tserr "bar/1.0 |
| 98 |
bar/2.0 |
| 99 |
foo/1.0" |
| 100 |
testouterr_cmd sh {--no-modulepath-ignore --ignore-cache avail -a -t -o }\ |
| 101 |
OK $tserr |
| 102 |
testouterr_cmd sh {--no-modulepath-ignore is-avail bar/2.0} ERR {} |
| 103 |
testouterr_cmd sh {--no-modulepath-ignore --ignore-cache is-avail bar/2.0}\ |
| 104 |
OK {} |
| 105 |
|
| 106 |
file delete $mp1cache |
| 107 |
|
| 108 |
skip_if_quick_mode $mp1 |
| 109 |
|
| 110 |
# every element is recorded in cache when modulepath_ignore is disabled |
| 111 |
setenv_var MODULES_MODULEPATH_IGNORE 0 |
| 112 |
set tserr [msg_create $mp1cache] |
| 113 |
set tscache "#%Module$cache_mcookie_version" |
| 114 |
append tscache \n[list modulerc-content .modulerc #%Module $mp1rc_content] |
| 115 |
append tscache \n[list modulerc-content bar/.modulerc #%Module\ |
| 116 |
$barrc_content] |
| 117 |
append tscache \n[list modulefile-content bar/1.0 [file mtime $mp1/bar/1.0]\ |
| 118 |
#%Module $mfcontent] |
| 119 |
append tscache \n[list modulefile-content bar/2.0 [file mtime $mp1/bar/2.0]\ |
| 120 |
#%Module $mfcontent] |
| 121 |
append tscache \n[list modulefile-content foo/1.0 [file mtime $mp1/foo/1.0]\ |
| 122 |
#%Module $mfcontent] |
| 123 |
append tscache \n[list modulefile-invalid foo/lib.tcl invalid {Magic cookie\ |
| 124 |
'#%Module' missing}] |
| 125 |
append tscache \n[list modulefile-invalid helper/util invalid {Magic cookie\ |
| 126 |
'#%Module' missing}] |
| 127 |
testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache |
| 128 |
unsetenv_var MODULES_MODULEPATH_IGNORE |
| 129 |
file delete $mp1cache |
| 130 |
|
| 131 |
|
| 132 |
# |
| 133 |
# Limited access elements |
| 134 |
# |
| 135 |
|
| 136 |
# cannot test access if cannot change file permission |
| 137 |
if {!$is_file_perms_editable} { |
| 138 |
send_user "\tskipping access tests as file permissions cannot be\ |
| 139 |
changed\n" |
| 140 |
# cannot test access if superuser privileges are in use |
| 141 |
} elseif {$tcl_platform(user) eq "root"} { |
| 142 |
send_user "\tskipping access tests as tests are run by superuser\n" |
| 143 |
# cannot test access if restricted file permissions have no effect |
| 144 |
} elseif {$is_locked_dir_file_readable && $is_locked_file_readable} { |
| 145 |
send_user "\tskipping access tests as locked files or directories are\ |
| 146 |
still readable\n" |
| 147 |
} else { |
| 148 |
|
| 149 |
file mkdir $mp1/bar/sub |
| 150 |
foreach f [list bar/sub/1.0 bar/sub/2.5 foo/norm] { |
| 151 |
set fid [open $mp1/$f w] |
| 152 |
puts -nonewline $fid $mfcontent |
| 153 |
close $fid |
| 154 |
} |
| 155 |
set fid [open $mp1/foo/priv.tcl w] |
| 156 |
puts -nonewline $fid "proc anotherproc {} {}" |
| 157 |
close $fid |
| 158 |
|
| 159 |
change_file_perms $mp1/bar/sub o-rx |
| 160 |
change_file_perms $mp1/foo/priv.tcl o-r |
| 161 |
change_file_perms $mp1/foo/norm o-r |
| 162 |
change_file_perms $mp1/helper o-rx |
| 163 |
|
| 164 |
# ignored elements with limited access (foo/priv.tcl and helper) are not |
| 165 |
# recorded in cache file, limited access elements not ignored (bar/sub and |
| 166 |
# foo/norm) are recorded |
| 167 |
set tserr [msg_create $mp1cache] |
| 168 |
set tscache "#%Module$cache_mcookie_version" |
| 169 |
append tscache \n[list modulerc-content .modulerc #%Module $mp1rc_content] |
| 170 |
append tscache \n[list modulerc-content bar/.modulerc #%Module\ |
| 171 |
$barrc_content] |
| 172 |
append tscache \n[list modulefile-content bar/1.0 [file mtime $mp1/bar/1.0]\ |
| 173 |
#%Module $mfcontent] |
| 174 |
append tscache \n[list limited-access-directory bar/sub] |
| 175 |
append tscache \n[list modulefile-content foo/1.0 [file mtime $mp1/foo/1.0]\ |
| 176 |
#%Module $mfcontent] |
| 177 |
append tscache \n[list limited-access-file foo/norm] |
| 178 |
testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache |
| 179 |
|
| 180 |
# patterns from rc files recorded in cache apply when walking down limited |
| 181 |
# access directories on cache use: bar/sub/2.5 matches the pattern defined |
| 182 |
# in bar/.modulerc, which is not walked through as it is readable |
| 183 |
set tserr "bar/1.0 |
| 184 |
bar/sub/1.0 |
| 185 |
foo/1.0 |
| 186 |
foo/norm" |
| 187 |
testouterr_cmd sh {avail -a -t -o } OK $tserr |
| 188 |
setenv_var MODULES_IGNORE_CACHE 1 |
| 189 |
testouterr_cmd sh {avail -a -t -o } OK $tserr |
| 190 |
unsetenv_var MODULES_IGNORE_CACHE |
| 191 |
|
| 192 |
# same not found error whether cache file is used or not |
| 193 |
testouterr_cmd sh {load bar/sub/2.5} ERR $err_path'bar/sub/2.5' |
| 194 |
setenv_var MODULES_IGNORE_CACHE 1 |
| 195 |
testouterr_cmd sh {load bar/sub/2.5} ERR $err_path'bar/sub/2.5' |
| 196 |
unsetenv_var MODULES_IGNORE_CACHE |
| 197 |
|
| 198 |
file delete $mp1cache |
| 199 |
restore_file_perms $mp1/bar/sub |
| 200 |
restore_file_perms $mp1/foo/priv.tcl |
| 201 |
restore_file_perms $mp1/foo/norm |
| 202 |
restore_file_perms $mp1/helper |
| 203 |
|
| 204 |
# rc files are exempt from ignore pattern check: a limited access rc file |
| 205 |
# matching a pattern (like '*' here) is still recorded as a limited access |
| 206 |
# entry, which keeps its content out of the cache file rather than having |
| 207 |
# it plainly recorded there despite its restricted access |
| 208 |
set mp2 $env(HOME)/mpigncache2 |
| 209 |
set mp2cache $mp2/.modulecache |
| 210 |
file mkdir $mp2/app |
| 211 |
set mp2rc_content "#%Module\nmodulepath-ignore * !*/ !*.mod" |
| 212 |
set fid [open $mp2/.modulerc w] |
| 213 |
puts -nonewline $fid $mp2rc_content |
| 214 |
close $fid |
| 215 |
set fid [open $mp2/app/.modulerc w] |
| 216 |
puts -nonewline $fid "#%Module\nmodule-version app/1.0.mod stable" |
| 217 |
close $fid |
| 218 |
foreach f [list app/1.0.mod app/2.0] { |
| 219 |
set fid [open $mp2/$f w] |
| 220 |
puts -nonewline $fid $mfcontent |
| 221 |
close $fid |
| 222 |
} |
| 223 |
change_file_perms $mp2/app/.modulerc o-r |
| 224 |
|
| 225 |
setenv_path_var MODULEPATH $mp2 |
| 226 |
set tserr [msg_create $mp2cache] |
| 227 |
set tscache "#%Module$cache_mcookie_version" |
| 228 |
append tscache \n[list modulerc-content .modulerc #%Module $mp2rc_content] |
| 229 |
append tscache \n[list limited-access-file app/.modulerc] |
| 230 |
append tscache \n[list modulefile-content app/1.0.mod [file mtime\ |
| 231 |
$mp2/app/1.0.mod] #%Module $mfcontent] |
| 232 |
testouterrfile_cmd sh cachebuild OK $tserr $mp2cache $tscache |
| 233 |
|
| 234 |
# limited access rc file is tested then evaluated from disk on cache use |
| 235 |
set tserr app/1.0.mod |
| 236 |
testouterr_cmd sh {avail -a -t -o } OK $tserr |
| 237 |
setenv_var MODULES_IGNORE_CACHE 1 |
| 238 |
testouterr_cmd sh {avail -a -t -o } OK $tserr |
| 239 |
unsetenv_var MODULES_IGNORE_CACHE |
| 240 |
|
| 241 |
restore_file_perms $mp2/app/.modulerc |
| 242 |
file delete -force $mp2 |
| 243 |
setenv_path_var MODULEPATH $mp1 |
| 244 |
|
| 245 |
} |
| 246 |
|
| 247 |
# |
| 248 |
# Cleanup |
| 249 |
# |
| 250 |
|
| 251 |
file delete -force $mp1 |
| 252 |
|
| 253 |
reset_test_env |