Debian Codegraph @

testsuite/modules.00-init/110-quar.exp

raw
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: 2017/11/02
8 # Last Mod.: %U%, %G%
9 #
10 # Authors: Xavier Delaruelle, [email protected]
11 #
12 # Description: Testuite testsequence
13 # Command:
14 # Sub-Command:
15 #
16 # Comment: %C{
17 # Check runtime quarantine mechanism of environment variables.
18 # }C%
19 #
20 ##############################################################################
21
22 # Test handling of quarantine-related variables, full runtime quarantine
23 # test is made in the install testsuite.
24 if {$install_quarantinesupport eq y} {
25
26 set modfile "$env(TESTSUITEDIR)/modulefiles.2/quar"
27
28 # set to mimic key variable transmitted by module shell function to tell some
29 # quarantine setup has been made
30 setenv_var __MODULES_QUARANTINE_SET 1
31
32 # no quarantine setup, nothing should be set
33 testouterr_cmd "ALL" "source $modfile" "OK" ""
34
35
36 # empty quarantine setup
37 set quar ""
38 if {$verbose} {
39 send_user "\tSetup MODULES_RUN_QUARANTINE = '$quar'\n"
40 }
41 set env(MODULES_RUN_QUARANTINE) $quar
42
43 set ans [list]
44 lappend ans "MODULES_RUN_QUARANTINE=$quar"
45
46 testouterr_cmd "ALL" "source $modfile" "OK" [join $ans "\n"]
47
48 skip_if_quick_mode
49
50 # one quarantine variable, no env value, no runtime value: nop
51 set quar "BAR"
52 if {$verbose} {
53 send_user "\tSetup MODULES_RUN_QUARANTINE = '$quar'\n"
54 send_user "\tUnset BAR\n"
55 }
56 set env(MODULES_RUN_QUARANTINE) $quar
57 if {[info exists env(BAR)]} {
58 unset env(BAR)
59 }
60
61 set ans [list]
62 lappend ans "MODULES_RUN_QUARANTINE=$quar"
63
64 testouterr_cmd "ALL" "source $modfile" "OK" [join $ans "\n"]
65
66
67 # one quarantine variable, no env value, with runtime value: envvar set, quarvar unset
68 set runenv1 "value valpart2 valspe\"ci\"al"
69 if {$verbose} {
70 send_user "\tSetup MODULES_RUNENV_BAR = '$runenv1'\n"
71 send_user "\tSetup BAR = '$runenv1'\n"
72 }
73 set env(MODULES_RUNENV_BAR) $runenv1
74 set env(BAR) $runenv1
75
76 set ans [list]
77 lappend ans "MODULES_RUN_QUARANTINE=$quar"
78 lappend ans "MODULES_RUNENV_BAR=$runenv1"
79
80 # quarantine mechanism also applies to csh/tcsh by modulecmd.tcl but as it is not
81 # implemented in module shell alias, the __MODULES_QUARANTINE_SET is never defined
82 # by this shell so the mechanism is in real life situation never activated
83 foreach shell $supported_shells {
84 testouterr_cmd "$shell" "source $modfile" "OK" [join $ans "\n"]
85 }
86
87
88 # one quarantine variable, with env value, no runtime value: envvar empty, quarvar set
89 set env1 "orig"
90 if {$verbose} {
91 send_user "\tUnset MODULES_RUNENV_BAR\n"
92 }
93 unset env(MODULES_RUNENV_BAR)
94 setenv_var __MODULES_QUAR_BAR $env1
95 setenv_var BAR {}
96
97 set ans [list]
98 lappend ans "MODULES_RUN_QUARANTINE=$quar"
99 lappend ans "BAR=$env1"
100
101 foreach shell $supported_shells {
102 testouterr_cmd "$shell" "source $modfile" "OK" [join $ans "\n"]
103 }
104
105
106 # one quarantine variable, with env value, with runtime value: envar set, quarvar set
107 if {$verbose} {
108 send_user "\tSetup MODULES_RUNENV_BAR = '$runenv1'\n"
109 send_user "\tSetup BAR = '$runenv1'\n"
110 }
111 set env(MODULES_RUNENV_BAR) $runenv1
112 set env(BAR) $runenv1
113
114 set ans [list]
115 lappend ans "MODULES_RUN_QUARANTINE=$quar"
116 lappend ans "BAR=$env1"
117 lappend ans "MODULES_RUNENV_BAR=$runenv1"
118
119 foreach shell $supported_shells {
120 testouterr_cmd "$shell" "source $modfile" "OK" [join $ans "\n"]
121 }
122
123
124 # one good quarantine variable (with env value & runtime value) among bad variable names
125 set quar "BAR F:OO B\\AD 0BAD"
126 if {$verbose} {
127 send_user "\tSetup MODULES_RUN_QUARANTINE = '$quar'\n"
128 }
129 set env(MODULES_RUN_QUARANTINE) $quar
130
131 set ans [list]
132 lappend ans "$warn_msgs: Bad variable name set in MODULES_RUN_QUARANTINE (F:OO)"
133 lappend ans "$warn_msgs: Bad variable name set in MODULES_RUN_QUARANTINE (B\\AD)"
134 lappend ans "$warn_msgs: Bad variable name set in MODULES_RUN_QUARANTINE (0BAD)"
135 lappend ans "MODULES_RUN_QUARANTINE=$quar"
136 lappend ans "BAR=$env1"
137 lappend ans "MODULES_RUNENV_BAR=$runenv1"
138
139 foreach shell $supported_shells {
140 testouterr_cmd "$shell" "source $modfile" "OK" [join $ans "\n"]
141 }
142
143
144 # two quarantine variables, first with env and runtime, second with env no runtime
145 set quar "BAR FOO"
146 set env2 "orig2 part2 spe\"ci\"al"
147 if {$verbose} {
148 send_user "\tSetup MODULES_RUN_QUARANTINE = '$quar'\n"
149 }
150 set env(MODULES_RUN_QUARANTINE) $quar
151 setenv_var __MODULES_QUAR_FOO $env2
152 setenv_var FOO {}
153
154 set ans [list]
155 lappend ans "MODULES_RUN_QUARANTINE=$quar"
156 lappend ans "BAR=$env1"
157 lappend ans "FOO=$env2"
158 lappend ans "MODULES_RUNENV_BAR=$runenv1"
159
160 foreach shell $supported_shells {
161 testouterr_cmd "$shell" "source $modfile" "OK" [join $ans "\n"]
162 }
163
164
165 # mimic if no variable transmitted by module shell function to tell some
166 # quarantine setup has been made
167 unsetenv_var __MODULES_QUARANTINE_SET
168
169 set ans [list]
170 lappend ans "MODULES_RUN_QUARANTINE=$quar"
171 lappend ans "BAR=$runenv1"
172 lappend ans "FOO="
173 lappend ans "MODULES_RUNENV_BAR=$runenv1"
174 lappend ans "__MODULES_QUAR_FOO=$env2"
175 lappend ans "__MODULES_QUAR_BAR=$env1"
176
177 foreach shell $supported_shells {
178 testouterr_cmd "$shell" "source $modfile" "OK" [join $ans "\n"]
179 }
180
181
182 #
183 # Clean up variables used in this test case
184 #
185
186 reset_test_env
187
188 } elseif {$verbose} {
189 send_user "\tSkipping quarantine mechanism checks\n"
190 }
191
192
193 #
194 # Quarantine protection of Tcl sub-interpreter creation (issue #623)
195 #
196
197 # fake Tcl library directories whose init.tcl script leaves a mark in
198 # environment when sourced by a sub-interpreter then applies the genuine
199 # init.tcl content of the Tcl interpreter running modulecmd. This content
200 # is embedded in the fake script, as raising an error instead would engage
201 # the init.tcl fallback search of tclInit, which panics on Tcl 9.1a1, like
202 # sourcing the genuine init.tcl file when it lies in a zipfs archive.
203 # ::argv only exists in the master interpreter, which also sources this
204 # script when TCL_LIBRARY designates one of these directories
205 set real_tcl_lib [exec $TCLSH << {puts -nonewline [info library]}]
206 set real_init_content [exec $TCLSH << {set fid [open [file join\
207 [info library] init.tcl] r]; puts -nonewline [read $fid]; close $fid}]
208 set fakelib1 [file join [pwd] faketcllib1]
209 set fakelib2 [file join [pwd] faketcllib2]
210 foreach {fakelib mark} [list $fakelib1 lib1 $fakelib2 lib2] {
211 file mkdir $fakelib
212 set fid [open $fakelib/init.tcl w]
213 puts $fid "if {!\[info exists ::argv\]} {"
214 puts $fid " set ::env(TESTSUITE_FAKE_TCL_INIT) $mark"
215 puts $fid "}"
216 puts $fid "set ::tcl_library {$real_tcl_lib}"
217 puts $fid $real_init_content
218 close $fid
219 }
220
221 # modulefile reporting mark left by fake Tcl library and TCL_LIBRARY value
222 set modfile [file join [pwd] faketcllib.mod]
223 set fid [open $modfile w]
224 puts $fid {#%Module
225 if {[info exists env(TESTSUITE_FAKE_TCL_INIT)]} {
226 puts stderr "TESTSUITE_FAKE_TCL_INIT=$env(TESTSUITE_FAKE_TCL_INIT)"
227 }
228 if {[info exists env(TCL_LIBRARY)]} {
229 puts stderr "TCL_LIBRARY=$env(TCL_LIBRARY)"
230 }}
231 close $fid
232
233 setenv_var TCL_LIBRARY $fakelib1
234
235 # no quarantine: sub-interpreter initialization is affected by the broken
236 # Tcl library installation found in environment
237 set ans [list]
238 lappend ans "TESTSUITE_FAKE_TCL_INIT=lib1"
239 lappend ans "TCL_LIBRARY=$fakelib1"
240 testouterr_cmd sh "source $modfile" OK [join $ans \n]
241
242 # variable in quarantine: sub-interpreter creation is protected but variable
243 # is restored afterward for modulefile evaluation
244 setenv_var MODULES_RUN_QUARANTINE TCL_LIBRARY
245 testouterr_cmd sh "source $modfile" OK "TCL_LIBRARY=$fakelib1"
246
247 # defined runtime value is applied during sub-interpreter creation
248 setenv_var MODULES_RUNENV_TCL_LIBRARY $fakelib2
249 set ans [list]
250 lappend ans "TESTSUITE_FAKE_TCL_INIT=lib2"
251 lappend ans "TCL_LIBRARY=$fakelib1"
252 testouterr_cmd sh "source $modfile" OK [join $ans \n]
253
254 # variable initially unset with a defined runtime value: sub-interpreter
255 # should not keep trace of the variable set during its creation once this
256 # variable is unset after this step
257 unsetenv_var TCL_LIBRARY
258 testouterr_cmd sh "source $modfile" OK "TESTSUITE_FAKE_TCL_INIT=lib2"
259
260
261 #
262 # Clean up variables used in this test case
263 #
264
265 file delete -force $fakelib1 $fakelib2 $modfile
266
267 reset_test_env