############################################################################## # Modules Revision 3.0 # Providing a flexible user environment # # File: modules.00-init/%M% # Revision: %I% # First Edition: 2017/11/02 # Last Mod.: %U%, %G% # # Authors: Xavier Delaruelle, xavier.delaruelle@cea.fr # # Description: Testuite testsequence # Command: # Sub-Command: # # Comment: %C{ # Check runtime quarantine mechanism of environment variables. # }C% # ############################################################################## # Test handling of quarantine-related variables, full runtime quarantine # test is made in the install testsuite. if {$install_quarantinesupport eq y} { set modfile "$env(TESTSUITEDIR)/modulefiles.2/quar" # set to mimic key variable transmitted by module shell function to tell some # quarantine setup has been made setenv_var __MODULES_QUARANTINE_SET 1 # no quarantine setup, nothing should be set testouterr_cmd "ALL" "source $modfile" "OK" "" # empty quarantine setup set quar "" if {$verbose} { send_user "\tSetup MODULES_RUN_QUARANTINE = '$quar'\n" } set env(MODULES_RUN_QUARANTINE) $quar set ans [list] lappend ans "MODULES_RUN_QUARANTINE=$quar" testouterr_cmd "ALL" "source $modfile" "OK" [join $ans "\n"] skip_if_quick_mode # one quarantine variable, no env value, no runtime value: nop set quar "BAR" if {$verbose} { send_user "\tSetup MODULES_RUN_QUARANTINE = '$quar'\n" send_user "\tUnset BAR\n" } set env(MODULES_RUN_QUARANTINE) $quar if {[info exists env(BAR)]} { unset env(BAR) } set ans [list] lappend ans "MODULES_RUN_QUARANTINE=$quar" testouterr_cmd "ALL" "source $modfile" "OK" [join $ans "\n"] # one quarantine variable, no env value, with runtime value: envvar set, quarvar unset set runenv1 "value valpart2 valspe\"ci\"al" if {$verbose} { send_user "\tSetup MODULES_RUNENV_BAR = '$runenv1'\n" send_user "\tSetup BAR = '$runenv1'\n" } set env(MODULES_RUNENV_BAR) $runenv1 set env(BAR) $runenv1 set ans [list] lappend ans "MODULES_RUN_QUARANTINE=$quar" lappend ans "MODULES_RUNENV_BAR=$runenv1" # quarantine mechanism also applies to csh/tcsh by modulecmd.tcl but as it is not # implemented in module shell alias, the __MODULES_QUARANTINE_SET is never defined # by this shell so the mechanism is in real life situation never activated foreach shell $supported_shells { testouterr_cmd "$shell" "source $modfile" "OK" [join $ans "\n"] } # one quarantine variable, with env value, no runtime value: envvar empty, quarvar set set env1 "orig" if {$verbose} { send_user "\tUnset MODULES_RUNENV_BAR\n" } unset env(MODULES_RUNENV_BAR) setenv_var __MODULES_QUAR_BAR $env1 setenv_var BAR {} set ans [list] lappend ans "MODULES_RUN_QUARANTINE=$quar" lappend ans "BAR=$env1" foreach shell $supported_shells { testouterr_cmd "$shell" "source $modfile" "OK" [join $ans "\n"] } # one quarantine variable, with env value, with runtime value: envar set, quarvar set if {$verbose} { send_user "\tSetup MODULES_RUNENV_BAR = '$runenv1'\n" send_user "\tSetup BAR = '$runenv1'\n" } set env(MODULES_RUNENV_BAR) $runenv1 set env(BAR) $runenv1 set ans [list] lappend ans "MODULES_RUN_QUARANTINE=$quar" lappend ans "BAR=$env1" lappend ans "MODULES_RUNENV_BAR=$runenv1" foreach shell $supported_shells { testouterr_cmd "$shell" "source $modfile" "OK" [join $ans "\n"] } # one good quarantine variable (with env value & runtime value) among bad variable names set quar "BAR F:OO B\\AD 0BAD" if {$verbose} { send_user "\tSetup MODULES_RUN_QUARANTINE = '$quar'\n" } set env(MODULES_RUN_QUARANTINE) $quar set ans [list] lappend ans "$warn_msgs: Bad variable name set in MODULES_RUN_QUARANTINE (F:OO)" lappend ans "$warn_msgs: Bad variable name set in MODULES_RUN_QUARANTINE (B\\AD)" lappend ans "$warn_msgs: Bad variable name set in MODULES_RUN_QUARANTINE (0BAD)" lappend ans "MODULES_RUN_QUARANTINE=$quar" lappend ans "BAR=$env1" lappend ans "MODULES_RUNENV_BAR=$runenv1" foreach shell $supported_shells { testouterr_cmd "$shell" "source $modfile" "OK" [join $ans "\n"] } # two quarantine variables, first with env and runtime, second with env no runtime set quar "BAR FOO" set env2 "orig2 part2 spe\"ci\"al" if {$verbose} { send_user "\tSetup MODULES_RUN_QUARANTINE = '$quar'\n" } set env(MODULES_RUN_QUARANTINE) $quar setenv_var __MODULES_QUAR_FOO $env2 setenv_var FOO {} set ans [list] lappend ans "MODULES_RUN_QUARANTINE=$quar" lappend ans "BAR=$env1" lappend ans "FOO=$env2" lappend ans "MODULES_RUNENV_BAR=$runenv1" foreach shell $supported_shells { testouterr_cmd "$shell" "source $modfile" "OK" [join $ans "\n"] } # mimic if no variable transmitted by module shell function to tell some # quarantine setup has been made unsetenv_var __MODULES_QUARANTINE_SET set ans [list] lappend ans "MODULES_RUN_QUARANTINE=$quar" lappend ans "BAR=$runenv1" lappend ans "FOO=" lappend ans "MODULES_RUNENV_BAR=$runenv1" lappend ans "__MODULES_QUAR_FOO=$env2" lappend ans "__MODULES_QUAR_BAR=$env1" foreach shell $supported_shells { testouterr_cmd "$shell" "source $modfile" "OK" [join $ans "\n"] } # # Clean up variables used in this test case # reset_test_env } elseif {$verbose} { send_user "\tSkipping quarantine mechanism checks\n" } # # Quarantine protection of Tcl sub-interpreter creation (issue #623) # # fake Tcl library directories whose init.tcl script leaves a mark in # environment when sourced by a sub-interpreter then applies the genuine # init.tcl content of the Tcl interpreter running modulecmd. This content # is embedded in the fake script, as raising an error instead would engage # the init.tcl fallback search of tclInit, which panics on Tcl 9.1a1, like # sourcing the genuine init.tcl file when it lies in a zipfs archive. # ::argv only exists in the master interpreter, which also sources this # script when TCL_LIBRARY designates one of these directories set real_tcl_lib [exec $TCLSH << {puts -nonewline [info library]}] set real_init_content [exec $TCLSH << {set fid [open [file join\ [info library] init.tcl] r]; puts -nonewline [read $fid]; close $fid}] set fakelib1 [file join [pwd] faketcllib1] set fakelib2 [file join [pwd] faketcllib2] foreach {fakelib mark} [list $fakelib1 lib1 $fakelib2 lib2] { file mkdir $fakelib set fid [open $fakelib/init.tcl w] puts $fid "if {!\[info exists ::argv\]} {" puts $fid " set ::env(TESTSUITE_FAKE_TCL_INIT) $mark" puts $fid "}" puts $fid "set ::tcl_library {$real_tcl_lib}" puts $fid $real_init_content close $fid } # modulefile reporting mark left by fake Tcl library and TCL_LIBRARY value set modfile [file join [pwd] faketcllib.mod] set fid [open $modfile w] puts $fid {#%Module if {[info exists env(TESTSUITE_FAKE_TCL_INIT)]} { puts stderr "TESTSUITE_FAKE_TCL_INIT=$env(TESTSUITE_FAKE_TCL_INIT)" } if {[info exists env(TCL_LIBRARY)]} { puts stderr "TCL_LIBRARY=$env(TCL_LIBRARY)" }} close $fid setenv_var TCL_LIBRARY $fakelib1 # no quarantine: sub-interpreter initialization is affected by the broken # Tcl library installation found in environment set ans [list] lappend ans "TESTSUITE_FAKE_TCL_INIT=lib1" lappend ans "TCL_LIBRARY=$fakelib1" testouterr_cmd sh "source $modfile" OK [join $ans \n] # variable in quarantine: sub-interpreter creation is protected but variable # is restored afterward for modulefile evaluation setenv_var MODULES_RUN_QUARANTINE TCL_LIBRARY testouterr_cmd sh "source $modfile" OK "TCL_LIBRARY=$fakelib1" # defined runtime value is applied during sub-interpreter creation setenv_var MODULES_RUNENV_TCL_LIBRARY $fakelib2 set ans [list] lappend ans "TESTSUITE_FAKE_TCL_INIT=lib2" lappend ans "TCL_LIBRARY=$fakelib1" testouterr_cmd sh "source $modfile" OK [join $ans \n] # variable initially unset with a defined runtime value: sub-interpreter # should not keep trace of the variable set during its creation once this # variable is unset after this step unsetenv_var TCL_LIBRARY testouterr_cmd sh "source $modfile" OK "TESTSUITE_FAKE_TCL_INIT=lib2" # # Clean up variables used in this test case # file delete -force $fakelib1 $fakelib2 $modfile reset_test_env