Debian Codegraph @

testsuite/install.00-init/060-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/03
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 in real operation
18 # }C%
19 #
20 ##############################################################################
21
22 if {$install_quarantinesupport eq y} {
23
24 # skip quarantine tests if modulecmd.tcl found installed in a path
25 # containing a space character
26 if {[string first { } $install_libexecdir] == -1} {
27
28 set modfile "$env(TESTSUITEDIR)/modulefiles.2/quar"
29
30 # if quarantine configured in init scripts at build time only check
31 # that defined configuration is operational
32 if {$install_quarantinevars ne ""} {
33
34 set ans [list]
35 set ansr [list]
36
37 # if test set LD_PRELOAD to a non-existent lib, ld will shout error
38 if {[lsearch -exact $install_quarlist LD_PRELOAD] != -1} {
39 lappend ans "(ERROR: ld.so: object 'foo'.*)*"
40 lappend ansr "(ERROR: ld.so: object 'foo'.*)*"
41 }
42
43 if {$::install_loadedmodules ne {}} {
44 set lmlist [split $::install_loadedmodules :]
45 for {set i 0} {$i < [llength $lmlist]} {incr i} {
46 set lm [lindex $lmlist $i]
47 set lmmsg "Loading $lm"
48 if {$i == ([llength $lmlist] - 1)} {
49 append lmmsg "(\\nERROR: ld.so: object 'foo'.*)*"
50 }
51 lappend ans $lmmsg
52 lappend ansr $lmmsg
53 }
54 }
55
56 set quar [join $install_quarlist " "]
57 if {$verbose} {
58 send_user "\tAlready configured MODULES_RUN_QUARANTINE = '$quar'\n"
59 }
60 lappend ans "MODULES_RUN_QUARANTINE=$quar"
61 lappend ansr "MODULES_RUN_QUARANTINE=$quar"
62
63 foreach vname $install_quarlist {
64 if {$verbose} {
65 send_user "\tSetup $vname = 'foo'\n"
66 }
67 set env($vname) "foo"
68 lappend ans "$vname=foo"
69 if {$vname eq "LD_LIBRARY_PATH"} {
70 lappend ansr "$vname=.*foo"
71 } else {
72 lappend ansr "$vname=foo"
73 }
74 }
75 foreach vname [lsort $install_quarlist] {
76 if {[info exists install_runenv($vname)]} {
77 if {$verbose} {
78 send_user "\tAlready configured MODULES_RUNENV_$vname = '$install_runenv($vname)'\n"
79 }
80 lappend ans "MODULES_RUNENV_$vname=$install_runenv($vname)"
81 lappend ansr "MODULES_RUNENV_$vname=$install_runenv($vname)"
82 }
83 }
84
85 # if test set LD_PRELOAD to a non-existent lib, ld will shout error
86 if {[lsearch -exact $install_quarlist LD_PRELOAD] != -1} {
87 set postmsg "(\nERROR: ld.so: object 'foo'.*)*"
88 } else {
89 set postmsg {}
90 }
91
92 #
93 # The tests
94 #
95
96 set no_loadedmodules_inject 1
97 foreach shell $shell_list {
98 switch -- $shell {
99 {csh} - {tcsh} {
100 if {$verbose} {
101 send_user "\tskip test for $shell, no quarantine support\n"
102 }
103 }
104 fish {
105 testall_cmd_re "$shell" "module source $modfile" "" [join $ans "\n"]$postmsg 0
106 }
107 default {
108 testall_cmd_re "$shell" "module source $modfile" "" [join $ans "\n"] 0
109 }
110 }
111 }
112 foreach shell $othlang_list {
113 switch -- $shell {
114 {r} {
115 # specific result for R as LD_LIBRARY_PATH value is altered by R on the way
116 testall_cmd_re "$shell" "source,$modfile" "" [join $ansr "\n"]$postmsg 0
117 }
118 default {
119 testall_cmd_re "$shell" "source,$modfile" "" [join $ans "\n"] 0
120 }
121 }
122 }
123 unset no_loadedmodules_inject
124
125 #
126 # Clean up variables used in this test case
127 #
128
129 foreach vname $install_quarlist {
130 unset env($vname)
131 }
132
133 if {[info exists vname]} {
134 unset vname
135 }
136
137 unset postmsg
138
139 # if quarantine has not been configured at build time, check the
140 # whole mechanism in various conditions
141 } else {
142
143 # Create a fake libtcl so file to trip up tclsh
144 if {![catch {exec ldd $install_tclsh} ldd_out]} {
145 regexp {(libtcl\S+so)} $ldd_out libtclname
146 if {[info exists libtclname]} {
147 set testlibfile "$env(TESTSUITEDIR)/$libtclname"
148 if {$verbose} {
149 send_user "\tCreate fake library $testlibfile\n"
150 }
151 set fid [open $testlibfile "a+"]
152 close $fid
153 }
154 }
155
156 #
157 # The tests
158 #
159
160 # no quarantine setup, nothing should be set
161 foreach shell $shell_list {
162 testall_cmd "$shell" "module source $modfile" "" "" 0
163 }
164 foreach shell $othlang_list {
165 testall_cmd "$shell" "source,$modfile" "" "" 0
166 }
167
168
169 # empty quarantine setup
170 set quar ""
171 if {$verbose} {
172 send_user "\tSetup MODULES_RUN_QUARANTINE = '$quar'\n"
173 }
174 set env(MODULES_RUN_QUARANTINE) $quar
175
176 set ans [list]
177 lappend ans "MODULES_RUN_QUARANTINE=$quar"
178
179 foreach shell $shell_list {
180 testall_cmd "$shell" "module source $modfile" "" [join $ans "\n"] 0
181 }
182 foreach shell $othlang_list {
183 testall_cmd "$shell" "source,$modfile" "" [join $ans "\n"] 0
184 }
185
186
187 # one good quarantine variable (with env value & runtime value) among bad variable names
188 set quar "BAR F:OO B\\AD 0BAD"
189 set env1 "orig"
190 set runenv1 "value"
191 if {$verbose} {
192 send_user "\tSetup MODULES_RUN_QUARANTINE = '$quar'\n"
193 send_user "\tSetup BAR = '$env1'\n"
194 send_user "\tSetup MODULES_RUNENV_BAR = '$runenv1'\n"
195 }
196 set env(MODULES_RUN_QUARANTINE) $quar
197 set env(BAR) $env1
198 set env(MODULES_RUNENV_BAR) $runenv1
199
200 # warnings are doubled (one for the init pass, second for source pass)
201 set ans [list]
202 lappend ans "$warn_msgs: Bad variable name set in MODULES_RUN_QUARANTINE (F:OO)"
203 lappend ans "$warn_msgs: Bad variable name set in MODULES_RUN_QUARANTINE (B\\AD)"
204 lappend ans "$warn_msgs: Bad variable name set in MODULES_RUN_QUARANTINE (0BAD)"
205 if {$::install_loadedmodules ne {}} {
206 foreach lm [split $::install_loadedmodules :] {
207 lappend ans "Loading $lm"
208 }
209 }
210 lappend ans "$warn_msgs: Bad variable name set in MODULES_RUN_QUARANTINE (F:OO)"
211 lappend ans "$warn_msgs: Bad variable name set in MODULES_RUN_QUARANTINE (B\\AD)"
212 lappend ans "$warn_msgs: Bad variable name set in MODULES_RUN_QUARANTINE (0BAD)"
213 lappend ans "MODULES_RUN_QUARANTINE=$quar"
214 lappend ans "BAR=$env1"
215 lappend ans "MODULES_RUNENV_BAR=$runenv1"
216
217 # quarantine mechanism is not supported on csh/tcsh shells
218 set anscsh [list]
219 lappend anscsh "MODULES_RUN_QUARANTINE=$quar"
220 lappend anscsh "BAR=$env1"
221 lappend anscsh "MODULES_RUNENV_BAR=$runenv1"
222
223 foreach shell $shell_list {
224 switch -- $shell {
225 {csh} - {tcsh} {
226 testall_cmd "$shell" "module source $modfile" "" [join $anscsh "\n"] 0
227 }
228 default {
229 set no_loadedmodules_inject 1
230 testall_cmd "$shell" "module source $modfile" "" [join $ans "\n"] 0
231 unset no_loadedmodules_inject
232 }
233 }
234 }
235 set no_loadedmodules_inject 1
236 foreach shell $othlang_list {
237 testall_cmd "$shell" "source,$modfile" "" [join $ans "\n"] 0
238 }
239 unset no_loadedmodules_inject
240
241 # two quarantine variables, first with env no runtime, second with env and runtime
242 set quar "LD_LIBRARY_PATH FOO"
243 set env1 $env(TESTSUITEDIR)
244 set env2 "orig2 part2 spe\"ci\"al"
245 set runenv2 "value2 valpart2 valspe\"ci\"al"
246 if {$verbose} {
247 send_user "\tSetup MODULES_RUN_QUARANTINE = '$quar'\n"
248 send_user "\tSetup LD_LIBRARY_PATH = '$env1'\n"
249 send_user "\tSetup FOO = '$env2'\n"
250 send_user "\tSetup MODULES_RUNENV_FOO = '$runenv2'\n"
251 send_user "\tUnset MODULES_RUNENV_BAR\n"
252 }
253 set env(MODULES_RUN_QUARANTINE) $quar
254 set env(LD_LIBRARY_PATH) $env1
255 set env(FOO) $env2
256 set env(MODULES_RUNENV_FOO) $runenv2
257 unset env(MODULES_RUNENV_BAR)
258
259 set ans [list]
260 lappend ans "MODULES_RUN_QUARANTINE=$quar"
261 lappend ans "LD_LIBRARY_PATH=$env1"
262 lappend ans "FOO=$env2"
263 lappend ans "MODULES_RUNENV_FOO=$runenv2"
264
265 set ansr [list]
266 lappend ansr "MODULES_RUN_QUARANTINE=$quar"
267 # escape path if regexp-sensitive character in path
268 set env1r [regsub -all "\(\[.+?\]\)" $env1 {\\\1}]
269 lappend ansr "LD_LIBRARY_PATH=.*$env1r"
270 lappend ansr "FOO=$env2"
271 lappend ansr "MODULES_RUNENV_FOO=$runenv2"
272
273 if {$sip_enabled} {
274 if {$verbose} {
275 send_user "\tSkip LD_LIBRARY_PATH-related tests as SIP is enabled\n"
276 }
277 } else {
278
279 foreach shell $shell_list {
280 switch -- $shell {
281 {csh} - {tcsh} {
282 if {$verbose} {
283 send_user "\tskip test for $shell, no quarantine support\n"
284 }
285 }
286 default {
287 testall_cmd "$shell" "module source $modfile" "" [join $ans "\n"] 0
288 }
289 }
290 }
291 foreach shell $othlang_list {
292 switch -- $shell {
293 {tcl} {
294 if {$verbose} {
295 send_user "\tspecific test for $shell\n"
296 }
297 }
298 {r} {
299 # specific result for R as LD_LIBRARY_PATH value is altered by R on the way
300 testall_cmd_re "$shell" "source,$modfile" "" [join $ansr "\n"] 0
301 }
302 default {
303 testall_cmd "$shell" "source,$modfile" "" [join $ans "\n"] 0
304 }
305 }
306 }
307
308 }
309
310 # same test than above with a disturbing IFS value, for real shells only
311 set ifs ":"
312 if {$verbose} {
313 send_user "\tSetup IFS = '$ifs'\n"
314 }
315 set env(IFS) $ifs
316
317 if {$sip_enabled} {
318 if {$verbose} {
319 send_user "\tSkip LD_LIBRARY_PATH-related tests as SIP is enabled\n"
320 }
321 } else {
322
323 foreach shell $shell_list {
324 switch -- $shell {
325 {csh} - {tcsh} {
326 if {$verbose} {
327 send_user "\tskip test for $shell, no quarantine support\n"
328 }
329 }
330 {fish} {
331 testall_cmd "$shell" "module source $modfile" "" [join $ans "\n"] 0
332 }
333 default {
334 testall_cmd "$shell" "IFS='$ifs' module source $modfile" "" [join $ans "\n"] 0
335 }
336 }
337 }
338
339 }
340
341 # make a specific test for tcl, as its install_test script is not
342 # shielded against bad LD_LIBRARY_PATH
343 set quar "BAR FOO"
344 if {$verbose} {
345 send_user "\tSetup MODULES_RUN_QUARANTINE = '$quar'\n"
346 send_user "\tSetup BAR = '$env1'\n"
347 send_user "\tUnset LD_LIBRARY_PATH\n"
348 send_user "\tUnset IFS\n"
349 }
350 set env(MODULES_RUN_QUARANTINE) $quar
351 set env(BAR) $env1
352 unset env(LD_LIBRARY_PATH)
353 unset env(IFS)
354
355 set ans [list]
356 lappend ans "MODULES_RUN_QUARANTINE=$quar"
357 lappend ans "BAR=$env1"
358 lappend ans "FOO=$env2"
359 lappend ans "MODULES_RUNENV_FOO=$runenv2"
360
361 testall_cmd "tcl" "source,$modfile" "" [join $ans "\n"] 0
362
363
364 # one quarantine variable, no env with runtime, inject bad runtime value
365 set quar "LD_LIBRARY_PATH"
366 set env1 ""
367 set runenv1 $env(TESTSUITEDIR)
368 if {$verbose} {
369 send_user "\tSetup MODULES_RUN_QUARANTINE = '$quar'\n"
370 send_user "\tSetup LD_LIBRARY_PATH = '$env1'\n"
371 send_user "\tSetup MODULES_RUNENV_LD_LIBRARY_PATH = '$runenv1'\n"
372 }
373 set env(MODULES_RUN_QUARANTINE) $quar
374 set env(LD_LIBRARY_PATH) $env1
375 set env(MODULES_RUNENV_LD_LIBRARY_PATH) $runenv1
376
377 if {[info exists testlibfile] && [file exists $testlibfile]\
378 && ![catch {exec ldd $install_tclsh} ldd_out]\
379 && [string first $testlibfile $ldd_out] != -1} {
380 set ans "$install_tclsh: error while loading shared libraries: $testlibfile: file too short\n.*"
381
382 foreach shell $shell_list {
383 switch -- $shell {
384 {csh} - {tcsh} {
385 if {$verbose} {
386 send_user "\tskip test for $shell, no quarantine support\n"
387 }
388 }
389 default {
390 if {$shell eq "ksh"} {
391 set ansexit 126
392 } else {
393 set ansexit 127
394 }
395 testall_cmd_re "$shell" "module source $modfile" "" $ans $ansexit
396 }
397 }
398 }
399 foreach shell $othlang_list {
400 testall_cmd_re "$shell" "source,$modfile" "" $ans 1
401 }
402 } elseif {$verbose} {
403 send_user "\tSkip test as fake library setup not understood by $install_tclsh\n"
404 }
405
406
407 #
408 # Clean up variables used in this test case
409 #
410
411 # remove temp file used for test
412 if {[info exists testlibfile] && [file exists $testlibfile]} {
413 if {$verbose} {
414 send_user "\tDelete fake library $testlibfile\n"
415 }
416 file delete $testlibfile
417 }
418
419 }
420
421 reset_test_env
422
423 } elseif {$verbose} {
424 send_user "\tSkipping quarantine mechanism checks due to install path\n"
425 }
426
427 } elseif {$verbose} {
428 send_user "\tSkipping quarantine mechanism checks\n"
429 }
430 # vim:set tabstop=3 shiftwidth=3 expandtab autoindent: