############################################################################## # Modules Revision 3.0 # Providing a flexible user environment # # File: modules.30-cache/%M% # Revision: %I% # First Edition: 2022/11/13 # Last Mod.: %U%, %G% # # Authors: Xavier Delaruelle, xavier.delaruelle@cea.fr # # Description: Testuite testsequence # Command: cachebuild # Modulefiles: # Sub-Command: # # Comment: %C{ # Test cachebuild sub-command # }C% # ############################################################################## # filesystem on Cygwin platform is responding in an unexpected way # skip these tests on this platform for now skip_if_os_in cygwin # no modulepath defined unsetenv_path_var MODULEPATH set tserr "$error_msgs: $msg_nomodpath" testouterr_cmd sh cachebuild ERR $tserr # empty modulepath setenv_path_var MODULEPATH {} testouterr_cmd sh cachebuild OK {} # create modulepaths for tests set mp1 $env(HOME)/mp1 set mp2 $env(HOME)/mp2 set mp1cache $mp1/.modulecache set mp2cache $mp2/.modulecache set mp1modfile $mp1/foo set mp2modfile $mp2/bar set mpunk $env(HOME)/mpunk set mpfile $mp1/qux file mkdir $mp1 file mkdir $mp2 # 2 modulepath set, cache to build in first, empty second setenv_path_var MODULEPATH $mp1:$mp2 create_dummy_modulefile $mp1modfile set tserr [msg_create $mp1cache]\n\n[msg_create $mp2cache $warn_cache_nothingtorec] set tscache "#%Module$cache_mcookie_version" append tscache \n[list modulefile-content foo [file mtime $mp1modfile] #%Module #%Module\n] testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache file delete $mp1modfile # cache file already exist in first, empty second modulepath create_dummy_modulefile $mp1modfile create_dummy_cachefile $mp1 set tserr [msg_create $mp1cache]\n\n[msg_create $mp2cache $warn_cache_nothingtorec] set tscache "#%Module$cache_mcookie_version" append tscache \n[list modulefile-content foo [file mtime $mp1modfile] #%Module #%Module\n] testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache file delete $mp1modfile file delete $mp1cache file delete $mp1 file delete $mp2 skip_if_quick_mode file mkdir $mp1 file mkdir $mp2 close [open $mpfile w] # silent mode create_dummy_modulefile $mp1modfile set tscache "#%Module$cache_mcookie_version" append tscache \n[list modulefile-content foo [file mtime $mp1modfile] #%Module #%Module\n] append tscache \n[list modulefile-invalid qux invalid {Magic cookie '#%Module' missing}] testouterrfile_cmd sh {cachebuild -s} OK {} $mp1cache $tscache # verbose mode set tserr [msg_create $mp1cache]\n\n[msg_create $mp2cache $warn_cache_nothingtorec] testouterrfile_cmd sh {cachebuild -v} OK $tserr $mp1cache $tscache file delete $mp1modfile file delete $mp1cache # unexistent modulepath, then cache to build in next path create_dummy_modulefile $mp2modfile setenv_path_var MODULEPATH $mpunk:$mp2 set tserr [msg_create $mpunk/.modulecache "$error_msgs: '$mpunk' is not a directory"]\n\n[msg_create $mp2cache] set tscache "#%Module$cache_mcookie_version" append tscache \n[list modulefile-content bar [file mtime $mp2modfile] #%Module #%Module\n] testouterrfile_cmd sh cachebuild ERR $tserr $mp2cache $tscache # modulepath is a file, then cache to build in next path setenv_path_var MODULEPATH $mpfile:$mp2 set tserr [msg_create $mpfile/.modulecache "$error_msgs: '$mpfile' is not a directory"]\n\n[msg_create $mp2cache] testouterrfile_cmd sh cachebuild ERR $tserr $mp2cache $tscache file delete $mp2modfile file delete $mp2cache # unexistent and file modulepaths passed as argument setenv_path_var MODULEPATH $mp1:$mp2 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"] testouterr_cmd sh "cachebuild $mpunk $mpfile" ERR $tserr file delete $mpfile # empty string modulepath passed as argument set tserr [msg_create /.modulecache "$error_msgs: '' is not a directory"] testouterr_cmd sh "cachebuild " ERR $tserr # 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 nowrite_perms ugo-w set noread_perms ugo-r set nosearch_perms ugo-x # first modulepath not writable, no module content in it setenv_path_var MODULEPATH $mp1:$mp2 change_file_perms $mp1 $nowrite_perms create_dummy_modulefile $mp2modfile set tserr [msg_create $mp1cache $warn_cache_build_nowritable]\n\n[msg_create $mp2cache] set tscache "#%Module$cache_mcookie_version" append tscache \n[list modulefile-content bar [file mtime $mp2modfile] #%Module #%Module\n] testouterrfile_cmd sh cachebuild OK $tserr $mp2cache $tscache set tscache [couldnotopen_nofile $mp1cache] testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache restore_file_perms $mp1 file delete $mp2modfile # first modulepath not writable, module content in it create_dummy_modulefile $mp1modfile create_dummy_modulefile $mp2modfile change_file_perms $mp1 $nowrite_perms set tserr [msg_create $mp1cache $warn_cache_build_nowritable]\n\n[msg_create $mp2cache] set tscache "#%Module$cache_mcookie_version" append tscache \n[list modulefile-content bar [file mtime $mp2modfile] #%Module #%Module\n] testouterrfile_cmd sh cachebuild OK $tserr $mp2cache $tscache set tscache [couldnotopen_nofile $mp1cache] testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache restore_file_perms $mp1 file delete $mp1modfile file delete $mp2modfile file delete $mp2cache # both modulepath not writable, module content in them create_dummy_modulefile $mp1modfile create_dummy_modulefile $mp2modfile change_file_perms $mp1 $nowrite_perms change_file_perms $mp2 $nowrite_perms set tserr [msg_create $mp1cache $warn_cache_build_nowritable]\n\n[msg_create $mp2cache $warn_cache_build_nowritable] set tscache [couldnotopen_nofile $mp2cache] testouterrfile_cmd sh cachebuild OK $tserr $mp2cache $tscache set tscache [couldnotopen_nofile $mp1cache] testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache restore_file_perms $mp1 restore_file_perms $mp2 file delete $mp1modfile file delete $mp2modfile # first modulepath not readable, second not searchable, module content in them create_dummy_modulefile $mp1modfile create_dummy_modulefile $mp2modfile change_file_perms $mp1 $noread_perms change_file_perms $mp2 $nosearch_perms set tserr [msg_create $mp1cache $warn_cache_nothingtorec]\n\n[msg_create $mp2cache [err_couldnotopen_permdenied $mp2cache]] set tscache [couldnotopen_permdenied $mp2cache] testouterrfile_cmd sh cachebuild ERR $tserr $mp2cache $tscache set tscache [couldnotopen_nofile $mp1cache] testouterrfile_cmd sh cachebuild ERR $tserr $mp1cache $tscache restore_file_perms $mp1 restore_file_perms $mp2 file delete $mp1modfile file delete $mp2modfile # modulepath writable, no module content in first path create_dummy_modulefile $mp2modfile set tserr [msg_create $mp1cache $warn_cache_nothingtorec]\n\n[msg_create $mp2cache] set tscache [couldnotopen_nofile $mp1cache] testouterrfile_cmd sh cachebuild OK $tserr $mp1cache $tscache file delete $mp2modfile # modulepath writable, pre-existing cache files: not readable in first, not writable in second create_dummy_modulefile $mp1modfile create_dummy_modulefile $mp2modfile create_dummy_cachefile $mp1 create_dummy_cachefile $mp2 change_file_perms $mp1cache $noread_perms change_file_perms $mp2cache $nowrite_perms set tserr [msg_create $mp1cache]\n\n[msg_create $mp2cache [err_couldnotopen_permdenied $mp2cache]] set tscache [couldnotopen_permdenied $mp1cache] testouterrfile_cmd sh cachebuild ERR $tserr $mp1cache $tscache set tscache "#%Module$cache_mcookie_version" testouterrfile_cmd sh cachebuild ERR $tserr $mp2cache $tscache file delete $mp1modfile file delete $mp2modfile file delete $mp1cache file delete $mp2cache # modulepath writable passed as argument, pre-existing cache files: not readable in first, not writable in second setenv_path_var MODULEPATH $mpunk create_dummy_modulefile $mp1modfile create_dummy_modulefile $mp2modfile create_dummy_cachefile $mp1 create_dummy_cachefile $mp2 change_file_perms $mp1cache $noread_perms change_file_perms $mp2cache $nowrite_perms set tserr [msg_create $mp1cache]\n\n[msg_create $mp2cache [err_couldnotopen_permdenied $mp2cache]] set tscache [couldnotopen_permdenied $mp1cache] testouterrfile_cmd sh "cachebuild $mp1 $mp2" ERR $tserr $mp1cache $tscache set tscache "#%Module$cache_mcookie_version" set tserr [msg_create $mp2cache [err_couldnotopen_permdenied $mp2cache]]\n\n[msg_create $mp1cache] testouterrfile_cmd sh "cachebuild $mp2 $mp1" ERR $tserr $mp2cache $tscache file delete $mp1modfile file delete $mp2modfile file delete $mp1cache file delete $mp2cache setenv_path_var MODULEPATH $mp1:$mp2 # check expected siteconfig file is installed set is_stderr_tty [siteconfig_isStderrTty] if {$is_stderr_tty} { # test a file creation failure by faking modulepath directory is writable setenv_var TESTSUITE_ENABLE_SITECONFIG_CACHEBUILD_CREATE 1 create_dummy_modulefile $mp1modfile create_dummy_modulefile $mp2modfile change_file_perms $mp1 $nowrite_perms set tserr [msg_create $mp1cache [err_couldnotopen_permdenied $mp1cache]]\n\n[msg_create $mp2cache] set tscache "#%Module$cache_mcookie_version" append tscache \n[list modulefile-content bar [file mtime $mp2modfile] #%Module #%Module\n] testouterrfile_cmd sh cachebuild ERR $tserr $mp2cache $tscache set tscache [couldnotopen_nofile $mp1cache] testouterrfile_cmd sh cachebuild ERR $tserr $mp1cache $tscache restore_file_perms $mp1 file delete $mp1modfile file delete $mp2modfile file delete $mp2cache unsetenv_var TESTSUITE_ENABLE_SITECONFIG_CACHEBUILD_CREATE } } # # Cleanup # file delete $mp1 file delete $mp2 reset_test_env