Files
modules/testsuite/modules.30-cache/040-cache-use.exp
2022-12-27 18:43:59 +01:00

516 lines
17 KiB
Plaintext

##############################################################################
# Modules Revision 3.0
# Providing a flexible user environment
#
# File: modules.30-cache/%M%
# Revision: %I%
# First Edition: 2022/11/24
# Last Mod.: %U%, %G%
#
# Authors: Xavier Delaruelle, xavier.delaruelle@cea.fr
#
# Description: Testuite testsequence
# Command: avail, whatis, load
# Modulefiles:
# Sub-Command:
#
# Comment: %C{
# Test use of cachefiles
# }C%
#
##############################################################################
# ensure avail tests are made using in depth mode
setenv_var MODULES_AVAIL_INDEPTH 1
# ensure avail tests have implicit default enabled
setenv_var MODULES_IMPLICIT_DEFAULT 1
# ensure auto symbolic versions are set for these tests
setenv_var MODULES_ADVANCED_VERSION_SPEC 1
# ensure regular avail search match is set for these tests
setenv_var MODULES_SEARCH_MATCH starts_with
# generate content in modulepaths
lassign [create_diverse_module_setup $mp1] dir_list file_list
array set file_arr $file_list
setenv_var MODULEPATH $mp1
# create file cache for test
set tserr [msg_create $mp1cache]
testouterr_cmd sh cachebuild OK $tserr
set tserr {}
foreach f [lsort [array names file_arr]] {
switch -glob -- $f {
*/.modulerc - */.version - foo/1.0 - foo/3.0 - quux/nok/5.0 -\
.git/ignmod - quux/SCCS/ignmod - {w s/1.0~} - foo/1.0,v -\
quxc/1.0~ - .svn/ignmod - .sos/ignmod {}
{* *} {lappend tserr '$f'}
default {lappend tserr $f}
}
}
set tserr_avail1 [join $tserr \n]
testouterr_cmd sh {avail -a -t -o } OK $tserr_avail1
set tserr_avail2 [join {foo/2.0 foo/4.0 foo/5.0 foo/6.0} \n]
testouterr_cmd sh {avail -a -t -o foo} OK $tserr_avail2
set tserr_whatis1 "$modlin [escre $mp1] $modlin
\\s+bar/1.0: bar/1.0
\\s+bar/2.0: bar/2.0
\\s+baz/w s: baz/w s
\\s+baz/w\"s: baz/w\"s
\\s+baz/w#s: baz/w#s
\\s+foo/2.0: foo/2.0
\\s+quux/oth/3.0: quux/oth/3.0
\\s+quux/oth/4.0: quux/oth/4.0
\\s+quux/sub/1.0: quux/sub/1.0
\\s+quux/sub/2.0: quux/sub/2.0
\\s+quxa/1.0: quxa/1.0
\\s+quxb/1.0: quxb/1.0
\\s+quxc/1.0: quxc/1.0
\\s+quxd/1.0: quxd/1.0
\\s+quxe/1.0: quxe/1.0
\\s+w s/1.0: w s/1.0
\\s+w\"s/1.0: w\"s/1.0
\\s+w#s/1.0: w#s/1.0"
testouterr_cmd_re sh whatis OK $tserr_whatis1
set tserr_whatis2 "$modlin [escre $mp1] $modlin
\\s+baz/w s: baz/w s
\\s+baz/w\"s: baz/w\"s
\\s+baz/w#s: baz/w#s"
testouterr_cmd_re sh {whatis baz} OK $tserr_whatis2
set ans_load1 [list]
lappend ans_load1 [list set __MODULES_LMALTNAME bar/1.0&bar/default&bar]
lappend ans_load1 [list set _LMFILES_ $mp1/bar/1.0]
lappend ans_load1 [list set LOADEDMODULES bar/1.0]
testouterr_cmd sh {load bar} $ans_load1 {}
set tserr_load2 "$err_magic'$mp1/foo/.modulerc'\n$err_contact
$err_magic'$mp1/foo/1.0'\n$err_contact"
testouterr_cmd sh {load foo/1.0} ERR $tserr_load2
set tserr_load3 "$err_magic'$mp1/foo/.modulerc'\n$err_contact
[moderr_minverreq $mp1/foo/3.0 99]"
testouterr_cmd sh {load foo/3.0} ERR $tserr_load3
set tserr_load4 "$err_magic'[escre $mp1]/foo/.modulerc'\n$err_contact
[escre [msg_load foo/5.0 [msg_moderr {missing close-brace} if\ \{<EXM> $mp1/foo/5.0 2]]]"
testouterr_cmd_re sh {load foo/5.0} ERR $tserr_load4
set ans_load5 [list]
lappend ans_load5 [list set __MODULES_LMALTNAME .hid/1.0&as|.hid/default&as|.hid/latest]
lappend ans_load5 [list set _LMFILES_ $mp1/.hid/1.0]
lappend ans_load5 [list set LOADEDMODULES .hid/1.0]
testouterr_cmd sh {load .hid} $ans_load5 {}
# delete generated cache file
file delete $mp1cache
# clean setup prior quitting if quick mode
if {[is_quick_mode]} {
delete_module_setup $mp1 [array names file_arr] $dir_list
}
skip_if_quick_mode
# same tests without a cache (should get same result)
testouterr_cmd sh {avail -a -t -o } OK $tserr_avail1
testouterr_cmd sh {avail -a -t -o foo} OK $tserr_avail2
testouterr_cmd_re sh whatis OK $tserr_whatis1
testouterr_cmd_re sh {whatis baz} OK $tserr_whatis2
testouterr_cmd sh {load bar} $ans_load1 {}
testouterr_cmd sh {load foo/1.0} ERR $tserr_load2
testouterr_cmd sh {load foo/3.0} ERR $tserr_load3
testouterr_cmd_re sh {load foo/5.0} ERR $tserr_load4
testouterr_cmd sh {load .hid} $ans_load5 {}
# tests with empty cache file
create_dummy_cachefile $mp1
testouterr_cmd sh {avail -a -t -o } OK {}
testouterr_cmd sh {avail -a -t -o foo} OK {}
testouterr_cmd_re sh whatis OK {}
testouterr_cmd_re sh {whatis baz} ERR $err_path'baz'
testouterr_cmd sh {load bar} ERR $err_path'bar'
testouterr_cmd sh {load foo/1.0} ERR $err_path'foo/1.0'
testouterr_cmd sh {load foo/3.0} ERR $err_path'foo/3.0'
testouterr_cmd sh {load foo/5.0} ERR $err_path'foo/5.0'
testouterr_cmd sh {load .hid} ERR $err_path'.hid'
file delete $mp1cache
# tests with a cache containing only few elements
set fid [open $mp1cache w]
puts $fid "#%Module$::major_minor_rel
modulefile-content bar/1.0 1664035017 #%Module #%Module"
close $fid
testouterr_cmd sh {avail -a -t -o } OK bar/1.0
testouterr_cmd sh {avail -a -t -o foo} OK {}
set tserr "- Package/Alias $modlin.- Versions $modlin.- Last mod. $modlin
[escre $mp1]:
bar/1.0\\s+[clock format 1664035017 -format {%Y/%m/%d %H:%M:%S}]"
testouterr_cmd_re sh {avail -l} OK $tserr
testouterr_cmd_re sh whatis OK {}
testouterr_cmd_re sh {whatis baz} ERR $err_path'baz'
set ans [list]
lappend ans [list set __MODULES_LMALTNAME bar/1.0&as|bar/default&as|bar/latest]
lappend ans [list set _LMFILES_ $mp1/bar/1.0]
lappend ans [list set LOADEDMODULES bar/1.0]
testouterr_cmd sh {load bar} $ans {}
testouterr_cmd sh {load foo/1.0} ERR $err_path'foo/1.0'
testouterr_cmd sh {load foo/3.0} ERR $err_path'foo/3.0'
testouterr_cmd sh {load foo/5.0} ERR $err_path'foo/5.0'
testouterr_cmd sh {load .hid} ERR $err_path'.hid'
file delete $mp1cache
# test with an empty file (no module header)
close [open $mp1cache w]
testouterr_cmd sh {avail -a -t -o } OK $tserr_avail1
testouterr_cmd sh {avail -a -t -o foo} OK $tserr_avail2
testouterr_cmd_re sh whatis OK $tserr_whatis1
testouterr_cmd_re sh {whatis baz} OK $tserr_whatis2
set ans_load1b [list]
lappend ans_load1b [list set __MODULES_LMALTNAME bar/1.0&bar/default&bar]
lappend ans_load1b [list set _LMFILES_ $mp1/bar/1.0]
lappend ans_load1b [list set LOADEDMODULES bar/1.0]
lappend ans_load1b [list ERR]
testouterr_cmd sh {load bar} $ans_load1b [cacheerr_magic $mp1cache]
testouterr_cmd sh {load foo/1.0} ERR [cacheerr_magic $mp1cache]\n$tserr_load2
testouterr_cmd sh {load foo/3.0} ERR [cacheerr_magic $mp1cache]\n$tserr_load3
testouterr_cmd_re sh {load foo/5.0} ERR [cacheerr_magic [escre $mp1cache]]\n$tserr_load4
set ans_load5b [list]
lappend ans_load5b [list set __MODULES_LMALTNAME .hid/1.0&as|.hid/default&as|.hid/latest]
lappend ans_load5b [list set _LMFILES_ $mp1/.hid/1.0]
lappend ans_load5b [list set LOADEDMODULES .hid/1.0]
lappend ans_load5b [list ERR]
testouterr_cmd sh {load .hid} $ans_load5b [cacheerr_magic $mp1cache]
file delete $mp1cache
# test with a module header without version specification
set fid [open $mp1cache w]
puts $fid "#%Module
modulefile-content bar/1.0 1664035017 #%Module #%Module"
close $fid
testouterr_cmd sh {avail -a -t -o } OK $tserr_avail1
testouterr_cmd sh {avail -a -t -o foo} OK $tserr_avail2
testouterr_cmd sh {load bar} $ans_load1b [cacheerr_misverreq $mp1cache]
file delete $mp1cache
# test with a module header with required version too high
set fid [open $mp1cache w]
puts $fid "#%Module99
modulefile-content bar/1.0 1664035017 #%Module #%Module"
close $fid
testouterr_cmd sh {avail -a -t -o } OK $tserr_avail1
testouterr_cmd sh {avail -a -t -o foo} OK $tserr_avail2
testouterr_cmd sh {load bar} $ans_load1b [cacheerr_minverreq $mp1cache 99]
file delete $mp1cache
# tests with a cache containing element that does not exists anymore in modulepath
set fid [open $mp1cache w]
puts $fid "#%Module$::major_minor_rel
modulefile-content bar/5.0 1664035017 #%Module #%Module"
close $fid
testouterr_cmd sh {avail -a -t -o } OK bar/5.0
set tserr "- Package/Alias $modlin.- Versions $modlin.- Last mod. $modlin
[escre $mp1]:
bar/5.0\\s+[clock format 1664035017 -format {%Y/%m/%d %H:%M:%S}]"
testouterr_cmd_re sh {avail -l} OK $tserr
set ans [list]
lappend ans [list set __MODULES_LMALTNAME bar/5.0&as|bar/default&as|bar/latest]
lappend ans [list set _LMFILES_ $mp1/bar/5.0]
lappend ans [list set LOADEDMODULES bar/5.0]
testouterr_cmd sh {load bar} $ans {}
file delete $mp1cache
# test potential double cache evaluation situation
setenv_var MODULEPATH $mp2
file mkdir $mp2
set fid [open $mp2/foo w]
puts $fid {#%Module
if {[is-avail bar]} {
module load bar
}
}
close $fid
create_dummy_modulefile $mp2/bar
set tserr [msg_create $mp2cache]
testouterr_cmd sh cachebuild OK $tserr
set ans [list]
lappend ans [list set __MODULES_LMPREREQ foo&bar]
lappend ans [list set _LMFILES_ $mp2/bar:$mp2/foo]
lappend ans [list set LOADEDMODULES bar:foo]
lappend ans [list set __MODULES_LMTAG bar&auto-loaded]
set tserr ".*
DEBUG findModulesInCacheFile: cache file '[escre $mp2cache]' exists and is readable
.*
DEBUG findModulesInCacheFile: 2 elements are cached for '[escre $mp2]'
DEBUG findModulesInCacheFile: 0 limited access files for '[escre $mp2]'
DEBUG findModulesInCacheFile: 0 limited access dirs for '[escre $mp2]'
.*
DEBUG findModulesInCacheFile: found foo \\(1\\)
.*
DEBUG \\\[#1:load:foo\\\] findModulesInCacheFile: cache file '[escre $mp2cache]' has already been evaluated
DEBUG \\\[#1:load:foo\\\] findModulesInCacheFile: 2 elements are cached for '[escre $mp2]'
DEBUG \\\[#1:load:foo\\\] findModulesInCacheFile: 0 limited access files for '[escre $mp2]'
DEBUG \\\[#1:load:foo\\\] findModulesInCacheFile: 0 limited access dirs for '[escre $mp2]'
DEBUG \\\[#1:load:foo\\\] findModulesInCacheFile: found bar \\(1\\)
.*"
testouterr_cmd_re sh {load foo -D} $ans $tserr
file delete $mp2cache
file delete $mp2/bar
file delete $mp2/foo
file delete $mp2
# test over a modulepath containing a space character
# skip test on MSYS platform or if symlink creation is not supported
if {$is_symlink_supported && ![regexp {^MSYS_NT.*} $tcl_platform(os)]} {
set mpws "$env(HOME)/mp ws"
set mpwscache $mpws/.modulecache
file link -symbolic $mpws $mp1
setenv_var MODULEPATH $mpws
set tserr [msg_create '$mpwscache']
testouterr_cmd sh cachebuild OK $tserr
testouterr_cmd sh {avail -a -t -o } OK $tserr_avail1
testouterr_cmd sh {avail -a -t -o foo} OK $tserr_avail2
set tserr "$modlin [escre $mpws] $modlin
\\s+bar/1.0: bar/1.0
\\s+bar/2.0: bar/2.0
\\s+baz/w s: baz/w s
\\s+baz/w\"s: baz/w\"s
\\s+baz/w#s: baz/w#s
\\s+foo/2.0: foo/2.0
\\s+quux/oth/3.0: quux/oth/3.0
\\s+quux/oth/4.0: quux/oth/4.0
\\s+quux/sub/1.0: quux/sub/1.0
\\s+quux/sub/2.0: quux/sub/2.0
\\s+quxa/1.0: quxa/1.0
\\s+quxb/1.0: quxb/1.0
\\s+quxc/1.0: quxc/1.0
\\s+quxd/1.0: quxd/1.0
\\s+quxe/1.0: quxe/1.0
\\s+w s/1.0: w s/1.0
\\s+w\"s/1.0: w\"s/1.0
\\s+w#s/1.0: w#s/1.0"
testouterr_cmd_re sh whatis OK $tserr
set tserr "$modlin [escre $mpws] $modlin
\\s+baz/w s: baz/w s
\\s+baz/w\"s: baz/w\"s
\\s+baz/w#s: baz/w#s"
testouterr_cmd_re sh {whatis baz} OK $tserr
set ans [list]
lappend ans [list set __MODULES_LMALTNAME bar/1.0&bar/default&bar]
lappend ans [list set _LMFILES_ $mpws/bar/1.0]
lappend ans [list set LOADEDMODULES bar/1.0]
testouterr_cmd sh {load bar} $ans {}
set tserr "$err_magic'$mpws/foo/.modulerc'\n$err_contact
$err_magic'$mpws/foo/1.0'\n$err_contact"
testouterr_cmd sh {load foo/1.0} ERR $tserr
set tserr "$err_magic'$mpws/foo/.modulerc'\n$err_contact
[moderr_minverreq $mpws/foo/3.0 99]"
testouterr_cmd sh {load foo/3.0} ERR $tserr
set tserr "$err_magic'[escre $mpws]/foo/.modulerc'\n$err_contact
[escre [msg_load foo/5.0 [msg_moderr {missing close-brace} if\ \{<EXM> $mpws/foo/5.0 2]]]"
testouterr_cmd_re sh {load foo/5.0} ERR $tserr
set ans [list]
lappend ans [list set __MODULES_LMALTNAME .hid/1.0&as|.hid/default&as|.hid/latest]
lappend ans [list set _LMFILES_ $mpws/.hid/1.0]
lappend ans [list set LOADEDMODULES .hid/1.0]
testouterr_cmd sh {load .hid} $ans {}
file delete $mpwscache
file delete $mpws
}
# test symbol/tag resolution
setenv_var MODULEPATH $mp1
set tserr [msg_create $mp1cache]
testouterr_cmd sh cachebuild OK $tserr
set tserr "$mp1:
quux/oth/(default)
quux/oth/3.0(sym) <bar>
quux/oth/4.0
quux/sub/1.0 <foo>
quux/sub/2.0"
testouterr_cmd sh {avail -t quux} OK $tserr
# test indepth/noindepth resolution
set tserr "$mp1:
bar/
baz/
foo/
quux/
quxa/
quxb/
quxc/
quxd/
quxe/
'w s'/
w\"s/
w#s/"
testouterr_cmd sh {avail -t --no-indepth} OK $tserr
set tserr "$mp1:
quux/"
testouterr_cmd sh {avail -t --no-indepth quux} OK $tserr
set tserr "$mp1:
quux/oth/(default)
quux/sub/"
testouterr_cmd sh {avail -t --no-indepth quux/} OK $tserr
testouterr_cmd sh {avail -t --no-indepth quux/*} OK $tserr
set tserr "$mp1:
quux/oth/(default)"
testouterr_cmd sh {avail -t --no-indepth quux/o} OK $tserr
set tserr ""
testouterr_cmd sh {avail -t --no-indepth quux/nok} OK $tserr
testouterr_cmd sh {avail -t --no-indepth quux/no} OK $tserr
file delete $mp1cache
# test debug output
setenv_var MODULEPATH $mp2
lassign [create_simple_module_setup $mp2] other_dir_list other_file_list
array set other_file_arr $other_file_list
set tserr [msg_create $mp2cache]
testouterr_cmd sh cachebuild OK $tserr
set tserr ".*
DEBUG findModulesInCacheFile: cache file '[escre $mp2]/.modulecache' exists and is readable
.*
DEBUG findModulesInCacheFile: 4 elements are cached for '[escre $mp2]'
DEBUG findModulesInCacheFile: 0 limited access files for '[escre $mp2]'
DEBUG findModulesInCacheFile: 0 limited access dirs for '[escre $mp2]'
.*
DEBUG findModulesInCacheFile: found foo/.modulerc foo/1.0 \\(2\\)
.*"
testouterr_cmd_re sh {avail -D -t foo/1.0} OK $tserr
set tserr ".*
DEBUG findModulesInCacheFile: cache file '[escre $mp2]/.modulecache' exists and is readable
DEBUG setConf: cache_expiry_secs set to '0'
DEBUG findModulesInCacheFile: execute-cachefile [escre $mp2]/.modulecache [escre $mp2]
.*
DEBUG findModulesInCacheFile: 4 elements are cached for '[escre $mp2]'
.*
DEBUG findModulesInCacheFile: found foo/.modulerc foo/1.0 \\(2\\)
.*"
testouterr_cmd_re sh {avail -DD -t foo/1.0} OK $tserr
set tserr ".*
TIMER findModulesInCacheFile [escre $mp2] foo 0 0 \\(.* ms\\)
.*
[escre $mp2]:
foo/1.0
.*"
testouterr_cmd_re sh {avail -D --timer -t foo/1.0} OK $tserr
testouterr_cmd_re sh {avail -DD --timer -t foo/1.0} OK $tserr
set tserr ".*
Get modules: {} matching 'foo/1.0' in ''
Evaluate cache file: '[escre $mp2cache]'
Evaluate modulerc: '[escre $mp2]/foo/.modulerc'
Get modules: {foo/1.0} matching 'foo/1.0' in '[escre $mp2]'
[escre $mp2]:
foo/1.0"
testouterr_cmd_re sh {avail -T -t foo/1.0} OK $tserr
file delete $mp2cache
set tserr ".*
Get modules: {} matching 'foo/1.0' in ''
Evaluate modulerc: '[escre $mp2]/foo/.modulerc'
Get modules: {foo/1.0} matching 'foo/1.0' in '[escre $mp2]'
[escre $mp2]:
foo/1.0"
testouterr_cmd_re sh {avail -T -t foo/1.0} OK $tserr
# cache usage when mcookie_check is set to eval (same result as if
# option is set to always)
setenv_path_var MODULEPATH $mp1
set tserr [msg_create $mp1cache]
testouterr_cmd sh cachebuild OK $tserr
setenv_var MODULES_MCOOKIE_CHECK eval
testouterr_cmd sh {avail -a -t -o } OK $tserr_avail1
testouterr_cmd sh {avail -a -t -o foo} OK $tserr_avail2
testouterr_cmd_re sh whatis OK $tserr_whatis1
testouterr_cmd_re sh {whatis baz} OK $tserr_whatis2
testouterr_cmd sh {load bar} $ans_load1 {}
testouterr_cmd sh {load foo/1.0} ERR $tserr_load2
testouterr_cmd sh {load foo/3.0} ERR $tserr_load3
testouterr_cmd_re sh {load foo/5.0} ERR $tserr_load4
testouterr_cmd sh {load .hid} $ans_load5 {}
setenv_var MODULES_MCOOKIE_CHECK always
# cache usage when mcookie_version_check is disabled (same result as if
# option is enabled)
setenv_var MODULES_MCOOKIE_VERSION_CHECK 0
testouterr_cmd sh {avail -a -t -o } OK $tserr_avail1
testouterr_cmd sh {avail -a -t -o foo} OK $tserr_avail2
testouterr_cmd_re sh whatis OK $tserr_whatis1
testouterr_cmd_re sh {whatis baz} OK $tserr_whatis2
testouterr_cmd sh {load bar} $ans_load1 {}
testouterr_cmd sh {load foo/1.0} ERR $tserr_load2
testouterr_cmd sh {load foo/3.0} ERR $tserr_load3
testouterr_cmd_re sh {load foo/5.0} ERR $tserr_load4
testouterr_cmd sh {load .hid} $ans_load5 {}
setenv_var MODULES_MCOOKIE_VERSION_CHECK 1
file delete $mp1cache
# 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 noread_perms ugo-r
# check expected siteconfig file is installed
set is_stderr_tty [siteconfig_isStderrTty]
if {$is_stderr_tty} {
# test a cache read failure by faking cache file is readable
setenv_var TESTSUITE_ENABLE_SITECONFIG_CACHE_READ 1
create_dummy_cachefile $mp1
change_file_perms $mp1cache $noread_perms
testouterr_cmd sh {avail -a -t -o } OK $tserr_avail1
testouterr_cmd sh {load bar} $ans_load1b [err_permdenied $mp1cache]
restore_file_perms $mp1cache
file delete $mp1cache
unsetenv_var TESTSUITE_ENABLE_SITECONFIG_CACHE_READ
}
}
#
# Cleanup
#
# delete created files and dirs
delete_module_setup $mp1 [array names file_arr] $dir_list
delete_module_setup $mp2 [array names other_file_arr] $other_dir_list
reset_test_env