| 1 |
############################################################################## |
| 2 |
# Modules Revision 3.0 |
| 3 |
# Providing a flexible user environment |
| 4 |
# |
| 5 |
# File: install.00-init/%M% |
| 6 |
# Revision: %I% |
| 7 |
# First Edition: 2017/05/06 |
| 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 |
# This module defines all patterns used further in the |
| 18 |
# testsuite |
| 19 |
# }C% |
| 20 |
# |
| 21 |
############################################################################## |
| 22 |
|
| 23 |
proc find_bin {name} { |
| 24 |
set path {} |
| 25 |
|
| 26 |
if {[info exists ::env(PATH)]} { |
| 27 |
foreach dir [split $::env(PATH) ":"] { |
| 28 |
if {[file executable "$dir/$name"]} { |
| 29 |
set path "$dir/$name" |
| 30 |
break |
| 31 |
} |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
return $path |
| 36 |
} |
| 37 |
|
| 38 |
if {$verbose} { |
| 39 |
send_user "\tInitializing the testsuite ...\n" |
| 40 |
} |
| 41 |
|
| 42 |
# test kind of sh-shell we have |
| 43 |
set shloc /bin/sh |
| 44 |
catch { |
| 45 |
while {[file type $shloc] eq {link}} { |
| 46 |
set shloc [file readlink $shloc] |
| 47 |
} |
| 48 |
} |
| 49 |
set sh_kind [file tail $shloc] |
| 50 |
# try to see if /bin/sh binary is a bash shell or something else |
| 51 |
if {$sh_kind eq {sh} && ![catch {exec /bin/sh -c {echo $BASH_VERSION}} errMsg] && $errMsg ne {}} { |
| 52 |
set sh_kind "bash" |
| 53 |
} |
| 54 |
send_user "\tsh_kind is '$sh_kind'\n" |
| 55 |
|
| 56 |
# extract and format os name |
| 57 |
set os_name [string tolower [lindex [split $tcl_platform(os) _] 0]] |
| 58 |
|
| 59 |
# determine if sh-shell is a strict sh implementation |
| 60 |
if {$sh_kind eq "dash" || $os_name ni {linux darwin cygwin mingw msys}} { |
| 61 |
set sh_strict 1 |
| 62 |
} else { |
| 63 |
set sh_strict 0 |
| 64 |
} |
| 65 |
send_user "\tsh_strict is '$sh_strict'\n" |
| 66 |
|
| 67 |
# grab bash shell version |
| 68 |
set bashbin [find_bin bash] |
| 69 |
if {$bashbin ne {}} { |
| 70 |
set bash_version [exec $bashbin -c {echo $BASH_VERSION}] |
| 71 |
set bash_version_is52 [string match 5.2.* $bash_version] |
| 72 |
send_user "\tbash_version_is52 is '$bash_version_is52'\n" |
| 73 |
} |
| 74 |
|
| 75 |
# check SIP is enabled or not on OS X |
| 76 |
if {$os_name eq "darwin"} { |
| 77 |
catch { |
| 78 |
regexp {System Integrity Protection status: enabled.} [exec csrutil status] csrutil_enabled |
| 79 |
} errMsg |
| 80 |
} |
| 81 |
if {[info exists csrutil_enabled]} { |
| 82 |
set sip_enabled 1 |
| 83 |
unset csrutil_enabled |
| 84 |
} else { |
| 85 |
set sip_enabled 0 |
| 86 |
} |
| 87 |
send_user "\tsip_enabled is '$sip_enabled'\n" |
| 88 |
|
| 89 |
# |
| 90 |
# Regular expressions matching error and warning outputs |
| 91 |
# |
| 92 |
|
| 93 |
set messages "(\[^(\]+)\[(\]\[0-9\]+\[)\]" |
| 94 |
set error_msgs "ERROR" |
| 95 |
set warn_msgs "WARNING" |
| 96 |
set prob_msgs "$messages:PROB:\[0-9\]+" |
| 97 |
set verb_msgs "$messages:VERB:\[0-9\]+" |
| 98 |
|
| 99 |
# Used as a line separator inside modules |
| 100 |
set modlin "\[-\]+" |
| 101 |
|
| 102 |
# properties to test the different available shells |
| 103 |
set shell_list {} |
| 104 |
set shell_sh_family {} |
| 105 |
set shell_redir_list {} |
| 106 |
array set shell_init {} |
| 107 |
array set shell_path {} |
| 108 |
array set shell_opts {} |
| 109 |
array set shell_test {} |
| 110 |
foreach shell [list sh bash basheu ksh zsh csh tcsh fish tcl perl python ruby cmake r pwsh] { |
| 111 |
if {$shell eq {basheu} && $bash_version_is52} { |
| 112 |
send_user "\t'basheu' shell tests ignored on Bash 5.2\n" |
| 113 |
continue |
| 114 |
} |
| 115 |
switch -- $shell { |
| 116 |
tcl { |
| 117 |
set shellbin $install_tclsh |
| 118 |
} |
| 119 |
r { |
| 120 |
set shellbin [find_bin Rscript] |
| 121 |
} |
| 122 |
basheu { |
| 123 |
set shellbin [find_bin bash] |
| 124 |
} |
| 125 |
ksh { |
| 126 |
set shellbin [find_bin ksh] |
| 127 |
if {$shellbin eq ""} { |
| 128 |
set shellbin [find_bin ksh93] |
| 129 |
} |
| 130 |
} |
| 131 |
pwsh { |
| 132 |
# Don't test pwsh in cygwin or msys (pwsh.exe won't work properly) |
| 133 |
if {$os_name ni {cygwin mingw msys}} { |
| 134 |
set shellbin [find_bin pwsh] |
| 135 |
} else { |
| 136 |
set shellbin "" |
| 137 |
} |
| 138 |
} |
| 139 |
default { |
| 140 |
set shellbin [find_bin $shell] |
| 141 |
} |
| 142 |
} |
| 143 |
if {$shellbin ne ""} { |
| 144 |
switch -- $shell { |
| 145 |
tcl - perl - python - ruby - cmake - r - pwsh { |
| 146 |
lappend othlang_list $shell |
| 147 |
} |
| 148 |
sh - bash - basheu - ksh - zsh { |
| 149 |
lappend shell_sh_family $shell |
| 150 |
lappend shell_list $shell |
| 151 |
} |
| 152 |
default { |
| 153 |
lappend shell_list $shell |
| 154 |
} |
| 155 |
} |
| 156 |
switch -- $shell { |
| 157 |
basheu { |
| 158 |
set shell_init($shell) "$install_initdir/bash" |
| 159 |
} |
| 160 |
perl { |
| 161 |
set shell_init($shell) "$install_initdir/$shell.pm" |
| 162 |
} |
| 163 |
python { |
| 164 |
set shell_init($shell) "$install_initdir/$shell.py" |
| 165 |
} |
| 166 |
ruby { |
| 167 |
set shell_init($shell) "$install_initdir/$shell.rb" |
| 168 |
} |
| 169 |
r { |
| 170 |
set shell_init($shell) "$install_initdir/$shell.R" |
| 171 |
} |
| 172 |
pwsh { |
| 173 |
set shell_init($shell) "$install_initdir/$shell.ps1" |
| 174 |
} |
| 175 |
default { |
| 176 |
set shell_init($shell) "$install_initdir/$shell" |
| 177 |
} |
| 178 |
} |
| 179 |
set shell_path($shell) $shellbin |
| 180 |
switch -- $shell { |
| 181 |
basheu { |
| 182 |
set shell_opts($shell) "-eu" |
| 183 |
} |
| 184 |
csh - tcsh { |
| 185 |
# ignore global csh system init file to avoid side effect |
| 186 |
set shell_opts($shell) "-f" |
| 187 |
} |
| 188 |
} |
| 189 |
switch -- $shell { |
| 190 |
bash - basheu - ksh - zsh { |
| 191 |
set shell_test($shell) "$env(TESTSUITEDIR)/bin/install_test_sh" |
| 192 |
} |
| 193 |
tcsh { |
| 194 |
set shell_test($shell) "$env(TESTSUITEDIR)/bin/install_test_csh" |
| 195 |
} |
| 196 |
default { |
| 197 |
set shell_test($shell) "$env(TESTSUITEDIR)/bin/install_test_${shell}" |
| 198 |
} |
| 199 |
} |
| 200 |
switch -- $shell { |
| 201 |
sh - bash - ksh - zsh - fish - pwsh { |
| 202 |
lappend shell_redir_list $shell |
| 203 |
} |
| 204 |
} |
| 205 |
} else { |
| 206 |
send_user "\t'$shell' shell is not installed, relative tests will be skipped\n" |
| 207 |
} |
| 208 |
} |
| 209 |
unset shell |
| 210 |
|
| 211 |
# where to find module tcl script to call for autoinit command |
| 212 |
set autoinit_script "$install_libexecdir/modulecmd.tcl" |
| 213 |
|
| 214 |
# where to find modulefiles for test |
| 215 |
set share_modpath "$env(TESTSUITEDIR)/../share/modulefiles" |
| 216 |
set testsuite_modpath "$env(TESTSUITEDIR)/modulefiles" |
| 217 |
|
| 218 |
# basic messages |
| 219 |
set type_help " Try 'module --help' for more information." |
| 220 |
set cur_loaded "Currently Loaded Modulefiles:" |
| 221 |
set no_loaded "No Modulefiles Currently Loaded." |
| 222 |
|
| 223 |
# path variables for regexp tests |
| 224 |
set install_mandirre [regsub -all "\(\[.+?\]\)" $install_mandir {\\\1}] |
| 225 |
set install_initdirre [regsub -all "\(\[.+?\]\)" $install_initdir {\\\1}] |
| 226 |
set install_libexecdirre [regsub -all "\(\[.+?\]\)" $install_libexecdir {\\\1}] |
| 227 |
set install_modulefilesdirre [regsub -all "\(\[.+?\]\)" $install_modulefilesdir {\\\1}] |
| 228 |
set install_modulepathre [regsub -all "\(\[.+?\]\)" $install_modulepath {\\\1}] |
| 229 |
set install_loadedmodulesre [regsub -all "\(\[.+?\]\)" $install_loadedmodules {\\\1}] |
| 230 |
set install_versionre [regsub -all "\(\[.+?\]\)" $install_version {\\\1}] |
| 231 |
set install_versionfilesdirre [regsub -all "\(\[.+?\]\)" "$install_baseprefix/versions" {\\\1}] |
| 232 |
|
| 233 |
# fetch quarantine configuration defined at build time |
| 234 |
if {$install_quarantinevars ne ""} { |
| 235 |
set install_quarlist {} |
| 236 |
array set install_runenv {} |
| 237 |
foreach vv [split $install_quarantinevars " "] { |
| 238 |
set vvlist [split $vv "="] |
| 239 |
if {[llength $vvlist] == 2} { |
| 240 |
set vname [lindex $vvlist 0] |
| 241 |
set install_runenv($vname) [lindex $vvlist 1] |
| 242 |
} else { |
| 243 |
set vname [lindex $vvlist 0] |
| 244 |
} |
| 245 |
lappend install_quarlist $vname |
| 246 |
} |
| 247 |
catch {unset vv} |
| 248 |
catch {unset vvlist} |
| 249 |
catch {unset vname} |
| 250 |
} |
| 251 |
|
| 252 |
# locate siteconfig file |
| 253 |
set siteconfig_file "$install_etcdir/siteconfig.tcl" |
| 254 |
|
| 255 |
# determine if siteconfig forces stderr terminal attachment state |
| 256 |
proc siteconfig_isStderrTty {} { |
| 257 |
interp create _siteconfig |
| 258 |
interp eval _siteconfig set ::siteconfig_file "{$::siteconfig_file}" |
| 259 |
set is_stderr_tty [interp eval _siteconfig { |
| 260 |
set is_stderr_tty 0 |
| 261 |
if {[file readable $::siteconfig_file]} { |
| 262 |
# evaluate siteconfig file to check initStateIsStderrTty procedure |
| 263 |
catch { |
| 264 |
source $::siteconfig_file |
| 265 |
if {[info procs initStateIsStderrTty] eq "initStateIsStderrTty"} { |
| 266 |
set is_stderr_tty [initStateIsStderrTty] |
| 267 |
} |
| 268 |
} errorMsg |
| 269 |
} |
| 270 |
return $is_stderr_tty |
| 271 |
}] |
| 272 |
interp delete _siteconfig |
| 273 |
return $is_stderr_tty |
| 274 |
} |
| 275 |
|
| 276 |
# determine overridden configuration in installed initrc conf file |
| 277 |
set initrc_file [expr {$install_initconfin eq {etcdir} ? "$install_etcdir/initrc" : "$install_initdir/modulerc"}] |
| 278 |
set fid [open $initrc_file] |
| 279 |
while {[gets $fid line] >= 0} { |
| 280 |
if {[string first {module config } $line] == 0} { |
| 281 |
lassign [lrange [split $line] 2 3] configname configval |
| 282 |
set initrc_$configname $configval |
| 283 |
} |
| 284 |
} |
| 285 |
close $fid |
| 286 |
unset fid |
| 287 |
unset line |
| 288 |
|
| 289 |
# check configuration enablement between ./configure option and initrc conf file |
| 290 |
proc is_set_shell_startup_enabled {} { |
| 291 |
if {[info exists ::initrc_set_shell_startup]} { |
| 292 |
return $::initrc_set_shell_startup |
| 293 |
} else { |
| 294 |
return [expr {$::install_setshellstartup eq {y} ? {1} : {0}}] |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
proc is_config_locked {option} { |
| 299 |
return [expr {[lsearch -exact $::install_lockedconfigs $option] != -1}] |
| 300 |
} |
| 301 |
|
| 302 |
# grab fish shell version to check if greater or equal to 3.1 |
| 303 |
if {[info exists shell_path(fish)]} { |
| 304 |
regexp {version (.+)$} [exec $shell_path(fish) --version] match fish_version |
| 305 |
set fish_version_ge31 [expr {[lindex [lsort -dictionary [list $fish_version 3.1.0]] 0] eq {3.1.0}}] |
| 306 |
set fish_version_ge32 [expr {[lindex [lsort -dictionary [list $fish_version 3.2.0]] 0] eq {3.2.0}}] |
| 307 |
set fish_version_is31 [string match 3.1.* $fish_version] |
| 308 |
send_user "\tfish_version_ge31 is '$fish_version_ge31'\n" |
| 309 |
send_user "\tfish_version_ge32 is '$fish_version_ge32'\n" |
| 310 |
send_user "\tfish_version_is31 is '$fish_version_is31'\n" |
| 311 |
} |
| 312 |
|
| 313 |
# find ksh flavor |
| 314 |
if {[set kshbin [lindex [auto_execok ksh] 0]] ne {}} { |
| 315 |
set ksh_is_mksh [expr {[string first MIRBSD [exec $kshbin -c "echo \$KSH_VERSION"]] != -1}] |
| 316 |
send_user "\tksh_is_mksh is '$ksh_is_mksh'\n" |
| 317 |
} |
| 318 |
|
| 319 |
# check if symbolic link registered in git repository have been effectively |
| 320 |
# created as symbolic link to determine if they are supported on filesystem |
| 321 |
set is_symlink_supported [file isdirectory $env(TESTSUITEDIR)/modulefiles/symlink] |
| 322 |
send_user "\tis_symlink_supported is '$is_symlink_supported'\n" |
| 323 |
|
| 324 |
# vim:set tabstop=3 shiftwidth=3 expandtab autoindent: |