| 1 |
############################################################################## |
| 2 |
# Modules Revision 3.0 |
| 3 |
# Providing a flexible user environment |
| 4 |
# |
| 5 |
# File: modules.00-init/%M% |
| 6 |
# Revision: %I% |
| 7 |
# First Edition: 2024/04/25 |
| 8 |
# Last Mod.: %U%, %G% |
| 9 |
# |
| 10 |
# Authors: Xavier Delaruelle, [email protected] |
| 11 |
# |
| 12 |
# Description: Testuite testsequence |
| 13 |
# Command: load, display, avail |
| 14 |
# Modulefiles: bar, foo |
| 15 |
# Sub-Command: |
| 16 |
# |
| 17 |
# Comment: %C{ |
| 18 |
# Test logger feature |
| 19 |
# }C% |
| 20 |
# |
| 21 |
############################################################################## |
| 22 |
|
| 23 |
if {[is_config_locked logger] || [is_config_locked logged_events]} { |
| 24 |
send_user "\tskipping logger tests as configuration option is locked\n" |
| 25 |
} elseif {$is_global_rc_file} { |
| 26 |
send_user "\tskipping logger tests as global RC file is present\n" |
| 27 |
} else { |
| 28 |
|
| 29 |
set mp $modpath.4 |
| 30 |
set mpre $modpathre.4 |
| 31 |
setenv_path_var MODULEPATH $mp |
| 32 |
|
| 33 |
setenv_var MODULES_SEARCH_MATCH starts_with |
| 34 |
setenv_var MODULES_IMPLICIT_DEFAULT 1 |
| 35 |
setenv_var MODULES_AUTO_HANDLING 1 |
| 36 |
|
| 37 |
set log_cmd $env(TESTSUITEDIR)/stdin_to_file |
| 38 |
set log_file $env(TESTSUITEDIR)/logfile |
| 39 |
|
| 40 |
proc log_file_content {struct_content_list} { |
| 41 |
set formatted_content_list {} |
| 42 |
foreach struct_line_list $struct_content_list { |
| 43 |
set formatted_line_list [list "user=\"$::username\""] |
| 44 |
foreach {key val} $struct_line_list { |
| 45 |
lappend formatted_line_list "$key=\"$val\"" |
| 46 |
} |
| 47 |
lappend formatted_content_list [join $formatted_line_list] |
| 48 |
} |
| 49 |
return [join $formatted_content_list \n] |
| 50 |
} |
| 51 |
|
| 52 |
setenv_var TESTSUITE_LOGGER load_dep_and_alias |
| 53 |
|
| 54 |
set ans [list] |
| 55 |
lappend ans [list set __MODULES_LMREFRESH bar/1] |
| 56 |
lappend ans [list set __MODULES_LMPREREQ bar/1&foo/1.0] |
| 57 |
lappend ans [list set _LMFILES_ $mp/foo/1.0:$mp/bar/1] |
| 58 |
lappend ans [list set LOADEDMODULES foo/1.0:bar/1] |
| 59 |
lappend ans [list set __MODULES_LMTAG foo/1.0&auto-loaded] |
| 60 |
lappend ans [list alias albar bar] |
| 61 |
|
| 62 |
set ans_unload [list] |
| 63 |
lappend ans_unload [list unset __MODULES_LMPREREQ] |
| 64 |
lappend ans_unload [list unset _LMFILES_] |
| 65 |
lappend ans_unload [list unset LOADEDMODULES] |
| 66 |
lappend ans_unload [list unset __MODULES_LMREFRESH] |
| 67 |
lappend ans_unload [list unset __MODULES_LMTAG] |
| 68 |
lappend ans_unload [list unalias albar] |
| 69 |
|
| 70 |
set ans_reload [list] |
| 71 |
lappend ans_reload [list set __MODULES_LMPREREQ bar/1&foo/1.0] |
| 72 |
lappend ans_reload [list set _LMFILES_ $mp/foo/1.0:$mp/bar/1] |
| 73 |
lappend ans_reload [list set LOADEDMODULES foo/1.0:bar/1] |
| 74 |
lappend ans_reload [list set __MODULES_LMREFRESH bar/1] |
| 75 |
lappend ans_reload [list set __MODULES_LMTAG foo/1.0&auto-loaded] |
| 76 |
lappend ans_reload [list alias albar bar] |
| 77 |
|
| 78 |
|
| 79 |
# |
| 80 |
# basic log tests |
| 81 |
# |
| 82 |
|
| 83 |
unsetenv_var MODULERCFILE |
| 84 |
setenv_var MODULES_LOGGER "$log_cmd $log_file" |
| 85 |
|
| 86 |
setenv_var MODULES_LOGGED_EVENTS requested_cmd |
| 87 |
|
| 88 |
set tserr "$mp:\nbar/1" |
| 89 |
set anslog [list] |
| 90 |
lappend anslog [list command avail arguments {bar/1 -t}] |
| 91 |
set tslog [log_file_content $anslog] |
| 92 |
testouterrfile_cmd sh {avail -t bar/1} OK $tserr $log_file $tslog |
| 93 |
|
| 94 |
|
| 95 |
setenv_var MODULES_LOGGED_EVENTS requested_cmd:requested_eval |
| 96 |
|
| 97 |
set tserr [msg_top_load bar/1 {} foo/1.0 {}] |
| 98 |
set anslog [list] |
| 99 |
lappend anslog [list command load arguments bar/1] |
| 100 |
lappend anslog [list mode load module bar/1 specified bar/1 modulefile $mp/bar/1 requested 1] |
| 101 |
set tslog [log_file_content $anslog] |
| 102 |
testouterrfile_cmd sh {load bar/1} $ans $tserr $log_file $tslog |
| 103 |
|
| 104 |
|
| 105 |
setenv_var MODULES_LOGGED_EVENTS auto_eval |
| 106 |
set anslog [list] |
| 107 |
lappend anslog [list mode load module foo/1.0 specified foo/1.0 modulefile $mp/foo/1.0 requested 0] |
| 108 |
set tslog [log_file_content $anslog] |
| 109 |
testouterrfile_cmd sh {load bar/1} $ans $tserr $log_file $tslog |
| 110 |
|
| 111 |
|
| 112 |
setenv_var MODULES_LOGGED_EVENTS requested_cmd:requested_eval:auto_eval |
| 113 |
set anslog [list] |
| 114 |
lappend anslog [list command load arguments bar/1] |
| 115 |
lappend anslog [list mode load module foo/1.0 specified foo/1.0 modulefile $mp/foo/1.0 requested 0] |
| 116 |
lappend anslog [list mode load module bar/1 specified bar/1 modulefile $mp/bar/1 requested 1] |
| 117 |
set tslog [log_file_content $anslog] |
| 118 |
testouterrfile_cmd sh {load bar/1} $ans $tserr $log_file $tslog |
| 119 |
|
| 120 |
file delete $log_file |
| 121 |
skip_if_quick_mode |
| 122 |
|
| 123 |
|
| 124 |
# |
| 125 |
# command log tests |
| 126 |
# |
| 127 |
|
| 128 |
setenv_var MODULES_LOGGED_EVENTS requested_cmd |
| 129 |
|
| 130 |
set anslog [list] |
| 131 |
lappend anslog [list command ml arguments bar/1] |
| 132 |
set tslog [log_file_content $anslog] |
| 133 |
testouterrfile_cmd sh {ml bar/1} $ans $tserr $log_file $tslog |
| 134 |
|
| 135 |
setenv_var MODULES_LOGGED_EVENTS {} |
| 136 |
|
| 137 |
file delete $log_file |
| 138 |
set tslog [couldnotopen_nofile $log_file] |
| 139 |
testouterrfile_cmd sh {ml bar/1} $ans $tserr $log_file $tslog |
| 140 |
|
| 141 |
setenv_var MODULES_LOGGED_EVENTS requested_cmd |
| 142 |
|
| 143 |
set anslog [list] |
| 144 |
lappend anslog [list command load arguments bar/1] |
| 145 |
set tslog [log_file_content $anslog] |
| 146 |
testouterrfile_cmd sh {ml load bar/1} $ans $tserr $log_file $tslog |
| 147 |
|
| 148 |
set anslog [list] |
| 149 |
lappend anslog [list command ml arguments -bar/1] |
| 150 |
set tslog [log_file_content $anslog] |
| 151 |
testouterrfile_cmd sh {ml -bar/1} OK {} $log_file $tslog |
| 152 |
|
| 153 |
# junk value in option |
| 154 |
setenv_var MODULES_LOGGED_EVENTS unk:requested_cmd |
| 155 |
testouterrfile_cmd sh {ml -bar/1} OK {} $log_file $tslog |
| 156 |
|
| 157 |
setenv_var MODULES_LOGGED_EVENTS unk |
| 158 |
file delete $log_file |
| 159 |
set tslog [couldnotopen_nofile $log_file] |
| 160 |
testouterrfile_cmd sh {ml load bar/1} $ans $tserr $log_file $tslog |
| 161 |
|
| 162 |
setenv_var MODULES_LOGGED_EVENTS requested_cmd |
| 163 |
|
| 164 |
file delete $log_file |
| 165 |
set tserr [err_invopt --bar-arg] |
| 166 |
set tslog [couldnotopen_nofile $log_file] |
| 167 |
testouterrfile_cmd sh {ml --bar-arg bar/1} ERR $tserr $log_file $tslog |
| 168 |
|
| 169 |
testouterrfile_cmd sh {--bar-arg load bar/1} ERR $tserr $log_file $tslog |
| 170 |
|
| 171 |
set tserr [err_invcmd unk] |
| 172 |
testouterrfile_cmd sh {unk bar/1} ERR $tserr $log_file $tslog |
| 173 |
|
| 174 |
# basic options are not recorded |
| 175 |
file delete $log_file |
| 176 |
testoutfile_cmd sh {-V} OK $log_file $tslog |
| 177 |
testoutfile_cmd sh {--help} OK $log_file $tslog |
| 178 |
|
| 179 |
|
| 180 |
# |
| 181 |
# evaluation log tests |
| 182 |
# |
| 183 |
|
| 184 |
# top commands |
| 185 |
setenv_var MODULES_LOGGED_EVENTS requested_eval |
| 186 |
set anslog [list] |
| 187 |
lappend anslog [list mode display module bar/2 specified bar modulefile $mp/bar/2 requested 1] |
| 188 |
set tslog [log_file_content $anslog] |
| 189 |
testoutfile_cmd sh {display bar} OK $log_file $tslog |
| 190 |
|
| 191 |
set anslog [list] |
| 192 |
lappend anslog [list mode help module bar/2 specified bar modulefile $mp/bar/2 requested 1] |
| 193 |
set tslog [log_file_content $anslog] |
| 194 |
testoutfile_cmd sh {help bar} OK $log_file $tslog |
| 195 |
|
| 196 |
set anslog [list] |
| 197 |
lappend anslog [list mode test module bar/2 specified bar modulefile $mp/bar/2 requested 1] |
| 198 |
set tslog [log_file_content $anslog] |
| 199 |
testoutfile_cmd sh {test bar} OK $log_file $tslog |
| 200 |
|
| 201 |
set anslog [list] |
| 202 |
lappend anslog [list mode load module bar/2 specified bar modulefile $mp/bar/2 requested 1] |
| 203 |
set tslog [log_file_content $anslog] |
| 204 |
testoutfile_cmd sh {source bar} OK $log_file $tslog |
| 205 |
|
| 206 |
setenv_var MODULES_LOGGED_EVENTS auto_eval |
| 207 |
file delete $log_file |
| 208 |
set tslog [couldnotopen_nofile $log_file] |
| 209 |
testoutfile_cmd sh {display bar} OK $log_file $tslog |
| 210 |
testoutfile_cmd sh {help bar} OK $log_file $tslog |
| 211 |
testoutfile_cmd sh {test bar} OK $log_file $tslog |
| 212 |
testoutfile_cmd sh {source bar} OK $log_file $tslog |
| 213 |
|
| 214 |
|
| 215 |
setenv_var MODULES_LOGGED_EVENTS requested_eval:auto_eval |
| 216 |
|
| 217 |
setenv_loaded_module [list foo/1.0 bar/1] [list $mp/foo/1.0 $mp/bar/1] [list foo/1.0] |
| 218 |
setenv_var __MODULES_LMPREREQ bar/1&foo/1.0 |
| 219 |
setenv_var __MODULES_LMREFRESH bar/1 |
| 220 |
|
| 221 |
set anslog [list] |
| 222 |
lappend anslog [list mode unload module bar/1 specified bar modulefile $mp/bar/1 requested 1] |
| 223 |
lappend anslog [list mode unload module foo/1.0 specified foo/1.0 modulefile $mp/foo/1.0 requested 0] |
| 224 |
set tslog [log_file_content $anslog] |
| 225 |
testoutfile_cmd sh {unload bar} $ans_unload $log_file $tslog |
| 226 |
|
| 227 |
set anslog [list] |
| 228 |
lappend anslog [list mode unload module bar/1 specified bar/1 modulefile $mp/bar/1 requested 1] |
| 229 |
lappend anslog [list mode unload module foo/1.0 specified foo/1.0 modulefile $mp/foo/1.0 requested 0] |
| 230 |
lappend anslog [list mode load module foo/1.0 specified foo/1.0 modulefile $mp/foo/1.0 requested 0] |
| 231 |
lappend anslog [list mode load module bar/1 specified bar/1 modulefile $mp/bar/1 requested 1] |
| 232 |
set tslog [log_file_content $anslog] |
| 233 |
testoutfile_cmd sh {reload} $ans_reload $log_file $tslog |
| 234 |
|
| 235 |
setenv_var MODULES_LOGGED_EVENTS requested_eval |
| 236 |
set anslog [list] |
| 237 |
lappend anslog [list mode unload module bar/1 specified bar/1 modulefile $mp/bar/1 requested 1] |
| 238 |
lappend anslog [list mode load module bar/1 specified bar/1 modulefile $mp/bar/1 requested 1] |
| 239 |
set tslog [log_file_content $anslog] |
| 240 |
testoutfile_cmd sh {reload} $ans_reload $log_file $tslog |
| 241 |
|
| 242 |
set anslog [list] |
| 243 |
lappend anslog [list mode unload module bar/1 specified bar modulefile $mp/bar/1 requested 1] |
| 244 |
set tslog [log_file_content $anslog] |
| 245 |
testoutfile_cmd sh {unload bar} $ans_unload $log_file $tslog |
| 246 |
|
| 247 |
setenv_var MODULES_LOGGED_EVENTS auto_eval |
| 248 |
set anslog [list] |
| 249 |
lappend anslog [list mode unload module foo/1.0 specified foo/1.0 modulefile $mp/foo/1.0 requested 0] |
| 250 |
lappend anslog [list mode load module foo/1.0 specified foo/1.0 modulefile $mp/foo/1.0 requested 0] |
| 251 |
set tslog [log_file_content $anslog] |
| 252 |
testoutfile_cmd sh {reload} $ans_reload $log_file $tslog |
| 253 |
|
| 254 |
set anslog [list] |
| 255 |
lappend anslog [list mode unload module foo/1.0 specified foo/1.0 modulefile $mp/foo/1.0 requested 0] |
| 256 |
set tslog [log_file_content $anslog] |
| 257 |
testoutfile_cmd sh {unload bar} $ans_unload $log_file $tslog |
| 258 |
|
| 259 |
|
| 260 |
# internal evaluation are not recorded (whatis, scan, refresh) |
| 261 |
setenv_var MODULES_LOGGED_EVENTS requested_eval:auto_eval |
| 262 |
|
| 263 |
file delete $log_file |
| 264 |
set tslog [couldnotopen_nofile $log_file] |
| 265 |
testoutfile_cmd sh {whatis bar} OK $log_file $tslog |
| 266 |
|
| 267 |
set ans_search [list] |
| 268 |
lappend ans_search [list out all-pre-out] |
| 269 |
lappend ans_search [list out all-out] |
| 270 |
testoutfile_cmd sh {search bar} $ans_search $log_file $tslog |
| 271 |
|
| 272 |
testoutfile_cmd sh {avail bar tag:loaded} OK $log_file $tslog |
| 273 |
|
| 274 |
set ans_refresh [list] |
| 275 |
lappend ans_refresh [list alias albar bar] |
| 276 |
testoutfile_cmd sh {refresh} $ans_refresh $log_file $tslog |
| 277 |
|
| 278 |
unsetenv_loaded_module |
| 279 |
unsetenv_var __MODULES_LMREFRESH |
| 280 |
unsetenv_var __MODULES_LMPREREQ |
| 281 |
|
| 282 |
|
| 283 |
# global modulerc evaluation (appears as requested evaluation) |
| 284 |
setenv_var MODULES_LOGGED_EVENTS requested_eval |
| 285 |
setenv_var MODULERCFILE $mp/bar/2 |
| 286 |
|
| 287 |
set tserr [msg_top_load bar/1 {} foo/1.0 {}] |
| 288 |
set anslog [list] |
| 289 |
lappend anslog [list mode load module $mp/bar/2 specified $mp/bar/2 modulefile $mp/bar/2 requested 1] |
| 290 |
lappend anslog [list mode load module bar/1 specified bar/1 modulefile $mp/bar/1 requested 1] |
| 291 |
set tslog [log_file_content $anslog] |
| 292 |
testouterrfile_cmd sh {load bar/1} $ans $tserr $log_file $tslog |
| 293 |
|
| 294 |
unsetenv_var MODULERCFILE |
| 295 |
|
| 296 |
|
| 297 |
# broken evaluation |
| 298 |
setenv_var MODULES_LOGGED_EVENTS requested_eval:auto_eval |
| 299 |
|
| 300 |
setenv_var TESTSUITE_LOGGER load_dep_and_break |
| 301 |
file delete $log_file |
| 302 |
set anslog [list] |
| 303 |
lappend anslog [list mode load module foo/1.0 specified foo/1.0 modulefile $mp/foo/1.0 requested 0] |
| 304 |
lappend anslog [list mode load module bar/1 specified bar/1 modulefile $mp/bar/1 requested 1] |
| 305 |
set tslog [log_file_content $anslog] |
| 306 |
testoutfile_cmd sh {load bar/1} ERR $log_file $tslog |
| 307 |
|
| 308 |
setenv_var TESTSUITE_LOGGER load_dep_and_unk |
| 309 |
file delete $log_file |
| 310 |
testoutfile_cmd sh {load bar/1} ERR $log_file $tslog |
| 311 |
|
| 312 |
setenv_var TESTSUITE_LOGGER dep_break |
| 313 |
file delete $log_file |
| 314 |
testoutfile_cmd sh {load bar/1} ERR $log_file $tslog |
| 315 |
|
| 316 |
setenv_var TESTSUITE_LOGGER dep_unk |
| 317 |
file delete $log_file |
| 318 |
testoutfile_cmd sh {load bar/1} ERR $log_file $tslog |
| 319 |
|
| 320 |
|
| 321 |
# |
| 322 |
# broken configurations |
| 323 |
# |
| 324 |
|
| 325 |
setenv_var TESTSUITE_LOGGER load_dep_and_alias |
| 326 |
|
| 327 |
# no logger command defined |
| 328 |
setenv_var MODULES_LOGGED_EVENTS requested_cmd |
| 329 |
setenv_var MODULES_LOGGER {} |
| 330 |
|
| 331 |
file delete $log_file |
| 332 |
set tserr "$mp:\nbar/1" |
| 333 |
set tslog [couldnotopen_nofile $log_file] |
| 334 |
testouterrfile_cmd sh {avail -t bar/1} OK $tserr $log_file $tslog |
| 335 |
|
| 336 |
setenv_var MODULES_LOGGED_EVENTS requested_cmd:requested_eval |
| 337 |
|
| 338 |
set tserr [msg_top_load bar/1 {} foo/1.0 {}] |
| 339 |
testouterrfile_cmd sh {load bar/1} $ans $tserr $log_file $tslog |
| 340 |
|
| 341 |
|
| 342 |
# bad logger command defined |
| 343 |
setenv_var MODULES_LOGGER {/path/to/unk} |
| 344 |
|
| 345 |
file delete $log_file |
| 346 |
set tserr "$mp:\nbar/1\n\n[warn_couldnotexec_nofile /path/to/unk]" |
| 347 |
set tslog [couldnotopen_nofile $log_file] |
| 348 |
testouterrfile_cmd sh {avail -t bar/1} OK $tserr $log_file $tslog |
| 349 |
|
| 350 |
setenv_var MODULES_LOGGED_EVENTS requested_cmd:requested_eval |
| 351 |
|
| 352 |
set tserr [msg_top_load bar/1 {} foo/1.0 {}]\n\n[warn_couldnotexec_nofile /path/to/unk] |
| 353 |
testouterrfile_cmd sh {load bar/1} $ans $tserr $log_file $tslog |
| 354 |
|
| 355 |
|
| 356 |
# |
| 357 |
# logger command behaving strangely |
| 358 |
# |
| 359 |
|
| 360 |
setenv_var MODULES_LOGGER "$log_cmd $log_file" |
| 361 |
|
| 362 |
setenv_var MODULES_LOGGED_EVENTS requested_eval:auto_eval |
| 363 |
setenv_loaded_module [list foo/1.0 bar/1] [list $mp/foo/1.0 $mp/bar/1] [list foo/1.0] |
| 364 |
setenv_var __MODULES_LMPREREQ bar/1&foo/1.0 |
| 365 |
setenv_var __MODULES_LMREFRESH bar/1 |
| 366 |
|
| 367 |
# logger command sends output message |
| 368 |
setenv_var TESTSUITE_LOGGER logger_cmd_out_msg |
| 369 |
|
| 370 |
file delete $log_file |
| 371 |
set anslog [list] |
| 372 |
lappend anslog [list mode unload module bar/1 specified bar/1 modulefile $mp/bar/1 requested 1] |
| 373 |
lappend anslog [list mode unload module foo/1.0 specified foo/1.0 modulefile $mp/foo/1.0 requested 0] |
| 374 |
lappend anslog [list mode load module foo/1.0 specified foo/1.0 modulefile $mp/foo/1.0 requested 0] |
| 375 |
lappend anslog [list mode load module bar/1 specified bar/1 modulefile $mp/bar/1 requested 1] |
| 376 |
set tslog [log_file_content $anslog] |
| 377 |
testouterrfile_cmd sh {reload} $ans_reload {} $log_file $tslog |
| 378 |
|
| 379 |
# logger command sends error message |
| 380 |
setenv_var TESTSUITE_LOGGER logger_cmd_err_msg |
| 381 |
|
| 382 |
file delete $log_file |
| 383 |
testouterrfile_cmd sh {reload} $ans_reload {} $log_file $tslog |
| 384 |
|
| 385 |
# logger command exits with non-zero code |
| 386 |
setenv_var TESTSUITE_LOGGER logger_cmd_exit_code |
| 387 |
|
| 388 |
file delete $log_file |
| 389 |
set tserr $warn_issue_logging |
| 390 |
testouterrfile_cmd sh {reload} $ans_reload $tserr $log_file $tslog |
| 391 |
|
| 392 |
# logger command crashes after first log message sent |
| 393 |
setenv_var TESTSUITE_LOGGER logger_cmd_crash |
| 394 |
|
| 395 |
file delete $log_file |
| 396 |
set anslog [list] |
| 397 |
lappend anslog [list mode unload module bar/1 specified bar/1 modulefile $mp/bar/1 requested 1] |
| 398 |
set tslog [log_file_content $anslog] |
| 399 |
testouterrfile_cmd sh {reload} $ans_reload $tserr $log_file $tslog |
| 400 |
|
| 401 |
# logger command crashes without setting a non-zero exit code after first log message sent |
| 402 |
setenv_var TESTSUITE_LOGGER logger_cmd_silent_crash |
| 403 |
|
| 404 |
file delete $log_file |
| 405 |
testouterrfile_cmd sh {reload} $ans_reload {} $log_file $tslog |
| 406 |
|
| 407 |
unsetenv_loaded_module |
| 408 |
unsetenv_var __MODULES_LMREFRESH |
| 409 |
unsetenv_var __MODULES_LMPREREQ |
| 410 |
|
| 411 |
|
| 412 |
# |
| 413 |
# Cleanup |
| 414 |
# |
| 415 |
|
| 416 |
file delete $log_file |
| 417 |
rename log_file_content {} |
| 418 |
|
| 419 |
} |
| 420 |
|
| 421 |
reset_test_env |