| 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/20 |
| 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 with fully recorded content |
| 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 |
skip_if_quick_mode |
| 28 |
|
| 29 |
# ensure avail tests are made using in depth mode |
| 30 |
setenv_var MODULES_AVAIL_INDEPTH 1 |
| 31 |
|
| 32 |
# create modulefile/modulerc complex setup |
| 33 |
lassign [create_diverse_module_setup $mp1] dir_list file_list |
| 34 |
array set file_arr $file_list |
| 35 |
|
| 36 |
# expected cache file |
| 37 |
set tscache "#%Module$cache_mcookie_version" |
| 38 |
foreach f [lsort [array names file_arr]] { |
| 39 |
set entry {} |
| 40 |
switch -- $f { |
| 41 |
.git/ignmod - quux/SCCS/ignmod - {w s/1.0~} -\ |
| 42 |
foo/1.0,v - quxc/1.0~ - .svn/ignmod - .sos/ignmod {} |
| 43 |
foo/1.0 { |
| 44 |
set entry [list modulefile-invalid $f invalid {Magic cookie '#%Module' missing}] |
| 45 |
} |
| 46 |
foo/3.0 - quux/nok/5.0 { |
| 47 |
set entry [list modulefile-invalid $f invalid {Modulefile requires at least Modules version 99}] |
| 48 |
} |
| 49 |
default { |
| 50 |
switch -- $f { |
| 51 |
foo/.modulerc {set header {}} |
| 52 |
foo/4.0 - quxc/.modulerc {set header {#%Module5.2}} |
| 53 |
quxb/.modulerc {set header {#%Module99}} |
| 54 |
default {set header {#%Module}} |
| 55 |
} |
| 56 |
|
| 57 |
if {[file tail $f] in {.modulerc .version}} { |
| 58 |
set entry [list modulerc-content $f $header $file_arr($f)] |
| 59 |
} else { |
| 60 |
set mtime [file mtime $mp1/$f] |
| 61 |
set entry [list modulefile-content $f $mtime $header $file_arr($f)] |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
if {[string length $entry]} { |
| 66 |
append tscache "\n$entry" |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
setenv_path_var MODULEPATH $mp1 |
| 72 |
|
| 73 |
# make cache on built modulepath |
| 74 |
set tserr [msg_create $mp1cache] |
| 75 |
testouterrfile_cmd sh "cachebuild $mp1" OK $tserr $mp1cache $tscache |
| 76 |
|
| 77 |
# build a second time, should get exact same cache file |
| 78 |
testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache |
| 79 |
|
| 80 |
# build when an empty cachefile pre-exist |
| 81 |
file delete $mp1cache |
| 82 |
create_dummy_cachefile $mp1 |
| 83 |
testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache |
| 84 |
|
| 85 |
|
| 86 |
# .modulecache should be ignored from avail results |
| 87 |
set tserr {} |
| 88 |
foreach f [lsort [array names file_arr]] { |
| 89 |
switch -glob -- $f { |
| 90 |
.git/ignmod - quux/SCCS/ignmod - {w s/1.0~} -\ |
| 91 |
foo/1.0,v - quxc/1.0~ - .svn/ignmod - .sos/ignmod {} |
| 92 |
*/.modulerc - */.version - foo/1.0 - foo/3.0 - quux/nok/5.0 {} |
| 93 |
{* *} {lappend tserr '$f'} |
| 94 |
default {lappend tserr $f} |
| 95 |
} |
| 96 |
} |
| 97 |
set tserr [join $tserr \n] |
| 98 |
testouterr_cmd sh {avail -a -t -o } OK $tserr |
| 99 |
|
| 100 |
# delete generated cache file |
| 101 |
file delete $mp1cache |
| 102 |
|
| 103 |
|
| 104 |
# test cache generation when mcookie_check is set to eval (should not change |
| 105 |
# cache content) |
| 106 |
setenv_path_var MODULEPATH $mp1 |
| 107 |
setenv_var MODULES_MCOOKIE_CHECK eval |
| 108 |
set tserr [msg_create $mp1cache] |
| 109 |
testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache |
| 110 |
setenv_var MODULES_MCOOKIE_CHECK always |
| 111 |
file delete $mp1cache |
| 112 |
|
| 113 |
# test cache generation when mcookie_version_check is disabled (should not |
| 114 |
# change cache content) |
| 115 |
setenv_path_var MODULEPATH $mp1 |
| 116 |
setenv_var MODULES_MCOOKIE_VERSION_CHECK 0 |
| 117 |
set tserr [msg_create $mp1cache] |
| 118 |
testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache |
| 119 |
setenv_var MODULES_MCOOKIE_VERSION_CHECK 1 |
| 120 |
file delete $mp1cache |
| 121 |
|
| 122 |
|
| 123 |
# generate simpler setup |
| 124 |
lassign [create_simple_module_setup $mp2] other_dir_list other_file_list |
| 125 |
array set other_file_arr $other_file_list |
| 126 |
|
| 127 |
|
| 128 |
# cannot test access if cannot change file permission |
| 129 |
if {!$is_file_perms_editable} { |
| 130 |
send_user "\tskipping access tests as file permissions cannot be changed\n" |
| 131 |
# cannot test access if superuser privileges are in use |
| 132 |
} elseif {$tcl_platform(user) eq "root"} { |
| 133 |
send_user "\tskipping access tests as tests are run by superuser\n" |
| 134 |
# cannot test access if restricted file permissions have no effect |
| 135 |
} elseif {$is_locked_dir_file_readable && $is_locked_file_readable} { |
| 136 |
send_user "\tskipping access tests as locked files or directories are still readable\n" |
| 137 |
} else { |
| 138 |
|
| 139 |
set noread_perms ugo-r |
| 140 |
|
| 141 |
setenv_path_var MODULEPATH $mp2:$mp1 |
| 142 |
|
| 143 |
# one modulefile not readable |
| 144 |
change_file_perms $mp2/bar/1.0 $noread_perms |
| 145 |
set tserr [msg_create $mp2cache]\n[msg_create $mp1cache] |
| 146 |
set tscache "#%Module$cache_mcookie_version" |
| 147 |
foreach f [lsort [array names other_file_arr]] { |
| 148 |
switch -- $f { |
| 149 |
bar/1.0 { |
| 150 |
set entry [list limited-access-file $f] |
| 151 |
} |
| 152 |
default { |
| 153 |
if {[file tail $f] in {.modulerc .version}} { |
| 154 |
set entry [list modulerc-content $f {#%Module} $other_file_arr($f)] |
| 155 |
} else { |
| 156 |
set mtime [file mtime $mp2/$f] |
| 157 |
set entry [list modulefile-content $f $mtime {#%Module} $other_file_arr($f)] |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
append tscache "\n$entry" |
| 162 |
} |
| 163 |
testouterrfile_cmd sh cachebuild OK $tserr $mp2cache $tscache |
| 164 |
restore_file_perms $mp2/bar/1.0 |
| 165 |
|
| 166 |
# one modulerc not readable |
| 167 |
change_file_perms $mp2/foo/.modulerc $noread_perms |
| 168 |
set tserr [msg_create $mp2cache]\n[msg_create $mp1cache] |
| 169 |
set tscache "#%Module$cache_mcookie_version" |
| 170 |
foreach f [lsort [array names other_file_arr]] { |
| 171 |
set entry {} |
| 172 |
switch -- $f { |
| 173 |
foo/.modulerc { |
| 174 |
set entry [list limited-access-file $f] |
| 175 |
} |
| 176 |
default { |
| 177 |
if {[file tail $f] in {.modulerc .version}} { |
| 178 |
set entry [list modulerc-content $f {#%Module} $other_file_arr($f)] |
| 179 |
} else { |
| 180 |
set mtime [file mtime $mp2/$f] |
| 181 |
set entry [list modulefile-content $f $mtime {#%Module} $other_file_arr($f)] |
| 182 |
} |
| 183 |
} |
| 184 |
} |
| 185 |
if {[string length $entry]} { |
| 186 |
append tscache "\n$entry" |
| 187 |
} |
| 188 |
} |
| 189 |
testouterrfile_cmd sh cachebuild OK $tserr $mp2cache $tscache |
| 190 |
restore_file_perms $mp2/foo/.modulerc |
| 191 |
|
| 192 |
# one directory not readable |
| 193 |
change_file_perms $mp2/foo $noread_perms |
| 194 |
set tserr [msg_create $mp2cache]\n[msg_create $mp1cache] |
| 195 |
set tscache "#%Module$cache_mcookie_version" |
| 196 |
foreach f [lsort [array names other_file_arr]] { |
| 197 |
set entry {} |
| 198 |
switch -- $f { |
| 199 |
foo/.modulerc - foo/1.0 {} |
| 200 |
default { |
| 201 |
if {[file tail $f] in {.modulerc .version}} { |
| 202 |
set entry [list modulerc-content $f {#%Module} $other_file_arr($f)] |
| 203 |
} else { |
| 204 |
set mtime [file mtime $mp2/$f] |
| 205 |
set entry [list modulefile-content $f $mtime {#%Module} $other_file_arr($f)] |
| 206 |
} |
| 207 |
} |
| 208 |
} |
| 209 |
if {[string length $entry]} { |
| 210 |
append tscache "\n$entry" |
| 211 |
} |
| 212 |
} |
| 213 |
set entry [list limited-access-directory foo] |
| 214 |
append tscache "\n$entry" |
| 215 |
testouterrfile_cmd sh cachebuild OK $tserr $mp2cache $tscache |
| 216 |
restore_file_perms $mp2/foo |
| 217 |
|
| 218 |
# access ok, but read fails |
| 219 |
# check expected siteconfig file is installed |
| 220 |
set is_stderr_tty [siteconfig_isStderrTty] |
| 221 |
if {$is_stderr_tty} { |
| 222 |
|
| 223 |
# test a modulefile read failure during cache build by faking modulefile is readable |
| 224 |
setenv_var TESTSUITE_ENABLE_SITECONFIG_CACHEBUILD_READ1 1 |
| 225 |
set tserr [msg_create $mp2cache]\n[msg_create $mp1cache] |
| 226 |
set tscache "#%Module$cache_mcookie_version" |
| 227 |
foreach f [lsort [array names other_file_arr]] { |
| 228 |
set entry {} |
| 229 |
switch -- $f { |
| 230 |
bar/1.0 { |
| 231 |
set entry [list modulefile-invalid $f accesserr "No such file or directory on '$mp2/bar/1.0'"] |
| 232 |
} |
| 233 |
default { |
| 234 |
if {[file tail $f] in {.modulerc .version}} { |
| 235 |
set entry [list modulerc-content $f {#%Module} $other_file_arr($f)] |
| 236 |
} else { |
| 237 |
set mtime [file mtime $mp2/$f] |
| 238 |
set entry [list modulefile-content $f $mtime {#%Module} $other_file_arr($f)] |
| 239 |
} |
| 240 |
} |
| 241 |
} |
| 242 |
if {[string length $entry]} { |
| 243 |
append tscache "\n$entry" |
| 244 |
} |
| 245 |
} |
| 246 |
testouterrfile_cmd sh cachebuild OK $tserr $mp2cache $tscache |
| 247 |
unsetenv_var TESTSUITE_ENABLE_SITECONFIG_CACHEBUILD_READ1 |
| 248 |
|
| 249 |
# test a modulerc read failure during cache build by faking modulerc is readable |
| 250 |
file delete $mp2cache |
| 251 |
setenv_var TESTSUITE_ENABLE_SITECONFIG_CACHEBUILD_READ2 1 |
| 252 |
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'"] |
| 253 |
set tscache [couldnotopen_nofile $mp2cache] |
| 254 |
testouterrfile_cmd sh {cachebuild} ERR $tserr $mp2cache $tscache |
| 255 |
unsetenv_var TESTSUITE_ENABLE_SITECONFIG_CACHEBUILD_READ2 |
| 256 |
} |
| 257 |
|
| 258 |
# delete generated cache files |
| 259 |
file delete $mp1cache |
| 260 |
file delete $mp2cache |
| 261 |
|
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
# |
| 266 |
# Cleanup |
| 267 |
# |
| 268 |
|
| 269 |
# delete created files and dirs |
| 270 |
delete_module_setup $mp1 [array names file_arr] $dir_list |
| 271 |
delete_module_setup $mp2 [array names other_file_arr] $other_dir_list |
| 272 |
|
| 273 |
reset_test_env |